mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/messaging/TestMessageSenderImpl.java
@Test
    public void testQueueResponseWithVaryingId() throws IOException
    {
        // id to use for the request and response
        int messageId = 100;
        
        // id for the remote channel as returned by the remote channel lookup.
        int sourceId = 50;
        
        // construct fake request message that should be used by service to construct the response
        MissionProgrammingNamespace requestMessage = MissionProgrammingNamespace.newBuilder()
                .setType(MissionProgrammingMessageType.GetTemplatesRequest).build();
        TerraHarvestMessage request = 
                createMessageWithDestSource(sourceId, m_LocalId, 0 , Namespace.MissionProgramming, requestMessage);
        
        // construct data message
        MissionProgramTemplate template = MissionProgramTemplate.newBuilder().setName("test").setSource("src").build();
        GetTemplatesResponseData getTemplateData = GetTemplatesResponseData.newBuilder().addTemplate(template).build();
        
        MissionProgrammingNamespace responseMessage = MissionProgrammingNamespace.newBuilder()
                .setType(MissionProgrammingMessageType.GetTemplatesResponse)
                .setData(getTemplateData.toByteString()).build();
        
        TerraHarvestMessage response = 
                createTerraHarvestMessage(messageId, Namespace.MissionProgramming, responseMessage, true);
        TerraHarvestPayload payload = TerraHarvestPayload.parseFrom(response.getTerraHarvestPayload());
        
        when(m_EncryptService.encryptMessage(Mockito.any(Builder.class), Mockito.any(TerraHarvestPayload.class))).
            thenReturn(response);
        when(m_RemoteChannelLookup.getChannelSystemId(m_Channel)).thenReturn(m_RemoteId);
        
        boolean result = m_SUT.queueMessageResponse(request, payload, m_Channel);
        assertThat("message is queued as reported by channel", result, is(true));
        
        // verify message is sent to the associated channel
        verify(m_Channel).queueMessage(response);
        
        ArgumentCaptor<TerraHarvestMessage.Builder> builderCaptor = 
                ArgumentCaptor.forClass(TerraHarvestMessage.Builder.class);
        verify(m_EncryptService).encryptMessage(builderCaptor.capture(), eq(payload));
        TerraHarvestMessage.Builder builder = builderCaptor.getValue();
        
        //Verify source ID for the request is used as the destination ID of the response and not the channel's remote
        //system ID.
        assertThat(builder.getDestId(), is(sourceId));
    }
/**
     * Verify that the response message uses source ID of request message since the remote channel system ID does not
     * match that of the requests source ID.
     */
Verify that the response message uses source ID of request message since the remote channel system ID does not
match that of the requests source ID.
Verify that the response message uses source ID of request message since the remote channel system ID does not match that of the requests source ID .
@Test
    public void testQueueResponseWithVaryingId() throws IOException
    {
        int messageId = 100;
        int sourceId = 50;
        MissionProgrammingNamespace requestMessage = MissionProgrammingNamespace.newBuilder()
                .setType(MissionProgrammingMessageType.GetTemplatesRequest).build();
        TerraHarvestMessage request = 
                createMessageWithDestSource(sourceId, m_LocalId, 0 , Namespace.MissionProgramming, requestMessage);
        MissionProgramTemplate template = MissionProgramTemplate.newBuilder().setName("test").setSource("src").build();
        GetTemplatesResponseData getTemplateData = GetTemplatesResponseData.newBuilder().addTemplate(template).build();
        MissionProgrammingNamespace responseMessage = MissionProgrammingNamespace.newBuilder()
                .setType(MissionProgrammingMessageType.GetTemplatesResponse)
                .setData(getTemplateData.toByteString()).build();
        TerraHarvestMessage response = 
                createTerraHarvestMessage(messageId, Namespace.MissionProgramming, responseMessage, true);
        TerraHarvestPayload payload = TerraHarvestPayload.parseFrom(response.getTerraHarvestPayload());
        when(m_EncryptService.encryptMessage(Mockito.any(Builder.class), Mockito.any(TerraHarvestPayload.class))).
            thenReturn(response);
        when(m_RemoteChannelLookup.getChannelSystemId(m_Channel)).thenReturn(m_RemoteId);
        boolean result = m_SUT.queueMessageResponse(request, payload, m_Channel);
        assertThat("message is queued as reported by channel", result, is(true));
        verify(m_Channel).queueMessage(response);
        ArgumentCaptor<TerraHarvestMessage.Builder> builderCaptor = 
                ArgumentCaptor.forClass(TerraHarvestMessage.Builder.class);
        verify(m_EncryptService).encryptMessage(builderCaptor.capture(), eq(payload));
        TerraHarvestMessage.Builder builder = builderCaptor.getValue();
        assertThat(builder.getDestId(), is(sourceId));
    }
@ Test public void testQueueResponseWithVaryingId ( ) throws IOException { int messageId = 100 ; int sourceId = 50 ; MissionProgrammingNamespace requestMessage = MissionProgrammingNamespace . newBuilder ( ) . setType ( MissionProgrammingMessageType . GetTemplatesRequest ) . build ( ) ; TerraHarvestMessage request = createMessageWithDestSource ( sourceId , m_LocalId , 0 , Namespace . MissionProgramming , requestMessage ) ; MissionProgramTemplate template = MissionProgramTemplate . newBuilder ( ) . setName ( "test" ) . setSource ( "src" ) . build ( ) ; GetTemplatesResponseData getTemplateData = GetTemplatesResponseData . newBuilder ( ) . addTemplate ( template ) . build ( ) ; MissionProgrammingNamespace responseMessage = MissionProgrammingNamespace . newBuilder ( ) . setType ( MissionProgrammingMessageType . GetTemplatesResponse ) . setData ( getTemplateData . toByteString ( ) ) . build ( ) ; TerraHarvestMessage response = createTerraHarvestMessage ( messageId , Namespace . MissionProgramming , responseMessage , true ) ; TerraHarvestPayload payload = TerraHarvestPayload . parseFrom ( response . getTerraHarvestPayload ( ) ) ; when ( m_EncryptService . encryptMessage ( Mockito . any ( Builder . class ) , Mockito . any ( TerraHarvestPayload . class ) ) ) . thenReturn ( response ) ; when ( m_RemoteChannelLookup . getChannelSystemId ( m_Channel ) ) . thenReturn ( m_RemoteId ) ; boolean result = m_SUT . queueMessageResponse ( request , payload , m_Channel ) ; assertThat ( "message is queued as reported by channel" , result , is ( true ) ) ; verify ( m_Channel ) . queueMessage ( response ) ; ArgumentCaptor < TerraHarvestMessage . Builder > builderCaptor = ArgumentCaptor . forClass ( TerraHarvestMessage . Builder . class ) ; verify ( m_EncryptService ) . encryptMessage ( builderCaptor . capture ( ) , eq ( payload ) ) ; TerraHarvestMessage . Builder builder = builderCaptor . getValue ( ) ; assertThat ( builder . getDestId ( ) , is ( sourceId ) ) ; }
Verify that the response message uses source ID of request message since the remote channel system ID does not
 match that of the requests source ID.
Verify that the response message uses source ID of request message since the remote channel system ID does not match that of the requests source ID .
// id to use for the request and response // id for the remote channel as returned by the remote channel lookup. // construct fake request message that should be used by service to construct the response // construct data message // verify message is sent to the associated channel //Verify source ID for the request is used as the destination ID of the response and not the channel's remote //system ID.