mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/asset/TestAssetDirectoryMessageService.java
@Test
    public void testGenericHandleMessage() throws IOException
    {
        GetCapabilitiesRequestData request = GetCapabilitiesRequestData.newBuilder().
               setProductType("a").build();
        AssetDirectoryServiceNamespace assetDirMessage = AssetDirectoryServiceNamespace.newBuilder().
                setType(AssetDirectoryServiceMessageType.GetCapabilitiesRequest).
                setData(request.toByteString()).build();
        TerraHarvestPayload payload = createPayload(assetDirMessage);
        TerraHarvestMessage message = createMessage(assetDirMessage);
        
        Asset asset = mock(Asset.class);
        when(this.m_AssetDirectoryService.getAssetByUuid(testUuid)).thenReturn(asset);
        when(asset.getActiveStatus()).thenReturn(AssetActiveStatus.ACTIVATED);
        
        // 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(assetDirMessage.getType().toString()));
        assertThat((AssetDirectoryServiceNamespace)postedEvent.
                getProperty(RemoteConstants.EVENT_PROP_NAMESPACE_MESSAGE), is(assetDirMessage));
        assertThat((GetCapabilitiesRequestData)postedEvent.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE), 
                is(request));
        assertThat((RemoteChannel)postedEvent.getProperty(RemoteConstants.EVENT_PROP_CHANNEL), is(channel));      
    }
/**
     * Verify generic handling of message, that it posts an event locally.
     */
Verify generic handling of message, that it posts an event locally.
Verify generic handling of message that it posts an event locally .
@Test
    public void testGenericHandleMessage() throws IOException
    {
        GetCapabilitiesRequestData request = GetCapabilitiesRequestData.newBuilder().
               setProductType("a").build();
        AssetDirectoryServiceNamespace assetDirMessage = AssetDirectoryServiceNamespace.newBuilder().
                setType(AssetDirectoryServiceMessageType.GetCapabilitiesRequest).
                setData(request.toByteString()).build();
        TerraHarvestPayload payload = createPayload(assetDirMessage);
        TerraHarvestMessage message = createMessage(assetDirMessage);
        Asset asset = mock(Asset.class);
        when(this.m_AssetDirectoryService.getAssetByUuid(testUuid)).thenReturn(asset);
        when(asset.getActiveStatus()).thenReturn(AssetActiveStatus.ACTIVATED);
        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(assetDirMessage.getType().toString()));
        assertThat((AssetDirectoryServiceNamespace)postedEvent.
                getProperty(RemoteConstants.EVENT_PROP_NAMESPACE_MESSAGE), is(assetDirMessage));
        assertThat((GetCapabilitiesRequestData)postedEvent.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE), 
                is(request));
        assertThat((RemoteChannel)postedEvent.getProperty(RemoteConstants.EVENT_PROP_CHANNEL), is(channel));      
    }
@ Test public void testGenericHandleMessage ( ) throws IOException { GetCapabilitiesRequestData request = GetCapabilitiesRequestData . newBuilder ( ) . setProductType ( "a" ) . build ( ) ; AssetDirectoryServiceNamespace assetDirMessage = AssetDirectoryServiceNamespace . newBuilder ( ) . setType ( AssetDirectoryServiceMessageType . GetCapabilitiesRequest ) . setData ( request . toByteString ( ) ) . build ( ) ; TerraHarvestPayload payload = createPayload ( assetDirMessage ) ; TerraHarvestMessage message = createMessage ( assetDirMessage ) ; Asset asset = mock ( Asset . class ) ; when ( this . m_AssetDirectoryService . getAssetByUuid ( testUuid ) ) . thenReturn ( asset ) ; when ( asset . getActiveStatus ( ) ) . thenReturn ( AssetActiveStatus . ACTIVATED ) ; 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 ( assetDirMessage . getType ( ) . toString ( ) ) ) ; assertThat ( ( AssetDirectoryServiceNamespace ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_NAMESPACE_MESSAGE ) , is ( assetDirMessage ) ) ; assertThat ( ( GetCapabilitiesRequestData ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_DATA_MESSAGE ) , is ( request ) ) ; assertThat ( ( RemoteChannel ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_CHANNEL ) , is ( channel ) ) ; }
Verify generic handling of message, that it posts an event locally.
Verify generic handling of message that it posts an event locally .
// mock the channel the message came from // replay // verify event is posted