mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/asset/TestAssetMessageService.java
@Test
    public final void testCaptureData_ObjectConverterException() throws Exception
    {   
        //mock necessary objects/actions
        Asset asset = mock(Asset.class);
        Observation obs = mock(Observation.class);
        UUID obsUuid = UUID.randomUUID();
        
        RemoteChannel channel = mock(RemoteChannel.class);
        
        // build request
        CaptureDataRequestData request = CaptureDataRequestData.newBuilder()
                .setUuid(SharedMessageUtils.convertUUIDToProtoUUID(m_AssetUuid))
                .setObservationFormat(RemoteTypesGen.LexiconFormat.Enum.NATIVE).build();        
        AssetNamespace assetMessage = AssetNamespace.newBuilder().
                setType(AssetMessageType.CaptureDataRequest).
                setData(request.toByteString()).build();
        TerraHarvestPayload payload = createPayload(assetMessage);
        TerraHarvestMessage message = createMessage(assetMessage);

        //re-mock necessary objects/actions
        asset = mock(Asset.class);
        obs = mock(Observation.class);
        obsUuid = UUID.randomUUID();

        when(asset.captureData()).thenReturn(obs);
        when(obs.getUuid()).thenReturn(obsUuid);
        when(m_Converter.convertToProto(obs)).thenThrow(new ObjectConverterException("convert error 2"));
        when(m_AssetDirectoryService.getAssetByUuid(m_AssetUuid)).thenReturn(asset);

        m_SUT.handleMessage(message, payload, channel);
        verify(m_MessageFactory).createBaseErrorMessage(message, ErrorCode.CONVERTER_ERROR, 
                "Cannot complete request. convert error 2");
        //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 testCaptureData_ObjectConverterException() throws Exception
    {   
        Asset asset = mock(Asset.class);
        Observation obs = mock(Observation.class);
        UUID obsUuid = UUID.randomUUID();
        RemoteChannel channel = mock(RemoteChannel.class);
        CaptureDataRequestData request = CaptureDataRequestData.newBuilder()
                .setUuid(SharedMessageUtils.convertUUIDToProtoUUID(m_AssetUuid))
                .setObservationFormat(RemoteTypesGen.LexiconFormat.Enum.NATIVE).build();        
        AssetNamespace assetMessage = AssetNamespace.newBuilder().
                setType(AssetMessageType.CaptureDataRequest).
                setData(request.toByteString()).build();
        TerraHarvestPayload payload = createPayload(assetMessage);
        TerraHarvestMessage message = createMessage(assetMessage);
        asset = mock(Asset.class);
        obs = mock(Observation.class);
        obsUuid = UUID.randomUUID();
        when(asset.captureData()).thenReturn(obs);
        when(obs.getUuid()).thenReturn(obsUuid);
        when(m_Converter.convertToProto(obs)).thenThrow(new ObjectConverterException("convert error 2"));
        when(m_AssetDirectoryService.getAssetByUuid(m_AssetUuid)).thenReturn(asset);
        m_SUT.handleMessage(message, payload, channel);
        verify(m_MessageFactory).createBaseErrorMessage(message, ErrorCode.CONVERTER_ERROR, 
                "Cannot complete request. convert error 2");
        verify(m_ResponseWrapper).queue(channel);
    }
@ Test public final void testCaptureData_ObjectConverterException ( ) throws Exception { Asset asset = mock ( Asset . class ) ; Observation obs = mock ( Observation . class ) ; UUID obsUuid = UUID . randomUUID ( ) ; RemoteChannel channel = mock ( RemoteChannel . class ) ; CaptureDataRequestData request = CaptureDataRequestData . newBuilder ( ) . setUuid ( SharedMessageUtils . convertUUIDToProtoUUID ( m_AssetUuid ) ) . setObservationFormat ( RemoteTypesGen . LexiconFormat . Enum . NATIVE ) . build ( ) ; AssetNamespace assetMessage = AssetNamespace . newBuilder ( ) . setType ( AssetMessageType . CaptureDataRequest ) . setData ( request . toByteString ( ) ) . build ( ) ; TerraHarvestPayload payload = createPayload ( assetMessage ) ; TerraHarvestMessage message = createMessage ( assetMessage ) ; asset = mock ( Asset . class ) ; obs = mock ( Observation . class ) ; obsUuid = UUID . randomUUID ( ) ; when ( asset . captureData ( ) ) . thenReturn ( obs ) ; when ( obs . getUuid ( ) ) . thenReturn ( obsUuid ) ; when ( m_Converter . convertToProto ( obs ) ) . thenThrow ( new ObjectConverterException ( "convert error 2" ) ) ; when ( m_AssetDirectoryService . getAssetByUuid ( m_AssetUuid ) ) . thenReturn ( asset ) ; m_SUT . handleMessage ( message , payload , channel ) ; verify ( m_MessageFactory ) . createBaseErrorMessage ( message , ErrorCode . CONVERTER_ERROR , "Cannot complete request. convert error 2" ) ; 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
//mock necessary objects/actions // build request //re-mock necessary objects/actions //reused channel