mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/TestRemoteChannelLookupImpl.java
@SuppressWarnings("unchecked")
    @Test
    public void testGetTransportChannel()
    {
        // mock factory specially to create unique instances for both calls
        ComponentInstance transportChannelInstance1 = mock(ComponentInstance.class);
        TransportChannel channel1 = mock(TransportChannel.class);
        when(transportChannelInstance1.getInstance()).thenReturn(channel1);
        ComponentInstance transportChannelInstance2 = mock(ComponentInstance.class);
        TransportChannel channel2 = mock(TransportChannel.class);
        when(transportChannelInstance2.getInstance()).thenReturn(channel2);
        when(m_TransportChannelFactory.newInstance(Mockito.any(Dictionary.class)))
            .thenReturn(transportChannelInstance1, transportChannelInstance2);
        
        stubTransportChannel(channel1, "test", "local", "remote");
        stubTransportChannel(channel2, "test2", "local2", "remote2");
        
        // replay
        m_SUT.syncTransportChannel("test", "local", "remote", 2);
        m_SUT.syncTransportChannel("test2", "local2", "remote2", 2);
        // sync socket channel just to make sure those are ignored later
        Socket socket = mock(Socket.class);
        m_SUT.newServerSocketChannel(socket);
        
        // mock channels to be completely different
        when(channel1.getTransportLayerName()).thenReturn("tl1");
        when(channel1.getLocalMessageAddress()).thenReturn("local1");
        when(channel1.getRemoteMessageAddress()).thenReturn("remote1");
        when(channel2.getTransportLayerName()).thenReturn("tl2");
        when(channel2.getLocalMessageAddress()).thenReturn("local2");
        when(channel2.getRemoteMessageAddress()).thenReturn("remote2");
        
        // verify channel is returned for the given transport info
        assertThat(m_SUT.getTransportChannel("tl1", "local1", "remote1"), is(channel1));
        assertThat(m_SUT.getTransportChannel("tl2", "local2", "remote2"), is(channel2));
        
        // mock channels so layers are the same
        when(channel1.getTransportLayerName()).thenReturn("tl-same");
        when(channel1.getLocalMessageAddress()).thenReturn("local1");
        when(channel1.getRemoteMessageAddress()).thenReturn("remote1");
        when(channel2.getTransportLayerName()).thenReturn("tl-same");
        when(channel2.getLocalMessageAddress()).thenReturn("local2");
        when(channel2.getRemoteMessageAddress()).thenReturn("remote2");
        
        // verify channel is returned for the given transport info to show differentiates by more than transport layers
        assertThat(m_SUT.getTransportChannel("tl-same", "local1", "remote1"), is(channel1));
        assertThat(m_SUT.getTransportChannel("tl-same", "local2", "remote2"), is(channel2));
        
        // verify null returned if not found
        assertThat(m_SUT.getTransportChannel("bad-tl", "foo", "bar"), is(nullValue()));
    }
/**
     * Verify getTransportChannel returns a channel if added only (not synced).

     * Verify null is returned for transport channel not in the lookup.
     */
Verify getTransportChannel returns a channel if added only (not synced).
Verify null is returned for transport channel not in the lookup.
Verify getTransportChannel returns a channel if added only ( not synced ) . Verify null is returned for transport channel not in the lookup .
@SuppressWarnings("unchecked")
    @Test
    public void testGetTransportChannel()
    {
        ComponentInstance transportChannelInstance1 = mock(ComponentInstance.class);
        TransportChannel channel1 = mock(TransportChannel.class);
        when(transportChannelInstance1.getInstance()).thenReturn(channel1);
        ComponentInstance transportChannelInstance2 = mock(ComponentInstance.class);
        TransportChannel channel2 = mock(TransportChannel.class);
        when(transportChannelInstance2.getInstance()).thenReturn(channel2);
        when(m_TransportChannelFactory.newInstance(Mockito.any(Dictionary.class)))
            .thenReturn(transportChannelInstance1, transportChannelInstance2);
        stubTransportChannel(channel1, "test", "local", "remote");
        stubTransportChannel(channel2, "test2", "local2", "remote2");
        m_SUT.syncTransportChannel("test", "local", "remote", 2);
        m_SUT.syncTransportChannel("test2", "local2", "remote2", 2);
        Socket socket = mock(Socket.class);
        m_SUT.newServerSocketChannel(socket);
        when(channel1.getTransportLayerName()).thenReturn("tl1");
        when(channel1.getLocalMessageAddress()).thenReturn("local1");
        when(channel1.getRemoteMessageAddress()).thenReturn("remote1");
        when(channel2.getTransportLayerName()).thenReturn("tl2");
        when(channel2.getLocalMessageAddress()).thenReturn("local2");
        when(channel2.getRemoteMessageAddress()).thenReturn("remote2");
        assertThat(m_SUT.getTransportChannel("tl1", "local1", "remote1"), is(channel1));
        assertThat(m_SUT.getTransportChannel("tl2", "local2", "remote2"), is(channel2));
        when(channel1.getTransportLayerName()).thenReturn("tl-same");
        when(channel1.getLocalMessageAddress()).thenReturn("local1");
        when(channel1.getRemoteMessageAddress()).thenReturn("remote1");
        when(channel2.getTransportLayerName()).thenReturn("tl-same");
        when(channel2.getLocalMessageAddress()).thenReturn("local2");
        when(channel2.getRemoteMessageAddress()).thenReturn("remote2");
         to show differentiates by more than transport layers
        assertThat(m_SUT.getTransportChannel("tl-same", "local1", "remote1"), is(channel1));
        assertThat(m_SUT.getTransportChannel("tl-same", "local2", "remote2"), is(channel2));
        assertThat(m_SUT.getTransportChannel("bad-tl", "foo", "bar"), is(nullValue()));
    }
@ SuppressWarnings ( "unchecked" ) @ Test public void testGetTransportChannel ( ) { ComponentInstance transportChannelInstance1 = mock ( ComponentInstance . class ) ; TransportChannel channel1 = mock ( TransportChannel . class ) ; when ( transportChannelInstance1 . getInstance ( ) ) . thenReturn ( channel1 ) ; ComponentInstance transportChannelInstance2 = mock ( ComponentInstance . class ) ; TransportChannel channel2 = mock ( TransportChannel . class ) ; when ( transportChannelInstance2 . getInstance ( ) ) . thenReturn ( channel2 ) ; when ( m_TransportChannelFactory . newInstance ( Mockito . any ( Dictionary . class ) ) ) . thenReturn ( transportChannelInstance1 , transportChannelInstance2 ) ; stubTransportChannel ( channel1 , "test" , "local" , "remote" ) ; stubTransportChannel ( channel2 , "test2" , "local2" , "remote2" ) ; m_SUT . syncTransportChannel ( "test" , "local" , "remote" , 2 ) ; m_SUT . syncTransportChannel ( "test2" , "local2" , "remote2" , 2 ) ; Socket socket = mock ( Socket . class ) ; m_SUT . newServerSocketChannel ( socket ) ; when ( channel1 . getTransportLayerName ( ) ) . thenReturn ( "tl1" ) ; when ( channel1 . getLocalMessageAddress ( ) ) . thenReturn ( "local1" ) ; when ( channel1 . getRemoteMessageAddress ( ) ) . thenReturn ( "remote1" ) ; when ( channel2 . getTransportLayerName ( ) ) . thenReturn ( "tl2" ) ; when ( channel2 . getLocalMessageAddress ( ) ) . thenReturn ( "local2" ) ; when ( channel2 . getRemoteMessageAddress ( ) ) . thenReturn ( "remote2" ) ; assertThat ( m_SUT . getTransportChannel ( "tl1" , "local1" , "remote1" ) , is ( channel1 ) ) ; assertThat ( m_SUT . getTransportChannel ( "tl2" , "local2" , "remote2" ) , is ( channel2 ) ) ; when ( channel1 . getTransportLayerName ( ) ) . thenReturn ( "tl-same" ) ; when ( channel1 . getLocalMessageAddress ( ) ) . thenReturn ( "local1" ) ; when ( channel1 . getRemoteMessageAddress ( ) ) . thenReturn ( "remote1" ) ; when ( channel2 . getTransportLayerName ( ) ) . thenReturn ( "tl-same" ) ; when ( channel2 . getLocalMessageAddress ( ) ) . thenReturn ( "local2" ) ; when ( channel2 . getRemoteMessageAddress ( ) ) . thenReturn ( "remote2" ) ; assertThat ( m_SUT . getTransportChannel ( "tl-same" , "local1" , "remote1" ) , is ( channel1 ) ) ; assertThat ( m_SUT . getTransportChannel ( "tl-same" , "local2" , "remote2" ) , is ( channel2 ) ) ; assertThat ( m_SUT . getTransportChannel ( "bad-tl" , "foo" , "bar" ) , is ( nullValue ( ) ) ) ; }
Verify getTransportChannel returns a channel if added only (not synced).
Verify getTransportChannel returns a channel if added only ( not synced ) .
// mock factory specially to create unique instances for both calls // replay // sync socket channel just to make sure those are ignored later // mock channels to be completely different // verify channel is returned for the given transport info // mock channels so layers are the same // verify channel is returned for the given transport info to show differentiates by more than transport layers // verify null returned if not found