mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/ccomms/TestCustomCommsMessageService.java
@Test
    public void testGetAvailableCommTypesPhysicalLinks() throws IOException, CCommException
    {
        GetAvailableCommTypesRequestData request = GetAvailableCommTypesRequestData.newBuilder()
                .setCommType(CommType.PhysicalLink)
                .build();
        
        CustomCommsNamespace ccommMessage = CustomCommsNamespace.newBuilder()
                .setType(CustomCommsMessageType.GetAvailableCommTypesRequest)
                .setData(request.toByteString())
                .build();
        
        TerraHarvestPayload payload = createPayload(ccommMessage);
        TerraHarvestMessage message = createCustomCommsMessage(ccommMessage);
        
        // mock the channel the message came from
        RemoteChannel channel = mock(RemoteChannel.class);

        //mock device factory behavior
        PhysicalLinkFactory factory = mock(PhysicalLinkFactory.class);
        when(factory.getProductName()).thenReturn("name");
        doReturn(PhysicalLink.class.getName()).when(factory).getProductType();
        
        Set<PhysicalLinkFactory> factorySet = new HashSet<>();
        factorySet.add(factory);

        when(m_CustomCommsService.getPhysicalLinkFactories()).thenReturn(factorySet);
        
        m_SUT.handleMessage(message, payload, channel);
        
        // verify the event contains the data message
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin).postEvent(eventCaptor.capture());
        Event event = eventCaptor.getValue();
        
        assertThat((GetAvailableCommTypesRequestData)event.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE),
                is(request));
        
        //capture and verify response
        ArgumentCaptor<GetAvailableCommTypesResponseData> messageCaptor = ArgumentCaptor.forClass(
                GetAvailableCommTypesResponseData.class);  
        
        verify(m_MessageFactory).createCustomCommsResponseMessage(eq(message), 
                eq(CustomCommsMessageType.GetAvailableCommTypesResponse), messageCaptor.capture());
        verify(m_ResponseWrapper).queue(channel);
        
        GetAvailableCommTypesResponseData response = messageCaptor.getValue();
 
        assertThat(response.getProductTypeList().size(), is(1));
        assertThat(response.getProductTypeList().contains(PhysicalLink.class.getName()), is(true));
        assertThat(response.getCommType(), is(CommType.PhysicalLink));
    }
/**
     * Verify that the core service is requested to get available comms types from a specified comm type, verify event 
     * posted for request message, verify event property key in the posted event is the correct request for the message 
     * that was sent, also capture argument values for the response message and make sure that the data sent is correct.
     */
Verify that the core service is requested to get available comms types from a specified comm type, verify event
posted for request message, verify event property key in the posted event is the correct request for the message
that was sent, also capture argument values for the response message and make sure that the data sent is correct.
Verify that the core service is requested to get available comms types from a specified comm type verify event posted for request message verify event property key in the posted event is the correct request for the message that was sent also capture argument values for the response message and make sure that the data sent is correct .
@Test
    public void testGetAvailableCommTypesPhysicalLinks() throws IOException, CCommException
    {
        GetAvailableCommTypesRequestData request = GetAvailableCommTypesRequestData.newBuilder()
                .setCommType(CommType.PhysicalLink)
                .build();
        CustomCommsNamespace ccommMessage = CustomCommsNamespace.newBuilder()
                .setType(CustomCommsMessageType.GetAvailableCommTypesRequest)
                .setData(request.toByteString())
                .build();
        TerraHarvestPayload payload = createPayload(ccommMessage);
        TerraHarvestMessage message = createCustomCommsMessage(ccommMessage);
        RemoteChannel channel = mock(RemoteChannel.class);
        PhysicalLinkFactory factory = mock(PhysicalLinkFactory.class);
        when(factory.getProductName()).thenReturn("name");
        doReturn(PhysicalLink.class.getName()).when(factory).getProductType();
        Set<PhysicalLinkFactory> factorySet = new HashSet<>();
        factorySet.add(factory);
        when(m_CustomCommsService.getPhysicalLinkFactories()).thenReturn(factorySet);
        m_SUT.handleMessage(message, payload, channel);
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin).postEvent(eventCaptor.capture());
        Event event = eventCaptor.getValue();
        assertThat((GetAvailableCommTypesRequestData)event.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE),
                is(request));
        ArgumentCaptor<GetAvailableCommTypesResponseData> messageCaptor = ArgumentCaptor.forClass(
                GetAvailableCommTypesResponseData.class);  
        verify(m_MessageFactory).createCustomCommsResponseMessage(eq(message), 
                eq(CustomCommsMessageType.GetAvailableCommTypesResponse), messageCaptor.capture());
        verify(m_ResponseWrapper).queue(channel);
        GetAvailableCommTypesResponseData response = messageCaptor.getValue();
        assertThat(response.getProductTypeList().size(), is(1));
        assertThat(response.getProductTypeList().contains(PhysicalLink.class.getName()), is(true));
        assertThat(response.getCommType(), is(CommType.PhysicalLink));
    }
@ Test public void testGetAvailableCommTypesPhysicalLinks ( ) throws IOException , CCommException { GetAvailableCommTypesRequestData request = GetAvailableCommTypesRequestData . newBuilder ( ) . setCommType ( CommType . PhysicalLink ) . build ( ) ; CustomCommsNamespace ccommMessage = CustomCommsNamespace . newBuilder ( ) . setType ( CustomCommsMessageType . GetAvailableCommTypesRequest ) . setData ( request . toByteString ( ) ) . build ( ) ; TerraHarvestPayload payload = createPayload ( ccommMessage ) ; TerraHarvestMessage message = createCustomCommsMessage ( ccommMessage ) ; RemoteChannel channel = mock ( RemoteChannel . class ) ; PhysicalLinkFactory factory = mock ( PhysicalLinkFactory . class ) ; when ( factory . getProductName ( ) ) . thenReturn ( "name" ) ; doReturn ( PhysicalLink . class . getName ( ) ) . when ( factory ) . getProductType ( ) ; Set < PhysicalLinkFactory > factorySet = new HashSet < > ( ) ; factorySet . add ( factory ) ; when ( m_CustomCommsService . getPhysicalLinkFactories ( ) ) . thenReturn ( factorySet ) ; m_SUT . handleMessage ( message , payload , channel ) ; ArgumentCaptor < Event > eventCaptor = ArgumentCaptor . forClass ( Event . class ) ; verify ( m_EventAdmin ) . postEvent ( eventCaptor . capture ( ) ) ; Event event = eventCaptor . getValue ( ) ; assertThat ( ( GetAvailableCommTypesRequestData ) event . getProperty ( RemoteConstants . EVENT_PROP_DATA_MESSAGE ) , is ( request ) ) ; ArgumentCaptor < GetAvailableCommTypesResponseData > messageCaptor = ArgumentCaptor . forClass ( GetAvailableCommTypesResponseData . class ) ; verify ( m_MessageFactory ) . createCustomCommsResponseMessage ( eq ( message ) , eq ( CustomCommsMessageType . GetAvailableCommTypesResponse ) , messageCaptor . capture ( ) ) ; verify ( m_ResponseWrapper ) . queue ( channel ) ; GetAvailableCommTypesResponseData response = messageCaptor . getValue ( ) ; assertThat ( response . getProductTypeList ( ) . size ( ) , is ( 1 ) ) ; assertThat ( response . getProductTypeList ( ) . contains ( PhysicalLink . class . getName ( ) ) , is ( true ) ) ; assertThat ( response . getCommType ( ) , is ( CommType . PhysicalLink ) ) ; }
Verify that the core service is requested to get available comms types from a specified comm type, verify event
 posted for request message, verify event property key in the posted event is the correct request for the message
 that was sent, also capture argument values for the response message and make sure that the data sent is correct.
Verify that the core service is requested to get available comms types from a specified comm type verify event posted for request message verify event property key in the posted event is the correct request for the message that was sent also capture argument values for the response message and make sure that the data sent is correct .
// mock the channel the message came from //mock device factory behavior // verify the event contains the data message //capture and verify response