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.replyto;
8    
9   import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
10  import org.hamcrest.core.Is;
11  import org.hamcrest.core.IsNull;
12  import org.junit.Test;
13  import org.mule.tck.functional.EventCallback;
14  import org.mule.tck.functional.FunctionalTestComponent;
15  import org.mule.tck.junit4.FunctionalTestCase;
16   
17  
18  import static org.junit.Assert.assertThat;
19   
20  public class ReplyToChainIntegration5TestCase extends FunctionalTestCase
21  {
22   
23     public static final String TEST_PAYLOAD = "test payload";
24     public static final String EXPECTED_PAYLOAD = TEST_PAYLOAD + " modified";
25     public static final int TIMEOUT = 5000;
26   
27     @Override
28     protected String getConfigResources()
29     {
30         return "org/mule/test/integration/routing/replyto/replyto-chain-integration-test-5.xml";
31     }
32   
33     @Test
34     public void testReplyToIsHonoredInFlowUsingAsyncBlock() throws Exception
35     {
36         org.mule.api.client.LocalMuleClient client = muleContext.getClient();
37         final org.mule.util.concurrent.Latch flowExecutedLatch = new org.mule.util.concurrent.Latch();
38         FunctionalTestComponent ftc = getFunctionalTestComponent("replierService");
39         ftc.setEventCallback(new EventCallback()
40         {
41             public void eventReceived(org.mule.api.MuleEventContext context, Object component) throws Exception
42             {
43                 flowExecutedLatch.release();
44             }
45         });
46         org.mule.api.MuleMessage muleMessage = new org.mule.DefaultMuleMessage(TEST_PAYLOAD, muleContext);
47         muleMessage.setOutboundProperty(org.mule.api.config.MuleProperties.MULE_REPLY_TO_PROPERTY,"jms://response");
48         client.dispatch("jms://jmsIn1", muleMessage);
49         flowExecutedLatch.await(TIMEOUT, TimeUnit.MILLISECONDS);
50         org.mule.api.MuleMessage response = client.request("jms://response", TIMEOUT);
51         assertThat(response, IsNull.<Object>notNullValue());
52         assertThat(response.getPayloadAsString(), Is.is(EXPECTED_PAYLOAD));
53     }
54  }