mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/ccomms/TestCustomCommsMessageService.java
@Test
    public void testCreatePhysicalLinkNoPID() throws IOException, CCommException
    {
        CreatePhysicalLinkRequestData request = CreatePhysicalLinkRequestData.newBuilder()
                .setPhysicalLinkType(CustomCommTypesGen.PhysicalLinkType.Enum.GPIO)
                .setPhysicalLinkName("PhysicallyImpossible")
                .build();
        
        CustomCommsNamespace ccommMessage = CustomCommsNamespace.newBuilder()
                .setType(CustomCommsMessageType.CreatePhysicalLinkRequest)
                .setData(request.toByteString())
                .build();
        

        TerraHarvestPayload payload = createPayload(ccommMessage);
        TerraHarvestMessage message = createCustomCommsMessage(ccommMessage);
        
        // mock the channel the message came from
        RemoteChannel channel = mock(RemoteChannel.class);
        
        final PhysicalLink createdPhysicalLink = mock(PhysicalLink.class);
        when(createdPhysicalLink.getUuid()).thenReturn(testUuid);
        when(createdPhysicalLink.getPid()).thenReturn(null);
        when(createdPhysicalLink.getFactory()).thenReturn(m_PhysicalLinkFactory);
        
        when(m_CustomCommsService.createPhysicalLink(PhysicalLinkTypeEnum.GPIO, "PhysicallyImpossible")).
            thenReturn(createdPhysicalLink);
        
        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((CreatePhysicalLinkRequestData)event.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE),
                is(request));
        
        //capture and verify response
        ArgumentCaptor<CreatePhysicalLinkResponseData> messageCaptor = ArgumentCaptor.forClass(
                CreatePhysicalLinkResponseData.class);  
        verify(m_MessageFactory).createCustomCommsResponseMessage(eq(message), 
                eq(CustomCommsMessageType.CreatePhysicalLinkResponse), messageCaptor.capture());
        verify(m_ResponseWrapper).queue(channel);
        
        CreatePhysicalLinkResponseData response = messageCaptor.getValue();
 
        assertThat(SharedMessageUtils.convertProtoUUIDtoUUID(response.getInfo().getUuid()), is(testUuid));
        assertThat(response.getInfo().hasPid(), is(false));
    }
/**
     * Verify response message is still sent even if PID is not set for the physical link created.
     */
Verify response message is still sent even if PID is not set for the physical link created.
Verify response message is still sent even if PID is not set for the physical link created .
@Test
    public void testCreatePhysicalLinkNoPID() throws IOException, CCommException
    {
        CreatePhysicalLinkRequestData request = CreatePhysicalLinkRequestData.newBuilder()
                .setPhysicalLinkType(CustomCommTypesGen.PhysicalLinkType.Enum.GPIO)
                .setPhysicalLinkName("PhysicallyImpossible")
                .build();
        CustomCommsNamespace ccommMessage = CustomCommsNamespace.newBuilder()
                .setType(CustomCommsMessageType.CreatePhysicalLinkRequest)
                .setData(request.toByteString())
                .build();
        TerraHarvestPayload payload = createPayload(ccommMessage);
        TerraHarvestMessage message = createCustomCommsMessage(ccommMessage);
        RemoteChannel channel = mock(RemoteChannel.class);
        final PhysicalLink createdPhysicalLink = mock(PhysicalLink.class);
        when(createdPhysicalLink.getUuid()).thenReturn(testUuid);
        when(createdPhysicalLink.getPid()).thenReturn(null);
        when(createdPhysicalLink.getFactory()).thenReturn(m_PhysicalLinkFactory);
        when(m_CustomCommsService.createPhysicalLink(PhysicalLinkTypeEnum.GPIO, "PhysicallyImpossible")).
            thenReturn(createdPhysicalLink);
        m_SUT.handleMessage(message, payload, channel);
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin).postEvent(eventCaptor.capture());
        Event event = eventCaptor.getValue();
        assertThat((CreatePhysicalLinkRequestData)event.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE),
                is(request));
        ArgumentCaptor<CreatePhysicalLinkResponseData> messageCaptor = ArgumentCaptor.forClass(
                CreatePhysicalLinkResponseData.class);  
        verify(m_MessageFactory).createCustomCommsResponseMessage(eq(message), 
                eq(CustomCommsMessageType.CreatePhysicalLinkResponse), messageCaptor.capture());
        verify(m_ResponseWrapper).queue(channel);
        CreatePhysicalLinkResponseData response = messageCaptor.getValue();
        assertThat(SharedMessageUtils.convertProtoUUIDtoUUID(response.getInfo().getUuid()), is(testUuid));
        assertThat(response.getInfo().hasPid(), is(false));
    }
@ Test public void testCreatePhysicalLinkNoPID ( ) throws IOException , CCommException { CreatePhysicalLinkRequestData request = CreatePhysicalLinkRequestData . newBuilder ( ) . setPhysicalLinkType ( CustomCommTypesGen . PhysicalLinkType . Enum . GPIO ) . setPhysicalLinkName ( "PhysicallyImpossible" ) . build ( ) ; CustomCommsNamespace ccommMessage = CustomCommsNamespace . newBuilder ( ) . setType ( CustomCommsMessageType . CreatePhysicalLinkRequest ) . setData ( request . toByteString ( ) ) . build ( ) ; TerraHarvestPayload payload = createPayload ( ccommMessage ) ; TerraHarvestMessage message = createCustomCommsMessage ( ccommMessage ) ; RemoteChannel channel = mock ( RemoteChannel . class ) ; final PhysicalLink createdPhysicalLink = mock ( PhysicalLink . class ) ; when ( createdPhysicalLink . getUuid ( ) ) . thenReturn ( testUuid ) ; when ( createdPhysicalLink . getPid ( ) ) . thenReturn ( null ) ; when ( createdPhysicalLink . getFactory ( ) ) . thenReturn ( m_PhysicalLinkFactory ) ; when ( m_CustomCommsService . createPhysicalLink ( PhysicalLinkTypeEnum . GPIO , "PhysicallyImpossible" ) ) . thenReturn ( createdPhysicalLink ) ; m_SUT . handleMessage ( message , payload , channel ) ; ArgumentCaptor < Event > eventCaptor = ArgumentCaptor . forClass ( Event . class ) ; verify ( m_EventAdmin ) . postEvent ( eventCaptor . capture ( ) ) ; Event event = eventCaptor . getValue ( ) ; assertThat ( ( CreatePhysicalLinkRequestData ) event . getProperty ( RemoteConstants . EVENT_PROP_DATA_MESSAGE ) , is ( request ) ) ; ArgumentCaptor < CreatePhysicalLinkResponseData > messageCaptor = ArgumentCaptor . forClass ( CreatePhysicalLinkResponseData . class ) ; verify ( m_MessageFactory ) . createCustomCommsResponseMessage ( eq ( message ) , eq ( CustomCommsMessageType . CreatePhysicalLinkResponse ) , messageCaptor . capture ( ) ) ; verify ( m_ResponseWrapper ) . queue ( channel ) ; CreatePhysicalLinkResponseData response = messageCaptor . getValue ( ) ; assertThat ( SharedMessageUtils . convertProtoUUIDtoUUID ( response . getInfo ( ) . getUuid ( ) ) , is ( testUuid ) ) ; assertThat ( response . getInfo ( ) . hasPid ( ) , is ( false ) ) ; }
Verify response message is still sent even if PID is not set for the physical link created.
Verify response message is still sent even if PID is not set for the physical link created .
// mock the channel the message came from // verify the event contains the data message //capture and verify response