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 = getFunctionalTestComponent("hop1Service");
34 FunctionalTestComponent hop2 = getFunctionalTestComponent("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
56 assertEquals("Property not propagated from the first hop.", "hop1", msg.getInboundProperty("TICKET"));
57 FunctionalTestComponent ftc = (FunctionalTestComponent) component;
58 ftc.setReturnData(msg.getPayload() + " Hop2 ACK");
59 }
60 };
61
62 hop1.setEventCallback(callback1);
63 hop2.setEventCallback(callback2);
64
65 MuleClient client = new MuleClient(muleContext);
66 DefaultMuleMessage request = new DefaultMuleMessage("payload", muleContext);
67 MuleMessage reply = client.send("inboundEndpoint", request);
68 assertNotNull(reply);
69
70 assertTrue("First callback never fired", hop1made.get());
71 assertTrue("Second callback never fired", hop2made.get());
72 assertEquals("Hop1 ACK Hop2 ACK", reply.getPayload());
73 assertEquals("hop1", reply.getInboundProperty("TICKET"));
74 assertEquals("10000", reply.getInboundProperty("TTL"));
75 }
76
77 }