View Javadoc

1   /*
2    * $Id: MulticastConnectorTestCase.java 22377 2011-07-11 12:41:42Z dirk.olmes $
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.multicast;
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  import org.junit.Test;
22  
23  import static org.junit.Assert.assertEquals;
24  import static org.junit.Assert.assertTrue;
25  import static org.junit.Assert.fail;
26  
27  public class MulticastConnectorTestCase extends AbstractConnectorTestCase
28  {
29  
30      @Override
31      public Connector createConnector() throws Exception
32      {
33          MulticastConnector c = new MulticastConnector(muleContext);
34          c.setName("MulticastConnector");
35          return c;
36      }
37  
38      @Override
39      public String getTestEndpointURI()
40      {
41          return "multicast://228.3.4.5:60106";
42      }
43  
44      @Override
45      public Object getValidMessage() throws Exception
46      {
47          return new DatagramPacket("Hello".getBytes(), 5);
48      }
49  
50      @Test
51      public void testValidListener() throws Exception
52      {
53          Service service = getTestService("orange", Orange.class);
54          Connector connector = getConnector();
55  
56          InboundEndpoint endpoint2 = muleContext.getEndpointFactory()
57              .getInboundEndpoint("multicast://228.2.3.4:10100");
58  
59          connector.registerListener(endpoint2, getSensingNullMessageProcessor(), service);
60          try
61          {
62              connector.registerListener(endpoint2, getSensingNullMessageProcessor(), service);
63              fail("cannot register on the same endpointUri");
64          }
65          catch (Exception e)
66          {
67              // expected
68          }
69      }
70  
71      @Test
72      public void testProperties() throws Exception
73      {
74          MulticastConnector c = new MulticastConnector(muleContext);
75          c.setReceiveBufferSize(1024);
76          assertEquals(1024, c.getReceiveBufferSize());
77          c.setReceiveBufferSize(0);
78          assertEquals(MulticastConnector.DEFAULT_BUFFER_SIZE, c.getReceiveBufferSize());
79  
80          c.setTimeout(-1);
81          assertEquals(MulticastConnector.DEFAULT_SOCKET_TIMEOUT, c.getTimeout());
82  
83          c.setLoopback(true);
84          assertTrue(c.isLoopback());
85      }
86  
87  }