mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/TestRemoteChannelLookupImpl.java
@SuppressWarnings({ "rawtypes", "unchecked" })
    @Test
    public void testSyncTransportChannel()
    {
        // mock the transport layer and address used for syncing, have transport channel match with it
        stubTransportChannel(m_TransportChannel, "tl-1", "tl:1.2.3", "tl:1.2.4");
        stubAsExistingTransportChannel(m_TransportChannel);
        
        int systemId = 300;
        
        TransportChannel channel = m_SUT.syncTransportChannel("tl-1", "tl:1.2.3", "tl:1.2.4", systemId);
        
        // should be the transport channel that gets created by the factory
        assertThat((TransportChannel)m_SUT.getChannel(systemId), is(channel));
        ArgumentCaptor<Dictionary> dictionaryCaptor = ArgumentCaptor.forClass(Dictionary.class);
        verify(m_TransportChannelFactory).newInstance(dictionaryCaptor.capture());
        assertThat(channel, is(m_TransportChannel));
        // verify transport channel is created with proper properties
        assertThat((String)dictionaryCaptor.getValue().get(TransportChannelImpl.TRANSPORT_NAME_PROP_KEY), 
                is("tl-1"));
        assertThat((String)dictionaryCaptor.getValue().get(TransportChannelImpl.LOCAL_ADDRESS_PROP_KEY), 
                is("tl:1.2.3"));
        assertThat((String)dictionaryCaptor.getValue().get(TransportChannelImpl.REMOTE_ADDRESS_PROP_KEY), 
                is("tl:1.2.4"));
        
        //verify that the channel added topic is created
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin).postEvent(eventCaptor.capture());
        
        Event event = eventCaptor.getValue();
        assertThat(event.getTopic(), is(RemoteChannelLookup.TOPIC_CHANNEL_UPDATED));
        assertThat((Integer)event.getProperty(RemoteConstants.EVENT_PROP_SYS_ID), is(300));
        assertThat(event.getProperty(RemoteConstants.EVENT_PROP_CHANNEL), notNullValue());
                
        // syncing again should not create a new channel
        m_SUT.syncTransportChannel("tl-1", "tl:1.2.3", "tl:1.2.4", systemId);
        
        channel = (TransportChannel)m_SUT.getChannel(systemId);
        verify(m_TransportChannelFactory, times(1)).newInstance(Mockito.any(Dictionary.class)); // still holding at 1
        assertThat(channel, is(m_TransportChannel));
        
        verify(m_EventAdmin, times(2)).postEvent(eventCaptor.capture());
        
        // sync to a different system id, shouldn't be available at the old one anymore
        int otherSystemId = 400;
        m_SUT.syncTransportChannel("tl-1", "tl:1.2.3", "tl:1.2.4", otherSystemId);
        
        try
        {
            m_SUT.getChannel(systemId);
            fail("Expecting exception since channel is no longer associated with this id");
        }
        catch (IllegalArgumentException e)
        {
            
        }
        
        verify(m_EventAdmin, times(3)).postEvent(eventCaptor.capture());
        
        channel = (TransportChannel)m_SUT.getChannel(otherSystemId);
        verify(m_TransportChannelFactory, times(1)).newInstance(Mockito.any(Dictionary.class)); // still holding at 1
        assertThat(channel, is(m_TransportChannel));
    }
/**
     * Verify syncing a transport will allow it to be retrieved later.
     * 
     * Verify channel is not created if already in lookup
     * 
     * Verify syncing channel to a new id is handled correctly (should move channel)
     */
Verify syncing a transport will allow it to be retrieved later.

Verify channel is not created if already in lookup

Verify syncing channel to a new id is handled correctly (should move channel)
Verify syncing a transport will allow it to be retrieved later . Verify channel is not created if already in lookup Verify syncing channel to a new id is handled correctly ( should move channel )
@SuppressWarnings({ "rawtypes", "unchecked" })
    @Test
    public void testSyncTransportChannel()
    {
        stubTransportChannel(m_TransportChannel, "tl-1", "tl:1.2.3", "tl:1.2.4");
        stubAsExistingTransportChannel(m_TransportChannel);
        int systemId = 300;
        TransportChannel channel = m_SUT.syncTransportChannel("tl-1", "tl:1.2.3", "tl:1.2.4", systemId);
        assertThat((TransportChannel)m_SUT.getChannel(systemId), is(channel));
        ArgumentCaptor<Dictionary> dictionaryCaptor = ArgumentCaptor.forClass(Dictionary.class);
        verify(m_TransportChannelFactory).newInstance(dictionaryCaptor.capture());
        assertThat(channel, is(m_TransportChannel));
        assertThat((String)dictionaryCaptor.getValue().get(TransportChannelImpl.TRANSPORT_NAME_PROP_KEY), 
                is("tl-1"));
        assertThat((String)dictionaryCaptor.getValue().get(TransportChannelImpl.LOCAL_ADDRESS_PROP_KEY), 
                is("tl:1.2.3"));
        assertThat((String)dictionaryCaptor.getValue().get(TransportChannelImpl.REMOTE_ADDRESS_PROP_KEY), 
                is("tl:1.2.4"));
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin).postEvent(eventCaptor.capture());
        Event event = eventCaptor.getValue();
        assertThat(event.getTopic(), is(RemoteChannelLookup.TOPIC_CHANNEL_UPDATED));
        assertThat((Integer)event.getProperty(RemoteConstants.EVENT_PROP_SYS_ID), is(300));
        assertThat(event.getProperty(RemoteConstants.EVENT_PROP_CHANNEL), notNullValue());
        m_SUT.syncTransportChannel("tl-1", "tl:1.2.3", "tl:1.2.4", systemId);
        channel = (TransportChannel)m_SUT.getChannel(systemId);
        verify(m_TransportChannelFactory, times(1)).newInstance(Mockito.any(Dictionary.class)); 
        assertThat(channel, is(m_TransportChannel));
        verify(m_EventAdmin, times(2)).postEvent(eventCaptor.capture());
        int otherSystemId = 400;
        m_SUT.syncTransportChannel("tl-1", "tl:1.2.3", "tl:1.2.4", otherSystemId);
        try
        {
            m_SUT.getChannel(systemId);
            fail("Expecting exception since channel is no longer associated with this id");
        }
        catch (IllegalArgumentException e)
        {
        }
        verify(m_EventAdmin, times(3)).postEvent(eventCaptor.capture());
        channel = (TransportChannel)m_SUT.getChannel(otherSystemId);
        verify(m_TransportChannelFactory, times(1)).newInstance(Mockito.any(Dictionary.class)); 
        assertThat(channel, is(m_TransportChannel));
    }
@ SuppressWarnings ( { "rawtypes" , "unchecked" } ) @ Test public void testSyncTransportChannel ( ) { stubTransportChannel ( m_TransportChannel , "tl-1" , "tl:1.2.3" , "tl:1.2.4" ) ; stubAsExistingTransportChannel ( m_TransportChannel ) ; int systemId = 300 ; TransportChannel channel = m_SUT . syncTransportChannel ( "tl-1" , "tl:1.2.3" , "tl:1.2.4" , systemId ) ; assertThat ( ( TransportChannel ) m_SUT . getChannel ( systemId ) , is ( channel ) ) ; ArgumentCaptor < Dictionary > dictionaryCaptor = ArgumentCaptor . forClass ( Dictionary . class ) ; verify ( m_TransportChannelFactory ) . newInstance ( dictionaryCaptor . capture ( ) ) ; assertThat ( channel , is ( m_TransportChannel ) ) ; assertThat ( ( String ) dictionaryCaptor . getValue ( ) . get ( TransportChannelImpl . TRANSPORT_NAME_PROP_KEY ) , is ( "tl-1" ) ) ; assertThat ( ( String ) dictionaryCaptor . getValue ( ) . get ( TransportChannelImpl . LOCAL_ADDRESS_PROP_KEY ) , is ( "tl:1.2.3" ) ) ; assertThat ( ( String ) dictionaryCaptor . getValue ( ) . get ( TransportChannelImpl . REMOTE_ADDRESS_PROP_KEY ) , is ( "tl:1.2.4" ) ) ; ArgumentCaptor < Event > eventCaptor = ArgumentCaptor . forClass ( Event . class ) ; verify ( m_EventAdmin ) . postEvent ( eventCaptor . capture ( ) ) ; Event event = eventCaptor . getValue ( ) ; assertThat ( event . getTopic ( ) , is ( RemoteChannelLookup . TOPIC_CHANNEL_UPDATED ) ) ; assertThat ( ( Integer ) event . getProperty ( RemoteConstants . EVENT_PROP_SYS_ID ) , is ( 300 ) ) ; assertThat ( event . getProperty ( RemoteConstants . EVENT_PROP_CHANNEL ) , notNullValue ( ) ) ; m_SUT . syncTransportChannel ( "tl-1" , "tl:1.2.3" , "tl:1.2.4" , systemId ) ; channel = ( TransportChannel ) m_SUT . getChannel ( systemId ) ; verify ( m_TransportChannelFactory , times ( 1 ) ) . newInstance ( Mockito . any ( Dictionary . class ) ) ; assertThat ( channel , is ( m_TransportChannel ) ) ; verify ( m_EventAdmin , times ( 2 ) ) . postEvent ( eventCaptor . capture ( ) ) ; int otherSystemId = 400 ; m_SUT . syncTransportChannel ( "tl-1" , "tl:1.2.3" , "tl:1.2.4" , otherSystemId ) ; try { m_SUT . getChannel ( systemId ) ; fail ( "Expecting exception since channel is no longer associated with this id" ) ; } catch ( IllegalArgumentException e ) { } verify ( m_EventAdmin , times ( 3 ) ) . postEvent ( eventCaptor . capture ( ) ) ; channel = ( TransportChannel ) m_SUT . getChannel ( otherSystemId ) ; verify ( m_TransportChannelFactory , times ( 1 ) ) . newInstance ( Mockito . any ( Dictionary . class ) ) ; assertThat ( channel , is ( m_TransportChannel ) ) ; }
Verify syncing a transport will allow it to be retrieved later.
Verify syncing a transport will allow it to be retrieved later .
// mock the transport layer and address used for syncing, have transport channel match with it // should be the transport channel that gets created by the factory // verify transport channel is created with proper properties //verify that the channel added topic is created // syncing again should not create a new channel // still holding at 1 // sync to a different system id, shouldn't be available at the old one anymore // still holding at 1