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.MuleEventContext;
10  import org.mule.tck.functional.CountdownCallback;
11  import org.mule.tck.functional.FunctionalTestComponent;
12  import org.mule.tck.junit4.FunctionalTestCase;
13  
14  import java.util.ArrayList;
15  import java.util.List;
16  
17  import org.junit.Test;
18  
19  import static org.junit.Assert.assertEquals;
20  import static org.junit.Assert.assertNotNull;
21  import static org.junit.Assert.assertTrue;
22  
23  public class QuartzEventGeneratorTestCase extends FunctionalTestCase
24  {
25      
26      private static final String PAYLOAD = "TRIGGER STRING";
27  
28      private final List<String> receivedPayloads = new ArrayList<String>();
29      
30      @Override
31      protected String getConfigResources()
32      {
33          return "quartz-event-generator.xml";
34      }
35  
36      @Test
37      public void testEventGeneratorPayload() throws Exception
38      {
39          FunctionalTestComponent component = (FunctionalTestComponent) getComponent("quartzService");
40          assertNotNull(component);
41          CountdownCallback callback = new Callback(1, receivedPayloads);
42          component.setEventCallback(callback);
43  
44          // wait for incoming messages
45          assertTrue(callback.await(60000));
46          assertTrue(receivedPayloads.size() > 0);
47          assertEquals(PAYLOAD, receivedPayloads.get(0));
48      }
49      
50      private static class Callback extends CountdownCallback
51      {
52          private List<String> messageList;
53  
54          public Callback(int messagesExpected, List<String> payloadStore)
55          {
56              super(messagesExpected);
57              messageList = payloadStore;
58          }
59  
60          @Override
61          public void eventReceived(MuleEventContext context, Object component) throws Exception
62          {
63              synchronized (this)
64              {
65                  String payloadString = context.getMessage().getPayloadAsString();
66                  messageList.add(payloadString);
67              }
68              
69              super.eventReceived(context, component);
70          }        
71      }
72      
73  }
74  
75