mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/remoteconfiguration/TestRemoteChannelLookupService.java
@Test
    public void testSyncTransportChannelRequestMessage() throws IOException
    {
        // construct a single message containing data within a namespace message
        SyncTransportChannelRequestData transportRequestData = SyncTransportChannelRequestData.newBuilder()
                .setDestSystemAddress("destination").setRemoteSystemAddress("system")
                .setTransportLayerName("transport").setRemoteSystemId(7)
                .build();
        
        RemoteChannelLookupNamespace remoteNamespaceMessage = RemoteChannelLookupNamespace.newBuilder()
                .setType(RemoteChannelLookupMessageType.SyncTransportChannelRequest)
                .setData(transportRequestData.toByteString()).build();
        
        TransportChannel transportChannel = mock(TransportChannel.class);
        when(transportChannel.getTransportLayerName()).thenReturn("transport");
        when(transportChannel.getRemoteMessageAddress()).thenReturn("system");
        when(transportChannel.getLocalMessageAddress()).thenReturn("local");
        when(m_RemoteChannelLookup.syncTransportChannel(
                transportRequestData.getTransportLayerName(),transportRequestData.getDestSystemAddress()
                , transportRequestData.getRemoteSystemAddress(), transportRequestData.getRemoteSystemId()))
                .thenReturn(transportChannel);

        TerraHarvestMessage message = createRemoteChannelMessage(remoteNamespaceMessage);
        TerraHarvestPayload payload = createPayload(remoteNamespaceMessage);
                
        // mock the channel the message came from
        RemoteChannel channel = mock(RemoteChannel.class);
        
        // replay
        m_SUT.handleMessage(message, payload, channel);
        
        verify(m_RemoteChannelLookup).syncTransportChannel("transport", "destination", "system", 7);

        // verify event is posted
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin).postEvent(eventCaptor.capture());
        Event postedEvent = eventCaptor.getValue();
        assertThat(postedEvent.getTopic(), is(RemoteConstants.TOPIC_MESSAGE_RECEIVED));
        assertThat((TerraHarvestMessage)postedEvent.getProperty(RemoteConstants.EVENT_PROP_MESSAGE), is(message));
        assertThat((String)postedEvent.getProperty(RemoteConstants.EVENT_PROP_MESSAGE_TYPE), 
                is(remoteNamespaceMessage.getType().toString()));
        assertThat((RemoteChannelLookupNamespace)postedEvent.getProperty(RemoteConstants.EVENT_PROP_NAMESPACE_MESSAGE), 
                is(remoteNamespaceMessage));
        assertThat((SyncTransportChannelRequestData)postedEvent.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE), 
                is(transportRequestData));
        assertThat((RemoteChannel)postedEvent.getProperty(RemoteConstants.EVENT_PROP_CHANNEL), is(channel));
    }
/**
     * Verify handling of sync transport layer channel request message
     */
Verify handling of sync transport layer channel request message
Verify handling of sync transport layer channel request message
@Test
    public void testSyncTransportChannelRequestMessage() throws IOException
    {
        SyncTransportChannelRequestData transportRequestData = SyncTransportChannelRequestData.newBuilder()
                .setDestSystemAddress("destination").setRemoteSystemAddress("system")
                .setTransportLayerName("transport").setRemoteSystemId(7)
                .build();
        RemoteChannelLookupNamespace remoteNamespaceMessage = RemoteChannelLookupNamespace.newBuilder()
                .setType(RemoteChannelLookupMessageType.SyncTransportChannelRequest)
                .setData(transportRequestData.toByteString()).build();
        TransportChannel transportChannel = mock(TransportChannel.class);
        when(transportChannel.getTransportLayerName()).thenReturn("transport");
        when(transportChannel.getRemoteMessageAddress()).thenReturn("system");
        when(transportChannel.getLocalMessageAddress()).thenReturn("local");
        when(m_RemoteChannelLookup.syncTransportChannel(
                transportRequestData.getTransportLayerName(),transportRequestData.getDestSystemAddress()
                , transportRequestData.getRemoteSystemAddress(), transportRequestData.getRemoteSystemId()))
                .thenReturn(transportChannel);
        TerraHarvestMessage message = createRemoteChannelMessage(remoteNamespaceMessage);
        TerraHarvestPayload payload = createPayload(remoteNamespaceMessage);
        RemoteChannel channel = mock(RemoteChannel.class);
        m_SUT.handleMessage(message, payload, channel);
        verify(m_RemoteChannelLookup).syncTransportChannel("transport", "destination", "system", 7);
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin).postEvent(eventCaptor.capture());
        Event postedEvent = eventCaptor.getValue();
        assertThat(postedEvent.getTopic(), is(RemoteConstants.TOPIC_MESSAGE_RECEIVED));
        assertThat((TerraHarvestMessage)postedEvent.getProperty(RemoteConstants.EVENT_PROP_MESSAGE), is(message));
        assertThat((String)postedEvent.getProperty(RemoteConstants.EVENT_PROP_MESSAGE_TYPE), 
                is(remoteNamespaceMessage.getType().toString()));
        assertThat((RemoteChannelLookupNamespace)postedEvent.getProperty(RemoteConstants.EVENT_PROP_NAMESPACE_MESSAGE), 
                is(remoteNamespaceMessage));
        assertThat((SyncTransportChannelRequestData)postedEvent.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE), 
                is(transportRequestData));
        assertThat((RemoteChannel)postedEvent.getProperty(RemoteConstants.EVENT_PROP_CHANNEL), is(channel));
    }
@ Test public void testSyncTransportChannelRequestMessage ( ) throws IOException { SyncTransportChannelRequestData transportRequestData = SyncTransportChannelRequestData . newBuilder ( ) . setDestSystemAddress ( "destination" ) . setRemoteSystemAddress ( "system" ) . setTransportLayerName ( "transport" ) . setRemoteSystemId ( 7 ) . build ( ) ; RemoteChannelLookupNamespace remoteNamespaceMessage = RemoteChannelLookupNamespace . newBuilder ( ) . setType ( RemoteChannelLookupMessageType . SyncTransportChannelRequest ) . setData ( transportRequestData . toByteString ( ) ) . build ( ) ; TransportChannel transportChannel = mock ( TransportChannel . class ) ; when ( transportChannel . getTransportLayerName ( ) ) . thenReturn ( "transport" ) ; when ( transportChannel . getRemoteMessageAddress ( ) ) . thenReturn ( "system" ) ; when ( transportChannel . getLocalMessageAddress ( ) ) . thenReturn ( "local" ) ; when ( m_RemoteChannelLookup . syncTransportChannel ( transportRequestData . getTransportLayerName ( ) , transportRequestData . getDestSystemAddress ( ) , transportRequestData . getRemoteSystemAddress ( ) , transportRequestData . getRemoteSystemId ( ) ) ) . thenReturn ( transportChannel ) ; TerraHarvestMessage message = createRemoteChannelMessage ( remoteNamespaceMessage ) ; TerraHarvestPayload payload = createPayload ( remoteNamespaceMessage ) ; RemoteChannel channel = mock ( RemoteChannel . class ) ; m_SUT . handleMessage ( message , payload , channel ) ; verify ( m_RemoteChannelLookup ) . syncTransportChannel ( "transport" , "destination" , "system" , 7 ) ; ArgumentCaptor < Event > eventCaptor = ArgumentCaptor . forClass ( Event . class ) ; verify ( m_EventAdmin ) . postEvent ( eventCaptor . capture ( ) ) ; Event postedEvent = eventCaptor . getValue ( ) ; assertThat ( postedEvent . getTopic ( ) , is ( RemoteConstants . TOPIC_MESSAGE_RECEIVED ) ) ; assertThat ( ( TerraHarvestMessage ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_MESSAGE ) , is ( message ) ) ; assertThat ( ( String ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_MESSAGE_TYPE ) , is ( remoteNamespaceMessage . getType ( ) . toString ( ) ) ) ; assertThat ( ( RemoteChannelLookupNamespace ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_NAMESPACE_MESSAGE ) , is ( remoteNamespaceMessage ) ) ; assertThat ( ( SyncTransportChannelRequestData ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_DATA_MESSAGE ) , is ( transportRequestData ) ) ; assertThat ( ( RemoteChannel ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_CHANNEL ) , is ( channel ) ) ; }
Verify handling of sync transport layer channel request message
Verify handling of sync transport layer channel request message
// construct a single message containing data within a namespace message // mock the channel the message came from // replay // verify event is posted