View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.test.integration.routing.outbound;
8   
9   import org.mule.DefaultMuleMessage;
10  import org.mule.api.MuleMessage;
11  import org.mule.api.config.MuleProperties;
12  import org.mule.module.client.MuleClient;
13  import org.mule.tck.junit4.FunctionalTestCase;
14  import org.mule.transport.NullPayload;
15  
16  import org.junit.Test;
17  
18  import static org.junit.Assert.assertEquals;
19  import static org.junit.Assert.assertFalse;
20  import static org.junit.Assert.assertNull;
21  
22  public class ChainingRouterRemoteSyncTestCase extends FunctionalTestCase
23  {
24  
25      @Override
26      protected String getConfigResources()
27      {
28          return "org/mule/test/integration/routing/outbound/chaining-router-remote-sync.xml";
29      }
30  
31      @Test
32      public void testRemoteSync() throws Exception
33      {
34  
35          MuleClient muleClient = new MuleClient(muleContext);
36          MuleMessage result = muleClient.send("vm://in", new DefaultMuleMessage("test", muleContext));
37  
38          assertNull("Shouldn't have any exceptions", result.getExceptionPayload());
39          assertEquals("test [REMOTESYNC RESPONSE] [REMOTESYNC RESPONSE 2]", result.getPayloadAsString());
40      }
41  
42      /**
43       * MULE-4619 ChainingRouter sets MULE_REMOTE_SYNC_PROPERTY true on message when dispatching to last endpoint
44       * @throws Exception
45       */
46      @Test
47      public void testRemoteSyncLastEndpointDispatch() throws Exception
48      {
49  
50          MuleClient muleClient = new MuleClient(muleContext);
51          MuleMessage result = muleClient.send("vm://in2", new DefaultMuleMessage("test", muleContext));
52  
53          assertNull("Shouldn't have any exceptions", result.getExceptionPayload());
54          // When last endpoint on chaining router is async the outbound phase behaves as out-only and null is returned
55          assertEquals(NullPayload.getInstance(), result.getPayload());
56  
57          MuleMessage jmsMessage = muleClient.request("jms://out2", FunctionalTestCase.RECEIVE_TIMEOUT);
58          assertEquals("test [REMOTESYNC RESPONSE] [REMOTESYNC RESPONSE 2]", jmsMessage.getPayloadAsString());
59          assertFalse(jmsMessage.getOutboundProperty(MuleProperties.MULE_REMOTE_SYNC_PROPERTY, false));
60      }
61  
62  }