View Javadoc

1   /*
2    * $Id: TcpSocketKeyTestCase.java 19817 2010-10-04 18:10:39Z dzapata $
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.DynamicPortTestCase;
16  import org.mule.tck.FunctionalTestCase;
17  import org.mule.transport.tcp.TcpSocketKey;
18  
19  public class TcpSocketKeyTestCase extends DynamicPortTestCase
20  {
21  
22      public void testHashAndEquals() throws MuleException
23      {
24          ImmutableEndpoint endpoint1in =
25                  muleContext.getRegistry().lookupEndpointFactory().getInboundEndpoint("globalEndpoint1");
26          TcpSocketKey key1in = new TcpSocketKey(endpoint1in);
27          ImmutableEndpoint endpoint1out =
28                  muleContext.getRegistry().lookupEndpointFactory().getOutboundEndpoint("globalEndpoint1");
29          TcpSocketKey key1out = new TcpSocketKey(endpoint1out);
30          ImmutableEndpoint endpoint2in =
31                  muleContext.getRegistry().lookupEndpointFactory().getInboundEndpoint("globalEndpoint2");
32          TcpSocketKey key2in = new TcpSocketKey(endpoint2in);
33  
34          assertEquals(key1in, key1in);
35          assertEquals(key1in, key1out);
36          assertNotSame(key1in, key2in);
37          assertEquals(key1in.hashCode(), key1in.hashCode());
38          assertEquals(key1in.hashCode(), key1out.hashCode());
39          assertFalse(key1in.hashCode() == key2in.hashCode());
40      }
41  
42      protected String getConfigResources()
43      {
44          return "tcp-socket-key-test.xml";
45      }
46  
47      @Override
48      protected int getNumPortsToFind()
49      {
50          return 2;
51      }
52  
53  }