View Javadoc

1   /*
2    * $Id: UdpConnectorTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.transport.udp;
12  
13  import org.mule.api.endpoint.InboundEndpoint;
14  import org.mule.api.service.Service;
15  import org.mule.api.transport.Connector;
16  import org.mule.tck.testmodels.fruit.Orange;
17  import org.mule.transport.AbstractConnectorTestCase;
18  
19  import java.net.DatagramPacket;
20  
21  public class UdpConnectorTestCase extends AbstractConnectorTestCase
22  {
23  
24      @Override
25      public Connector createConnector() throws Exception
26      {
27          UdpConnector c = new UdpConnector(muleContext);
28          c.setName("UdpConnector");
29          return c;
30      }
31  
32      public String getTestEndpointURI()
33      {
34          return "udp://localhost:61024";
35      }
36  
37      public Object getValidMessage() throws Exception
38      {
39          return new DatagramPacket("Hello".getBytes(), 5);
40      }
41  
42      public void testValidListener() throws Exception
43      {
44          Service service = getTestService("orange", Orange.class);
45          Connector connector = getConnector();
46  
47          InboundEndpoint endpoint2 = muleContext.getRegistry()
48              .lookupEndpointFactory()
49              .getInboundEndpoint("udp://localhost:3456");
50  
51          connector.registerListener(endpoint2, getSensingNullMessageProcessor(), service);
52          try
53          {
54              connector.registerListener(endpoint2, getSensingNullMessageProcessor(), service);
55              fail("cannot register on the same endpointUri");
56          }
57          catch (Exception e)
58          {
59              // expected
60          }
61      }
62  
63      public void testProperties() throws Exception
64      {
65          UdpConnector connector = (UdpConnector)this.getConnector();
66  
67          connector.setReceiveBufferSize(1024);
68          assertEquals(1024, connector.getReceiveBufferSize());
69          connector.setReceiveBufferSize(0);
70          assertEquals(UdpConnector.DEFAULT_BUFFER_SIZE, connector.getReceiveBufferSize());
71  
72          connector.setReceiveTimeout(-1);
73          assertEquals(UdpConnector.DEFAULT_SOCKET_TIMEOUT, connector.getReceiveTimeout());
74      }
75  
76  }