mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/ccomms/TestCustomCommsMessageService.java
@Test
    public void testCreateLinkLayer() throws IOException, CCommException
    {
        CreateLinkLayerRequestData request = CreateLinkLayerRequestData.newBuilder()
                .setLinkLayerProductType("meow")
                .setLinkLayerName("woof")
                .setPhysicalLinkUuid(SharedMessageUtils.convertUUIDToProtoUUID(testUuid))
                .build();
        
        CustomCommsNamespace ccommMessage = CustomCommsNamespace.newBuilder()
                .setType(CustomCommsMessageType.CreateLinkLayerRequest)
                .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 createdLinkLayer = mock(LinkLayer.class);
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put(LinkLayerAttributes.CONFIG_PROP_PHYSICAL_LINK_NAME, "chirp");
        when(m_CustomCommsService.createLinkLayer("meow", "woof", properties)).thenReturn(
                createdLinkLayer);
        when(createdLinkLayer.getUuid()).thenReturn(testUuid2);
        when(createdLinkLayer.getPid()).thenReturn("linkPid");
        when(createdLinkLayer.getFactory()).thenReturn(m_LinkLayerFactory);
        
        when(m_CustomCommsService.getPhysicalLinkName(testUuid)).thenReturn("chirp");
        
        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((CreateLinkLayerRequestData)event.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE),
                is(request));
        
        //capture and verify response
        ArgumentCaptor<CreateLinkLayerResponseData> messageCaptor = ArgumentCaptor.forClass(
                CreateLinkLayerResponseData.class);  
        
        verify(m_MessageFactory).createCustomCommsResponseMessage(eq(message), 
                eq(CustomCommsMessageType.CreateLinkLayerResponse), messageCaptor.capture());
        verify(m_ResponseWrapper).queue(channel);

        CreateLinkLayerResponseData response = messageCaptor.getValue();
 
        assertThat(response.getInfo().getUuid(), is(notNullValue()));
        assertThat(SharedMessageUtils.convertProtoUUIDtoUUID(response.getInfo().getUuid()), is(testUuid2));
        assertThat(response.getInfo().getPid(), is("linkPid"));
    }
/**
     * Verify that the core service is requested to create a link layer, 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 create a link layer, 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 create a link layer 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 testCreateLinkLayer() throws IOException, CCommException
    {
        CreateLinkLayerRequestData request = CreateLinkLayerRequestData.newBuilder()
                .setLinkLayerProductType("meow")
                .setLinkLayerName("woof")
                .setPhysicalLinkUuid(SharedMessageUtils.convertUUIDToProtoUUID(testUuid))
                .build();
        CustomCommsNamespace ccommMessage = CustomCommsNamespace.newBuilder()
                .setType(CustomCommsMessageType.CreateLinkLayerRequest)
                .setData(request.toByteString())
                .build();
        TerraHarvestPayload payload = createPayload(ccommMessage);
        TerraHarvestMessage message = createCustomCommsMessage(ccommMessage);
        RemoteChannel channel = mock(RemoteChannel.class);
        LinkLayer createdLinkLayer = mock(LinkLayer.class);
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put(LinkLayerAttributes.CONFIG_PROP_PHYSICAL_LINK_NAME, "chirp");
        when(m_CustomCommsService.createLinkLayer("meow", "woof", properties)).thenReturn(
                createdLinkLayer);
        when(createdLinkLayer.getUuid()).thenReturn(testUuid2);
        when(createdLinkLayer.getPid()).thenReturn("linkPid");
        when(createdLinkLayer.getFactory()).thenReturn(m_LinkLayerFactory);
        when(m_CustomCommsService.getPhysicalLinkName(testUuid)).thenReturn("chirp");
        m_SUT.handleMessage(message, payload, channel);
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin).postEvent(eventCaptor.capture());
        Event event = eventCaptor.getValue();
        assertThat((CreateLinkLayerRequestData)event.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE),
                is(request));
        ArgumentCaptor<CreateLinkLayerResponseData> messageCaptor = ArgumentCaptor.forClass(
                CreateLinkLayerResponseData.class);  
        verify(m_MessageFactory).createCustomCommsResponseMessage(eq(message), 
                eq(CustomCommsMessageType.CreateLinkLayerResponse), messageCaptor.capture());
        verify(m_ResponseWrapper).queue(channel);
        CreateLinkLayerResponseData response = messageCaptor.getValue();
        assertThat(response.getInfo().getUuid(), is(notNullValue()));
        assertThat(SharedMessageUtils.convertProtoUUIDtoUUID(response.getInfo().getUuid()), is(testUuid2));
        assertThat(response.getInfo().getPid(), is("linkPid"));
    }
@ Test public void testCreateLinkLayer ( ) throws IOException , CCommException { CreateLinkLayerRequestData request = CreateLinkLayerRequestData . newBuilder ( ) . setLinkLayerProductType ( "meow" ) . setLinkLayerName ( "woof" ) . setPhysicalLinkUuid ( SharedMessageUtils . convertUUIDToProtoUUID ( testUuid ) ) . build ( ) ; CustomCommsNamespace ccommMessage = CustomCommsNamespace . newBuilder ( ) . setType ( CustomCommsMessageType . CreateLinkLayerRequest ) . setData ( request . toByteString ( ) ) . build ( ) ; TerraHarvestPayload payload = createPayload ( ccommMessage ) ; TerraHarvestMessage message = createCustomCommsMessage ( ccommMessage ) ; RemoteChannel channel = mock ( RemoteChannel . class ) ; LinkLayer createdLinkLayer = mock ( LinkLayer . class ) ; Map < String , Object > properties = new HashMap < String , Object > ( ) ; properties . put ( LinkLayerAttributes . CONFIG_PROP_PHYSICAL_LINK_NAME , "chirp" ) ; when ( m_CustomCommsService . createLinkLayer ( "meow" , "woof" , properties ) ) . thenReturn ( createdLinkLayer ) ; when ( createdLinkLayer . getUuid ( ) ) . thenReturn ( testUuid2 ) ; when ( createdLinkLayer . getPid ( ) ) . thenReturn ( "linkPid" ) ; when ( createdLinkLayer . getFactory ( ) ) . thenReturn ( m_LinkLayerFactory ) ; when ( m_CustomCommsService . getPhysicalLinkName ( testUuid ) ) . thenReturn ( "chirp" ) ; m_SUT . handleMessage ( message , payload , channel ) ; ArgumentCaptor < Event > eventCaptor = ArgumentCaptor . forClass ( Event . class ) ; verify ( m_EventAdmin ) . postEvent ( eventCaptor . capture ( ) ) ; Event event = eventCaptor . getValue ( ) ; assertThat ( ( CreateLinkLayerRequestData ) event . getProperty ( RemoteConstants . EVENT_PROP_DATA_MESSAGE ) , is ( request ) ) ; ArgumentCaptor < CreateLinkLayerResponseData > messageCaptor = ArgumentCaptor . forClass ( CreateLinkLayerResponseData . class ) ; verify ( m_MessageFactory ) . createCustomCommsResponseMessage ( eq ( message ) , eq ( CustomCommsMessageType . CreateLinkLayerResponse ) , messageCaptor . capture ( ) ) ; verify ( m_ResponseWrapper ) . queue ( channel ) ; CreateLinkLayerResponseData response = messageCaptor . getValue ( ) ; assertThat ( response . getInfo ( ) . getUuid ( ) , is ( notNullValue ( ) ) ) ; assertThat ( SharedMessageUtils . convertProtoUUIDtoUUID ( response . getInfo ( ) . getUuid ( ) ) , is ( testUuid2 ) ) ; assertThat ( response . getInfo ( ) . getPid ( ) , is ( "linkPid" ) ) ; }
Verify that the core service is requested to create a link layer, 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 create a link layer 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