View Javadoc

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