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