KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > content > ContentStoreCleanupJobTest


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.content;
18
19 import java.util.Date JavaDoc;
20
21 import junit.framework.TestSuite;
22
23 import org.alfresco.service.cmr.repository.ContentReader;
24 import org.alfresco.service.cmr.repository.ContentWriter;
25 import org.alfresco.util.BaseSpringTest;
26 import org.quartz.JobDataMap;
27 import org.quartz.JobExecutionContext;
28 import org.quartz.JobExecutionException;
29 import org.quartz.Scheduler;
30 import org.quartz.SchedulerFactory;
31 import org.quartz.impl.StdSchedulerFactory;
32 import org.quartz.impl.calendar.BaseCalendar;
33 import org.quartz.spi.TriggerFiredBundle;
34 import org.springframework.scheduling.quartz.SimpleTriggerBean;
35
36 /**
37  * Content store cleanup job unit test
38  *
39  * @author Roy Wetherall
40  */

41 public class ContentStoreCleanupJobTest extends BaseSpringTest
42 {
43     private SimpleTriggerBean simpleTriggerBean;
44     private JobExecutionContext jobExecutionContext;
45     private ContentStoreCleanupJob job;
46     
47     private ContentStore contentStore;
48     private String JavaDoc url;
49     
50     /**
51      * This can be removed once the class being tested actually has a remote
52      * chance of working.
53      */

54     public static TestSuite suite()
55     {
56         return new TestSuite();
57     }
58     
59     /**
60      * On setup in transaction
61      */

62     @Override JavaDoc
63     protected void onSetUpInTransaction() throws Exception JavaDoc
64     {
65         this.contentStore = (ContentStore)this.applicationContext.getBean("fileContentStore");
66         this.simpleTriggerBean = (SimpleTriggerBean)this.applicationContext.getBean("fileContentStoreCleanerTrigger");
67         
68         SchedulerFactory factory = new StdSchedulerFactory();
69         Scheduler scheduler = factory.getScheduler();
70         
71         // Set the protect hours to 0 for the purpose of this test
72
JobDataMap jobDataMap = this.simpleTriggerBean.getJobDetail().getJobDataMap();
73         jobDataMap.put("protectHours", "0");
74         this.simpleTriggerBean.getJobDetail().setJobDataMap(jobDataMap);
75         
76         this.job = new ContentStoreCleanupJob();
77         TriggerFiredBundle triggerFiredBundle = new TriggerFiredBundle(
78                 this.simpleTriggerBean.getJobDetail(),
79                 this.simpleTriggerBean,
80                 new BaseCalendar(),
81                 false,
82                 new Date JavaDoc(),
83                 new Date JavaDoc(),
84                 new Date JavaDoc(),
85                 new Date JavaDoc());
86         
87         this.jobExecutionContext = new JobExecutionContext(scheduler, triggerFiredBundle, job);
88         
89         ContentWriter contentWriter = this.contentStore.getWriter(null, null);
90         contentWriter.putContent("This is some content that I am going to delete.");
91         this.url = contentWriter.getContentUrl();
92     }
93     
94     /**
95      * Test execute method
96      */

97     public void testExecute()
98     {
99         try
100         {
101             ContentReader before = this.contentStore.getReader(this.url);
102             assertTrue(before.exists());
103             
104             this.job.execute(this.jobExecutionContext);
105             
106             ContentReader after = this.contentStore.getReader(this.url);
107             assertFalse(after.exists());
108         }
109         catch (JobExecutionException exception)
110         {
111             fail("Exception raised!");
112         }
113     }
114 }
115
Popular Tags