mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/datastream/TestDataStreamMessageService.java
@Test
    public void testGetCapabilities() throws IOException, ObjectConverterException
    {
        m_SUT.activate();
        
        GetCapabilitiesRequestData request = GetCapabilitiesRequestData.newBuilder().
                setProductType(StreamProfileProxy.class.getName()).build();
        DataStreamServiceNamespace dataStreamMessage = DataStreamServiceNamespace.newBuilder().
                setType(DataStreamServiceMessageType.GetCapabilitiesRequest).
                setData(request.toByteString()).build();
        TerraHarvestPayload payload = createPayload(dataStreamMessage);
        TerraHarvestMessage message = createMessage(dataStreamMessage);

        Message capsGen = StreamProfileCapabilitiesGen.StreamProfileCapabilities.newBuilder().
                setBase(BaseCapabilitiesGen.BaseCapabilities.newBuilder().
                        setManufacturer("Worldwide").
                        setDescription("Streams").
                        setProductName("The Stream Profile").build()).
                addFormat(StreamTypesGen.StreamFormat.newBuilder().
                        setMimeFormat("video/mpeg").build()).
                setMinBitrateKbps(1.0).
                setMaxBitrateKbps(1000.0).build();
        
        StreamProfileFactory factory = mock(StreamProfileFactory.class);
        StreamProfileCapabilities capabilities = mock(StreamProfileCapabilities.class);
        Set<StreamProfileFactory> factories = new HashSet<>();
        factories.add(factory);
        doReturn(StreamProfileProxy.class.getName()).when(factory).getProductType();
        when(m_DataStreamService.getStreamProfileFactories()).thenReturn(factories);
        when(factory.getStreamProfileCapabilities()).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).createDataStreamServiceResponseMessage(eq(message),
                eq(DataStreamServiceMessageType.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(StreamProfileProxy.class.getName()));        
    }
/**
     * Test the get capabilities request/response message system for stream profiles.  
     * Specifically, the following behaviors are tested: 
     *      Verify incoming request message is posted to event admin.
     *      Verify capabilities are gotten from the stream profile factory.
     *      Verify response (containing correct data) is sent after completing request. 
     */
Test the get capabilities request/response message system for stream profiles.
Specifically, the following behaviors are tested:
Verify incoming request message is posted to event admin.
Verify capabilities are gotten from the stream profile factory.
Verify response (containing correct data) is sent after completing request.
Test the get capabilities request / response message system for stream profiles . Specifically the following behaviors are tested : Verify incoming request message is posted to event admin . Verify capabilities are gotten from the stream profile factory . Verify response ( containing correct data ) is sent after completing request .
@Test
    public void testGetCapabilities() throws IOException, ObjectConverterException
    {
        m_SUT.activate();
        GetCapabilitiesRequestData request = GetCapabilitiesRequestData.newBuilder().
                setProductType(StreamProfileProxy.class.getName()).build();
        DataStreamServiceNamespace dataStreamMessage = DataStreamServiceNamespace.newBuilder().
                setType(DataStreamServiceMessageType.GetCapabilitiesRequest).
                setData(request.toByteString()).build();
        TerraHarvestPayload payload = createPayload(dataStreamMessage);
        TerraHarvestMessage message = createMessage(dataStreamMessage);
        Message capsGen = StreamProfileCapabilitiesGen.StreamProfileCapabilities.newBuilder().
                setBase(BaseCapabilitiesGen.BaseCapabilities.newBuilder().
                        setManufacturer("Worldwide").
                        setDescription("Streams").
                        setProductName("The Stream Profile").build()).
                addFormat(StreamTypesGen.StreamFormat.newBuilder().
                        setMimeFormat("video/mpeg").build()).
                setMinBitrateKbps(1.0).
                setMaxBitrateKbps(1000.0).build();
        StreamProfileFactory factory = mock(StreamProfileFactory.class);
        StreamProfileCapabilities capabilities = mock(StreamProfileCapabilities.class);
        Set<StreamProfileFactory> factories = new HashSet<>();
        factories.add(factory);
        doReturn(StreamProfileProxy.class.getName()).when(factory).getProductType();
        when(m_DataStreamService.getStreamProfileFactories()).thenReturn(factories);
        when(factory.getStreamProfileCapabilities()).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).createDataStreamServiceResponseMessage(eq(message),
                eq(DataStreamServiceMessageType.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(StreamProfileProxy.class.getName()));        
    }
@ Test public void testGetCapabilities ( ) throws IOException , ObjectConverterException { m_SUT . activate ( ) ; GetCapabilitiesRequestData request = GetCapabilitiesRequestData . newBuilder ( ) . setProductType ( StreamProfileProxy . class . getName ( ) ) . build ( ) ; DataStreamServiceNamespace dataStreamMessage = DataStreamServiceNamespace . newBuilder ( ) . setType ( DataStreamServiceMessageType . GetCapabilitiesRequest ) . setData ( request . toByteString ( ) ) . build ( ) ; TerraHarvestPayload payload = createPayload ( dataStreamMessage ) ; TerraHarvestMessage message = createMessage ( dataStreamMessage ) ; Message capsGen = StreamProfileCapabilitiesGen . StreamProfileCapabilities . newBuilder ( ) . setBase ( BaseCapabilitiesGen . BaseCapabilities . newBuilder ( ) . setManufacturer ( "Worldwide" ) . setDescription ( "Streams" ) . setProductName ( "The Stream Profile" ) . build ( ) ) . addFormat ( StreamTypesGen . StreamFormat . newBuilder ( ) . setMimeFormat ( "video/mpeg" ) . build ( ) ) . setMinBitrateKbps ( 1.0 ) . setMaxBitrateKbps ( 1000.0 ) . build ( ) ; StreamProfileFactory factory = mock ( StreamProfileFactory . class ) ; StreamProfileCapabilities capabilities = mock ( StreamProfileCapabilities . class ) ; Set < StreamProfileFactory > factories = new HashSet < > ( ) ; factories . add ( factory ) ; doReturn ( StreamProfileProxy . class . getName ( ) ) . when ( factory ) . getProductType ( ) ; when ( m_DataStreamService . getStreamProfileFactories ( ) ) . thenReturn ( factories ) ; when ( factory . getStreamProfileCapabilities ( ) ) . 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 ) . createDataStreamServiceResponseMessage ( eq ( message ) , eq ( DataStreamServiceMessageType . 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 ( StreamProfileProxy . class . getName ( ) ) ) ; }
Test the get capabilities request/response message system for stream profiles.
Test the get capabilities request / response message system for stream profiles .
// mock the channel the message came from // replay //capture and verify event has been posted locally //capture and verify response