mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/observation/TestObservationMessageService.java
@Test
    public void testResponseMessages() throws IOException
    {
        //Get Observation
        GetObservationResponseData message = GetObservationResponseData.newBuilder()
            .addObservationNative(TerraHarvestMessageHelper.getProtoObs()).build();
        ObservationStoreNamespace namespace = ObservationStoreNamespace.newBuilder().
            setData(message.toByteString()).
            setType(ObservationStoreMessageType.GetObservationResponse).build();
        TerraHarvestPayload payload = createPayload(namespace);
        TerraHarvestMessage thMessage = createMessageObservationStore(namespace);

        // mock the channel the message came from
        RemoteChannel channel = mock(RemoteChannel.class);

        // replay
        m_SUT.handleMessage(thMessage, 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(thMessage));
        assertThat((String)postedEvent.getProperty(RemoteConstants.EVENT_PROP_MESSAGE_TYPE), 
                is(ObservationStoreMessageType.GetObservationResponse.toString()));
        assertThat((ObservationStoreNamespace)postedEvent.getProperty(RemoteConstants.EVENT_PROP_NAMESPACE_MESSAGE), 
                is(namespace));
        assertThat((GetObservationResponseData)postedEvent.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE), 
                is(message));
        assertThat((RemoteChannel)postedEvent.getProperty(RemoteConstants.EVENT_PROP_CHANNEL), is(channel));

        //Remove observation response
        RemoveObservationResponseData removeData = RemoveObservationResponseData
                .newBuilder().setNumberOfObsRemoved(22L).build();
        namespace = ObservationStoreNamespace.newBuilder().
            setType(ObservationStoreMessageType.RemoveObservationResponse)
            .setData(removeData.toByteString()).build();
        payload = createPayload(namespace);
        thMessage = createMessageObservationStore(namespace);

        // replay
        m_SUT.handleMessage(thMessage, 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(thMessage));
        assertThat((String)postedEvent.getProperty(RemoteConstants.EVENT_PROP_MESSAGE_TYPE), 
            is(ObservationStoreMessageType.RemoveObservationResponse.toString()));
        
        RemoveObservationResponseData response = (RemoveObservationResponseData)
                postedEvent.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE);
        assertThat(response.getNumberOfObsRemoved(), is(22L));
        
        assertThat((ObservationStoreNamespace)postedEvent.getProperty(RemoteConstants.EVENT_PROP_NAMESPACE_MESSAGE), 
            is(namespace));
        assertThat((RemoteChannel)postedEvent.getProperty(RemoteConstants.EVENT_PROP_CHANNEL), is(channel));

        //Remove observation response
        namespace = ObservationStoreNamespace.newBuilder().
            setType(ObservationStoreMessageType.RemoveObservationByUUIDResponse).build();
        payload = createPayload(namespace);
        thMessage = createMessageObservationStore(namespace);

        // replay
        m_SUT.handleMessage(thMessage, payload, channel);

        // verify event is posted
        verify(m_EventAdmin, times(3)).postEvent(eventCaptor.capture());
        postedEvent = eventCaptor.getValue();

        assertThat(postedEvent.getTopic(), is(RemoteConstants.TOPIC_MESSAGE_RECEIVED));
        assertThat((TerraHarvestMessage)postedEvent.getProperty(RemoteConstants.EVENT_PROP_MESSAGE), is(thMessage));
        assertThat((String)postedEvent.getProperty(RemoteConstants.EVENT_PROP_MESSAGE_TYPE), 
            is(ObservationStoreMessageType.RemoveObservationByUUIDResponse.toString()));
        assertThat((ObservationStoreNamespace)postedEvent.getProperty(RemoteConstants.EVENT_PROP_NAMESPACE_MESSAGE), 
            is(namespace));
        assertThat((RemoteChannel)postedEvent.getProperty(RemoteConstants.EVENT_PROP_CHANNEL), is(channel));
    }
/**
     * Test handling of response messages.
     * Verify that they post events locally.
     */
Test handling of response messages.
Verify that they post events locally.
Test handling of response messages . Verify that they post events locally .
@Test
    public void testResponseMessages() throws IOException
    {
        GetObservationResponseData message = GetObservationResponseData.newBuilder()
            .addObservationNative(TerraHarvestMessageHelper.getProtoObs()).build();
        ObservationStoreNamespace namespace = ObservationStoreNamespace.newBuilder().
            setData(message.toByteString()).
            setType(ObservationStoreMessageType.GetObservationResponse).build();
        TerraHarvestPayload payload = createPayload(namespace);
        TerraHarvestMessage thMessage = createMessageObservationStore(namespace);
        RemoteChannel channel = mock(RemoteChannel.class);
        m_SUT.handleMessage(thMessage, 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(thMessage));
        assertThat((String)postedEvent.getProperty(RemoteConstants.EVENT_PROP_MESSAGE_TYPE), 
                is(ObservationStoreMessageType.GetObservationResponse.toString()));
        assertThat((ObservationStoreNamespace)postedEvent.getProperty(RemoteConstants.EVENT_PROP_NAMESPACE_MESSAGE), 
                is(namespace));
        assertThat((GetObservationResponseData)postedEvent.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE), 
                is(message));
        assertThat((RemoteChannel)postedEvent.getProperty(RemoteConstants.EVENT_PROP_CHANNEL), is(channel));
        RemoveObservationResponseData removeData = RemoveObservationResponseData
                .newBuilder().setNumberOfObsRemoved(22L).build();
        namespace = ObservationStoreNamespace.newBuilder().
            setType(ObservationStoreMessageType.RemoveObservationResponse)
            .setData(removeData.toByteString()).build();
        payload = createPayload(namespace);
        thMessage = createMessageObservationStore(namespace);
        m_SUT.handleMessage(thMessage, 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(thMessage));
        assertThat((String)postedEvent.getProperty(RemoteConstants.EVENT_PROP_MESSAGE_TYPE), 
            is(ObservationStoreMessageType.RemoveObservationResponse.toString()));
        RemoveObservationResponseData response = (RemoveObservationResponseData)
                postedEvent.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE);
        assertThat(response.getNumberOfObsRemoved(), is(22L));
        assertThat((ObservationStoreNamespace)postedEvent.getProperty(RemoteConstants.EVENT_PROP_NAMESPACE_MESSAGE), 
            is(namespace));
        assertThat((RemoteChannel)postedEvent.getProperty(RemoteConstants.EVENT_PROP_CHANNEL), is(channel));
        namespace = ObservationStoreNamespace.newBuilder().
            setType(ObservationStoreMessageType.RemoveObservationByUUIDResponse).build();
        payload = createPayload(namespace);
        thMessage = createMessageObservationStore(namespace);
        m_SUT.handleMessage(thMessage, payload, channel);
        verify(m_EventAdmin, times(3)).postEvent(eventCaptor.capture());
        postedEvent = eventCaptor.getValue();
        assertThat(postedEvent.getTopic(), is(RemoteConstants.TOPIC_MESSAGE_RECEIVED));
        assertThat((TerraHarvestMessage)postedEvent.getProperty(RemoteConstants.EVENT_PROP_MESSAGE), is(thMessage));
        assertThat((String)postedEvent.getProperty(RemoteConstants.EVENT_PROP_MESSAGE_TYPE), 
            is(ObservationStoreMessageType.RemoveObservationByUUIDResponse.toString()));
        assertThat((ObservationStoreNamespace)postedEvent.getProperty(RemoteConstants.EVENT_PROP_NAMESPACE_MESSAGE), 
            is(namespace));
        assertThat((RemoteChannel)postedEvent.getProperty(RemoteConstants.EVENT_PROP_CHANNEL), is(channel));
    }
@ Test public void testResponseMessages ( ) throws IOException { GetObservationResponseData message = GetObservationResponseData . newBuilder ( ) . addObservationNative ( TerraHarvestMessageHelper . getProtoObs ( ) ) . build ( ) ; ObservationStoreNamespace namespace = ObservationStoreNamespace . newBuilder ( ) . setData ( message . toByteString ( ) ) . setType ( ObservationStoreMessageType . GetObservationResponse ) . build ( ) ; TerraHarvestPayload payload = createPayload ( namespace ) ; TerraHarvestMessage thMessage = createMessageObservationStore ( namespace ) ; RemoteChannel channel = mock ( RemoteChannel . class ) ; m_SUT . handleMessage ( thMessage , 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 ( thMessage ) ) ; assertThat ( ( String ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_MESSAGE_TYPE ) , is ( ObservationStoreMessageType . GetObservationResponse . toString ( ) ) ) ; assertThat ( ( ObservationStoreNamespace ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_NAMESPACE_MESSAGE ) , is ( namespace ) ) ; assertThat ( ( GetObservationResponseData ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_DATA_MESSAGE ) , is ( message ) ) ; assertThat ( ( RemoteChannel ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_CHANNEL ) , is ( channel ) ) ; RemoveObservationResponseData removeData = RemoveObservationResponseData . newBuilder ( ) . setNumberOfObsRemoved ( 22L ) . build ( ) ; namespace = ObservationStoreNamespace . newBuilder ( ) . setType ( ObservationStoreMessageType . RemoveObservationResponse ) . setData ( removeData . toByteString ( ) ) . build ( ) ; payload = createPayload ( namespace ) ; thMessage = createMessageObservationStore ( namespace ) ; m_SUT . handleMessage ( thMessage , 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 ( thMessage ) ) ; assertThat ( ( String ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_MESSAGE_TYPE ) , is ( ObservationStoreMessageType . RemoveObservationResponse . toString ( ) ) ) ; RemoveObservationResponseData response = ( RemoveObservationResponseData ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_DATA_MESSAGE ) ; assertThat ( response . getNumberOfObsRemoved ( ) , is ( 22L ) ) ; assertThat ( ( ObservationStoreNamespace ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_NAMESPACE_MESSAGE ) , is ( namespace ) ) ; assertThat ( ( RemoteChannel ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_CHANNEL ) , is ( channel ) ) ; namespace = ObservationStoreNamespace . newBuilder ( ) . setType ( ObservationStoreMessageType . RemoveObservationByUUIDResponse ) . build ( ) ; payload = createPayload ( namespace ) ; thMessage = createMessageObservationStore ( namespace ) ; m_SUT . handleMessage ( thMessage , payload , channel ) ; verify ( m_EventAdmin , times ( 3 ) ) . postEvent ( eventCaptor . capture ( ) ) ; postedEvent = eventCaptor . getValue ( ) ; assertThat ( postedEvent . getTopic ( ) , is ( RemoteConstants . TOPIC_MESSAGE_RECEIVED ) ) ; assertThat ( ( TerraHarvestMessage ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_MESSAGE ) , is ( thMessage ) ) ; assertThat ( ( String ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_MESSAGE_TYPE ) , is ( ObservationStoreMessageType . RemoveObservationByUUIDResponse . toString ( ) ) ) ; assertThat ( ( ObservationStoreNamespace ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_NAMESPACE_MESSAGE ) , is ( namespace ) ) ; assertThat ( ( RemoteChannel ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_CHANNEL ) , is ( channel ) ) ; }
Test handling of response messages.
Test handling of response messages .
//Get Observation // mock the channel the message came from // replay // verify event is posted //Remove observation response // replay // verify event is posted //Remove observation response // replay // verify event is posted