mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/osgi/TestMetatypeMessageService.java
@Test
    public void testGetBundlePidsResponse() throws IOException
    {
        GetBundlePidsResponseData getBungles = GetBundlePidsResponseData.newBuilder().
                setBundleId(1L)
                .build();
        
        MetaTypeNamespace message = MetaTypeNamespace.newBuilder().setType(MetaTypeMessageType.GetBundlePidsResponse).
                setData(getBungles.toByteString()).
                build();
        
        TerraHarvestPayload payload = TerraHarvestPayload.newBuilder().
               setNamespace(Namespace.MetaType).
               setNamespaceMessage(message.toByteString()).
               build();
        
        TerraHarvestMessage thMessage = TerraHarvestMessageUtil.getPartialMessage().
                setSourceId(0).
                setDestId(1).
                setTerraHarvestPayload(payload.toByteString()).
                setMessageId(100).
                build();
        
        //mock the channel the message came from
        RemoteChannel channel = mock(RemoteChannel.class);
        
        // handle the message
        m_SUT.handleMessage(thMessage, payload, channel);

        //capture the message
        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((Integer)postedEvent.getProperty(RemoteConstants.EVENT_PROP_SOURCE_ID), is(0));
        assertThat((Integer)postedEvent.getProperty(RemoteConstants.EVENT_PROP_DEST_ID), is(1));
        assertThat((String)postedEvent.getProperty(RemoteConstants.EVENT_PROP_NAMESPACE), is(Namespace.MetaType.
                toString()));
        
        assertThat((String)postedEvent.getProperty(RemoteConstants.EVENT_PROP_MESSAGE_TYPE), 
                is(MetaTypeMessageType.GetBundlePidsResponse.toString()));
        assertThat((RemoteChannel)postedEvent.getProperty(RemoteConstants.EVENT_PROP_CHANNEL), is(channel));
        assertThat((MetaTypeNamespace)postedEvent.getProperty(RemoteConstants.EVENT_PROP_NAMESPACE_MESSAGE), 
                is(getNamespaceMessage(thMessage)));
    }
/**
     * Verify get bundle pids response sends an event, and that the messages in the event are correct.
     */
Verify get bundle pids response sends an event, and that the messages in the event are correct.
Verify get bundle pids response sends an event and that the messages in the event are correct .
@Test
    public void testGetBundlePidsResponse() throws IOException
    {
        GetBundlePidsResponseData getBungles = GetBundlePidsResponseData.newBuilder().
                setBundleId(1L)
                .build();
        MetaTypeNamespace message = MetaTypeNamespace.newBuilder().setType(MetaTypeMessageType.GetBundlePidsResponse).
                setData(getBungles.toByteString()).
                build();
        TerraHarvestPayload payload = TerraHarvestPayload.newBuilder().
               setNamespace(Namespace.MetaType).
               setNamespaceMessage(message.toByteString()).
               build();
        TerraHarvestMessage thMessage = TerraHarvestMessageUtil.getPartialMessage().
                setSourceId(0).
                setDestId(1).
                setTerraHarvestPayload(payload.toByteString()).
                setMessageId(100).
                build();
        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((Integer)postedEvent.getProperty(RemoteConstants.EVENT_PROP_SOURCE_ID), is(0));
        assertThat((Integer)postedEvent.getProperty(RemoteConstants.EVENT_PROP_DEST_ID), is(1));
        assertThat((String)postedEvent.getProperty(RemoteConstants.EVENT_PROP_NAMESPACE), is(Namespace.MetaType.
                toString()));
        assertThat((String)postedEvent.getProperty(RemoteConstants.EVENT_PROP_MESSAGE_TYPE), 
                is(MetaTypeMessageType.GetBundlePidsResponse.toString()));
        assertThat((RemoteChannel)postedEvent.getProperty(RemoteConstants.EVENT_PROP_CHANNEL), is(channel));
        assertThat((MetaTypeNamespace)postedEvent.getProperty(RemoteConstants.EVENT_PROP_NAMESPACE_MESSAGE), 
                is(getNamespaceMessage(thMessage)));
    }
@ Test public void testGetBundlePidsResponse ( ) throws IOException { GetBundlePidsResponseData getBungles = GetBundlePidsResponseData . newBuilder ( ) . setBundleId ( 1L ) . build ( ) ; MetaTypeNamespace message = MetaTypeNamespace . newBuilder ( ) . setType ( MetaTypeMessageType . GetBundlePidsResponse ) . setData ( getBungles . toByteString ( ) ) . build ( ) ; TerraHarvestPayload payload = TerraHarvestPayload . newBuilder ( ) . setNamespace ( Namespace . MetaType ) . setNamespaceMessage ( message . toByteString ( ) ) . build ( ) ; TerraHarvestMessage thMessage = TerraHarvestMessageUtil . getPartialMessage ( ) . setSourceId ( 0 ) . setDestId ( 1 ) . setTerraHarvestPayload ( payload . toByteString ( ) ) . setMessageId ( 100 ) . build ( ) ; 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 ( ( Integer ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_SOURCE_ID ) , is ( 0 ) ) ; assertThat ( ( Integer ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_DEST_ID ) , is ( 1 ) ) ; assertThat ( ( String ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_NAMESPACE ) , is ( Namespace . MetaType . toString ( ) ) ) ; assertThat ( ( String ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_MESSAGE_TYPE ) , is ( MetaTypeMessageType . GetBundlePidsResponse . toString ( ) ) ) ; assertThat ( ( RemoteChannel ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_CHANNEL ) , is ( channel ) ) ; assertThat ( ( MetaTypeNamespace ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_NAMESPACE_MESSAGE ) , is ( getNamespaceMessage ( thMessage ) ) ) ; }
Verify get bundle pids response sends an event, and that the messages in the event are correct.
Verify get bundle pids response sends an event and that the messages in the event are correct .
//mock the channel the message came from // handle the message //capture the message