public void testCacheManagerInit()
throws Exception
{
// Start up security
SecuritySystem securitySystem = this.lookup(SecuritySystem.class);
RealmSecurityManager plexusSecurityManager = this.lookup(RealmSecurityManager.class, "default");
List<String> realms = securitySystem.getRealms();
realms.clear();
realms.add(SimpleAccountRealm.class.getName());
securitySystem.setRealms(realms);
// now if we grab one of the realms from the Realm locator, it should have its cache set
CachingRealm cRealm1 = (CachingRealm) plexusSecurityManager.getRealms().iterator().next();
Assert.assertNotNull("Realm has null cacheManager", cRealm1.getCacheManager());
// // so far so good, the cacheManager should be set on all the child realms, but what if we add one after the
// init method?
realms.add(SimpleAccountRealm.class.getName());
securitySystem.setRealms(realms);
// this list should have exactly 2 elements
Assert.assertEquals(2, plexusSecurityManager.getRealms().size());
for (Realm realm : plexusSecurityManager.getRealms()) {
Assert.assertNotNull("Realm has null cacheManager", ((CachingRealm) realm).getCacheManager());
}
}