mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/ccomms/TestCustomCommsMessageService.java
@Test
    public final void testGetLinkLayerCapabilities() throws UnmarshalException, ObjectConverterException, IOException
    { 
        CustomCommsNamespace linkLayerMessage = 
                createGetCapsRequestMessage(CommType.Linklayer, LinkLayer.class.getName());
        TerraHarvestPayload payload = createPayload(linkLayerMessage);
        TerraHarvestMessage message = createCustomCommsMessage(linkLayerMessage);
        
        Message capsGen = LinkLayerCapabilitiesGen.LinkLayerCapabilities.newBuilder().
                setBase(BaseCapabilitiesGen.BaseCapabilities.newBuilder().
                    setManufacturer("Super Cool Link Layers Inc").
                    setDescription("The best link layer.").
                    setProductName("CoolLinkLayer")).
                setPhysicalLinkRequired(false).
                setPerformBITSupported(false).
                setModality(CustomCommTypesGen.LinkLayerType.Enum.LINE_OF_SIGHT).
                setStaticMtu(false).
                setSupportsAddressing(false).build();
        
        //mock necessary objects/actions
        LinkLayerCapabilities capabilities = mock(LinkLayerCapabilities.class);
        when(m_LinkLayerFactory.getLinkLayerCapabilities()).thenReturn(capabilities);
        when(m_Converter.convertToProto(capabilities)).thenReturn(capsGen);
        
        //mock the channel the message came from
        RemoteChannel channel = mock(RemoteChannel.class);
        
        // reply
        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(GetCapabilitiesRequestData.newBuilder().
                        setCommType(CommType.Linklayer).setProductType(LinkLayer.class.getName()).build()));
        
        //capture and verify response
        ArgumentCaptor<GetCapabilitiesResponseData> messageCaptor = ArgumentCaptor.
                forClass(GetCapabilitiesResponseData.class);
        verify(m_MessageFactory).createCustomCommsResponseMessage(eq(message),
                eq(CustomCommsMessageType.GetCapabilitiesResponse), messageCaptor.capture());
        verify(m_ResponseWrapper).queue(channel);
        GetCapabilitiesResponseData response = messageCaptor.getValue();
        
        //ensure all necessary fields are set
        assertThat(response.hasLinkCapabilities(), is(true));
        assertThat(response.getLinkCapabilities(), is(capsGen));
        assertThat(response.getProductType(), is(LinkLayer.class.getName()));
    }
/**
     * Test the get capabilities request/response message system for link layers.
     * Specifically, the following behaviors are tested:
     *     Verify incoming request message is posted to the event admin.
     *     Verify capabilities are gotten from the appropriate link layer factory.
     *     Verify response (containing correct data) is sent after completing request.
     */
Test the get capabilities request/response message system for link layers.
Specifically, the following behaviors are tested:
Verify incoming request message is posted to the event admin.
Verify capabilities are gotten from the appropriate link layer factory.
Verify response (containing correct data) is sent after completing request.
Test the get capabilities request / response message system for link layers . Specifically the following behaviors are tested : Verify incoming request message is posted to the event admin . Verify capabilities are gotten from the appropriate link layer factory . Verify response ( containing correct data ) is sent after completing request .
@Test
    public final void testGetLinkLayerCapabilities() throws UnmarshalException, ObjectConverterException, IOException
    { 
        CustomCommsNamespace linkLayerMessage = 
                createGetCapsRequestMessage(CommType.Linklayer, LinkLayer.class.getName());
        TerraHarvestPayload payload = createPayload(linkLayerMessage);
        TerraHarvestMessage message = createCustomCommsMessage(linkLayerMessage);
        Message capsGen = LinkLayerCapabilitiesGen.LinkLayerCapabilities.newBuilder().
                setBase(BaseCapabilitiesGen.BaseCapabilities.newBuilder().
                    setManufacturer("Super Cool Link Layers Inc").
                    setDescription("The best link layer.").
                    setProductName("CoolLinkLayer")).
                setPhysicalLinkRequired(false).
                setPerformBITSupported(false).
                setModality(CustomCommTypesGen.LinkLayerType.Enum.LINE_OF_SIGHT).
                setStaticMtu(false).
                setSupportsAddressing(false).build();
        LinkLayerCapabilities capabilities = mock(LinkLayerCapabilities.class);
        when(m_LinkLayerFactory.getLinkLayerCapabilities()).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(GetCapabilitiesRequestData.newBuilder().
                        setCommType(CommType.Linklayer).setProductType(LinkLayer.class.getName()).build()));
        ArgumentCaptor<GetCapabilitiesResponseData> messageCaptor = ArgumentCaptor.
                forClass(GetCapabilitiesResponseData.class);
        verify(m_MessageFactory).createCustomCommsResponseMessage(eq(message),
                eq(CustomCommsMessageType.GetCapabilitiesResponse), messageCaptor.capture());
        verify(m_ResponseWrapper).queue(channel);
        GetCapabilitiesResponseData response = messageCaptor.getValue();
        assertThat(response.hasLinkCapabilities(), is(true));
        assertThat(response.getLinkCapabilities(), is(capsGen));
        assertThat(response.getProductType(), is(LinkLayer.class.getName()));
    }
@ Test public final void testGetLinkLayerCapabilities ( ) throws UnmarshalException , ObjectConverterException , IOException { CustomCommsNamespace linkLayerMessage = createGetCapsRequestMessage ( CommType . Linklayer , LinkLayer . class . getName ( ) ) ; TerraHarvestPayload payload = createPayload ( linkLayerMessage ) ; TerraHarvestMessage message = createCustomCommsMessage ( linkLayerMessage ) ; Message capsGen = LinkLayerCapabilitiesGen . LinkLayerCapabilities . newBuilder ( ) . setBase ( BaseCapabilitiesGen . BaseCapabilities . newBuilder ( ) . setManufacturer ( "Super Cool Link Layers Inc" ) . setDescription ( "The best link layer." ) . setProductName ( "CoolLinkLayer" ) ) . setPhysicalLinkRequired ( false ) . setPerformBITSupported ( false ) . setModality ( CustomCommTypesGen . LinkLayerType . Enum . LINE_OF_SIGHT ) . setStaticMtu ( false ) . setSupportsAddressing ( false ) . build ( ) ; LinkLayerCapabilities capabilities = mock ( LinkLayerCapabilities . class ) ; when ( m_LinkLayerFactory . getLinkLayerCapabilities ( ) ) . 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 ( GetCapabilitiesRequestData . newBuilder ( ) . setCommType ( CommType . Linklayer ) . setProductType ( LinkLayer . class . getName ( ) ) . build ( ) ) ) ; ArgumentCaptor < GetCapabilitiesResponseData > messageCaptor = ArgumentCaptor . forClass ( GetCapabilitiesResponseData . class ) ; verify ( m_MessageFactory ) . createCustomCommsResponseMessage ( eq ( message ) , eq ( CustomCommsMessageType . GetCapabilitiesResponse ) , messageCaptor . capture ( ) ) ; verify ( m_ResponseWrapper ) . queue ( channel ) ; GetCapabilitiesResponseData response = messageCaptor . getValue ( ) ; assertThat ( response . hasLinkCapabilities ( ) , is ( true ) ) ; assertThat ( response . getLinkCapabilities ( ) , is ( capsGen ) ) ; assertThat ( response . getProductType ( ) , is ( LinkLayer . class . getName ( ) ) ) ; }
Test the get capabilities request/response message system for link layers.
Test the get capabilities request / response message system for link layers .
//mock necessary objects/actions //mock the channel the message came from // reply //capture and verify event has been posted locally //capture and verify response //ensure all necessary fields are set