View Javadoc

1   /*
2    * $Id: DynamicEndpointWithAsyncResponseTestCase.java 22450 2011-07-19 08:20:41Z 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.test.integration.endpoints;
12  
13  import org.mule.DefaultMuleMessage;
14  import org.mule.api.MuleMessage;
15  import org.mule.client.DefaultLocalMuleClient;
16  import org.mule.tck.AbstractServiceAndFlowTestCase;
17  import org.mule.tck.junit4.rule.DynamicPort;
18  
19  import java.util.Arrays;
20  import java.util.Collection;
21  
22  import org.junit.Rule;
23  import org.junit.Test;
24  import org.junit.runners.Parameterized.Parameters;
25  
26  import static org.junit.Assert.assertEquals;
27  import static org.junit.Assert.assertNotNull;
28  
29  public class DynamicEndpointWithAsyncResponseTestCase extends AbstractServiceAndFlowTestCase
30  {
31      @Rule
32      public DynamicPort port1 = new DynamicPort("port1");
33  
34      @Parameters
35      public static Collection<Object[]> parameters()
36      {
37          return Arrays.asList(new Object[][]{{ConfigVariant.SERVICE,
38              "org/mule/test/integration/endpoints/dynamic-endpoint-with-async-response-config.xml"}
39  
40          });
41      }
42  
43      public DynamicEndpointWithAsyncResponseTestCase(ConfigVariant variant, String configResources)
44      {
45          super(variant, configResources);
46      }
47  
48      @Test
49      public void testDynamicEndpointWithAsyncResponse() throws Exception
50      {
51          DefaultMuleMessage message = new DefaultMuleMessage("hello", muleContext);
52          message.setOutboundProperty("host", "localhost");
53          message.setOutboundProperty("port", port1.getNumber());
54          message.setOutboundProperty("path", "/TEST");
55  
56          DefaultLocalMuleClient client = new DefaultLocalMuleClient(muleContext);
57          MuleMessage response = client.send("vm://vmProxy", message);
58          assertEquals("hello Received", response.getPayloadAsString());
59  
60          response = client.request("vm://vmOut", 5000);
61          assertNotNull(response);
62      }
63  }