public void testStoreDomain() throws Exception {
final String ID = "1"; //$NON-NLS-1$
MockSessionAwareMetadataDomainRepository mock = new MockSessionAwareMetadataDomainRepository();
SessionCachingMetadataDomainRepository repo = new SessionCachingMetadataDomainRepository( mock );
PentahoSessionHolder.setSession( new StandaloneSession( "Standalone Session", "1" ) ); //$NON-NLS-1$ //$NON-NLS-2$
repo.storeDomain( getTestDomain( ID ), false );
// No cache values when storing a domain
assertEquals( 0, PentahoSystem.getCacheManager( null ).getAllKeysFromRegionCache( CACHE_NAME ).size() );
// Cache one domain
repo.getDomain( ID );
// Storing a domain under a different session should wipe out all cached domains with the same id
PentahoSessionHolder.setSession( new StandaloneSession( "Standalone Session", "2" ) ); //$NON-NLS-1$ //$NON-NLS-2$
try {
repo.storeDomain( getTestDomain( ID ), false );
fail( "Should have thrown a " + DomainAlreadyExistsException.class.getSimpleName() ); //$NON-NLS-1$
} catch ( DomainAlreadyExistsException ex ) {
// expected
}
repo.storeDomain( getTestDomain( ID ), true );
// Storing a domain under a different session should wipe out all cached domains with the same id
assertEquals( 0, PentahoSystem.getCacheManager( null ).getAllKeysFromRegionCache( CACHE_NAME ).size() );
assertEquals( 1, repo.getDomainIds().size() );
repo.getDomain( ID );
assertEquals( 2, PentahoSystem.getCacheManager( null ).getAllKeysFromRegionCache( CACHE_NAME ).size() );
// Storing a domain should only wipe out the cached domains with the same id
repo.storeDomain( getTestDomain( "2" ), false ); //$NON-NLS-1$
assertEquals( 2, repo.getDomainIds().size() );
assertEquals( 2, PentahoSystem.getCacheManager( null ).getAllKeysFromRegionCache( CACHE_NAME ).size() );
}