mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/ccomms/TestCustomCommsMessageService.java
@Test
    public final void testObjectConverter() throws UnmarshalException, IOException, ObjectConverterException
    {
        // test LinkLayerCapabilities objectConverter exception:
        CustomCommsNamespace commsMessage = 
                createGetCapsRequestMessage(CommType.Linklayer, LinkLayer.class.getName());
        TerraHarvestPayload payload = createPayload(commsMessage);
        TerraHarvestMessage message = createCustomCommsMessage(commsMessage);
    
        //mock necessary objects/actions;
        LinkLayerCapabilities linkCaps = mock(LinkLayerCapabilities.class);
        when(m_LinkLayerFactory.getLinkLayerCapabilities()).thenReturn(linkCaps);
        when(m_Converter.convertToProto(linkCaps)).
                thenThrow(new ObjectConverterException("cannot convert"));
        
        //mock the channel the message came from
        RemoteChannel channel = mock(RemoteChannel.class);
        //reply
        m_SUT.handleMessage(message, payload, channel);
        
        verify(m_MessageFactory).createBaseErrorMessage(message, ErrorCode.CONVERTER_ERROR, 
                "Cannot complete request. cannot convert");
        verify(m_ResponseWrapper).queue(channel);
        
        // test TransportLayerCapabilities unmarshal exception:
        commsMessage = createGetCapsRequestMessage(CommType.TransportLayer, TransportLayer.class.getName());
        payload = createPayload(commsMessage);
        message = createCustomCommsMessage(commsMessage);
    
        //mock necessary objects/actions;
        TransportLayerCapabilities transportCaps = mock(TransportLayerCapabilities.class);
        when(m_TransportLayerFactory.getTransportLayerCapabilities()).thenReturn(transportCaps);
        when(m_Converter.convertToProto(transportCaps)).
                thenThrow(new ObjectConverterException("cannot convert"));
        
        //reply
        m_SUT.handleMessage(message, payload, channel);
        
        verify(m_MessageFactory).createBaseErrorMessage(message, ErrorCode.CONVERTER_ERROR, 
                "Cannot complete request. cannot convert");
        //reused channel
        verify(m_ResponseWrapper, times(2)).queue(channel);
        
        // test PhysicalLinkCapabilities unmarshal exception: 
        commsMessage = createGetCapsRequestMessage(CommType.PhysicalLink, PhysicalLink.class.getName());
        payload = createPayload(commsMessage);
        message = createCustomCommsMessage(commsMessage);
    
        //mock necessary objects/actions;
        PhysicalLinkCapabilities physicalCaps = mock(PhysicalLinkCapabilities.class);
        when(m_PhysicalLinkFactory.getPhysicalLinkCapabilities()).thenReturn(physicalCaps);
        when(m_Converter.convertToProto(physicalCaps)).
                thenThrow(new ObjectConverterException("cannot convert"));
        
        //reply
        m_SUT.handleMessage(message, payload, channel);
        
        verify(m_MessageFactory).createBaseErrorMessage(message, ErrorCode.CONVERTER_ERROR, 
                "Cannot complete request. cannot convert");
        //reused channel
        verify(m_ResponseWrapper, times(3)).queue(channel);
    }
/**
     * Test that the object converter is correctly handled when an error occurs converting the capabilities
     * to google protocol buffer format.
     */
Test that the object converter is correctly handled when an error occurs converting the capabilities
to google protocol buffer format.
Test that the object converter is correctly handled when an error occurs converting the capabilities to google protocol buffer format .
@Test
    public final void testObjectConverter() throws UnmarshalException, IOException, ObjectConverterException
    {
        CustomCommsNamespace commsMessage = 
                createGetCapsRequestMessage(CommType.Linklayer, LinkLayer.class.getName());
        TerraHarvestPayload payload = createPayload(commsMessage);
        TerraHarvestMessage message = createCustomCommsMessage(commsMessage);
        LinkLayerCapabilities linkCaps = mock(LinkLayerCapabilities.class);
        when(m_LinkLayerFactory.getLinkLayerCapabilities()).thenReturn(linkCaps);
        when(m_Converter.convertToProto(linkCaps)).
                thenThrow(new ObjectConverterException("cannot convert"));
        RemoteChannel channel = mock(RemoteChannel.class);
        m_SUT.handleMessage(message, payload, channel);
        verify(m_MessageFactory).createBaseErrorMessage(message, ErrorCode.CONVERTER_ERROR, 
                "Cannot complete request. cannot convert");
        verify(m_ResponseWrapper).queue(channel);
        commsMessage = createGetCapsRequestMessage(CommType.TransportLayer, TransportLayer.class.getName());
        payload = createPayload(commsMessage);
        message = createCustomCommsMessage(commsMessage);
        TransportLayerCapabilities transportCaps = mock(TransportLayerCapabilities.class);
        when(m_TransportLayerFactory.getTransportLayerCapabilities()).thenReturn(transportCaps);
        when(m_Converter.convertToProto(transportCaps)).
                thenThrow(new ObjectConverterException("cannot convert"));
        m_SUT.handleMessage(message, payload, channel);
        verify(m_MessageFactory).createBaseErrorMessage(message, ErrorCode.CONVERTER_ERROR, 
                "Cannot complete request. cannot convert");
        verify(m_ResponseWrapper, times(2)).queue(channel);
        commsMessage = createGetCapsRequestMessage(CommType.PhysicalLink, PhysicalLink.class.getName());
        payload = createPayload(commsMessage);
        message = createCustomCommsMessage(commsMessage);
        PhysicalLinkCapabilities physicalCaps = mock(PhysicalLinkCapabilities.class);
        when(m_PhysicalLinkFactory.getPhysicalLinkCapabilities()).thenReturn(physicalCaps);
        when(m_Converter.convertToProto(physicalCaps)).
                thenThrow(new ObjectConverterException("cannot convert"));
        m_SUT.handleMessage(message, payload, channel);
        verify(m_MessageFactory).createBaseErrorMessage(message, ErrorCode.CONVERTER_ERROR, 
                "Cannot complete request. cannot convert");
        verify(m_ResponseWrapper, times(3)).queue(channel);
    }
@ Test public final void testObjectConverter ( ) throws UnmarshalException , IOException , ObjectConverterException { CustomCommsNamespace commsMessage = createGetCapsRequestMessage ( CommType . Linklayer , LinkLayer . class . getName ( ) ) ; TerraHarvestPayload payload = createPayload ( commsMessage ) ; TerraHarvestMessage message = createCustomCommsMessage ( commsMessage ) ; LinkLayerCapabilities linkCaps = mock ( LinkLayerCapabilities . class ) ; when ( m_LinkLayerFactory . getLinkLayerCapabilities ( ) ) . thenReturn ( linkCaps ) ; when ( m_Converter . convertToProto ( linkCaps ) ) . thenThrow ( new ObjectConverterException ( "cannot convert" ) ) ; RemoteChannel channel = mock ( RemoteChannel . class ) ; m_SUT . handleMessage ( message , payload , channel ) ; verify ( m_MessageFactory ) . createBaseErrorMessage ( message , ErrorCode . CONVERTER_ERROR , "Cannot complete request. cannot convert" ) ; verify ( m_ResponseWrapper ) . queue ( channel ) ; commsMessage = createGetCapsRequestMessage ( CommType . TransportLayer , TransportLayer . class . getName ( ) ) ; payload = createPayload ( commsMessage ) ; message = createCustomCommsMessage ( commsMessage ) ; TransportLayerCapabilities transportCaps = mock ( TransportLayerCapabilities . class ) ; when ( m_TransportLayerFactory . getTransportLayerCapabilities ( ) ) . thenReturn ( transportCaps ) ; when ( m_Converter . convertToProto ( transportCaps ) ) . thenThrow ( new ObjectConverterException ( "cannot convert" ) ) ; m_SUT . handleMessage ( message , payload , channel ) ; verify ( m_MessageFactory ) . createBaseErrorMessage ( message , ErrorCode . CONVERTER_ERROR , "Cannot complete request. cannot convert" ) ; verify ( m_ResponseWrapper , times ( 2 ) ) . queue ( channel ) ; commsMessage = createGetCapsRequestMessage ( CommType . PhysicalLink , PhysicalLink . class . getName ( ) ) ; payload = createPayload ( commsMessage ) ; message = createCustomCommsMessage ( commsMessage ) ; PhysicalLinkCapabilities physicalCaps = mock ( PhysicalLinkCapabilities . class ) ; when ( m_PhysicalLinkFactory . getPhysicalLinkCapabilities ( ) ) . thenReturn ( physicalCaps ) ; when ( m_Converter . convertToProto ( physicalCaps ) ) . thenThrow ( new ObjectConverterException ( "cannot convert" ) ) ; m_SUT . handleMessage ( message , payload , channel ) ; verify ( m_MessageFactory ) . createBaseErrorMessage ( message , ErrorCode . CONVERTER_ERROR , "Cannot complete request. cannot convert" ) ; verify ( m_ResponseWrapper , times ( 3 ) ) . queue ( channel ) ; }
Test that the object converter is correctly handled when an error occurs converting the capabilities
 to google protocol buffer format.
Test that the object converter is correctly handled when an error occurs converting the capabilities to google protocol buffer format .
// test LinkLayerCapabilities objectConverter exception: //mock necessary objects/actions; //mock the channel the message came from //reply // test TransportLayerCapabilities unmarshal exception: //mock necessary objects/actions; //reply //reused channel // test PhysicalLinkCapabilities unmarshal exception:  //mock necessary objects/actions; //reply //reused channel