mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/asset/TestAssetDirectoryMessageService.java
@Test
    public final void testGetCapabilities() throws IOException, ObjectConverterException
    {
        //set up converter
        m_SUT.activate();
        
        GetCapabilitiesRequestData request = GetCapabilitiesRequestData.newBuilder().
                setProductType(AssetProxy.class.getName()).build();
        AssetDirectoryServiceNamespace assetMessage = AssetDirectoryServiceNamespace.newBuilder().
                setType(AssetDirectoryServiceMessageType.GetCapabilitiesRequest).
                setData(request.toByteString()).build();
        TerraHarvestPayload payload = createPayload(assetMessage);
        TerraHarvestMessage message = createMessage(assetMessage);


        Message capsGen = AssetCapabilitiesGen.AssetCapabilities.newBuilder().
                setNominalFov(22.0).
                setBase(BaseCapabilitiesGen.BaseCapabilities.newBuilder().
                    setManufacturer("teamAwesome").
                    setDescription("does stuff").
                    setProductName("Bill")).
                build();

        //mock necessary objects/actions
        AssetFactory factory = mock(AssetFactory.class);
        AssetCapabilities capabilities = mock(AssetCapabilities.class);
        Set<AssetFactory> factories = new HashSet<>();
        factories.add(factory);
        doReturn(AssetProxy.class.getName()).when(factory).getProductType();
        when(m_AssetDirectoryService.getAssetFactories()).thenReturn(factories);
        when(factory.getAssetCapabilities()).thenReturn(capabilities);
        when(m_Converter.convertToProto(capabilities)).thenReturn(capsGen);

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

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

        //capture and verify event has been posted locally
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin).postEvent(eventCaptor.capture());
        Event event = eventCaptor.getValue();
        assertThat((GetCapabilitiesRequestData)event.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE),
                is(request));

        //capture and verify response
        ArgumentCaptor<GetCapabilitiesResponseData> messageCaptor = ArgumentCaptor.
                forClass(GetCapabilitiesResponseData.class); 
        verify(m_MessageFactory).createAssetDirectoryServiceResponseMessage(eq(message), 
                eq(AssetDirectoryServiceMessageType.GetCapabilitiesResponse), messageCaptor.capture());
        verify(m_ResponseWrapper).queue(channel);
        GetCapabilitiesResponseData response = messageCaptor.getValue();

        // ensure all necessary fields are set
        assertThat(response.hasCapabilities(), is(true));
        assertThat(response.getCapabilities(), is(capsGen));
        assertThat(response.getProductType(), is(AssetProxy.class.getName()));
    }
/**
     * Test the get capabilities request/response message system for assets.  
     * Specifically, the following behaviors are tested: 
     *      Verify incoming request message is posted to event admin.
     *      Verify capabilities are gotten from the asset factory.
     *      Verify response (containing correct data) is sent after completing request. 
     */
Test the get capabilities request/response message system for assets.
Specifically, the following behaviors are tested:
Verify incoming request message is posted to event admin.
Verify capabilities are gotten from the asset factory.
Verify response (containing correct data) is sent after completing request.
Test the get capabilities request / response message system for assets . Specifically the following behaviors are tested : Verify incoming request message is posted to event admin . Verify capabilities are gotten from the asset factory . Verify response ( containing correct data ) is sent after completing request .
@Test
    public final void testGetCapabilities() throws IOException, ObjectConverterException
    {
        m_SUT.activate();
        GetCapabilitiesRequestData request = GetCapabilitiesRequestData.newBuilder().
                setProductType(AssetProxy.class.getName()).build();
        AssetDirectoryServiceNamespace assetMessage = AssetDirectoryServiceNamespace.newBuilder().
                setType(AssetDirectoryServiceMessageType.GetCapabilitiesRequest).
                setData(request.toByteString()).build();
        TerraHarvestPayload payload = createPayload(assetMessage);
        TerraHarvestMessage message = createMessage(assetMessage);
        Message capsGen = AssetCapabilitiesGen.AssetCapabilities.newBuilder().
                setNominalFov(22.0).
                setBase(BaseCapabilitiesGen.BaseCapabilities.newBuilder().
                    setManufacturer("teamAwesome").
                    setDescription("does stuff").
                    setProductName("Bill")).
                build();
        AssetFactory factory = mock(AssetFactory.class);
        AssetCapabilities capabilities = mock(AssetCapabilities.class);
        Set<AssetFactory> factories = new HashSet<>();
        factories.add(factory);
        doReturn(AssetProxy.class.getName()).when(factory).getProductType();
        when(m_AssetDirectoryService.getAssetFactories()).thenReturn(factories);
        when(factory.getAssetCapabilities()).thenReturn(capabilities);
        when(m_Converter.convertToProto(capabilities)).thenReturn(capsGen);
        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 event = eventCaptor.getValue();
        assertThat((GetCapabilitiesRequestData)event.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE),
                is(request));
        ArgumentCaptor<GetCapabilitiesResponseData> messageCaptor = ArgumentCaptor.
                forClass(GetCapabilitiesResponseData.class); 
        verify(m_MessageFactory).createAssetDirectoryServiceResponseMessage(eq(message), 
                eq(AssetDirectoryServiceMessageType.GetCapabilitiesResponse), messageCaptor.capture());
        verify(m_ResponseWrapper).queue(channel);
        GetCapabilitiesResponseData response = messageCaptor.getValue();
        assertThat(response.hasCapabilities(), is(true));
        assertThat(response.getCapabilities(), is(capsGen));
        assertThat(response.getProductType(), is(AssetProxy.class.getName()));
    }
@ Test public final void testGetCapabilities ( ) throws IOException , ObjectConverterException { m_SUT . activate ( ) ; GetCapabilitiesRequestData request = GetCapabilitiesRequestData . newBuilder ( ) . setProductType ( AssetProxy . class . getName ( ) ) . build ( ) ; AssetDirectoryServiceNamespace assetMessage = AssetDirectoryServiceNamespace . newBuilder ( ) . setType ( AssetDirectoryServiceMessageType . GetCapabilitiesRequest ) . setData ( request . toByteString ( ) ) . build ( ) ; TerraHarvestPayload payload = createPayload ( assetMessage ) ; TerraHarvestMessage message = createMessage ( assetMessage ) ; Message capsGen = AssetCapabilitiesGen . AssetCapabilities . newBuilder ( ) . setNominalFov ( 22.0 ) . setBase ( BaseCapabilitiesGen . BaseCapabilities . newBuilder ( ) . setManufacturer ( "teamAwesome" ) . setDescription ( "does stuff" ) . setProductName ( "Bill" ) ) . build ( ) ; AssetFactory factory = mock ( AssetFactory . class ) ; AssetCapabilities capabilities = mock ( AssetCapabilities . class ) ; Set < AssetFactory > factories = new HashSet < > ( ) ; factories . add ( factory ) ; doReturn ( AssetProxy . class . getName ( ) ) . when ( factory ) . getProductType ( ) ; when ( m_AssetDirectoryService . getAssetFactories ( ) ) . thenReturn ( factories ) ; when ( factory . getAssetCapabilities ( ) ) . thenReturn ( capabilities ) ; when ( m_Converter . convertToProto ( capabilities ) ) . thenReturn ( capsGen ) ; 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 event = eventCaptor . getValue ( ) ; assertThat ( ( GetCapabilitiesRequestData ) event . getProperty ( RemoteConstants . EVENT_PROP_DATA_MESSAGE ) , is ( request ) ) ; ArgumentCaptor < GetCapabilitiesResponseData > messageCaptor = ArgumentCaptor . forClass ( GetCapabilitiesResponseData . class ) ; verify ( m_MessageFactory ) . createAssetDirectoryServiceResponseMessage ( eq ( message ) , eq ( AssetDirectoryServiceMessageType . GetCapabilitiesResponse ) , messageCaptor . capture ( ) ) ; verify ( m_ResponseWrapper ) . queue ( channel ) ; GetCapabilitiesResponseData response = messageCaptor . getValue ( ) ; assertThat ( response . hasCapabilities ( ) , is ( true ) ) ; assertThat ( response . getCapabilities ( ) , is ( capsGen ) ) ; assertThat ( response . getProductType ( ) , is ( AssetProxy . class . getName ( ) ) ) ; }
Test the get capabilities request/response message system for assets.
Test the get capabilities request / response message system for assets .
//set up converter //mock necessary objects/actions // mock the channel the message came from // replay //capture and verify event has been posted locally //capture and verify response // ensure all necessary fields are set