1
2
3
4
5
6
7
8
9
10
11 package org.mule.routing.outbound;
12
13 import org.mule.DefaultMuleMessage;
14 import org.mule.api.MuleEventContext;
15 import org.mule.api.MuleMessage;
16 import org.mule.module.client.MuleClient;
17 import org.mule.tck.FunctionalTestCase;
18 import org.mule.tck.functional.EventCallback;
19 import org.mule.tck.functional.FunctionalTestComponent;
20
21 import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicBoolean;
22
23 public class ChainingRouterPropertyPropagationTestCase extends FunctionalTestCase
24 {
25
26 protected String getConfigResources()
27 {
28 return "org/mule/test/integration/routing/outbound/chaining-router-properties-propagation-config.xml";
29 }
30
31 public void testPropertiesPropagation() throws Exception
32 {
33 FunctionalTestComponent hop1 = (FunctionalTestComponent) getComponent(muleContext.getRegistry().lookupService("hop1Service"));
34 FunctionalTestComponent hop2 = (FunctionalTestComponent) getComponent(muleContext.getRegistry().lookupService("hop2Service"));
35 assertNotNull(hop1);
36
37 final AtomicBoolean hop1made = new AtomicBoolean(false);
38 EventCallback callback1 = new EventCallback()
39 {
40 public void eventReceived(final MuleEventContext context, final Object component) throws Exception
41 {
42 assertTrue(hop1made.compareAndSet(false, true));
43 FunctionalTestComponent ftc = (FunctionalTestComponent) component;
44 ftc.setReturnData("Hop1 ACK");
45 }
46 };
47
48 final AtomicBoolean hop2made = new AtomicBoolean(false);
49 EventCallback callback2 = new EventCallback()
50 {
51 public void eventReceived(final MuleEventContext context, final Object component) throws Exception
52 {
53 MuleMessage msg = context.getMessage();
54 assertTrue(hop2made.compareAndSet(false, true));
55 assertEquals("Property not propagated from the first hop.", "hop1", msg.getProperty("TICKET"));
56 FunctionalTestComponent ftc = (FunctionalTestComponent) component;
57 ftc.setReturnData(msg.getPayload() + " Hop2 ACK");
58 }
59 };
60
61 hop1.setEventCallback(callback1);
62 hop2.setEventCallback(callback2);
63
64 MuleClient client = new MuleClient();
65 DefaultMuleMessage request = new DefaultMuleMessage("payload");
66 MuleMessage reply = client.send("inboundEndpoint", request);
67 assertNotNull(reply);
68
69 assertTrue("First callback never fired", hop1made.get());
70 assertTrue("Second callback never fired", hop2made.get());
71 assertEquals("Hop1 ACK Hop2 ACK", reply.getPayload());
72 assertEquals("hop1", reply.getProperty("TICKET"));
73 assertEquals("10000", reply.getProperty("TTL"));
74 }
75
76 }