1
2
3
4
5
6
7
8
9
10
11 package org.mule.providers.udp;
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 import java.net.DatagramPacket;
22
23 public class UdpConnectorTestCase extends AbstractConnectorTestCase
24 {
25
26
27 public UMOConnector createConnector() throws Exception
28 {
29 UdpConnector c = new UdpConnector();
30 c.setName("UdpConnector");
31 c.initialise();
32 return c;
33 }
34
35 public String getTestEndpointURI()
36 {
37 return "udp://localhost:61024";
38 }
39
40 public Object getValidMessage() throws Exception
41 {
42 return new DatagramPacket("Hello".getBytes(), 5);
43 }
44
45 public void testValidListener() throws Exception
46 {
47 MuleDescriptor d = getTestDescriptor("orange", Orange.class.getName());
48 UMOComponent component = getTestComponent(d);
49 UMOEndpoint endpoint = getTestEndpoint("Test", UMOEndpoint.ENDPOINT_TYPE_RECEIVER);
50 UMOConnector connector = getConnector();
51 endpoint.setEndpointURI(null);
52 endpoint.setConnector(connector);
53
54 try
55 {
56 connector.registerListener(component, endpoint);
57 fail("cannot register with null endpointUri");
58 }
59 catch (Exception e)
60 {
61
62 }
63 endpoint.setEndpointURI(null);
64 try
65 {
66 connector.registerListener(component, endpoint);
67 fail("cannot register with empty endpointUri");
68 }
69 catch (Exception e)
70 {
71
72 }
73
74 endpoint.setEndpointURI(new MuleEndpointURI("udp://localhost:3456"));
75 connector.registerListener(component, endpoint);
76 try
77 {
78 connector.registerListener(component, endpoint);
79 fail("cannot register on the same endpointUri");
80 }
81 catch (Exception e)
82 {
83
84 }
85 connector.dispose();
86 }
87
88 public void testProperties() throws Exception
89 {
90 UdpConnector connector = (UdpConnector)this.getConnector();
91
92 connector.setReceiveBufferSize(1024);
93 assertEquals(1024, connector.getReceiveBufferSize());
94 connector.setReceiveBufferSize(0);
95 assertEquals(UdpConnector.DEFAULT_BUFFER_SIZE, connector.getReceiveBufferSize());
96
97 connector.setReceiveTimeout(-1);
98 assertEquals(UdpConnector.DEFAULT_SOCKET_TIMEOUT, connector.getReceiveTimeout());
99 }
100
101 }