View Javadoc

1   /*
2    * $Id: QuartzCustomJobFromMessageTestCase.java 22498 2011-07-21 13:01:39Z justin.calleja $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.transport.quartz;
12  
13  import static org.junit.Assert.assertNotNull;
14  import static org.junit.Assert.assertTrue;
15  
16  import java.util.Arrays;
17  import java.util.Collection;
18  import java.util.HashMap;
19  import java.util.Map;
20  
21  import org.junit.Test;
22  import org.junit.runners.Parameterized.Parameters;
23  import org.mule.api.client.MuleClient;
24  import org.mule.tck.AbstractServiceAndFlowTestCase;
25  import org.mule.tck.functional.CountdownCallback;
26  import org.mule.tck.functional.FunctionalTestComponent;
27  import org.mule.transport.NullPayload;
28  import org.mule.transport.quartz.jobs.ScheduledDispatchJobConfig;
29  
30  public class QuartzCustomJobFromMessageTestCase extends AbstractServiceAndFlowTestCase
31  {
32  
33      public QuartzCustomJobFromMessageTestCase(ConfigVariant variant, String configResources)
34      {
35          super(variant, configResources);
36      }
37  
38      @Parameters
39      public static Collection<Object[]> parameters()
40      {
41          return Arrays.asList(new Object[][]{
42              {ConfigVariant.SERVICE, "quartz-receive-dispatch-delegating-job-service.xml"},
43              {ConfigVariant.FLOW, "quartz-receive-dispatch-delegating-job-flow.xml"}});
44      }
45  
46      @Test
47      public void testDelegatingJobAsProperty() throws Exception
48      {
49          FunctionalTestComponent component = (FunctionalTestComponent) getComponent("scheduledService");
50          assertNotNull(component);
51          CountdownCallback count = new CountdownCallback(1);
52          component.setEventCallback(count);
53  
54          Map<String, Object> props = new HashMap<String, Object>();
55          ScheduledDispatchJobConfig jobConfig = new ScheduledDispatchJobConfig();
56          jobConfig.setMuleContext(muleContext);
57          jobConfig.setEndpointRef("vm://quartz.in");
58          props.put(QuartzConnector.PROPERTY_JOB_CONFIG, jobConfig);
59  
60          MuleClient client = muleContext.getClient();
61          client.dispatch("vm://quartz.scheduler1", NullPayload.getInstance(), props);
62          assertTrue(count.await(7000));
63  
64          // now that the scheduler sent the event, null out the event callback to
65          // avoid CountdownCallback
66          // report more messages than requested during shutdown of the test/Mule
67          // server
68          component.setEventCallback(null);
69      }
70  
71      @Test
72      public void testDelegatingJobAsPayload() throws Exception
73      {
74          FunctionalTestComponent component = (FunctionalTestComponent) getComponent("scheduledService");
75          assertNotNull(component);
76          CountdownCallback count = new CountdownCallback(1);
77          component.setEventCallback(count);
78  
79          ScheduledDispatchJobConfig jobConfig = new ScheduledDispatchJobConfig();
80          jobConfig.setMuleContext(muleContext);
81          jobConfig.setEndpointRef("vm://quartz.in");
82  
83          MuleClient client = muleContext.getClient();
84          client.dispatch("vm://quartz.scheduler2", jobConfig, null);
85          assertTrue(count.await(7000));
86  
87          // now that the scheduler sent the event, null out the event callback to
88          // avoid CountdownCallback
89          // report more messages than requested during shutdown of the test/Mule
90          // server
91          component.setEventCallback(null);
92      }
93  }