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.tcp;
8   
9   import org.mule.api.MuleException;
10  import org.mule.api.endpoint.ImmutableEndpoint;
11  import org.mule.tck.junit4.FunctionalTestCase;
12  import org.mule.tck.junit4.rule.DynamicPort;
13  
14  import org.junit.Rule;
15  import org.junit.Test;
16  
17  import static org.junit.Assert.assertEquals;
18  import static org.junit.Assert.assertFalse;
19  import static org.junit.Assert.assertNotSame;
20  
21  public class TcpSocketKeyTestCase extends FunctionalTestCase
22  {
23  
24      @Rule
25      public DynamicPort dynamicPort1 = new DynamicPort("port1");
26  
27      @Rule
28      public DynamicPort dynamicPort2 = new DynamicPort("port2");
29  
30      @Override
31      protected String getConfigResources()
32      {
33          return "tcp-socket-key-test.xml";
34      }
35  
36      @Test
37      public void testHashAndEquals() throws MuleException
38      {
39          ImmutableEndpoint endpoint1in =
40                  muleContext.getEndpointFactory().getInboundEndpoint("globalEndpoint1");
41          TcpSocketKey key1in = new TcpSocketKey(endpoint1in);
42          ImmutableEndpoint endpoint1out =
43                  muleContext.getEndpointFactory().getOutboundEndpoint("globalEndpoint1");
44          TcpSocketKey key1out = new TcpSocketKey(endpoint1out);
45          ImmutableEndpoint endpoint2in =
46                  muleContext.getEndpointFactory().getInboundEndpoint("globalEndpoint2");
47          TcpSocketKey key2in = new TcpSocketKey(endpoint2in);
48  
49          assertEquals(key1in, key1in);
50          assertEquals(key1in, key1out);
51          assertNotSame(key1in, key2in);
52          assertEquals(key1in.hashCode(), key1in.hashCode());
53          assertEquals(key1in.hashCode(), key1out.hashCode());
54          assertFalse(key1in.hashCode() == key2in.hashCode());
55      }
56  
57  }