View Javadoc
1   /**
2    * Copyright (C) 2003-2008 eXo Platform SAS.
3    *
4    * This program is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Affero General Public License
6    * as published by the Free Software Foundation; either version 3
7    * of the License, or (at your option) any later version.
8    * 
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   * 
14   * You should have received a copy of the GNU General Public License
15   * along with this program; if not, see<http://www.gnu.org/licenses/>.
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   * @author <a href="mailto:andrew00x@gmail.com">Andrey Parfonov</a>
36   * @version $Id: $
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  }