mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/messaging/TestMessageSenderImpl.java
@Test
    public void testQueueBaseMessage() throws IOException
    {
        // construct 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());
        
        when(m_EncryptService.encryptMessage(Mockito.any(Builder.class), Mockito.any(TerraHarvestPayload.class))).
            thenReturn(request);
        
        boolean result = m_SUT.queueMessage(m_RemoteId, payload, request.getEncryptType(), null);
        assertThat("message is queued/sent as reported by channel", result, is(true));
        
        // verify message is sent to the associated channel with correct namespace
        ArgumentCaptor<TerraHarvestMessage> messageCaptor = ArgumentCaptor.forClass(TerraHarvestMessage.class);
        verify(m_Channel).trySendMessage(messageCaptor.capture());
        TerraHarvestPayload payLoadTest = TerraHarvestPayload.parseFrom(messageCaptor.getValue().
                getTerraHarvestPayload());
        assertThat(payLoadTest.getNamespace(), is(Namespace.Base));

        // verify not queued as message was sent out
        verify(m_Channel, never()).queueMessage(Mockito.any(TerraHarvestMessage.class));
        
        // make channel return false now to see that message will be queued, but report queuing as successful
        when(m_Channel.trySendMessage(Mockito.any(TerraHarvestMessage.class))).thenReturn(false);
        when(m_Channel.queueMessage(Mockito.any(TerraHarvestMessage.class))).thenReturn(true);

        BaseNamespace baseNamespace = BaseNamespace.newBuilder().
                setType(BaseMessageType.ControllerInfo).
                setData(systemInfoData.toByteString()).build();
        
        request = createMessageWithDestSource(m_LocalId, m_RemoteId, 0 , Namespace.Base, baseNamespace);
        
        when(m_EncryptService.encryptMessage(Mockito.any(Builder.class), Mockito.any(TerraHarvestPayload.class))).
            thenReturn(request);
        
        // replay
        result = m_SUT.queueMessage(m_RemoteId, payload, request.getEncryptType(), null);
        assertThat("message is queued/sent as reported by channel", result, is(true));
        
        // verify queued since message could not be sent out
        verify(m_Channel).queueMessage(messageCaptor.capture());
        payLoadTest = TerraHarvestPayload.parseFrom(messageCaptor.getValue().
                getTerraHarvestPayload());
        assertThat(payLoadTest.getNamespace(), is(Namespace.Base));
        // verify inner namespace message
        BaseNamespace baseMessageResponse = BaseNamespace.parseFrom(payLoadTest.getNamespaceMessage());
        assertThat(baseMessageResponse.getType(), is(BaseMessageType.ControllerInfo));
        assertThat(baseMessageResponse.getData(), is(systemInfoData.toByteString()));
        
        // make channel return false now to see that message will be reported as not queue
        when(m_Channel.queueMessage(Mockito.any(TerraHarvestMessage.class))).thenReturn(false);

        // send message again with no data
        result = m_SUT.queueMessage(m_RemoteId, payload, request.getEncryptType(), null);
        assertThat("message is not queued as reported by channel", result, is(false));
    }
/**
     * Verifies that the queue remote base message method will pass the correct message.  
     *  
     * Verifies message is sent to channel and queued if could not be successfully sent.
     */
Verifies that the queue remote base message method will pass the correct message.

Verifies message is sent to channel and queued if could not be successfully sent.
Verifies that the queue remote base message method will pass the correct message . Verifies message is sent to channel and queued if could not be successfully sent .
@Test
    public void testQueueBaseMessage() throws IOException
    {
        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_EncryptService.encryptMessage(Mockito.any(Builder.class), Mockito.any(TerraHarvestPayload.class))).
            thenReturn(request);
        boolean result = m_SUT.queueMessage(m_RemoteId, payload, request.getEncryptType(), null);
        assertThat("message is queued/sent as reported by channel", result, is(true));
        ArgumentCaptor<TerraHarvestMessage> messageCaptor = ArgumentCaptor.forClass(TerraHarvestMessage.class);
        verify(m_Channel).trySendMessage(messageCaptor.capture());
        TerraHarvestPayload payLoadTest = TerraHarvestPayload.parseFrom(messageCaptor.getValue().
                getTerraHarvestPayload());
        assertThat(payLoadTest.getNamespace(), is(Namespace.Base));
        verify(m_Channel, never()).queueMessage(Mockito.any(TerraHarvestMessage.class));
        when(m_Channel.trySendMessage(Mockito.any(TerraHarvestMessage.class))).thenReturn(false);
        when(m_Channel.queueMessage(Mockito.any(TerraHarvestMessage.class))).thenReturn(true);
        BaseNamespace baseNamespace = BaseNamespace.newBuilder().
                setType(BaseMessageType.ControllerInfo).
                setData(systemInfoData.toByteString()).build();
        request = createMessageWithDestSource(m_LocalId, m_RemoteId, 0 , Namespace.Base, baseNamespace);
        when(m_EncryptService.encryptMessage(Mockito.any(Builder.class), Mockito.any(TerraHarvestPayload.class))).
            thenReturn(request);
        result = m_SUT.queueMessage(m_RemoteId, payload, request.getEncryptType(), null);
        assertThat("message is queued/sent as reported by channel", result, is(true));
        verify(m_Channel).queueMessage(messageCaptor.capture());
        payLoadTest = TerraHarvestPayload.parseFrom(messageCaptor.getValue().
                getTerraHarvestPayload());
        assertThat(payLoadTest.getNamespace(), is(Namespace.Base));
        BaseNamespace baseMessageResponse = BaseNamespace.parseFrom(payLoadTest.getNamespaceMessage());
        assertThat(baseMessageResponse.getType(), is(BaseMessageType.ControllerInfo));
        assertThat(baseMessageResponse.getData(), is(systemInfoData.toByteString()));
        when(m_Channel.queueMessage(Mockito.any(TerraHarvestMessage.class))).thenReturn(false);
        result = m_SUT.queueMessage(m_RemoteId, payload, request.getEncryptType(), null);
        assertThat("message is not queued as reported by channel", result, is(false));
    }
@ Test public void testQueueBaseMessage ( ) throws IOException { 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_EncryptService . encryptMessage ( Mockito . any ( Builder . class ) , Mockito . any ( TerraHarvestPayload . class ) ) ) . thenReturn ( request ) ; boolean result = m_SUT . queueMessage ( m_RemoteId , payload , request . getEncryptType ( ) , null ) ; assertThat ( "message is queued/sent as reported by channel" , result , is ( true ) ) ; ArgumentCaptor < TerraHarvestMessage > messageCaptor = ArgumentCaptor . forClass ( TerraHarvestMessage . class ) ; verify ( m_Channel ) . trySendMessage ( messageCaptor . capture ( ) ) ; TerraHarvestPayload payLoadTest = TerraHarvestPayload . parseFrom ( messageCaptor . getValue ( ) . getTerraHarvestPayload ( ) ) ; assertThat ( payLoadTest . getNamespace ( ) , is ( Namespace . Base ) ) ; verify ( m_Channel , never ( ) ) . queueMessage ( Mockito . any ( TerraHarvestMessage . class ) ) ; when ( m_Channel . trySendMessage ( Mockito . any ( TerraHarvestMessage . class ) ) ) . thenReturn ( false ) ; when ( m_Channel . queueMessage ( Mockito . any ( TerraHarvestMessage . class ) ) ) . thenReturn ( true ) ; BaseNamespace baseNamespace = BaseNamespace . newBuilder ( ) . setType ( BaseMessageType . ControllerInfo ) . setData ( systemInfoData . toByteString ( ) ) . build ( ) ; request = createMessageWithDestSource ( m_LocalId , m_RemoteId , 0 , Namespace . Base , baseNamespace ) ; when ( m_EncryptService . encryptMessage ( Mockito . any ( Builder . class ) , Mockito . any ( TerraHarvestPayload . class ) ) ) . thenReturn ( request ) ; result = m_SUT . queueMessage ( m_RemoteId , payload , request . getEncryptType ( ) , null ) ; assertThat ( "message is queued/sent as reported by channel" , result , is ( true ) ) ; verify ( m_Channel ) . queueMessage ( messageCaptor . capture ( ) ) ; payLoadTest = TerraHarvestPayload . parseFrom ( messageCaptor . getValue ( ) . getTerraHarvestPayload ( ) ) ; assertThat ( payLoadTest . getNamespace ( ) , is ( Namespace . Base ) ) ; BaseNamespace baseMessageResponse = BaseNamespace . parseFrom ( payLoadTest . getNamespaceMessage ( ) ) ; assertThat ( baseMessageResponse . getType ( ) , is ( BaseMessageType . ControllerInfo ) ) ; assertThat ( baseMessageResponse . getData ( ) , is ( systemInfoData . toByteString ( ) ) ) ; when ( m_Channel . queueMessage ( Mockito . any ( TerraHarvestMessage . class ) ) ) . thenReturn ( false ) ; result = m_SUT . queueMessage ( m_RemoteId , payload , request . getEncryptType ( ) , null ) ; assertThat ( "message is not queued as reported by channel" , result , is ( false ) ) ; }
Verifies that the queue remote base message method will pass the correct message.
Verifies that the queue remote base message method will pass the correct message .
// construct data message to send // verify message is sent to the associated channel with correct namespace // verify not queued as message was sent out // make channel return false now to see that message will be queued, but report queuing as successful // replay // verify queued since message could not be sent out // verify inner namespace message // make channel return false now to see that message will be reported as not queue // send message again with no data