Search in sources :

Example 46 with StaticApplicationContext

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);
}
Also used : lombok.val(lombok.val) EmailProperties(org.apereo.cas.configuration.model.support.email.EmailProperties) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) GroovyScriptResourceCacheManager(org.apereo.cas.util.scripting.GroovyScriptResourceCacheManager) Test(org.junit.jupiter.api.Test)

Example 47 with StaticApplicationContext

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());
}
Also used : lombok.val(lombok.val) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) PublisherIdentifier(org.apereo.cas.util.PublisherIdentifier) InMemoryServiceRegistry(org.apereo.cas.services.InMemoryServiceRegistry) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 48 with StaticApplicationContext

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());
}
Also used : lombok.val(lombok.val) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) PublisherIdentifier(org.apereo.cas.util.PublisherIdentifier) InMemoryServiceRegistry(org.apereo.cas.services.InMemoryServiceRegistry) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 49 with StaticApplicationContext

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();
}
Also used : lombok.val(lombok.val) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) PublisherIdentifier(org.apereo.cas.util.PublisherIdentifier) InMemoryServiceRegistry(org.apereo.cas.services.InMemoryServiceRegistry) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 50 with StaticApplicationContext

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());
}
Also used : lombok.val(lombok.val) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) Test(org.junit.jupiter.api.Test)

Aggregations

StaticApplicationContext (org.springframework.context.support.StaticApplicationContext)322 Test (org.junit.jupiter.api.Test)218 lombok.val (lombok.val)159 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)59 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)39 BeforeEach (org.junit.jupiter.api.BeforeEach)36 Test (org.junit.Test)34 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)31 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)25 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)20 HashSet (java.util.HashSet)19 MockRequestContext (org.springframework.webflow.test.MockRequestContext)19 InMemoryServiceRegistry (org.apereo.cas.services.InMemoryServiceRegistry)16 MockServletContext (org.springframework.mock.web.MockServletContext)16 MultifactorAuthenticationProviderBypassProperties (org.apereo.cas.configuration.model.support.mfa.MultifactorAuthenticationProviderBypassProperties)15 BeanDefinitionReader (org.springframework.beans.factory.support.BeanDefinitionReader)13 ApplicationContext (org.springframework.context.ApplicationContext)12 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)11 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)11 QueueChannel (org.springframework.integration.channel.QueueChannel)11