mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/asset/TestAssetMessageService.java
@Test
    public void testSetAssetNameRequestPersist() throws IOException, IllegalArgumentException, FactoryException
    {
        //mock behavior
        Asset asset = mock(Asset.class);
        when(asset.getName()).thenReturn("name");
        when(m_AssetDirectoryService.getAssetByUuid(testUuid)).thenReturn(asset);
        
        //verify
        doThrow(new AssetException("Exception")).when(asset).setName("name");
        
        SetNameRequestData request = SetNameRequestData.newBuilder().
                setAssetName("name").
                setUuid(SharedMessageUtils.convertUUIDToProtoUUID(testUuid)).build();
        AssetNamespace assetDirMessage = AssetNamespace.newBuilder().
                setType(AssetMessageType.SetNameRequest).
                setData(request.toByteString()).build();
        TerraHarvestMessage message = createMessage(assetDirMessage);

        //mock remote channel
        RemoteChannel channel = mock(RemoteChannel.class);

        //handle message
        m_SUT.handleMessage(message, createPayload(assetDirMessage), channel);

        verify(m_MessageFactory).createBaseErrorMessage(message, ErrorCode.ASSET_ERROR, 
            "Unable to set the name for asset with UUID " + testUuid.toString() + ". Exception");
        verify(m_ResponseWrapper).queue(channel);
    }
/**
     * Test set name for Asset request where the asset's name cannot be persisted.
     * Verify that the expected error message is sent.
     */
Test set name for Asset request where the asset's name cannot be persisted.
Verify that the expected error message is sent.
Test set name for Asset request where the asset ' s name cannot be persisted . Verify that the expected error message is sent .
@Test
    public void testSetAssetNameRequestPersist() throws IOException, IllegalArgumentException, FactoryException
    {
        Asset asset = mock(Asset.class);
        when(asset.getName()).thenReturn("name");
        when(m_AssetDirectoryService.getAssetByUuid(testUuid)).thenReturn(asset);
        doThrow(new AssetException("Exception")).when(asset).setName("name");
        SetNameRequestData request = SetNameRequestData.newBuilder().
                setAssetName("name").
                setUuid(SharedMessageUtils.convertUUIDToProtoUUID(testUuid)).build();
        AssetNamespace assetDirMessage = AssetNamespace.newBuilder().
                setType(AssetMessageType.SetNameRequest).
                setData(request.toByteString()).build();
        TerraHarvestMessage message = createMessage(assetDirMessage);
        RemoteChannel channel = mock(RemoteChannel.class);
        m_SUT.handleMessage(message, createPayload(assetDirMessage), channel);
        verify(m_MessageFactory).createBaseErrorMessage(message, ErrorCode.ASSET_ERROR, 
            "Unable to set the name for asset with UUID " + testUuid.toString() + ". Exception");
        verify(m_ResponseWrapper).queue(channel);
    }
@ Test public void testSetAssetNameRequestPersist ( ) throws IOException , IllegalArgumentException , FactoryException { Asset asset = mock ( Asset . class ) ; when ( asset . getName ( ) ) . thenReturn ( "name" ) ; when ( m_AssetDirectoryService . getAssetByUuid ( testUuid ) ) . thenReturn ( asset ) ; doThrow ( new AssetException ( "Exception" ) ) . when ( asset ) . setName ( "name" ) ; SetNameRequestData request = SetNameRequestData . newBuilder ( ) . setAssetName ( "name" ) . setUuid ( SharedMessageUtils . convertUUIDToProtoUUID ( testUuid ) ) . build ( ) ; AssetNamespace assetDirMessage = AssetNamespace . newBuilder ( ) . setType ( AssetMessageType . SetNameRequest ) . setData ( request . toByteString ( ) ) . build ( ) ; TerraHarvestMessage message = createMessage ( assetDirMessage ) ; RemoteChannel channel = mock ( RemoteChannel . class ) ; m_SUT . handleMessage ( message , createPayload ( assetDirMessage ) , channel ) ; verify ( m_MessageFactory ) . createBaseErrorMessage ( message , ErrorCode . ASSET_ERROR , "Unable to set the name for asset with UUID " + testUuid . toString ( ) + ". Exception" ) ; verify ( m_ResponseWrapper ) . queue ( channel ) ; }
Test set name for Asset request where the asset's name cannot be persisted.
Test set name for Asset request where the asset ' s name cannot be persisted .
//mock behavior //verify //mock remote channel //handle message