1
2
3
4
5
6
7
8
9
10
11 package org.mule.test.integration.spring.events;
12
13 import org.mule.api.MuleEventContext;
14 import org.mule.api.MuleMessage;
15 import org.mule.module.client.MuleClient;
16 import org.mule.tck.FunctionalTestCase;
17 import org.mule.tck.functional.EventCallback;
18
19 import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicInteger;
20
21
22
23
24
25
26 public class SpringEventsJmsExampleTestCase extends FunctionalTestCase
27 {
28 private final AtomicInteger eventCount = new AtomicInteger(0);
29
30 protected String getConfigResources()
31 {
32 return "org/mule/test/integration/spring/events/mule-events-example-app-context.xml";
33 }
34
35 public SpringEventsJmsExampleTestCase()
36 {
37 setStartContext(false);
38 }
39
40 protected void doSetUp() throws Exception
41 {
42 eventCount.set(0);
43 }
44
45 public void testReceivingASubscriptionEvent() throws Exception
46 {
47 OrderManagerBean subscriptionBean = (OrderManagerBean) muleContext.getRegistry().lookupObject(
48 "orderManagerBean");
49 assertNotNull(subscriptionBean);
50
51
52 EventCallback callback = new EventCallback()
53 {
54 public void eventReceived(MuleEventContext context, Object o) throws Exception
55 {
56 eventCount.incrementAndGet();
57 }
58 };
59 subscriptionBean.setEventCallback(callback);
60
61 MuleClient client = new MuleClient();
62 Order order = new Order("Sausage and Mash");
63 client.dispatch("jms://orders.queue", order, null);
64 Thread.sleep(2000);
65 assertTrue(eventCount.get() == 1);
66
67 MuleMessage result = client.request("jms://processed.queue", 10000);
68 assertEquals(1, eventCount.get());
69 assertNotNull(result);
70 assertEquals("Order 'Sausage and Mash' Processed", result.getPayload());
71 }
72
73 public void testReceiveAsWebService() throws Exception
74 {
75 MuleClient client = new MuleClient();
76 OrderManagerBean orderManager = (OrderManagerBean) muleContext.getRegistry().lookupObject("orderManagerBean");
77 assertNotNull(orderManager);
78 EventCallback callback = new EventCallback()
79 {
80 public void eventReceived(MuleEventContext context, Object o) throws Exception
81 {
82 eventCount.incrementAndGet();
83 }
84 };
85 orderManager.setEventCallback(callback);
86
87 Order order = new Order("Sausage and Mash");
88 MuleMessage result = client.send("axis:http://localhost:44444/mule/orderManager?method=processOrder", order,
89 null);
90
91 assertNotNull(result);
92 assertEquals("Order 'Sausage and Mash' Processed", (result.getPayload()));
93 }
94
95 }