mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/messaging/TestMessageSenderImpl.java
@Test
    public void testSendBaseMessageException() 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, 0xdeadbeef, 0 , Namespace.Base, baseNamespace);
        
        TerraHarvestPayload payload = TerraHarvestPayload.parseFrom(request.getTerraHarvestPayload());
        
        when(m_EncryptService.encryptMessage(Mockito.any(Builder.class), Mockito.any(TerraHarvestPayload.class))).
            thenReturn(request);
                
        // try sending to bad id, should throw exception
        try
        {
            m_SUT.trySendMessage(0xdeadbeef, payload, EncryptType.NONE);
            fail("Expecting exception, invalid destination id");
        }
        catch (IllegalArgumentException e)
        {
            
        }
        
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin).postEvent(eventCaptor.capture());
        
        Event sendEvent = eventCaptor.getValue();
        assertThat(sendEvent.getTopic(), is(RemoteConstants.TOPIC_MESSAGE_SEND_UNREACHABLE_DEST));
        assertThat(sendEvent.getProperty(RemoteConstants.EVENT_PROP_DEST_ID), is(0xdeadbeef));
        assertThat(sendEvent.getProperty(RemoteConstants.EVENT_PROP_SOURCE_ID), is(m_LocalId));
        assertThat(sendEvent.getProperty(RemoteConstants.EVENT_PROP_MESSAGE), is(request));
    }
/**
     * Verify that when an invalid destination id is passed, the send fails.
     */
Verify that when an invalid destination id is passed, the send fails.
Verify that when an invalid destination id is passed the send fails .
@Test
    public void testSendBaseMessageException() 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, 0xdeadbeef, 0 , Namespace.Base, baseNamespace);
        TerraHarvestPayload payload = TerraHarvestPayload.parseFrom(request.getTerraHarvestPayload());
        when(m_EncryptService.encryptMessage(Mockito.any(Builder.class), Mockito.any(TerraHarvestPayload.class))).
            thenReturn(request);
        try
        {
            m_SUT.trySendMessage(0xdeadbeef, payload, EncryptType.NONE);
            fail("Expecting exception, invalid destination id");
        }
        catch (IllegalArgumentException e)
        {
        }
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin).postEvent(eventCaptor.capture());
        Event sendEvent = eventCaptor.getValue();
        assertThat(sendEvent.getTopic(), is(RemoteConstants.TOPIC_MESSAGE_SEND_UNREACHABLE_DEST));
        assertThat(sendEvent.getProperty(RemoteConstants.EVENT_PROP_DEST_ID), is(0xdeadbeef));
        assertThat(sendEvent.getProperty(RemoteConstants.EVENT_PROP_SOURCE_ID), is(m_LocalId));
        assertThat(sendEvent.getProperty(RemoteConstants.EVENT_PROP_MESSAGE), is(request));
    }
@ Test public void testSendBaseMessageException ( ) 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 , 0xdeadbeef , 0 , Namespace . Base , baseNamespace ) ; TerraHarvestPayload payload = TerraHarvestPayload . parseFrom ( request . getTerraHarvestPayload ( ) ) ; when ( m_EncryptService . encryptMessage ( Mockito . any ( Builder . class ) , Mockito . any ( TerraHarvestPayload . class ) ) ) . thenReturn ( request ) ; try { m_SUT . trySendMessage ( 0xdeadbeef , payload , EncryptType . NONE ) ; fail ( "Expecting exception, invalid destination id" ) ; } catch ( IllegalArgumentException e ) { } ArgumentCaptor < Event > eventCaptor = ArgumentCaptor . forClass ( Event . class ) ; verify ( m_EventAdmin ) . postEvent ( eventCaptor . capture ( ) ) ; Event sendEvent = eventCaptor . getValue ( ) ; assertThat ( sendEvent . getTopic ( ) , is ( RemoteConstants . TOPIC_MESSAGE_SEND_UNREACHABLE_DEST ) ) ; assertThat ( sendEvent . getProperty ( RemoteConstants . EVENT_PROP_DEST_ID ) , is ( 0xdeadbeef ) ) ; assertThat ( sendEvent . getProperty ( RemoteConstants . EVENT_PROP_SOURCE_ID ) , is ( m_LocalId ) ) ; assertThat ( sendEvent . getProperty ( RemoteConstants . EVENT_PROP_MESSAGE ) , is ( request ) ) ; }
Verify that when an invalid destination id is passed, the send fails.
Verify that when an invalid destination id is passed the send fails .
// construct data message to send // try sending to bad id, should throw exception