View Javadoc
1   /*
2    * Copyright (C) 2003-2012 eXo Platform SAS.
3    *
4    * This program is free software: you can redistribute it and/or modify
5    * it under the terms of the GNU Affero General Public License as published by
6    * the Free Software Foundation, either version 3 of the License, or
7    * (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 Affero General Public License for more details.
13   *
14   * You should have received a copy of the GNU Affero General Public License
15   * along with this program. If not, see <http://www.gnu.org/licenses/>.
16   */
17  package org.exoplatform.job;
18  
19  import static org.mockito.Mockito.mock;
20  
21  import java.lang.reflect.Constructor;
22  import java.util.Date;
23  
24  import org.exoplatform.commons.testing.BaseCommonsTestCase;
25  import org.exoplatform.component.test.ConfigurationUnit;
26  import org.exoplatform.component.test.ConfiguredBy;
27  import org.exoplatform.component.test.ContainerScope;
28  
29  import org.quartz.Job;
30  import org.quartz.JobDetail;
31  import org.quartz.JobExecutionContext;
32  import org.quartz.Scheduler;
33  import org.quartz.impl.JobDetailImpl;
34  import org.quartz.impl.JobExecutionContextImpl;
35  import org.quartz.impl.triggers.SimpleTriggerImpl;
36  import org.quartz.spi.TriggerFiredBundle;
37  
38  /**
39   * Created by The eXo Platform SAS
40   * Author : Canh Pham Van
41   *          canhpv@exoplatform.com
42   * Oct 19, 2012  
43   */
44  @ConfiguredBy({ @ConfigurationUnit(scope = ContainerScope.ROOT, path = "conf/test-root-configuration.xml"),
45    @ConfigurationUnit(scope = ContainerScope.PORTAL, path = "conf/portal/configuration.xml"),
46    @ConfigurationUnit(scope = ContainerScope.PORTAL, path = "conf/test-portal-configuration.xml") })
47  public class MultiTenancyTaskTest extends BaseCommonsTestCase {
48    
49    private MultiTenancyJobImpl impl; 
50    private TriggerFiredBundle firedBundle; 
51    private String repoName = "repository";
52    private JobExecutionContext context;
53     
54     @Override
55     public void setUp() throws Exception {
56       super.setUp();
57       impl = new MultiTenancyJobImpl();    
58       
59       JobDetail jobDetail = new JobDetailImpl();
60       ((JobDetailImpl) jobDetail).setGroup(container.getName());
61       context = createContext(jobDetail);
62     }
63  
64     public void testRun(){
65       try {      
66         Constructor constructor = impl.getTask().getConstructor(MultiTenancyJobImpl.class, JobExecutionContext.class, String.class);
67         Runnable temp = (Runnable) constructor.newInstance(impl, context, repoName);
68         temp.run();
69         
70       } catch (Exception e) {
71         fail("testRun");
72       }
73       
74     }
75     
76     @Override
77     protected void tearDown() throws Exception {
78       super.tearDown();
79     }
80     
81     private JobExecutionContext createContext(JobDetail jobDetail) {
82       firedBundle = new TriggerFiredBundle(jobDetail, new SimpleTriggerImpl(), null, false, new Date(), new Date(), new Date(), new Date());
83       return new StubJobExecutionContext();
84     }
85  
86     @SuppressWarnings("serial")
87     private final class StubJobExecutionContext extends JobExecutionContextImpl {
88  
89       private StubJobExecutionContext() {
90         super(mock(Scheduler.class), firedBundle, mock(Job.class));
91       }
92  
93     }    
94  
95  }