mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/ccomms/TestCustomCommsMessageService.java
@Test
    public void testGetLayersRequestLinkLayer() throws IOException, CCommException
    {
        GetLayersRequestData request = GetLayersRequestData.newBuilder()
                .setCommType(CommType.Linklayer)
                .build();
        
        CustomCommsNamespace ccommMessage = CustomCommsNamespace.newBuilder()
                .setType(CustomCommsMessageType.GetLayersRequest)
                .setData(request.toByteString())
                .build();
        
        TerraHarvestPayload payload = createPayload(ccommMessage);
        TerraHarvestMessage message = createCustomCommsMessage(ccommMessage);
        
        // mock the channel the message came from
        RemoteChannel channel = mock(RemoteChannel.class);
        
        LinkLayer mockLink = FactoryObjectMocker.mockFactoryObject(LinkLayer.class, "pid1");
        LinkLayer mockLink2 = FactoryObjectMocker.mockFactoryObject(LinkLayer.class, "pid2");
        
        List<LinkLayer> linkLayerList = new ArrayList<LinkLayer>();
        linkLayerList.add(mockLink);
        linkLayerList.add(mockLink2);
        
        when(m_CustomCommsService.getLinkLayers()).thenReturn(linkLayerList);
        
        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((GetLayersRequestData)event.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE),
                is(request));
        
        //capture and verify response
        ArgumentCaptor<GetLayersResponseData> messageCaptor = ArgumentCaptor.forClass(GetLayersResponseData.class);  
        
        verify(m_MessageFactory).createCustomCommsResponseMessage(eq(message), 
                eq(CustomCommsMessageType.GetLayersResponse), messageCaptor.capture());
        verify(m_ResponseWrapper).queue(channel);
        
        GetLayersResponseData response = messageCaptor.getValue();
 
        assertThat(response.getLayerInfoCount(), is(2));
        assertThat(response.getLayerInfoList(), hasItem(FactoryObjectInfo.newBuilder()
                .setUuid(SharedMessageUtils.convertUUIDToProtoUUID(mockLink.getUuid()))
                .setPid("pid1")
                .setProductType(mockLink.getFactory().getProductType())
                .build()));
        assertThat(response.getLayerInfoList(), hasItem(FactoryObjectInfo.newBuilder()
                .setUuid(SharedMessageUtils.convertUUIDToProtoUUID(mockLink2.getUuid()))
                .setPid("pid2")
                .setProductType(mockLink2.getFactory().getProductType())
                .build()));
    }
/**
     * Verify that you can get all the layers known to the link layer 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 you can get all the layers known to the link layer 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 you can get all the layers known to the link layer 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 testGetLayersRequestLinkLayer() throws IOException, CCommException
    {
        GetLayersRequestData request = GetLayersRequestData.newBuilder()
                .setCommType(CommType.Linklayer)
                .build();
        CustomCommsNamespace ccommMessage = CustomCommsNamespace.newBuilder()
                .setType(CustomCommsMessageType.GetLayersRequest)
                .setData(request.toByteString())
                .build();
        TerraHarvestPayload payload = createPayload(ccommMessage);
        TerraHarvestMessage message = createCustomCommsMessage(ccommMessage);
        RemoteChannel channel = mock(RemoteChannel.class);
        LinkLayer mockLink = FactoryObjectMocker.mockFactoryObject(LinkLayer.class, "pid1");
        LinkLayer mockLink2 = FactoryObjectMocker.mockFactoryObject(LinkLayer.class, "pid2");
        List<LinkLayer> linkLayerList = new ArrayList<LinkLayer>();
        linkLayerList.add(mockLink);
        linkLayerList.add(mockLink2);
        when(m_CustomCommsService.getLinkLayers()).thenReturn(linkLayerList);
        m_SUT.handleMessage(message, payload, channel);
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin).postEvent(eventCaptor.capture());
        Event event = eventCaptor.getValue();
        assertThat((GetLayersRequestData)event.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE),
                is(request));
        ArgumentCaptor<GetLayersResponseData> messageCaptor = ArgumentCaptor.forClass(GetLayersResponseData.class);  
        verify(m_MessageFactory).createCustomCommsResponseMessage(eq(message), 
                eq(CustomCommsMessageType.GetLayersResponse), messageCaptor.capture());
        verify(m_ResponseWrapper).queue(channel);
        GetLayersResponseData response = messageCaptor.getValue();
        assertThat(response.getLayerInfoCount(), is(2));
        assertThat(response.getLayerInfoList(), hasItem(FactoryObjectInfo.newBuilder()
                .setUuid(SharedMessageUtils.convertUUIDToProtoUUID(mockLink.getUuid()))
                .setPid("pid1")
                .setProductType(mockLink.getFactory().getProductType())
                .build()));
        assertThat(response.getLayerInfoList(), hasItem(FactoryObjectInfo.newBuilder()
                .setUuid(SharedMessageUtils.convertUUIDToProtoUUID(mockLink2.getUuid()))
                .setPid("pid2")
                .setProductType(mockLink2.getFactory().getProductType())
                .build()));
    }
@ Test public void testGetLayersRequestLinkLayer ( ) throws IOException , CCommException { GetLayersRequestData request = GetLayersRequestData . newBuilder ( ) . setCommType ( CommType . Linklayer ) . build ( ) ; CustomCommsNamespace ccommMessage = CustomCommsNamespace . newBuilder ( ) . setType ( CustomCommsMessageType . GetLayersRequest ) . setData ( request . toByteString ( ) ) . build ( ) ; TerraHarvestPayload payload = createPayload ( ccommMessage ) ; TerraHarvestMessage message = createCustomCommsMessage ( ccommMessage ) ; RemoteChannel channel = mock ( RemoteChannel . class ) ; LinkLayer mockLink = FactoryObjectMocker . mockFactoryObject ( LinkLayer . class , "pid1" ) ; LinkLayer mockLink2 = FactoryObjectMocker . mockFactoryObject ( LinkLayer . class , "pid2" ) ; List < LinkLayer > linkLayerList = new ArrayList < LinkLayer > ( ) ; linkLayerList . add ( mockLink ) ; linkLayerList . add ( mockLink2 ) ; when ( m_CustomCommsService . getLinkLayers ( ) ) . thenReturn ( linkLayerList ) ; m_SUT . handleMessage ( message , payload , channel ) ; ArgumentCaptor < Event > eventCaptor = ArgumentCaptor . forClass ( Event . class ) ; verify ( m_EventAdmin ) . postEvent ( eventCaptor . capture ( ) ) ; Event event = eventCaptor . getValue ( ) ; assertThat ( ( GetLayersRequestData ) event . getProperty ( RemoteConstants . EVENT_PROP_DATA_MESSAGE ) , is ( request ) ) ; ArgumentCaptor < GetLayersResponseData > messageCaptor = ArgumentCaptor . forClass ( GetLayersResponseData . class ) ; verify ( m_MessageFactory ) . createCustomCommsResponseMessage ( eq ( message ) , eq ( CustomCommsMessageType . GetLayersResponse ) , messageCaptor . capture ( ) ) ; verify ( m_ResponseWrapper ) . queue ( channel ) ; GetLayersResponseData response = messageCaptor . getValue ( ) ; assertThat ( response . getLayerInfoCount ( ) , is ( 2 ) ) ; assertThat ( response . getLayerInfoList ( ) , hasItem ( FactoryObjectInfo . newBuilder ( ) . setUuid ( SharedMessageUtils . convertUUIDToProtoUUID ( mockLink . getUuid ( ) ) ) . setPid ( "pid1" ) . setProductType ( mockLink . getFactory ( ) . getProductType ( ) ) . build ( ) ) ) ; assertThat ( response . getLayerInfoList ( ) , hasItem ( FactoryObjectInfo . newBuilder ( ) . setUuid ( SharedMessageUtils . convertUUIDToProtoUUID ( mockLink2 . getUuid ( ) ) ) . setPid ( "pid2" ) . setProductType ( mockLink2 . getFactory ( ) . getProductType ( ) ) . build ( ) ) ) ; }
Verify that you can get all the layers known to the link layer 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 you can get all the layers known to the link layer 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 // verify the event contains the data message //capture and verify response