1   /*
2    * $Id: TcpConnectorTestCase.java 7968 2007-08-21 12:01:57Z holger $
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.impl.MuleDescriptor;
14  import org.mule.impl.endpoint.MuleEndpointURI;
15  import org.mule.tck.providers.AbstractConnectorTestCase;
16  import org.mule.tck.testmodels.fruit.Orange;
17  import org.mule.umo.UMOComponent;
18  import org.mule.umo.endpoint.UMOEndpoint;
19  import org.mule.umo.provider.UMOConnector;
20  
21  public class TcpConnectorTestCase extends AbstractConnectorTestCase
22  {
23  
24      // @Override
25      public UMOConnector createConnector() throws Exception
26      {
27          TcpConnector c = new TcpConnector();
28          c.setName("TcpConnector");
29          c.initialise();
30          return c;
31      }
32  
33      public String getTestEndpointURI()
34      {
35          return "tcp://localhost:56801";
36      }
37  
38      public Object getValidMessage() throws Exception
39      {
40          return "Hello".getBytes();
41      }
42  
43      public void testValidListener() throws Exception
44      {
45          MuleDescriptor d = getTestDescriptor("orange", Orange.class.getName());
46          UMOComponent component = getTestComponent(d);
47          UMOEndpoint endpoint = getTestEndpoint("Test", UMOEndpoint.ENDPOINT_TYPE_RECEIVER);
48          UMOConnector connector = getConnector();
49          endpoint.setEndpointURI(null);
50          endpoint.setConnector(connector);
51  
52          try
53          {
54              connector.registerListener(component, endpoint);
55              fail("cannot register with null endpointUri");
56          }
57          catch (Exception e)
58          {
59              /* expected */
60          }
61  
62          endpoint.setEndpointURI(null);
63          try
64          {
65              connector.registerListener(component, endpoint);
66              fail("cannot register with empty endpointUri");
67          }
68          catch (Exception e)
69          {
70              /* expected */
71          }
72  
73          endpoint.setEndpointURI(new MuleEndpointURI("tcp://localhost:30303"));
74          connector.registerListener(component, endpoint);
75          try
76          {
77              // connector.registerListener(component, endpoint);
78              // fail("cannot register on the same endpointUri");
79          }
80          catch (Exception e)
81          {
82              /* expected */
83          }
84      }
85  
86      public void testProperties() throws Exception
87      {
88          TcpConnector c = (TcpConnector)getConnector();
89  
90          c.setSendBufferSize(1024);
91          assertEquals(1024, c.getSendBufferSize());
92          c.setSendBufferSize(0);
93          assertEquals(TcpConnector.DEFAULT_BUFFER_SIZE, c.getSendBufferSize());
94  
95          // timeouts
96          c.setReceiveTimeout(-1);
97          assertEquals(TcpConnector.DEFAULT_SOCKET_TIMEOUT, c.getReceiveTimeout());
98          c.setSendTimeout(-1);
99          assertEquals(TcpConnector.DEFAULT_SOCKET_TIMEOUT, c.getSendTimeout());
100         c.setSendTimeout(1000);
101         c.setReceiveTimeout(1000);
102         assertEquals(1000, c.getReceiveTimeout());
103         assertEquals(1000, c.getSendTimeout());
104 
105         c.dispose();
106     }
107 }