use of org.apereo.cas.util.PublisherIdentifier in project cas by apereo.
the class DefaultRegisteredServiceReplicationStrategyTests method verifyUpdateWithNoMatch.
@Test
public void verifyUpdateWithNoMatch() {
val id = new PublisherIdentifier();
val appCtx = new StaticApplicationContext();
appCtx.refresh();
val serviceRegistry = new InMemoryServiceRegistry(appCtx);
val stream = casProperties.getServiceRegistry().getStream();
val mgr = mock(DistributedCacheManager.class);
val service = newService("Test1");
service.setId(500);
val cachedService = newService("Test2");
val object = DistributedCacheObject.<RegisteredService>builder().value(cachedService).publisherIdentifier(id).build();
when(mgr.getAll()).thenReturn(CollectionUtils.wrapList(object));
val strategy = new DefaultRegisteredServiceReplicationStrategy(mgr, stream, id);
val results = strategy.updateLoadedRegisteredServicesFromCache(CollectionUtils.wrapList(service), serviceRegistry);
assertFalse(results.isEmpty());
assertEquals(2, results.size());
}
use of org.apereo.cas.util.PublisherIdentifier in project cas by apereo.
the class DefaultRegisteredServiceReplicationStrategyTests method verifyGetInCacheAndUpdate.
@Test
public void verifyGetInCacheAndUpdate() {
val id = new PublisherIdentifier();
val appCtx = new StaticApplicationContext();
appCtx.refresh();
val serviceRegistry = new InMemoryServiceRegistry(appCtx);
val stream = casProperties.getServiceRegistry().getStream();
val mgr = mock(DistributedCacheManager.class);
val strategy = new DefaultRegisteredServiceReplicationStrategy(mgr, stream, id);
val service = newService("Test");
val service2 = newService("Test1");
val object = DistributedCacheObject.<RegisteredService>builder().value(service2).publisherIdentifier(id).build();
when(mgr.find(any())).thenReturn(Optional.of(object));
var svc = strategy.getRegisteredServiceFromCacheIfAny(service, 1000, serviceRegistry);
assertNotNull(svc);
assertEquals(serviceRegistry.size(), 1);
svc = serviceRegistry.findServiceById(1000);
assertEquals("Test1", svc.getName());
}
use of org.apereo.cas.util.PublisherIdentifier in project cas by apereo.
the class DefaultRegisteredServiceReplicationStrategyTests method verifySetInCache.
@Test
public void verifySetInCache() {
val id = new PublisherIdentifier();
val appCtx = new StaticApplicationContext();
appCtx.refresh();
val serviceRegistry = new InMemoryServiceRegistry(appCtx);
val stream = casProperties.getServiceRegistry().getStream();
val mgr = mock(DistributedCacheManager.class);
val strategy = new DefaultRegisteredServiceReplicationStrategy(mgr, stream, id);
when(mgr.find(any())).thenReturn(Optional.empty());
var svc = strategy.getRegisteredServiceFromCacheIfAny(newService("Test"), 1000, serviceRegistry);
assertNotNull(svc);
svc = strategy.getRegisteredServiceFromCacheIfAny(newService("Test"), "https://example.org", serviceRegistry);
assertNotNull(svc);
strategy.destroy();
}
use of org.apereo.cas.util.PublisherIdentifier in project cas by apereo.
the class DefaultRegisteredServiceReplicationStrategyTests method verifyGetInCacheAndMatch.
@Test
public void verifyGetInCacheAndMatch() {
val id = new PublisherIdentifier();
val appCtx = new StaticApplicationContext();
appCtx.refresh();
val serviceRegistry = new InMemoryServiceRegistry(appCtx);
val stream = casProperties.getServiceRegistry().getStream();
val mgr = mock(DistributedCacheManager.class);
val strategy = new DefaultRegisteredServiceReplicationStrategy(mgr, stream, id);
val service = newService("Test");
val service2 = newService("Test");
val object = DistributedCacheObject.<RegisteredService>builder().value(service2).publisherIdentifier(id).build();
when(mgr.find(any())).thenReturn(Optional.of(object));
var svc = strategy.getRegisteredServiceFromCacheIfAny(service, 1000, serviceRegistry);
assertNotNull(svc);
assertEquals(serviceRegistry.size(), 0);
}
use of org.apereo.cas.util.PublisherIdentifier in project cas by apereo.
the class DistributedCacheManagerTests method verifyDefaults.
@Test
public void verifyDefaults() {
val mgr = DistributedCacheManager.noOp();
assertNull(mgr.get("key"));
assertNotNull(mgr.getAll());
assertNotNull(mgr.findAll(distributedCacheObject -> true));
assertNotNull(mgr.getName());
assertFalse(mgr.contains("key"));
assertFalse(mgr.find(distributedCacheObject -> true).isPresent());
val id = new PublisherIdentifier();
val object = DistributedCacheObject.<String>builder().value("value").publisherIdentifier(id).build();
assertDoesNotThrow(() -> mgr.set("key", object, true));
assertDoesNotThrow(mgr::clear);
assertDoesNotThrow(() -> mgr.set("key", object, true));
assertDoesNotThrow(() -> mgr.remove("key", object, true));
assertNotNull(mgr.update("key", object, true));
mgr.close();
}
Aggregations