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 public UMOConnector getConnector() throws Exception
27 {
28 UdpConnector c = new UdpConnector();
29 c.setName("UdpConnector");
30 c.initialise();
31 return c;
32 }
33
34 public String getTestEndpointURI()
35 {
36 return "udp://localhost:61024";
37 }
38
39 public Object getValidMessage() throws Exception
40 {
41 return new DatagramPacket("Hello".getBytes(), 5);
42 }
43
44 public void testValidListener() throws Exception
45 {
46 MuleDescriptor d = getTestDescriptor("orange", Orange.class.getName());
47 UMOComponent component = getTestComponent(d);
48 UMOEndpoint endpoint = getTestEndpoint("Test", UMOEndpoint.ENDPOINT_TYPE_RECEIVER);
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
60 }
61 endpoint.setEndpointURI(null);
62 try
63 {
64 connector.registerListener(component, endpoint);
65 fail("cannot register with empty endpointUri");
66 }
67 catch (Exception e)
68 {
69
70 }
71
72 endpoint.setEndpointURI(new MuleEndpointURI("udp://localhost:3456"));
73 connector.registerListener(component, endpoint);
74 try
75 {
76 connector.registerListener(component, endpoint);
77 fail("cannot register on the same endpointUri");
78 }
79 catch (Exception e)
80 {
81
82 }
83 connector.dispose();
84 }
85
86 public void testProperties() throws Exception
87 {
88 UdpConnector connector = (UdpConnector)this.connector;
89
90 connector.setReceiveBufferSize(1024);
91 assertEquals(1024, connector.getReceiveBufferSize());
92 connector.setReceiveBufferSize(0);
93 assertEquals(UdpConnector.DEFAULT_BUFFER_SIZE, connector.getReceiveBufferSize());
94
95 connector.setReceiveTimeout(-1);
96 assertEquals(UdpConnector.DEFAULT_SOCKET_TIMEOUT, connector.getReceiveTimeout());
97 }
98
99 }