mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/asset/TestAssetDirectoryMessageService.java
@Test
    public final void testCatchObjectConverterException() throws IOException, ObjectConverterException
    {   
        //set up converter
        m_SUT.activate();
        
        //mock channel
        RemoteChannel channel = mock(RemoteChannel.class);

        // build request
        GetCapabilitiesRequestData request3 = GetCapabilitiesRequestData.newBuilder().
                setProductType(AssetProxy.class.getName()).build();     
        AssetDirectoryServiceNamespace assetMessage = AssetDirectoryServiceNamespace.newBuilder().
                setType(AssetDirectoryServiceMessageType.GetCapabilitiesRequest).
                setData(request3.toByteString()).build();
        TerraHarvestPayload payload = createPayload(assetMessage);
        TerraHarvestMessage message = createMessage(assetMessage);

        AssetCapabilities capabilities = mock(AssetCapabilities.class);
        AssetFactory factory = mock(AssetFactory.class);
        Set<AssetFactory> factories = new HashSet<>();
        factories.add(factory);
        doReturn(AssetProxy.class.getName()).when(factory).getProductType();
        when(m_AssetDirectoryService.getAssetFactories()).thenReturn(factories);
        when(factory.getCapabilities()).thenReturn(capabilities);
        when(m_Converter.convertToProto(Mockito.anyObject())).
            thenThrow(new ObjectConverterException("convert error"));
        
        m_SUT.handleMessage(message, payload, channel);
        verify(m_MessageFactory).createBaseErrorMessage(message, ErrorCode.CONVERTER_ERROR, 
                "Cannot complete request. convert error");
        //reused channel
        verify(m_ResponseWrapper).queue(channel);
    }
/**
     * Test and verify that object converter exception is caught and error message is queued
     */
Test and verify that object converter exception is caught and error message is queued
Test and verify that object converter exception is caught and error message is queued
@Test
    public final void testCatchObjectConverterException() throws IOException, ObjectConverterException
    {   
        m_SUT.activate();
        RemoteChannel channel = mock(RemoteChannel.class);
        GetCapabilitiesRequestData request3 = GetCapabilitiesRequestData.newBuilder().
                setProductType(AssetProxy.class.getName()).build();     
        AssetDirectoryServiceNamespace assetMessage = AssetDirectoryServiceNamespace.newBuilder().
                setType(AssetDirectoryServiceMessageType.GetCapabilitiesRequest).
                setData(request3.toByteString()).build();
        TerraHarvestPayload payload = createPayload(assetMessage);
        TerraHarvestMessage message = createMessage(assetMessage);
        AssetCapabilities capabilities = mock(AssetCapabilities.class);
        AssetFactory factory = mock(AssetFactory.class);
        Set<AssetFactory> factories = new HashSet<>();
        factories.add(factory);
        doReturn(AssetProxy.class.getName()).when(factory).getProductType();
        when(m_AssetDirectoryService.getAssetFactories()).thenReturn(factories);
        when(factory.getCapabilities()).thenReturn(capabilities);
        when(m_Converter.convertToProto(Mockito.anyObject())).
            thenThrow(new ObjectConverterException("convert error"));
        m_SUT.handleMessage(message, payload, channel);
        verify(m_MessageFactory).createBaseErrorMessage(message, ErrorCode.CONVERTER_ERROR, 
                "Cannot complete request. convert error");
        verify(m_ResponseWrapper).queue(channel);
    }
@ Test public final void testCatchObjectConverterException ( ) throws IOException , ObjectConverterException { m_SUT . activate ( ) ; RemoteChannel channel = mock ( RemoteChannel . class ) ; GetCapabilitiesRequestData request3 = GetCapabilitiesRequestData . newBuilder ( ) . setProductType ( AssetProxy . class . getName ( ) ) . build ( ) ; AssetDirectoryServiceNamespace assetMessage = AssetDirectoryServiceNamespace . newBuilder ( ) . setType ( AssetDirectoryServiceMessageType . GetCapabilitiesRequest ) . setData ( request3 . toByteString ( ) ) . build ( ) ; TerraHarvestPayload payload = createPayload ( assetMessage ) ; TerraHarvestMessage message = createMessage ( assetMessage ) ; AssetCapabilities capabilities = mock ( AssetCapabilities . class ) ; AssetFactory factory = mock ( AssetFactory . class ) ; Set < AssetFactory > factories = new HashSet < > ( ) ; factories . add ( factory ) ; doReturn ( AssetProxy . class . getName ( ) ) . when ( factory ) . getProductType ( ) ; when ( m_AssetDirectoryService . getAssetFactories ( ) ) . thenReturn ( factories ) ; when ( factory . getCapabilities ( ) ) . thenReturn ( capabilities ) ; when ( m_Converter . convertToProto ( Mockito . anyObject ( ) ) ) . thenThrow ( new ObjectConverterException ( "convert error" ) ) ; m_SUT . handleMessage ( message , payload , channel ) ; verify ( m_MessageFactory ) . createBaseErrorMessage ( message , ErrorCode . CONVERTER_ERROR , "Cannot complete request. convert error" ) ; verify ( m_ResponseWrapper ) . queue ( channel ) ; }
Test and verify that object converter exception is caught and error message is queued
Test and verify that object converter exception is caught and error message is queued
//set up converter //mock channel // build request //reused channel