mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/base/TestBaseMessageService.java
@Test
    public void testGenericHandleMessageWithTime() throws IOException
    {
        // construct a single message containing data within a namespace message
        ControllerInfoData systemInfoData = ControllerInfoData.newBuilder()
                .setName("test-name")
                .build();
        
        BaseNamespace baseNamespaceMessage = BaseNamespace.newBuilder()
                .setType(BaseMessageType.ControllerInfo)
                .setData(systemInfoData.toByteString())
                .build();
        
        TerraHarvestMessage message = createBaseMessage(baseNamespaceMessage);
        TerraHarvestPayload payload = createPayload(baseNamespaceMessage);
                
        // mock the channel the message came from
        RemoteChannel channel = mock(RemoteChannel.class);
        
        // replay
        m_SUT.handleMessage(message, payload, channel);
        
        // verify event is posted
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin).postEvent(eventCaptor.capture());
        Event postedEvent = eventCaptor.getValue();
        assertThat(postedEvent.getTopic(), is(RemoteConstants.TOPIC_MESSAGE_RECEIVED));
        assertThat((TerraHarvestMessage)postedEvent.getProperty(RemoteConstants.EVENT_PROP_MESSAGE), is(message));
        assertThat((String)postedEvent.getProperty(RemoteConstants.EVENT_PROP_MESSAGE_TYPE), 
                is(baseNamespaceMessage.getType().toString()));
        
         // Replay with time
        systemInfoData = ControllerInfoData.newBuilder()
                .setName("test-name")
                .setCurrentSystemTime(System.currentTimeMillis())
                .build();
        
        baseNamespaceMessage = BaseNamespace.newBuilder()
                .setType(BaseMessageType.ControllerInfo)
                .setData(systemInfoData.toByteString())
                .build();
        
        message = createBaseMessage(baseNamespaceMessage);
        payload = createPayload(baseNamespaceMessage);
        
        // replay
        m_SUT.handleMessage(message, payload, channel);
        
        // verify event is posted
        verify(m_EventAdmin, times(2)).postEvent(eventCaptor.capture());
        postedEvent = eventCaptor.getValue();
        assertThat(postedEvent.getTopic(), is(RemoteConstants.TOPIC_MESSAGE_RECEIVED));
        assertThat((TerraHarvestMessage)postedEvent.getProperty(RemoteConstants.EVENT_PROP_MESSAGE), is(message));
        assertThat((String)postedEvent.getProperty(RemoteConstants.EVENT_PROP_MESSAGE_TYPE), 
                is(baseNamespaceMessage.getType().toString()));
    }
/**
     * Verify generic handling of message, with the optional time and without. 
     */
Verify generic handling of message, with the optional time and without.
Verify generic handling of message with the optional time and without .
@Test
    public void testGenericHandleMessageWithTime() throws IOException
    {
        ControllerInfoData systemInfoData = ControllerInfoData.newBuilder()
                .setName("test-name")
                .build();
        BaseNamespace baseNamespaceMessage = BaseNamespace.newBuilder()
                .setType(BaseMessageType.ControllerInfo)
                .setData(systemInfoData.toByteString())
                .build();
        TerraHarvestMessage message = createBaseMessage(baseNamespaceMessage);
        TerraHarvestPayload payload = createPayload(baseNamespaceMessage);
        RemoteChannel channel = mock(RemoteChannel.class);
        m_SUT.handleMessage(message, payload, channel);
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin).postEvent(eventCaptor.capture());
        Event postedEvent = eventCaptor.getValue();
        assertThat(postedEvent.getTopic(), is(RemoteConstants.TOPIC_MESSAGE_RECEIVED));
        assertThat((TerraHarvestMessage)postedEvent.getProperty(RemoteConstants.EVENT_PROP_MESSAGE), is(message));
        assertThat((String)postedEvent.getProperty(RemoteConstants.EVENT_PROP_MESSAGE_TYPE), 
                is(baseNamespaceMessage.getType().toString()));
        systemInfoData = ControllerInfoData.newBuilder()
                .setName("test-name")
                .setCurrentSystemTime(System.currentTimeMillis())
                .build();
        baseNamespaceMessage = BaseNamespace.newBuilder()
                .setType(BaseMessageType.ControllerInfo)
                .setData(systemInfoData.toByteString())
                .build();
        message = createBaseMessage(baseNamespaceMessage);
        payload = createPayload(baseNamespaceMessage);
        m_SUT.handleMessage(message, payload, channel);
        verify(m_EventAdmin, times(2)).postEvent(eventCaptor.capture());
        postedEvent = eventCaptor.getValue();
        assertThat(postedEvent.getTopic(), is(RemoteConstants.TOPIC_MESSAGE_RECEIVED));
        assertThat((TerraHarvestMessage)postedEvent.getProperty(RemoteConstants.EVENT_PROP_MESSAGE), is(message));
        assertThat((String)postedEvent.getProperty(RemoteConstants.EVENT_PROP_MESSAGE_TYPE), 
                is(baseNamespaceMessage.getType().toString()));
    }
@ Test public void testGenericHandleMessageWithTime ( ) throws IOException { ControllerInfoData systemInfoData = ControllerInfoData . newBuilder ( ) . setName ( "test-name" ) . build ( ) ; BaseNamespace baseNamespaceMessage = BaseNamespace . newBuilder ( ) . setType ( BaseMessageType . ControllerInfo ) . setData ( systemInfoData . toByteString ( ) ) . build ( ) ; TerraHarvestMessage message = createBaseMessage ( baseNamespaceMessage ) ; TerraHarvestPayload payload = createPayload ( baseNamespaceMessage ) ; RemoteChannel channel = mock ( RemoteChannel . class ) ; m_SUT . handleMessage ( message , payload , channel ) ; ArgumentCaptor < Event > eventCaptor = ArgumentCaptor . forClass ( Event . class ) ; verify ( m_EventAdmin ) . postEvent ( eventCaptor . capture ( ) ) ; Event postedEvent = eventCaptor . getValue ( ) ; assertThat ( postedEvent . getTopic ( ) , is ( RemoteConstants . TOPIC_MESSAGE_RECEIVED ) ) ; assertThat ( ( TerraHarvestMessage ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_MESSAGE ) , is ( message ) ) ; assertThat ( ( String ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_MESSAGE_TYPE ) , is ( baseNamespaceMessage . getType ( ) . toString ( ) ) ) ; systemInfoData = ControllerInfoData . newBuilder ( ) . setName ( "test-name" ) . setCurrentSystemTime ( System . currentTimeMillis ( ) ) . build ( ) ; baseNamespaceMessage = BaseNamespace . newBuilder ( ) . setType ( BaseMessageType . ControllerInfo ) . setData ( systemInfoData . toByteString ( ) ) . build ( ) ; message = createBaseMessage ( baseNamespaceMessage ) ; payload = createPayload ( baseNamespaceMessage ) ; m_SUT . handleMessage ( message , payload , channel ) ; verify ( m_EventAdmin , times ( 2 ) ) . postEvent ( eventCaptor . capture ( ) ) ; postedEvent = eventCaptor . getValue ( ) ; assertThat ( postedEvent . getTopic ( ) , is ( RemoteConstants . TOPIC_MESSAGE_RECEIVED ) ) ; assertThat ( ( TerraHarvestMessage ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_MESSAGE ) , is ( message ) ) ; assertThat ( ( String ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_MESSAGE_TYPE ) , is ( baseNamespaceMessage . getType ( ) . toString ( ) ) ) ; }
Verify generic handling of message, with the optional time and without.
Verify generic handling of message with the optional time and without .
// construct a single message containing data within a namespace message // mock the channel the message came from // replay // verify event is posted // Replay with time // replay // verify event is posted