1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.exoplatform.webservice.cs.rest;
19
20 import org.exoplatform.commons.chromattic.ChromatticManager;
21 import org.exoplatform.component.test.AbstractKernelTest;
22 import org.exoplatform.component.test.ConfigurationUnit;
23 import org.exoplatform.component.test.ConfiguredBy;
24 import org.exoplatform.component.test.ContainerScope;
25 import org.exoplatform.container.ExoContainerContext;
26 import org.exoplatform.container.PortalContainer;
27 import org.exoplatform.container.component.ComponentRequestLifecycle;
28 import org.exoplatform.services.organization.OrganizationService;
29 import org.exoplatform.services.rest.impl.ApplicationContextImpl;
30 import org.exoplatform.services.rest.impl.ProviderBinder;
31 import org.exoplatform.services.rest.impl.RequestHandlerImpl;
32 import org.exoplatform.services.rest.impl.ResourceBinder;
33
34
35
36
37
38 @ConfiguredBy({
39 @ConfigurationUnit(scope = ContainerScope.PORTAL, path = "conf/exo.portal.component.portal-configuration.xml"),
40 @ConfigurationUnit(scope = ContainerScope.PORTAL, path = "conf/exo.portal.component.test.jcr-configuration.xml"),
41 @ConfigurationUnit(scope = ContainerScope.PORTAL, path = "conf/exo.portal.component.identity-configuration.xml"),
42 @ConfigurationUnit(scope = ContainerScope.PORTAL, path = "conf/portal/test-portal-configuration.xml"),
43 @ConfigurationUnit(scope = ContainerScope.PORTAL, path = "conf/portal/exo.calendar.component.core.test.configuration.xml"),
44 @ConfigurationUnit(scope = ContainerScope.PORTAL, path = "conf/portal/exo.calendar.test.jcr-configuration.xml"),
45 @ConfigurationUnit(scope = ContainerScope.PORTAL, path = "conf/portal/exo.calendar.test.portal-configuration.xml")
46 })
47 public abstract class BaseTest extends AbstractKernelTest {
48
49 protected PortalContainer container;
50
51 protected ProviderBinder providers;
52
53 protected ResourceBinder binder;
54
55 protected RequestHandlerImpl requestHandler;
56
57 protected OrganizationService orgService;
58
59 protected ChromatticManager chromatticManager;
60
61 public BaseTest() {
62 setForceContainerReload(true);
63 }
64
65 public void setUp() throws Exception {
66 super.setUp();
67 container = getContainer();
68 ExoContainerContext.setCurrentContainer(container);
69 chromatticManager = (ChromatticManager)container.getComponentInstanceOfType(ChromatticManager.class);
70 orgService = (OrganizationService) container.getComponentInstanceOfType(OrganizationService.class);
71 binder = (ResourceBinder) container.getComponentInstanceOfType(ResourceBinder.class);
72 requestHandler = (RequestHandlerImpl) container.getComponentInstanceOfType(RequestHandlerImpl.class);
73 ProviderBinder.setInstance(new ProviderBinder());
74 providers = ProviderBinder.getInstance();
75 ApplicationContextImpl.setCurrent(new ApplicationContextImpl(null, null, providers));
76 binder.clear();
77 begin();
78 }
79
80 protected void start() {
81 ((ComponentRequestLifecycle)orgService).startRequest(container);
82 }
83
84 protected void stop() {
85 ((ComponentRequestLifecycle)orgService).endRequest(container);
86 }
87 }