SessionCachingMetadataDomainRepository repo = new SessionCachingMetadataDomainRepository( mock );
PentahoSessionHolder.setSession( new StandaloneSession( "Standalone Session", SESSION_ID1 ) ); //$NON-NLS-1$
assertEquals( 0, mock.getInvocationCount( "getDomain" ) ); //$NON-NLS-1$
Domain d = repo.getDomain( ID );
assertEquals( ID, d.getId() );
assertEquals( SESSION_ID1, d.getDescription( TEST_LOCALE ) );
assertEquals( 1, mock.getInvocationCount( "getDomain" ) ); //$NON-NLS-1$
// Cache should contain a domain for this session
assertEquals( 1, PentahoSystem.getCacheManager( null ).getAllKeysFromRegionCache( CACHE_NAME ).size() );
// Get the same domain from a different session
PentahoSessionHolder.setSession( new StandaloneSession( "Standalone Session", SESSION_ID2 ) ); //$NON-NLS-1$
d = repo.getDomain( ID );
// Make sure we got a new, session-specific, domain
assertEquals( SESSION_ID2, d.getDescription( TEST_LOCALE ) );
// Make sure cache was missed and delegate was called
assertEquals( 2, mock.getInvocationCount( "getDomain" ) ); //$NON-NLS-1$
// We should now have two objects in the cache (1 domain per session)
assertEquals( 2, PentahoSystem.getCacheManager( null ).getAllKeysFromRegionCache( CACHE_NAME ).size() );