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