View Javadoc

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