mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/asset/TestAssetDirectoryMessageService.java
@Test
    public void testAssetException() throws IllegalArgumentException, FactoryException, IOException
    {
        ScanForNewAssetsRequestData request = ScanForNewAssetsRequestData.newBuilder().
                setProductType("myProductType").build();
        AssetDirectoryServiceNamespace assetDirMessage = AssetDirectoryServiceNamespace.newBuilder().
                setType(AssetDirectoryServiceMessageType.ScanForNewAssetsRequest).
                setData(request.toByteString()).build();
        TerraHarvestPayload payload = createPayload(assetDirMessage);
        TerraHarvestMessage message = createMessage(assetDirMessage);

        doThrow(new IllegalArgumentException("Factory not found for given class name"))
            .when(m_AssetDirectoryService).scanForNewAssets("myProductType");

        RemoteChannel channel = mock(RemoteChannel.class);
        m_SUT.handleMessage(message, payload, channel);    
        verify(m_MessageFactory).createBaseErrorMessage(message, ErrorCode.ASSET_ERROR, 
                "Cannot complete request. Factory not found for given class name");
        verify(m_ResponseWrapper).queue(channel);
        
        //Create asset request exception
        CreateAssetRequestData request2 = CreateAssetRequestData.newBuilder().
                setProductType("my.FQ.className").build();
        assetDirMessage = AssetDirectoryServiceNamespace.newBuilder().
                setType(AssetDirectoryServiceMessageType.CreateAssetRequest).
                setData(request2.toByteString()).build();
        payload = createPayload(assetDirMessage);
        message = createMessage(assetDirMessage);
        
        when(m_AssetDirectoryService.createAsset(Mockito.anyString(), Mockito.anyString())).
            thenThrow(new AssetException("create asset error"));
        
        m_SUT.handleMessage(message, payload, channel);
        verify(m_MessageFactory).createBaseErrorMessage(message, ErrorCode.ASSET_ERROR, 
                "Cannot complete request. create asset error");
        //reused channel
        verify(m_ResponseWrapper, times(2)).queue(channel);
    }
/**
     * Test and verify that asset exception is caught and error message is queued.
     */
Test and verify that asset exception is caught and error message is queued.
Test and verify that asset exception is caught and error message is queued .
@Test
    public void testAssetException() throws IllegalArgumentException, FactoryException, IOException
    {
        ScanForNewAssetsRequestData request = ScanForNewAssetsRequestData.newBuilder().
                setProductType("myProductType").build();
        AssetDirectoryServiceNamespace assetDirMessage = AssetDirectoryServiceNamespace.newBuilder().
                setType(AssetDirectoryServiceMessageType.ScanForNewAssetsRequest).
                setData(request.toByteString()).build();
        TerraHarvestPayload payload = createPayload(assetDirMessage);
        TerraHarvestMessage message = createMessage(assetDirMessage);
        doThrow(new IllegalArgumentException("Factory not found for given class name"))
            .when(m_AssetDirectoryService).scanForNewAssets("myProductType");
        RemoteChannel channel = mock(RemoteChannel.class);
        m_SUT.handleMessage(message, payload, channel);    
        verify(m_MessageFactory).createBaseErrorMessage(message, ErrorCode.ASSET_ERROR, 
                "Cannot complete request. Factory not found for given class name");
        verify(m_ResponseWrapper).queue(channel);
        CreateAssetRequestData request2 = CreateAssetRequestData.newBuilder().
                setProductType("my.FQ.className").build();
        assetDirMessage = AssetDirectoryServiceNamespace.newBuilder().
                setType(AssetDirectoryServiceMessageType.CreateAssetRequest).
                setData(request2.toByteString()).build();
        payload = createPayload(assetDirMessage);
        message = createMessage(assetDirMessage);
        when(m_AssetDirectoryService.createAsset(Mockito.anyString(), Mockito.anyString())).
            thenThrow(new AssetException("create asset error"));
        m_SUT.handleMessage(message, payload, channel);
        verify(m_MessageFactory).createBaseErrorMessage(message, ErrorCode.ASSET_ERROR, 
                "Cannot complete request. create asset error");
        verify(m_ResponseWrapper, times(2)).queue(channel);
    }
@ Test public void testAssetException ( ) throws IllegalArgumentException , FactoryException , IOException { ScanForNewAssetsRequestData request = ScanForNewAssetsRequestData . newBuilder ( ) . setProductType ( "myProductType" ) . build ( ) ; AssetDirectoryServiceNamespace assetDirMessage = AssetDirectoryServiceNamespace . newBuilder ( ) . setType ( AssetDirectoryServiceMessageType . ScanForNewAssetsRequest ) . setData ( request . toByteString ( ) ) . build ( ) ; TerraHarvestPayload payload = createPayload ( assetDirMessage ) ; TerraHarvestMessage message = createMessage ( assetDirMessage ) ; doThrow ( new IllegalArgumentException ( "Factory not found for given class name" ) ) . when ( m_AssetDirectoryService ) . scanForNewAssets ( "myProductType" ) ; RemoteChannel channel = mock ( RemoteChannel . class ) ; m_SUT . handleMessage ( message , payload , channel ) ; verify ( m_MessageFactory ) . createBaseErrorMessage ( message , ErrorCode . ASSET_ERROR , "Cannot complete request. Factory not found for given class name" ) ; verify ( m_ResponseWrapper ) . queue ( channel ) ; CreateAssetRequestData request2 = CreateAssetRequestData . newBuilder ( ) . setProductType ( "my.FQ.className" ) . build ( ) ; assetDirMessage = AssetDirectoryServiceNamespace . newBuilder ( ) . setType ( AssetDirectoryServiceMessageType . CreateAssetRequest ) . setData ( request2 . toByteString ( ) ) . build ( ) ; payload = createPayload ( assetDirMessage ) ; message = createMessage ( assetDirMessage ) ; when ( m_AssetDirectoryService . createAsset ( Mockito . anyString ( ) , Mockito . anyString ( ) ) ) . thenThrow ( new AssetException ( "create asset error" ) ) ; m_SUT . handleMessage ( message , payload , channel ) ; verify ( m_MessageFactory ) . createBaseErrorMessage ( message , ErrorCode . ASSET_ERROR , "Cannot complete request. create asset error" ) ; verify ( m_ResponseWrapper , times ( 2 ) ) . queue ( channel ) ; }
Test and verify that asset exception is caught and error message is queued.
Test and verify that asset exception is caught and error message is queued .
//Create asset request exception //reused channel