mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/messaging/TestMessageSenderImpl.java
@Test
    public void testQueueMessageByChannel() throws InvalidProtocolBufferException
    {
        ResponseHandler handler = mock(ResponseHandler.class);
        
        // construct test data message to send
        ControllerInfoData systemInfoData = ControllerInfoData.newBuilder().setName("blah").build();
        TerraHarvestMessage request = 
                createMessageWithDestSource(m_LocalId, m_RemoteId, 0 , Namespace.Base, systemInfoData);
        TerraHarvestPayload payload = TerraHarvestPayload.parseFrom(request.getTerraHarvestPayload());
        
        //Mock behavior.
        when(m_RemoteChannelLookup.getChannelSystemId(m_Channel)).thenReturn(m_RemoteId);
        when(m_Channel.queueMessage(Mockito.any(TerraHarvestMessage.class))).thenReturn(true);
        when(m_RemoteSettings.getEncryptionMode()).thenReturn(EncryptionMode.NONE);
        when(m_RemoteSystemEncryption.getEncryptType(m_RemoteId)).thenReturn(EncryptType.NONE);
        when(m_EncryptService.encryptMessage(Mockito.any(Builder.class), Mockito.any(TerraHarvestPayload.class))).
            thenReturn(request);
        
        //Verify true is return if the message is successfully queue to the channel. No handler so list should be empty.
        assertThat(m_SUT.queueMessage(m_Channel, payload, null), is(true));
        assertThat(m_SUT.getResponseHandleRegCount(), is(0));
        
        //Verify true is return if the message is successfully queue to the channel. Also verify that the response 
        //handler was added.
        assertThat(m_SUT.queueMessage(m_Channel, payload, handler), is(true));
        assertThat(m_SUT.getResponseHandleRegCount(), is(1));
        
        //Mock failing to queue to channel.
        when(m_Channel.queueMessage(Mockito.any(TerraHarvestMessage.class))).thenReturn(false);
        
        //Verify false is returned if the message is not successfully queue to the channel. Also verify no that the
        //response handler count remains at one.
        assertThat(m_SUT.queueMessage(m_Channel, payload, handler), is(false));
        assertThat(m_SUT.getResponseHandleRegCount(), is(1));
    }
/**
     * Verify that a message can be queued for a specific remote channel.
     */
Verify that a message can be queued for a specific remote channel.
Verify that a message can be queued for a specific remote channel .
@Test
    public void testQueueMessageByChannel() throws InvalidProtocolBufferException
    {
        ResponseHandler handler = mock(ResponseHandler.class);
        ControllerInfoData systemInfoData = ControllerInfoData.newBuilder().setName("blah").build();
        TerraHarvestMessage request = 
                createMessageWithDestSource(m_LocalId, m_RemoteId, 0 , Namespace.Base, systemInfoData);
        TerraHarvestPayload payload = TerraHarvestPayload.parseFrom(request.getTerraHarvestPayload());
        when(m_RemoteChannelLookup.getChannelSystemId(m_Channel)).thenReturn(m_RemoteId);
        when(m_Channel.queueMessage(Mockito.any(TerraHarvestMessage.class))).thenReturn(true);
        when(m_RemoteSettings.getEncryptionMode()).thenReturn(EncryptionMode.NONE);
        when(m_RemoteSystemEncryption.getEncryptType(m_RemoteId)).thenReturn(EncryptType.NONE);
        when(m_EncryptService.encryptMessage(Mockito.any(Builder.class), Mockito.any(TerraHarvestPayload.class))).
            thenReturn(request);
        assertThat(m_SUT.queueMessage(m_Channel, payload, null), is(true));
        assertThat(m_SUT.getResponseHandleRegCount(), is(0));
        assertThat(m_SUT.queueMessage(m_Channel, payload, handler), is(true));
        assertThat(m_SUT.getResponseHandleRegCount(), is(1));
        when(m_Channel.queueMessage(Mockito.any(TerraHarvestMessage.class))).thenReturn(false);
        assertThat(m_SUT.queueMessage(m_Channel, payload, handler), is(false));
        assertThat(m_SUT.getResponseHandleRegCount(), is(1));
    }
@ Test public void testQueueMessageByChannel ( ) throws InvalidProtocolBufferException { ResponseHandler handler = mock ( ResponseHandler . class ) ; ControllerInfoData systemInfoData = ControllerInfoData . newBuilder ( ) . setName ( "blah" ) . build ( ) ; TerraHarvestMessage request = createMessageWithDestSource ( m_LocalId , m_RemoteId , 0 , Namespace . Base , systemInfoData ) ; TerraHarvestPayload payload = TerraHarvestPayload . parseFrom ( request . getTerraHarvestPayload ( ) ) ; when ( m_RemoteChannelLookup . getChannelSystemId ( m_Channel ) ) . thenReturn ( m_RemoteId ) ; when ( m_Channel . queueMessage ( Mockito . any ( TerraHarvestMessage . class ) ) ) . thenReturn ( true ) ; when ( m_RemoteSettings . getEncryptionMode ( ) ) . thenReturn ( EncryptionMode . NONE ) ; when ( m_RemoteSystemEncryption . getEncryptType ( m_RemoteId ) ) . thenReturn ( EncryptType . NONE ) ; when ( m_EncryptService . encryptMessage ( Mockito . any ( Builder . class ) , Mockito . any ( TerraHarvestPayload . class ) ) ) . thenReturn ( request ) ; assertThat ( m_SUT . queueMessage ( m_Channel , payload , null ) , is ( true ) ) ; assertThat ( m_SUT . getResponseHandleRegCount ( ) , is ( 0 ) ) ; assertThat ( m_SUT . queueMessage ( m_Channel , payload , handler ) , is ( true ) ) ; assertThat ( m_SUT . getResponseHandleRegCount ( ) , is ( 1 ) ) ; when ( m_Channel . queueMessage ( Mockito . any ( TerraHarvestMessage . class ) ) ) . thenReturn ( false ) ; assertThat ( m_SUT . queueMessage ( m_Channel , payload , handler ) , is ( false ) ) ; assertThat ( m_SUT . getResponseHandleRegCount ( ) , is ( 1 ) ) ; }
Verify that a message can be queued for a specific remote channel.
Verify that a message can be queued for a specific remote channel .
// construct test data message to send //Mock behavior. //Verify true is return if the message is successfully queue to the channel. No handler so list should be empty. //Verify true is return if the message is successfully queue to the channel. Also verify that the response  //handler was added. //Mock failing to queue to channel. //Verify false is returned if the message is not successfully queue to the channel. Also verify no that the //response handler count remains at one.