mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/messaging/TestMessageSenderImpl.java
@Test
    public void testSendBaseMessage() throws IOException
    {
        // construct data message to send
        ControllerInfoData systemInfoData = ControllerInfoData.newBuilder().setName("blah").build();
        BaseNamespace baseNamespace = BaseNamespace.newBuilder().
                setType(BaseMessageType.ControllerInfo).
                setData(systemInfoData.toByteString()).build();
        
        TerraHarvestMessage request = 
                createMessageWithDestSource(m_LocalId, m_RemoteId, 0 , Namespace.Base, baseNamespace);
        
        TerraHarvestPayload payload = TerraHarvestPayload.parseFrom(request.getTerraHarvestPayload());
        
        when(m_EncryptService.encryptMessage(Mockito.any(Builder.class), Mockito.any(TerraHarvestPayload.class))).
            thenReturn(request);
        
        boolean sent = m_SUT.trySendMessage(m_RemoteId, payload, EncryptType.NONE);
        assertThat("message reported as sent", sent, is(true));
        
        // verify message is sent to the associated channel with proper fields set
        ArgumentCaptor<TerraHarvestMessage> messageCaptor = ArgumentCaptor.forClass(TerraHarvestMessage.class);
        verify(m_Channel).trySendMessage(messageCaptor.capture());
        TerraHarvestPayload payLoadTest = TerraHarvestPayload.parseFrom(messageCaptor.getValue().
                getTerraHarvestPayload());
        assertThat(messageCaptor.getValue().getSourceId(), is(m_LocalId));
        assertThat(messageCaptor.getValue().getDestId(), is(m_RemoteId));
        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()));
    }
/**
     * Verify that the send base message method will pass the correct message based on the destination id.
     */
Verify that the send base message method will pass the correct message based on the destination id.
Verify that the send base message method will pass the correct message based on the destination id .
@Test
    public void testSendBaseMessage() throws IOException
    {
        ControllerInfoData systemInfoData = ControllerInfoData.newBuilder().setName("blah").build();
        BaseNamespace baseNamespace = BaseNamespace.newBuilder().
                setType(BaseMessageType.ControllerInfo).
                setData(systemInfoData.toByteString()).build();
        TerraHarvestMessage request = 
                createMessageWithDestSource(m_LocalId, m_RemoteId, 0 , Namespace.Base, baseNamespace);
        TerraHarvestPayload payload = TerraHarvestPayload.parseFrom(request.getTerraHarvestPayload());
        when(m_EncryptService.encryptMessage(Mockito.any(Builder.class), Mockito.any(TerraHarvestPayload.class))).
            thenReturn(request);
        boolean sent = m_SUT.trySendMessage(m_RemoteId, payload, EncryptType.NONE);
        assertThat("message reported as sent", sent, is(true));
        ArgumentCaptor<TerraHarvestMessage> messageCaptor = ArgumentCaptor.forClass(TerraHarvestMessage.class);
        verify(m_Channel).trySendMessage(messageCaptor.capture());
        TerraHarvestPayload payLoadTest = TerraHarvestPayload.parseFrom(messageCaptor.getValue().
                getTerraHarvestPayload());
        assertThat(messageCaptor.getValue().getSourceId(), is(m_LocalId));
        assertThat(messageCaptor.getValue().getDestId(), is(m_RemoteId));
        assertThat(payLoadTest.getNamespace(), is(Namespace.Base));
        BaseNamespace baseMessageResponse = BaseNamespace.parseFrom(payLoadTest.getNamespaceMessage());
        assertThat(baseMessageResponse.getType(), is(BaseMessageType.ControllerInfo));
        assertThat(baseMessageResponse.getData(), is(systemInfoData.toByteString()));
    }
@ Test public void testSendBaseMessage ( ) throws IOException { ControllerInfoData systemInfoData = ControllerInfoData . newBuilder ( ) . setName ( "blah" ) . build ( ) ; BaseNamespace baseNamespace = BaseNamespace . newBuilder ( ) . setType ( BaseMessageType . ControllerInfo ) . setData ( systemInfoData . toByteString ( ) ) . build ( ) ; TerraHarvestMessage request = createMessageWithDestSource ( m_LocalId , m_RemoteId , 0 , Namespace . Base , baseNamespace ) ; TerraHarvestPayload payload = TerraHarvestPayload . parseFrom ( request . getTerraHarvestPayload ( ) ) ; when ( m_EncryptService . encryptMessage ( Mockito . any ( Builder . class ) , Mockito . any ( TerraHarvestPayload . class ) ) ) . thenReturn ( request ) ; boolean sent = m_SUT . trySendMessage ( m_RemoteId , payload , EncryptType . NONE ) ; assertThat ( "message reported as sent" , sent , is ( true ) ) ; ArgumentCaptor < TerraHarvestMessage > messageCaptor = ArgumentCaptor . forClass ( TerraHarvestMessage . class ) ; verify ( m_Channel ) . trySendMessage ( messageCaptor . capture ( ) ) ; TerraHarvestPayload payLoadTest = TerraHarvestPayload . parseFrom ( messageCaptor . getValue ( ) . getTerraHarvestPayload ( ) ) ; assertThat ( messageCaptor . getValue ( ) . getSourceId ( ) , is ( m_LocalId ) ) ; assertThat ( messageCaptor . getValue ( ) . getDestId ( ) , is ( m_RemoteId ) ) ; assertThat ( payLoadTest . getNamespace ( ) , is ( Namespace . Base ) ) ; BaseNamespace baseMessageResponse = BaseNamespace . parseFrom ( payLoadTest . getNamespaceMessage ( ) ) ; assertThat ( baseMessageResponse . getType ( ) , is ( BaseMessageType . ControllerInfo ) ) ; assertThat ( baseMessageResponse . getData ( ) , is ( systemInfoData . toByteString ( ) ) ) ; }
Verify that the send base message method will pass the correct message based on the destination id.
Verify that the send base message method will pass the correct message based on the destination id .
// construct data message to send // verify message is sent to the associated channel with proper fields set // verify inner namespace message