mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/asset/TestAssetMessageService.java
@Test
    public void testGetAssetNameRequest() throws IOException, IllegalArgumentException
    {
        //mock behavior
        Asset asset = mock(Asset.class);
        when(asset.getName()).thenReturn("name");
        when(m_AssetDirectoryService.getAssetByUuid(testUuid)).thenReturn(asset);
        
        //request
        GetNameRequestData response = GetNameRequestData.newBuilder().
                setUuid(SharedMessageUtils.convertUUIDToProtoUUID(testUuid)).build();
        AssetNamespace assetDirMessage = AssetNamespace.newBuilder().
                setType(AssetMessageType.GetNameRequest).
                setData(response.toByteString()).build();
        TerraHarvestMessage message = createMessage(assetDirMessage);

        //mock remote channel
        RemoteChannel channel = mock(RemoteChannel.class);

        //handle message
        m_SUT.handleMessage(message, createPayload(assetDirMessage), channel);
        
        //capture event
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin).postEvent(eventCaptor.capture());
        Event event = eventCaptor.getValue();
        
        //verify
        assertThat((AssetNamespace)event.getProperty(RemoteConstants.EVENT_PROP_NAMESPACE_MESSAGE),
                is(assetDirMessage));
        assertThat((String)event.getProperty(RemoteConstants.EVENT_PROP_MESSAGE_TYPE),
                is(AssetMessageType.GetNameRequest.toString()));
        assertThat((GetNameRequestData)event.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE),
                is(response));
        
        //verify
        ArgumentCaptor<GetNameResponseData> responseCap = ArgumentCaptor.forClass(GetNameResponseData.class);
        verify(m_MessageFactory).createAssetResponseMessage(eq(message), 
            eq(AssetMessageType.GetNameResponse), responseCap.capture());
        verify(m_ResponseWrapper).queue(channel);
        
        GetNameResponseData data = responseCap.getValue();
        assertThat(data.getAssetName(), is("name"));
        assertThat(data.getUuid(), is(SharedMessageUtils.convertUUIDToProtoUUID(testUuid)));
    }
/**
     * Test get name for asset request.
     * Verify that expected event is posted.
     */
Test get name for asset request.
Verify that expected event is posted.
Test get name for asset request . Verify that expected event is posted .
@Test
    public void testGetAssetNameRequest() throws IOException, IllegalArgumentException
    {
        Asset asset = mock(Asset.class);
        when(asset.getName()).thenReturn("name");
        when(m_AssetDirectoryService.getAssetByUuid(testUuid)).thenReturn(asset);
        GetNameRequestData response = GetNameRequestData.newBuilder().
                setUuid(SharedMessageUtils.convertUUIDToProtoUUID(testUuid)).build();
        AssetNamespace assetDirMessage = AssetNamespace.newBuilder().
                setType(AssetMessageType.GetNameRequest).
                setData(response.toByteString()).build();
        TerraHarvestMessage message = createMessage(assetDirMessage);
        RemoteChannel channel = mock(RemoteChannel.class);
        m_SUT.handleMessage(message, createPayload(assetDirMessage), channel);
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin).postEvent(eventCaptor.capture());
        Event event = eventCaptor.getValue();
        assertThat((AssetNamespace)event.getProperty(RemoteConstants.EVENT_PROP_NAMESPACE_MESSAGE),
                is(assetDirMessage));
        assertThat((String)event.getProperty(RemoteConstants.EVENT_PROP_MESSAGE_TYPE),
                is(AssetMessageType.GetNameRequest.toString()));
        assertThat((GetNameRequestData)event.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE),
                is(response));
        ArgumentCaptor<GetNameResponseData> responseCap = ArgumentCaptor.forClass(GetNameResponseData.class);
        verify(m_MessageFactory).createAssetResponseMessage(eq(message), 
            eq(AssetMessageType.GetNameResponse), responseCap.capture());
        verify(m_ResponseWrapper).queue(channel);
        GetNameResponseData data = responseCap.getValue();
        assertThat(data.getAssetName(), is("name"));
        assertThat(data.getUuid(), is(SharedMessageUtils.convertUUIDToProtoUUID(testUuid)));
    }
@ Test public void testGetAssetNameRequest ( ) throws IOException , IllegalArgumentException { Asset asset = mock ( Asset . class ) ; when ( asset . getName ( ) ) . thenReturn ( "name" ) ; when ( m_AssetDirectoryService . getAssetByUuid ( testUuid ) ) . thenReturn ( asset ) ; GetNameRequestData response = GetNameRequestData . newBuilder ( ) . setUuid ( SharedMessageUtils . convertUUIDToProtoUUID ( testUuid ) ) . build ( ) ; AssetNamespace assetDirMessage = AssetNamespace . newBuilder ( ) . setType ( AssetMessageType . GetNameRequest ) . setData ( response . toByteString ( ) ) . build ( ) ; TerraHarvestMessage message = createMessage ( assetDirMessage ) ; RemoteChannel channel = mock ( RemoteChannel . class ) ; m_SUT . handleMessage ( message , createPayload ( assetDirMessage ) , channel ) ; ArgumentCaptor < Event > eventCaptor = ArgumentCaptor . forClass ( Event . class ) ; verify ( m_EventAdmin ) . postEvent ( eventCaptor . capture ( ) ) ; Event event = eventCaptor . getValue ( ) ; assertThat ( ( AssetNamespace ) event . getProperty ( RemoteConstants . EVENT_PROP_NAMESPACE_MESSAGE ) , is ( assetDirMessage ) ) ; assertThat ( ( String ) event . getProperty ( RemoteConstants . EVENT_PROP_MESSAGE_TYPE ) , is ( AssetMessageType . GetNameRequest . toString ( ) ) ) ; assertThat ( ( GetNameRequestData ) event . getProperty ( RemoteConstants . EVENT_PROP_DATA_MESSAGE ) , is ( response ) ) ; ArgumentCaptor < GetNameResponseData > responseCap = ArgumentCaptor . forClass ( GetNameResponseData . class ) ; verify ( m_MessageFactory ) . createAssetResponseMessage ( eq ( message ) , eq ( AssetMessageType . GetNameResponse ) , responseCap . capture ( ) ) ; verify ( m_ResponseWrapper ) . queue ( channel ) ; GetNameResponseData data = responseCap . getValue ( ) ; assertThat ( data . getAssetName ( ) , is ( "name" ) ) ; assertThat ( data . getUuid ( ) , is ( SharedMessageUtils . convertUUIDToProtoUUID ( testUuid ) ) ) ; }
Test get name for asset request.
Test get name for asset request .
//mock behavior //request //mock remote channel //handle message //capture event //verify //verify