mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/ccomms/TestCustomCommsMessageService.java
@Test
    public void testCreatePhysicalLinkGPIO() throws IOException, CCommException
    {
        CreatePhysicalLinkRequestData request = CreatePhysicalLinkRequestData.newBuilder()
                .setPhysicalLinkType(CustomCommTypesGen.PhysicalLinkType.Enum.GPIO)
                .setPhysicalLinkName("trident")
                .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);
        
        PhysicalLink createdPhysicalLink = mock(PhysicalLink.class);
        when(createdPhysicalLink.getUuid()).thenReturn(testUuid);
        when(createdPhysicalLink.getPid()).thenReturn("physPid");
        when(createdPhysicalLink.getFactory()).thenReturn(m_PhysicalLinkFactory);
        
        when(m_CustomCommsService.createPhysicalLink(PhysicalLinkTypeEnum.GPIO, "trident"))
            .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().getPid(), is("physPid"));
    }
/**
     * Verify ability to create GPIO phys link
     */
Verify ability to create GPIO phys link
Verify ability to create GPIO phys link
@Test
    public void testCreatePhysicalLinkGPIO() throws IOException, CCommException
    {
        CreatePhysicalLinkRequestData request = CreatePhysicalLinkRequestData.newBuilder()
                .setPhysicalLinkType(CustomCommTypesGen.PhysicalLinkType.Enum.GPIO)
                .setPhysicalLinkName("trident")
                .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);
        PhysicalLink createdPhysicalLink = mock(PhysicalLink.class);
        when(createdPhysicalLink.getUuid()).thenReturn(testUuid);
        when(createdPhysicalLink.getPid()).thenReturn("physPid");
        when(createdPhysicalLink.getFactory()).thenReturn(m_PhysicalLinkFactory);
        when(m_CustomCommsService.createPhysicalLink(PhysicalLinkTypeEnum.GPIO, "trident"))
            .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().getPid(), is("physPid"));
    }
@ Test public void testCreatePhysicalLinkGPIO ( ) throws IOException , CCommException { CreatePhysicalLinkRequestData request = CreatePhysicalLinkRequestData . newBuilder ( ) . setPhysicalLinkType ( CustomCommTypesGen . PhysicalLinkType . Enum . GPIO ) . setPhysicalLinkName ( "trident" ) . 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 ) ; PhysicalLink createdPhysicalLink = mock ( PhysicalLink . class ) ; when ( createdPhysicalLink . getUuid ( ) ) . thenReturn ( testUuid ) ; when ( createdPhysicalLink . getPid ( ) ) . thenReturn ( "physPid" ) ; when ( createdPhysicalLink . getFactory ( ) ) . thenReturn ( m_PhysicalLinkFactory ) ; when ( m_CustomCommsService . createPhysicalLink ( PhysicalLinkTypeEnum . GPIO , "trident" ) ) . 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 ( ) . getPid ( ) , is ( "physPid" ) ) ; }
Verify ability to create GPIO phys link
Verify ability to create GPIO phys link
// mock the channel the message came from // verify the event contains the data message //capture and verify response