1
2
3
4
5
6
7
8
9
10
11 package org.mule.transport.quartz;
12
13 import static org.junit.Assert.assertEquals;
14 import static org.junit.Assert.assertNotNull;
15 import static org.junit.Assert.assertTrue;
16
17 import java.util.ArrayList;
18 import java.util.Arrays;
19 import java.util.Collection;
20 import java.util.List;
21
22 import org.junit.Test;
23 import org.junit.runners.Parameterized.Parameters;
24 import org.mule.api.MuleEventContext;
25 import org.mule.tck.AbstractServiceAndFlowTestCase;
26 import org.mule.tck.functional.CountdownCallback;
27 import org.mule.tck.functional.FunctionalTestComponent;
28
29 public class QuartzEventGeneratorTestCase extends AbstractServiceAndFlowTestCase
30 {
31
32 private static final String PAYLOAD = "TRIGGER STRING";
33
34 private final List<String> receivedPayloads = new ArrayList<String>();
35
36 public QuartzEventGeneratorTestCase(ConfigVariant variant, String configResources)
37 {
38 super(variant, configResources);
39 }
40
41 @Parameters
42 public static Collection<Object[]> parameters()
43 {
44 return Arrays.asList(new Object[][]{{ConfigVariant.SERVICE, "quartz-event-generator-service.xml"},
45 {ConfigVariant.FLOW, "quartz-event-generator-flow.xml"}});
46 }
47
48 @Test
49 public void testEventGeneratorPayload() throws Exception
50 {
51 FunctionalTestComponent component = (FunctionalTestComponent) getComponent("quartzService");
52 assertNotNull(component);
53 CountdownCallback callback = new Callback(1, receivedPayloads);
54 component.setEventCallback(callback);
55
56
57 assertTrue(callback.await(60000));
58 assertTrue(receivedPayloads.size() > 0);
59 assertEquals(PAYLOAD, receivedPayloads.get(0));
60 }
61
62 private static class Callback extends CountdownCallback
63 {
64 private List<String> messageList;
65
66 public Callback(int messagesExpected, List<String> payloadStore)
67 {
68 super(messagesExpected);
69 messageList = payloadStore;
70 }
71
72 @Override
73 public void eventReceived(MuleEventContext context, Object component) throws Exception
74 {
75 synchronized (this)
76 {
77 String payloadString = context.getMessage().getPayloadAsString();
78 messageList.add(payloadString);
79 }
80
81 super.eventReceived(context, component);
82 }
83 }
84
85 }