mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/ccomms/TestLinkLayerMessageService.java
@Test
    public void testGetStatus() throws IOException
    {
        // build the terra harvest message
        GetStatusRequestData request = GetStatusRequestData.newBuilder()
                .setUuid(SharedMessageUtils.convertUUIDToProtoUUID(testUuid))
                .build();
        
        LinkLayerNamespace llMessage = LinkLayerNamespace.newBuilder()
                .setType(LinkLayerMessageType.GetStatusRequest)
                .setData(request.toByteString())
                .build();
        
        TerraHarvestPayload payload = createPayload(llMessage);
        TerraHarvestMessage message = createLinkLayerMessage(llMessage);
        
        // mock the channel the message came from
        RemoteChannel channel = mock(RemoteChannel.class);
        
        //-----testing ok status-----
        LinkStatus testStatus = LinkStatus.OK;
        
        when(testLayer.getLinkStatus()).thenReturn(testStatus);
        
        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((GetStatusRequestData)event.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE),
                is(request));
        
        //capture and verify response
        ArgumentCaptor<GetStatusResponseData> messageCaptor = ArgumentCaptor.forClass(
                GetStatusResponseData.class);  
        verify(m_MessageFactory).createLinkLayerResponseMessage(eq(message), 
                eq(LinkLayerMessageType.GetStatusResponse), messageCaptor.capture());
        verify(m_ResponseWrapper).queue(channel);
        
        GetStatusResponseData response = messageCaptor.getValue();
 
        assertThat(response.getLinkStatus(), is(CustomCommsTypes.LinkStatus.OK));
        
        //-----testing lost status-----
        testStatus = LinkStatus.LOST;
        
        when(testLayer.getLinkStatus()).thenReturn(testStatus);
        
        m_SUT.handleMessage(message, payload, channel);

        
        //capture and verify response
        verify(m_MessageFactory, times(2)).createLinkLayerResponseMessage(eq(message), 
                eq(LinkLayerMessageType.GetStatusResponse), messageCaptor.capture());
        //reused the channel
        verify(m_ResponseWrapper, times(2)).queue(channel);
        
        response = messageCaptor.getValue();
 
        assertThat(response.getLinkStatus(), is(CustomCommsTypes.LinkStatus.LOST));
        assertThat(response.getUuid(), is(SharedMessageUtils.convertUUIDToProtoUUID(testUuid)));
    }
/**
     * 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 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 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 testGetStatus() throws IOException
    {
        GetStatusRequestData request = GetStatusRequestData.newBuilder()
                .setUuid(SharedMessageUtils.convertUUIDToProtoUUID(testUuid))
                .build();
        LinkLayerNamespace llMessage = LinkLayerNamespace.newBuilder()
                .setType(LinkLayerMessageType.GetStatusRequest)
                .setData(request.toByteString())
                .build();
        TerraHarvestPayload payload = createPayload(llMessage);
        TerraHarvestMessage message = createLinkLayerMessage(llMessage);
        RemoteChannel channel = mock(RemoteChannel.class);
        LinkStatus testStatus = LinkStatus.OK;
        when(testLayer.getLinkStatus()).thenReturn(testStatus);
        m_SUT.handleMessage(message, payload, channel);
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin).postEvent(eventCaptor.capture());
        Event event = eventCaptor.getValue();
        assertThat((GetStatusRequestData)event.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE),
                is(request));
        ArgumentCaptor<GetStatusResponseData> messageCaptor = ArgumentCaptor.forClass(
                GetStatusResponseData.class);  
        verify(m_MessageFactory).createLinkLayerResponseMessage(eq(message), 
                eq(LinkLayerMessageType.GetStatusResponse), messageCaptor.capture());
        verify(m_ResponseWrapper).queue(channel);
        GetStatusResponseData response = messageCaptor.getValue();
        assertThat(response.getLinkStatus(), is(CustomCommsTypes.LinkStatus.OK));
        testStatus = LinkStatus.LOST;
        when(testLayer.getLinkStatus()).thenReturn(testStatus);
        m_SUT.handleMessage(message, payload, channel);
        verify(m_MessageFactory, times(2)).createLinkLayerResponseMessage(eq(message), 
                eq(LinkLayerMessageType.GetStatusResponse), messageCaptor.capture());
        verify(m_ResponseWrapper, times(2)).queue(channel);
        response = messageCaptor.getValue();
        assertThat(response.getLinkStatus(), is(CustomCommsTypes.LinkStatus.LOST));
        assertThat(response.getUuid(), is(SharedMessageUtils.convertUUIDToProtoUUID(testUuid)));
    }
@ Test public void testGetStatus ( ) throws IOException { GetStatusRequestData request = GetStatusRequestData . newBuilder ( ) . setUuid ( SharedMessageUtils . convertUUIDToProtoUUID ( testUuid ) ) . build ( ) ; LinkLayerNamespace llMessage = LinkLayerNamespace . newBuilder ( ) . setType ( LinkLayerMessageType . GetStatusRequest ) . setData ( request . toByteString ( ) ) . build ( ) ; TerraHarvestPayload payload = createPayload ( llMessage ) ; TerraHarvestMessage message = createLinkLayerMessage ( llMessage ) ; RemoteChannel channel = mock ( RemoteChannel . class ) ; LinkStatus testStatus = LinkStatus . OK ; when ( testLayer . getLinkStatus ( ) ) . thenReturn ( testStatus ) ; m_SUT . handleMessage ( message , payload , channel ) ; ArgumentCaptor < Event > eventCaptor = ArgumentCaptor . forClass ( Event . class ) ; verify ( m_EventAdmin ) . postEvent ( eventCaptor . capture ( ) ) ; Event event = eventCaptor . getValue ( ) ; assertThat ( ( GetStatusRequestData ) event . getProperty ( RemoteConstants . EVENT_PROP_DATA_MESSAGE ) , is ( request ) ) ; ArgumentCaptor < GetStatusResponseData > messageCaptor = ArgumentCaptor . forClass ( GetStatusResponseData . class ) ; verify ( m_MessageFactory ) . createLinkLayerResponseMessage ( eq ( message ) , eq ( LinkLayerMessageType . GetStatusResponse ) , messageCaptor . capture ( ) ) ; verify ( m_ResponseWrapper ) . queue ( channel ) ; GetStatusResponseData response = messageCaptor . getValue ( ) ; assertThat ( response . getLinkStatus ( ) , is ( CustomCommsTypes . LinkStatus . OK ) ) ; testStatus = LinkStatus . LOST ; when ( testLayer . getLinkStatus ( ) ) . thenReturn ( testStatus ) ; m_SUT . handleMessage ( message , payload , channel ) ; verify ( m_MessageFactory , times ( 2 ) ) . createLinkLayerResponseMessage ( eq ( message ) , eq ( LinkLayerMessageType . GetStatusResponse ) , messageCaptor . capture ( ) ) ; verify ( m_ResponseWrapper , times ( 2 ) ) . queue ( channel ) ; response = messageCaptor . getValue ( ) ; assertThat ( response . getLinkStatus ( ) , is ( CustomCommsTypes . LinkStatus . LOST ) ) ; assertThat ( response . getUuid ( ) , is ( SharedMessageUtils . convertUUIDToProtoUUID ( testUuid ) ) ) ; }
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 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 .
// build the terra harvest message // mock the channel the message came from //-----testing ok status----- // verify the event contains the data message //capture and verify response //-----testing lost status----- //capture and verify response //reused the channel