mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/messaging/TestMessageSenderImpl.java
@Test
    public void testQueueResponse() throws IOException
    {
        // id to use for the request and response
        int messageId = 100;
        
        // 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(m_RemoteId, 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);
        
        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 with proper fields set
        ArgumentCaptor<TerraHarvestMessage> messageCaptor = ArgumentCaptor.forClass(TerraHarvestMessage.class);
        verify(m_Channel).queueMessage(messageCaptor.capture());
        TerraHarvestPayload payLoadTest = TerraHarvestPayload.parseFrom(messageCaptor.getValue().
                getTerraHarvestPayload());
        assertThat(messageCaptor.getValue().getSourceId(), is(m_LocalId));
        assertThat(messageCaptor.getValue().getDestId(), is(m_RemoteId));
        assertThat(messageCaptor.getValue().getMessageId(), is(messageId));
        assertThat(messageCaptor.getValue().getIsResponse(), is(true));
        assertThat(payLoadTest.getNamespace(), is(Namespace.MissionProgramming));
        assertThat(messageCaptor.getValue().getMessageId(), is(messageId));
         
        // verify inner namespace message
        MissionProgrammingNamespace messageResponse = 
                MissionProgrammingNamespace.parseFrom(payLoadTest.getNamespaceMessage());
        assertThat(messageResponse.getType(), is(MissionProgrammingMessageType.GetTemplatesResponse));
        assertThat(messageResponse.getData(), is(getTemplateData.toByteString()));
    }
/**
     * Verifies that the queue remote message response method will pass the correct message based on the request.
     *  
     * Verify the channel used is the one requested and not from the lookup.
     * 
     * Verify the message is passed to the channel queue.
     */
Verifies that the queue remote message response method will pass the correct message based on the request.

Verify the channel used is the one requested and not from the lookup.

Verify the message is passed to the channel queue.
Verifies that the queue remote message response method will pass the correct message based on the request . Verify the channel used is the one requested and not from the lookup . Verify the message is passed to the channel queue .
@Test
    public void testQueueResponse() throws IOException
    {
        int messageId = 100;
        MissionProgrammingNamespace requestMessage = MissionProgrammingNamespace.newBuilder()
                .setType(MissionProgrammingMessageType.GetTemplatesRequest).build();
        TerraHarvestMessage request = 
                createMessageWithDestSource(m_RemoteId, 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);
        boolean result = m_SUT.queueMessageResponse(request, payload, m_Channel);
        assertThat("message is queued as reported by channel", result, is(true));
        ArgumentCaptor<TerraHarvestMessage> messageCaptor = ArgumentCaptor.forClass(TerraHarvestMessage.class);
        verify(m_Channel).queueMessage(messageCaptor.capture());
        TerraHarvestPayload payLoadTest = TerraHarvestPayload.parseFrom(messageCaptor.getValue().
                getTerraHarvestPayload());
        assertThat(messageCaptor.getValue().getSourceId(), is(m_LocalId));
        assertThat(messageCaptor.getValue().getDestId(), is(m_RemoteId));
        assertThat(messageCaptor.getValue().getMessageId(), is(messageId));
        assertThat(messageCaptor.getValue().getIsResponse(), is(true));
        assertThat(payLoadTest.getNamespace(), is(Namespace.MissionProgramming));
        assertThat(messageCaptor.getValue().getMessageId(), is(messageId));
        MissionProgrammingNamespace messageResponse = 
                MissionProgrammingNamespace.parseFrom(payLoadTest.getNamespaceMessage());
        assertThat(messageResponse.getType(), is(MissionProgrammingMessageType.GetTemplatesResponse));
        assertThat(messageResponse.getData(), is(getTemplateData.toByteString()));
    }
@ Test public void testQueueResponse ( ) throws IOException { int messageId = 100 ; MissionProgrammingNamespace requestMessage = MissionProgrammingNamespace . newBuilder ( ) . setType ( MissionProgrammingMessageType . GetTemplatesRequest ) . build ( ) ; TerraHarvestMessage request = createMessageWithDestSource ( m_RemoteId , 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 ) ; boolean result = m_SUT . queueMessageResponse ( request , payload , m_Channel ) ; assertThat ( "message is queued as reported by channel" , result , is ( true ) ) ; ArgumentCaptor < TerraHarvestMessage > messageCaptor = ArgumentCaptor . forClass ( TerraHarvestMessage . class ) ; verify ( m_Channel ) . queueMessage ( messageCaptor . capture ( ) ) ; TerraHarvestPayload payLoadTest = TerraHarvestPayload . parseFrom ( messageCaptor . getValue ( ) . getTerraHarvestPayload ( ) ) ; assertThat ( messageCaptor . getValue ( ) . getSourceId ( ) , is ( m_LocalId ) ) ; assertThat ( messageCaptor . getValue ( ) . getDestId ( ) , is ( m_RemoteId ) ) ; assertThat ( messageCaptor . getValue ( ) . getMessageId ( ) , is ( messageId ) ) ; assertThat ( messageCaptor . getValue ( ) . getIsResponse ( ) , is ( true ) ) ; assertThat ( payLoadTest . getNamespace ( ) , is ( Namespace . MissionProgramming ) ) ; assertThat ( messageCaptor . getValue ( ) . getMessageId ( ) , is ( messageId ) ) ; MissionProgrammingNamespace messageResponse = MissionProgrammingNamespace . parseFrom ( payLoadTest . getNamespaceMessage ( ) ) ; assertThat ( messageResponse . getType ( ) , is ( MissionProgrammingMessageType . GetTemplatesResponse ) ) ; assertThat ( messageResponse . getData ( ) , is ( getTemplateData . toByteString ( ) ) ) ; }
Verifies that the queue remote message response method will pass the correct message based on the request.
Verifies that the queue remote message response method will pass the correct message based on the request .
// id to use for the request and response // 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 with proper fields set // verify inner namespace message