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