mil.dod.th.ose.core.integration/src/mil/dod/th/ose/core/integration/TestAssetDirectoryService.java
public void testSetAssetNameAtCreation() throws Exception
    {
        AssetDirectoryService assetDirectoryService = ServiceUtils.getService(m_Context, AssetDirectoryService.class);
        assertThat(assetDirectoryService, is(notNullValue()));
        
        ConfigurationAdmin configAdmin = ServiceUtils.getService(m_Context, ConfigurationAdmin.class);
        assertThat(configAdmin, is(notNullValue()));
        
        Asset asset = assetDirectoryService.createAsset(ExampleAsset.class.getName(), "testSetNameAsset");
        int size = assetDirectoryService.getAssets().size();
        
        try
        {
            assetDirectoryService.createAsset(ExampleAsset.class.getName(), "testSetNameAsset");
            fail("expecting exception");
        }
        catch (Exception e)
        {
            // this exception is expected
            assertThat(e.getCause().getMessage(), 
                    containsString("Duplicate name: [testSetNameAsset] is already in use"));
        }

        assertThat(assetDirectoryService.getAssetByName("testSetNameAsset"), is(asset));
        // verify that no new asset was created
        assertThat(assetDirectoryService.getAssets().size(), is(size));
    }
/*
     * Test that an asset name is correctly set at creation if the name is unique. If the name is not unique 
     * it should not be set and no asset should be created.
     */
Test that an asset name is correctly set at creation if the name is unique. If the name is not unique
it should not be set and no asset should be created.
Test that an asset name is correctly set at creation if the name is unique . If the name is not unique it should not be set and no asset should be created .
public void testSetAssetNameAtCreation() throws Exception
    {
        AssetDirectoryService assetDirectoryService = ServiceUtils.getService(m_Context, AssetDirectoryService.class);
        assertThat(assetDirectoryService, is(notNullValue()));
        ConfigurationAdmin configAdmin = ServiceUtils.getService(m_Context, ConfigurationAdmin.class);
        assertThat(configAdmin, is(notNullValue()));
        Asset asset = assetDirectoryService.createAsset(ExampleAsset.class.getName(), "testSetNameAsset");
        int size = assetDirectoryService.getAssets().size();
        try
        {
            assetDirectoryService.createAsset(ExampleAsset.class.getName(), "testSetNameAsset");
            fail("expecting exception");
        }
        catch (Exception e)
        {
            assertThat(e.getCause().getMessage(), 
                    containsString("Duplicate name: [testSetNameAsset] is already in use"));
        }
        assertThat(assetDirectoryService.getAssetByName("testSetNameAsset"), is(asset));
        assertThat(assetDirectoryService.getAssets().size(), is(size));
    }
public void testSetAssetNameAtCreation ( ) throws Exception { AssetDirectoryService assetDirectoryService = ServiceUtils . getService ( m_Context , AssetDirectoryService . class ) ; assertThat ( assetDirectoryService , is ( notNullValue ( ) ) ) ; ConfigurationAdmin configAdmin = ServiceUtils . getService ( m_Context , ConfigurationAdmin . class ) ; assertThat ( configAdmin , is ( notNullValue ( ) ) ) ; Asset asset = assetDirectoryService . createAsset ( ExampleAsset . class . getName ( ) , "testSetNameAsset" ) ; int size = assetDirectoryService . getAssets ( ) . size ( ) ; try { assetDirectoryService . createAsset ( ExampleAsset . class . getName ( ) , "testSetNameAsset" ) ; fail ( "expecting exception" ) ; } catch ( Exception e ) { assertThat ( e . getCause ( ) . getMessage ( ) , containsString ( "Duplicate name: [testSetNameAsset] is already in use" ) ) ; } assertThat ( assetDirectoryService . getAssetByName ( "testSetNameAsset" ) , is ( asset ) ) ; assertThat ( assetDirectoryService . getAssets ( ) . size ( ) , is ( size ) ) ; }
Test that an asset name is correctly set at creation if the name is unique.
Test that an asset name is correctly set at creation if the name is unique .
// this exception is expected // verify that no new asset was created