View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.transport.multicast;
8   
9   import org.mule.api.endpoint.InboundEndpoint;
10  import org.mule.api.service.Service;
11  import org.mule.api.transport.Connector;
12  import org.mule.tck.testmodels.fruit.Orange;
13  import org.mule.transport.AbstractConnectorTestCase;
14  
15  import java.net.DatagramPacket;
16  
17  import org.junit.Test;
18  
19  import static org.junit.Assert.assertEquals;
20  import static org.junit.Assert.assertTrue;
21  import static org.junit.Assert.fail;
22  
23  public class MulticastConnectorTestCase extends AbstractConnectorTestCase
24  {
25  
26      @Override
27      public Connector createConnector() throws Exception
28      {
29          MulticastConnector c = new MulticastConnector(muleContext);
30          c.setName("MulticastConnector");
31          return c;
32      }
33  
34      @Override
35      public String getTestEndpointURI()
36      {
37          return "multicast://228.3.4.5:60106";
38      }
39  
40      @Override
41      public Object getValidMessage() throws Exception
42      {
43          return new DatagramPacket("Hello".getBytes(), 5);
44      }
45  
46      @Test
47      public void testValidListener() throws Exception
48      {
49          Service service = getTestService("orange", Orange.class);
50          Connector connector = getConnector();
51  
52          InboundEndpoint endpoint2 = muleContext.getEndpointFactory()
53              .getInboundEndpoint("multicast://228.2.3.4:10100");
54  
55          connector.registerListener(endpoint2, getSensingNullMessageProcessor(), service);
56          try
57          {
58              connector.registerListener(endpoint2, getSensingNullMessageProcessor(), service);
59              fail("cannot register on the same endpointUri");
60          }
61          catch (Exception e)
62          {
63              // expected
64          }
65      }
66  
67      @Test
68      public void testProperties() throws Exception
69      {
70          MulticastConnector c = new MulticastConnector(muleContext);
71          c.setReceiveBufferSize(1024);
72          assertEquals(1024, c.getReceiveBufferSize());
73          c.setReceiveBufferSize(0);
74          assertEquals(MulticastConnector.DEFAULT_BUFFER_SIZE, c.getReceiveBufferSize());
75  
76          c.setTimeout(-1);
77          assertEquals(MulticastConnector.DEFAULT_SOCKET_TIMEOUT, c.getTimeout());
78  
79          c.setLoopback(true);
80          assertTrue(c.isLoopback());
81      }
82  
83  }