use of org.springframework.context.support.StaticApplicationContext in project cas by apereo.
the class EmailMessageBodyBuilderTests method verifyGroovyOperation.
@Test
public void verifyGroovyOperation() {
val appCtx = new StaticApplicationContext();
appCtx.refresh();
val cacheMgr = new GroovyScriptResourceCacheManager();
ApplicationContextProvider.registerBeanIntoApplicationContext(appCtx, cacheMgr, ScriptResourceCacheManager.BEAN_NAME);
ApplicationContextProvider.holdApplicationContext(appCtx);
val props = new EmailProperties().setText("classpath:/GroovyMessageBody.groovy");
val results = EmailMessageBodyBuilder.builder().properties(props).locale(Optional.of(Locale.CANADA)).parameters(CollectionUtils.wrap("key", "Hello")).build().addParameter("key2", "World");
val result = results.produce();
assertEquals("Hello, World", result);
}
use of org.springframework.context.support.StaticApplicationContext 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.springframework.context.support.StaticApplicationContext 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.springframework.context.support.StaticApplicationContext 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.springframework.context.support.StaticApplicationContext in project cas by apereo.
the class DefaultRegisteredServiceUsernameProviderTests method verifyNoCanonAndEncrypt.
@Test
public void verifyNoCanonAndEncrypt() {
val applicationContext = new StaticApplicationContext();
val beanFactory = applicationContext.getBeanFactory();
val cipher = RegisteredServiceCipherExecutor.noOp();
beanFactory.initializeBean(cipher, RegisteredServiceCipherExecutor.DEFAULT_BEAN_NAME);
beanFactory.autowireBean(cipher);
beanFactory.registerSingleton(RegisteredServiceCipherExecutor.DEFAULT_BEAN_NAME, cipher);
applicationContext.refresh();
ApplicationContextProvider.holdApplicationContext(applicationContext);
val provider = new DefaultRegisteredServiceUsernameProvider();
provider.setCanonicalizationMode(null);
provider.setEncryptUsername(true);
val principal = mock(Principal.class);
when(principal.getId()).thenReturn("ID");
val service = RegisteredServiceTestUtils.getRegisteredService("usernameAttributeProviderService");
val id = provider.resolveUsername(principal, RegisteredServiceTestUtils.getService(), service);
provider.initialize();
assertEquals(id, principal.getId().toUpperCase());
}
Aggregations