View Javadoc

1   /*
2    * $Id: TcpLengthFunctionalTestCase.java 19817 2010-10-04 18:10:39Z dzapata $
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;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.module.client.MuleClient;
15  import org.mule.tck.DynamicPortTestCase;
16  import org.mule.tck.FunctionalTestCase;
17  
18  public class TcpLengthFunctionalTestCase extends DynamicPortTestCase
19  {
20      protected static String TEST_MESSAGE = "Test TCP Request";
21      private int timeout = 60 * 1000 / 20;
22  
23      public TcpLengthFunctionalTestCase()
24      {
25          setDisposeManagerPerSuite(true);
26      }
27  
28      protected String getConfigResources()
29      {
30          return "tcp-length-functional-test.xml";
31      }
32  
33      public void testSend() throws Exception
34      {
35          MuleClient client = new MuleClient(muleContext);
36          MuleMessage result = client.send("clientEndpoint", TEST_MESSAGE, null);
37          assertEquals(TEST_MESSAGE + " Received", result.getPayloadAsString());
38      }
39  
40      public void testDispatchAndReplyViaStream() throws Exception
41      {
42          MuleClient client = new MuleClient(muleContext);
43          client.dispatch("asyncClientEndpoint1", TEST_MESSAGE, null);
44          // MULE-2754
45          Thread.sleep(200);
46          MuleMessage result =  client.request("asyncClientEndpoint1", timeout);
47          // expect failure - streaming not supported
48          assertNull(result);
49      }
50  
51      public void testDispatchAndReply() throws Exception
52      {
53          MuleClient client = new MuleClient(muleContext);
54          client.dispatch("asyncClientEndpoint2", TEST_MESSAGE, null);
55          // MULE-2754
56          Thread.sleep(200);
57          MuleMessage result =  client.request("asyncClientEndpoint2", timeout);
58          // expect failure - TCP simply can't work like this
59          assertNull(result);
60      }
61  
62      @Override
63      protected int getNumPortsToFind()
64      {
65          return 3;
66      }
67  }