View Javadoc

1   /*
2    * $Id: QuartzCustomJobFromMessageTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
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 org.mule.module.client.MuleClient;
14  import org.mule.tck.FunctionalTestCase;
15  import org.mule.tck.functional.CountdownCallback;
16  import org.mule.tck.functional.FunctionalTestComponent;
17  import org.mule.transport.NullPayload;
18  import org.mule.transport.quartz.jobs.ScheduledDispatchJobConfig;
19  
20  import java.util.HashMap;
21  import java.util.Map;
22  
23  public class QuartzCustomJobFromMessageTestCase extends FunctionalTestCase
24  {
25      protected String getConfigResources()
26      {
27          return "quartz-receive-dispatch-delegating-job.xml";
28      }
29  
30      public void testDelegatingJobAsProperty() throws Exception
31      {
32          FunctionalTestComponent component = (FunctionalTestComponent) getComponent("scheduledService");
33          assertNotNull(component);
34          CountdownCallback count = new CountdownCallback(1);
35          component.setEventCallback(count);
36  
37          MuleClient client = new MuleClient(muleContext);
38  
39          Map<String, Object> props = new HashMap<String, Object>();
40          ScheduledDispatchJobConfig jobConfig = new ScheduledDispatchJobConfig();
41          jobConfig.setMuleContext(muleContext);
42          jobConfig.setEndpointRef("vm://quartz.in");
43          props.put(QuartzConnector.PROPERTY_JOB_CONFIG, jobConfig);
44  
45          client.send("vm://quartz.scheduler1", NullPayload.getInstance(), props);
46          assertTrue(count.await(7000));
47          
48          // now that the scheduler sent the event, null out the event callback to avoid CountdownCallback
49          // report more messages than requested during shutdown of the test/Mule server
50          component.setEventCallback(null);
51      }
52  
53      public void testDelegatingJobAsPayload() throws Exception
54      {
55          FunctionalTestComponent component = (FunctionalTestComponent) getComponent("scheduledService");
56          assertNotNull(component);
57          CountdownCallback count = new CountdownCallback(1);
58          component.setEventCallback(count);
59  
60          MuleClient client = new MuleClient(muleContext);
61  
62          ScheduledDispatchJobConfig jobConfig = new ScheduledDispatchJobConfig();
63          jobConfig.setMuleContext(muleContext);
64          jobConfig.setEndpointRef("vm://quartz.in");
65  
66          client.send("vm://quartz.scheduler2", jobConfig, null);
67          assertTrue(count.await(7000));
68  
69          // now that the scheduler sent the event, null out the event callback to avoid CountdownCallback
70          // report more messages than requested during shutdown of the test/Mule server
71          component.setEventCallback(null);
72      }
73  }