View Javadoc

1   /*
2    * $Id: ChainingRouterPropertyPropagationTestCase.java 22419 2011-07-15 03:41:06Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
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                  // this is a service callback, props are on the inbound
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  }