1 17 package org.alfresco.repo.content; 18 19 import java.util.Date ; 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 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 url; 49 50 54 public static TestSuite suite() 55 { 56 return new TestSuite(); 57 } 58 59 62 @Override 63 protected void onSetUpInTransaction() throws Exception 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 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 (), 83 new Date (), 84 new Date (), 85 new Date ()); 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 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 |