View Javadoc

1   /*
2    * $Id: AsynchMule1869TestCase.java 22462 2011-07-20 07:55:35Z justin.calleja $
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.transport.tcp.issues;
12  
13  import static org.junit.Assert.assertEquals;
14  import static org.junit.Assert.assertNotNull;
15  
16  import java.util.Arrays;
17  import java.util.Collection;
18  import java.util.HashMap;
19  import java.util.Map;
20  
21  import org.junit.Rule;
22  import org.junit.Test;
23  import org.junit.runners.Parameterized.Parameters;
24  import org.mule.api.MuleMessage;
25  import org.mule.module.client.MuleClient;
26  import org.mule.tck.AbstractServiceAndFlowTestCase;
27  import org.mule.tck.junit4.rule.DynamicPort;
28  
29  public class AsynchMule1869TestCase extends AbstractServiceAndFlowTestCase
30  {
31  
32      protected static String TEST_MESSAGE = "Test TCP Request";
33  
34      @Rule
35      public DynamicPort dynamicPort1 = new DynamicPort("port1");
36  
37      @Rule
38      public DynamicPort dynamicPort2 = new DynamicPort("port2");
39  
40      public AsynchMule1869TestCase(ConfigVariant variant, String configResources)
41      {
42          super(variant, configResources);
43      }
44      
45      @Parameters
46      public static Collection<Object[]> parameters()
47      {
48          return Arrays.asList(new Object[][]{{ConfigVariant.SERVICE, "tcp-functional-test-service.xml"},
49              {ConfigVariant.FLOW, "tcp-functional-test-flow.xml"}});
50      }
51  
52      @Test
53      public void testDispatchAndReply() throws Exception
54      {
55          MuleClient client = new MuleClient(muleContext);
56          Map props = new HashMap();
57          client.dispatch("asyncClientEndpoint", TEST_MESSAGE, props);
58          // MULE-2754
59          Thread.sleep(100);
60          MuleMessage result =  client.request("asyncClientEndpoint", 10000);
61          assertNotNull("No message received", result);
62          assertEquals(TEST_MESSAGE + " Received Async", result.getPayloadAsString());
63      }
64  
65  }