1   /*
2    * $Id: TcpSyncTestCase.java 7976 2007-08-21 14:26:13Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.providers.tcp;
12  
13  import org.mule.MuleManager;
14  import org.mule.extras.client.MuleClient;
15  import org.mule.tck.FunctionalTestCase;
16  import org.mule.umo.UMOMessage;
17  import org.mule.util.StringUtils;
18  
19  import java.util.Arrays;
20  
21  public class TcpSyncTestCase extends FunctionalTestCase
22  {
23  
24      public TcpSyncTestCase()
25      {
26          setDisposeManagerPerSuite(true);
27      }
28  
29      protected String getConfigResources()
30      {
31          return "tcp-sync.xml";
32      }
33  
34      public void testSendString() throws Exception
35      {
36          MuleClient client = new MuleClient();
37  
38          UMOMessage message = client.send("clientEndpoint", "data", null);
39          assertNotNull(message);
40          String response = message.getPayloadAsString();
41          assertEquals("data", response);
42      }
43  
44      public void testSyncResponseOfBufferSize() throws Exception
45      {
46          MuleClient client = new MuleClient();
47  
48          TcpConnector tcp = (TcpConnector)MuleManager.getInstance().lookupConnector("tcpConnector");
49          tcp.setSendBufferSize(1024 * 16);
50          byte[] data = StringUtils.repeat("0123456789", tcp.getSendBufferSize() / 10).getBytes();
51          UMOMessage message = client.send("clientEndpoint", data, null);
52          assertNotNull(message);
53          byte[] response = message.getPayloadAsBytes();
54  
55          assertEquals(data.length, response.length);
56          assertTrue(Arrays.equals(data, response));
57      }
58  
59      public void testSyncResponseVeryBig() throws Exception
60      {
61          MuleClient client = new MuleClient();
62          byte[] data = StringUtils.repeat("0123456789", 10000).getBytes();
63  
64          UMOMessage message = client.send("clientEndpoint", data, null);
65          assertNotNull(message);
66          byte[] response = message.getPayloadAsBytes();
67          assertEquals(data.length, response.length);
68          assertTrue(Arrays.equals(data, response));
69      }
70  
71  }