View Javadoc

1   /*
2    * $Id: QuartzFunctionalTestCase.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  
19  import org.junit.Test;
20  import org.junit.runners.Parameterized.Parameters;
21  import org.mule.tck.AbstractServiceAndFlowTestCase;
22  import org.mule.tck.functional.CountdownCallback;
23  import org.mule.tck.functional.FunctionalTestComponent;
24  
25  public class QuartzFunctionalTestCase extends AbstractServiceAndFlowTestCase
26  {
27  
28      public QuartzFunctionalTestCase(ConfigVariant variant, String configResources)
29      {
30          super(variant, configResources);
31      }
32  
33      @Parameters
34      public static Collection<Object[]> parameters()
35      {
36          return Arrays.asList(new Object[][]{
37              {ConfigVariant.SERVICE, "quartz-functional-test-service.xml"},
38              {ConfigVariant.FLOW, "quartz-functional-test-flow.xml"}
39          });
40      }
41  
42      @Test
43      public void testMuleReceiverJob() throws Exception
44      {
45          FunctionalTestComponent component = (FunctionalTestComponent) getComponent("quartzService1");
46          assertNotNull(component);
47          CountdownCallback count1 = new CountdownCallback(4);
48          component.setEventCallback(count1);
49  
50          component = (FunctionalTestComponent) getComponent("quartzService2");
51          assertNotNull(component);
52          CountdownCallback count2 = new CountdownCallback(2);
53          component.setEventCallback(count2);
54  
55          // we wait up to 60 seconds here which is WAY too long for three ticks with 1
56          // second interval, but it seems that "sometimes" it takes a very long time
57          // for Quartz go kick in. Once it starts ticking everything is fine.
58          assertTrue("Count 1 timed out: expected 0, value is: " + count1.getCount(), count1.await(60000));
59          assertTrue("Count 2 timed out: expected 0, value is: " + count2.getCount(), count2.await(5000));
60      }
61  
62  }