1   /*
2    * $Id: UdpConnectorTestCase.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.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      // @Override
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              /* expected */
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              /* expected */
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              /* expected */
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 }