1
2
3
4
5
6
7
8
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 public UMOConnector getConnector() throws Exception
25 {
26 TcpConnector c = new TcpConnector();
27 c.setName("TcpConnector");
28 c.initialise();
29 return c;
30 }
31
32 public String getTestEndpointURI()
33 {
34 return "tcp://localhost:56801";
35 }
36
37 public Object getValidMessage() throws Exception
38 {
39 return "Hello".getBytes();
40 }
41
42 public void testValidListener() throws Exception
43 {
44 MuleDescriptor d = getTestDescriptor("orange", Orange.class.getName());
45 UMOComponent component = getTestComponent(d);
46 UMOEndpoint endpoint = getTestEndpoint("Test", UMOEndpoint.ENDPOINT_TYPE_RECEIVER);
47 endpoint.setEndpointURI(null);
48 endpoint.setConnector(connector);
49
50 try
51 {
52 connector.registerListener(component, endpoint);
53 fail("cannot register with null endpointUri");
54 }
55 catch (Exception e)
56 {
57
58 }
59
60 endpoint.setEndpointURI(null);
61 try
62 {
63 connector.registerListener(component, endpoint);
64 fail("cannot register with empty endpointUri");
65 }
66 catch (Exception e)
67 {
68
69 }
70
71 endpoint.setEndpointURI(new MuleEndpointURI("tcp://localhost:30303"));
72 connector.registerListener(component, endpoint);
73 try
74 {
75
76
77 }
78 catch (Exception e)
79 {
80
81 }
82 }
83
84 public void testProperties() throws Exception
85 {
86 TcpConnector c = (TcpConnector)connector;
87
88 c.setSendBufferSize(1024);
89 assertEquals(1024, c.getSendBufferSize());
90 c.setSendBufferSize(0);
91 assertEquals(TcpConnector.DEFAULT_BUFFER_SIZE, c.getSendBufferSize());
92
93
94 c.setReceiveTimeout(-1);
95 assertEquals(TcpConnector.DEFAULT_SOCKET_TIMEOUT, c.getReceiveTimeout());
96 c.setSendTimeout(-1);
97 assertEquals(TcpConnector.DEFAULT_SOCKET_TIMEOUT, c.getSendTimeout());
98 c.setSendTimeout(1000);
99 c.setReceiveTimeout(1000);
100 assertEquals(1000, c.getReceiveTimeout());
101 assertEquals(1000, c.getSendTimeout());
102
103 c.dispose();
104 }
105 }