mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/messaging/TestMessageSenderImpl.java
@Test
    public void testResponseSystemIds() throws IOException
    {
        // id to use for the request and response
        int messageId = 100;  
        //first build a TerraHarvestPayload message
        TerraHarvestPayload payload = TerraHarvestPayload.newBuilder().
            setNamespace(Namespace.Base).
            setNamespaceMessage(ByteString.EMPTY).
            build();
        // create the original request message that the response will be based on
        // required to be set Don't care what it is though
        TerraHarvestMessage request =  TerraHarvestMessageUtil.getPartialMessage()
                .setTerraHarvestPayload(payload.toByteString())
                .setSourceId(m_RemoteId)
                .setDestId(m_LocalId)
                .setMessageId(messageId).build();
        
        GenericErrorResponseData errorData = GenericErrorResponseData.newBuilder().
                setError(ErrorCode.ILLEGAL_STATE).
                setErrorDescription("Illegal State errror").build();
        BaseNamespace baseResponseMessage = BaseNamespace.newBuilder().
                setType(BaseMessageType.GenericErrorResponse).
                setData(errorData.toByteString()).build();
        TerraHarvestMessage response = 
                createMessageWithDestSource(m_LocalId, m_RemoteId, 100 , Namespace.Base, baseResponseMessage);
        
        when(m_EncryptService.encryptMessage(Mockito.any(Builder.class), Mockito.any(TerraHarvestPayload.class))).
            thenReturn(response);
        
        m_SUT.queueMessageResponse(request, TerraHarvestPayload.parseFrom(response.getTerraHarvestPayload()), 
            m_Channel);
        
        // messages submitted to the encryption service
        ArgumentCaptor<TerraHarvestMessage> messageCaptor = ArgumentCaptor.forClass(TerraHarvestMessage.class);
        verify(m_Channel).queueMessage(messageCaptor.capture());
        ArgumentCaptor<TerraHarvestPayload> payloadCaptor = ArgumentCaptor.forClass(TerraHarvestPayload.class);
        ArgumentCaptor<TerraHarvestMessage.Builder> builderCaptor = 
                ArgumentCaptor.forClass(TerraHarvestMessage.Builder.class);
        verify(m_EncryptService).encryptMessage(builderCaptor.capture(), payloadCaptor.capture());
        
        TerraHarvestPayload payLoadTest = TerraHarvestPayload.parseFrom(messageCaptor.getValue().
             getTerraHarvestPayload());
        TerraHarvestPayload payloadFromCaptor = payloadCaptor.getValue();
        assertThat(payloadFromCaptor, is(payLoadTest));

        //verify that fields are correct in the builder message before the built th message is returned
        //The source id should now be what was the dest id since this is a response message and vice a versa for
        //dest id, it should now be the source
        assertThat(builderCaptor.getValue().getSourceId(), is(messageCaptor.getValue().getSourceId()));
        assertThat(messageCaptor.getValue().getSourceId(), is(m_LocalId));
        assertThat(builderCaptor.getValue().getDestId(), is(messageCaptor.getValue().getDestId()));
        assertThat(messageCaptor.getValue().getDestId(), is(m_RemoteId));
        assertThat(builderCaptor.getValue().getMessageId(), is(messageCaptor.getValue().getMessageId()));
        assertThat(messageCaptor.getValue().getMessageId(), is(messageId));
    }
/**
     * Verify that when a message is a response that the source information from the request is correctly transferred
     * to be the destination.
     */
Verify that when a message is a response that the source information from the request is correctly transferred
to be the destination.
Verify that when a message is a response that the source information from the request is correctly transferred to be the destination .
@Test
    public void testResponseSystemIds() throws IOException
    {
        int messageId = 100;  
        TerraHarvestPayload payload = TerraHarvestPayload.newBuilder().
            setNamespace(Namespace.Base).
            setNamespaceMessage(ByteString.EMPTY).
            build();
        TerraHarvestMessage request =  TerraHarvestMessageUtil.getPartialMessage()
                .setTerraHarvestPayload(payload.toByteString())
                .setSourceId(m_RemoteId)
                .setDestId(m_LocalId)
                .setMessageId(messageId).build();
        GenericErrorResponseData errorData = GenericErrorResponseData.newBuilder().
                setError(ErrorCode.ILLEGAL_STATE).
                setErrorDescription("Illegal State errror").build();
        BaseNamespace baseResponseMessage = BaseNamespace.newBuilder().
                setType(BaseMessageType.GenericErrorResponse).
                setData(errorData.toByteString()).build();
        TerraHarvestMessage response = 
                createMessageWithDestSource(m_LocalId, m_RemoteId, 100 , Namespace.Base, baseResponseMessage);
        when(m_EncryptService.encryptMessage(Mockito.any(Builder.class), Mockito.any(TerraHarvestPayload.class))).
            thenReturn(response);
        m_SUT.queueMessageResponse(request, TerraHarvestPayload.parseFrom(response.getTerraHarvestPayload()), 
            m_Channel);
        ArgumentCaptor<TerraHarvestMessage> messageCaptor = ArgumentCaptor.forClass(TerraHarvestMessage.class);
        verify(m_Channel).queueMessage(messageCaptor.capture());
        ArgumentCaptor<TerraHarvestPayload> payloadCaptor = ArgumentCaptor.forClass(TerraHarvestPayload.class);
        ArgumentCaptor<TerraHarvestMessage.Builder> builderCaptor = 
                ArgumentCaptor.forClass(TerraHarvestMessage.Builder.class);
        verify(m_EncryptService).encryptMessage(builderCaptor.capture(), payloadCaptor.capture());
        TerraHarvestPayload payLoadTest = TerraHarvestPayload.parseFrom(messageCaptor.getValue().
             getTerraHarvestPayload());
        TerraHarvestPayload payloadFromCaptor = payloadCaptor.getValue();
        assertThat(payloadFromCaptor, is(payLoadTest));
        assertThat(builderCaptor.getValue().getSourceId(), is(messageCaptor.getValue().getSourceId()));
        assertThat(messageCaptor.getValue().getSourceId(), is(m_LocalId));
        assertThat(builderCaptor.getValue().getDestId(), is(messageCaptor.getValue().getDestId()));
        assertThat(messageCaptor.getValue().getDestId(), is(m_RemoteId));
        assertThat(builderCaptor.getValue().getMessageId(), is(messageCaptor.getValue().getMessageId()));
        assertThat(messageCaptor.getValue().getMessageId(), is(messageId));
    }
@ Test public void testResponseSystemIds ( ) throws IOException { int messageId = 100 ; TerraHarvestPayload payload = TerraHarvestPayload . newBuilder ( ) . setNamespace ( Namespace . Base ) . setNamespaceMessage ( ByteString . EMPTY ) . build ( ) ; TerraHarvestMessage request = TerraHarvestMessageUtil . getPartialMessage ( ) . setTerraHarvestPayload ( payload . toByteString ( ) ) . setSourceId ( m_RemoteId ) . setDestId ( m_LocalId ) . setMessageId ( messageId ) . build ( ) ; GenericErrorResponseData errorData = GenericErrorResponseData . newBuilder ( ) . setError ( ErrorCode . ILLEGAL_STATE ) . setErrorDescription ( "Illegal State errror" ) . build ( ) ; BaseNamespace baseResponseMessage = BaseNamespace . newBuilder ( ) . setType ( BaseMessageType . GenericErrorResponse ) . setData ( errorData . toByteString ( ) ) . build ( ) ; TerraHarvestMessage response = createMessageWithDestSource ( m_LocalId , m_RemoteId , 100 , Namespace . Base , baseResponseMessage ) ; when ( m_EncryptService . encryptMessage ( Mockito . any ( Builder . class ) , Mockito . any ( TerraHarvestPayload . class ) ) ) . thenReturn ( response ) ; m_SUT . queueMessageResponse ( request , TerraHarvestPayload . parseFrom ( response . getTerraHarvestPayload ( ) ) , m_Channel ) ; ArgumentCaptor < TerraHarvestMessage > messageCaptor = ArgumentCaptor . forClass ( TerraHarvestMessage . class ) ; verify ( m_Channel ) . queueMessage ( messageCaptor . capture ( ) ) ; ArgumentCaptor < TerraHarvestPayload > payloadCaptor = ArgumentCaptor . forClass ( TerraHarvestPayload . class ) ; ArgumentCaptor < TerraHarvestMessage . Builder > builderCaptor = ArgumentCaptor . forClass ( TerraHarvestMessage . Builder . class ) ; verify ( m_EncryptService ) . encryptMessage ( builderCaptor . capture ( ) , payloadCaptor . capture ( ) ) ; TerraHarvestPayload payLoadTest = TerraHarvestPayload . parseFrom ( messageCaptor . getValue ( ) . getTerraHarvestPayload ( ) ) ; TerraHarvestPayload payloadFromCaptor = payloadCaptor . getValue ( ) ; assertThat ( payloadFromCaptor , is ( payLoadTest ) ) ; assertThat ( builderCaptor . getValue ( ) . getSourceId ( ) , is ( messageCaptor . getValue ( ) . getSourceId ( ) ) ) ; assertThat ( messageCaptor . getValue ( ) . getSourceId ( ) , is ( m_LocalId ) ) ; assertThat ( builderCaptor . getValue ( ) . getDestId ( ) , is ( messageCaptor . getValue ( ) . getDestId ( ) ) ) ; assertThat ( messageCaptor . getValue ( ) . getDestId ( ) , is ( m_RemoteId ) ) ; assertThat ( builderCaptor . getValue ( ) . getMessageId ( ) , is ( messageCaptor . getValue ( ) . getMessageId ( ) ) ) ; assertThat ( messageCaptor . getValue ( ) . getMessageId ( ) , is ( messageId ) ) ; }
Verify that when a message is a response that the source information from the request is correctly transferred
 to be the destination.
Verify that when a message is a response that the source information from the request is correctly transferred to be the destination .
// id to use for the request and response //first build a TerraHarvestPayload message // create the original request message that the response will be based on // required to be set Don't care what it is though // messages submitted to the encryption service //verify that fields are correct in the builder message before the built th message is returned //The source id should now be what was the dest id since this is a response message and vice a versa for //dest id, it should now be the source