1
2
3
4
5
6
7
8
9
10
11 package org.mule.transport.quartz;
12
13 import static org.junit.Assert.assertTrue;
14
15 import java.util.Arrays;
16 import java.util.Collection;
17 import java.util.concurrent.CountDownLatch;
18 import java.util.concurrent.TimeUnit;
19
20 import org.junit.Test;
21 import org.junit.runners.Parameterized.Parameters;
22 import org.mule.tck.AbstractServiceAndFlowTestCase;
23 import org.quartz.JobExecutionContext;
24 import org.quartz.JobExecutionException;
25 import org.quartz.StatefulJob;
26
27 public class QuartzCustomStatefulJobTestCase extends AbstractServiceAndFlowTestCase
28 {
29 public QuartzCustomStatefulJobTestCase(ConfigVariant variant, String configResources)
30 {
31 super(variant, configResources);
32 }
33
34
35 @Parameters
36 public static Collection<Object[]> parameters()
37 {
38 return Arrays.asList(new Object[][]{
39 {ConfigVariant.SERVICE, "quartz-custom-stateful-job-service.xml"},
40 {ConfigVariant.FLOW, "quartz-custom-stateful-job-flow.xml"}
41 });
42 }
43
44 @Test
45 public void testCustomStatefulJob() throws Exception
46 {
47 CountDownLatch eventLatch = (CountDownLatch) muleContext.getRegistry().lookupObject("latch");
48
49
50
51
52 assertTrue(eventLatch.await(60000, TimeUnit.MILLISECONDS));
53 }
54
55 public static class MyStatefulJob implements StatefulJob
56 {
57 private CountDownLatch latch;
58
59 public MyStatefulJob(CountDownLatch latch)
60 {
61 super();
62 this.latch = latch;
63 }
64
65 public void execute(JobExecutionContext context) throws JobExecutionException
66 {
67 assertTrue(context.getJobDetail().isStateful());
68 latch.countDown();
69 }
70 }
71 }