Search in sources :

Example 51 with StaticApplicationContext

use of org.springframework.context.support.StaticApplicationContext in project cas by apereo.

the class DefaultServicesManagerCachingTests method verifyServicesCache.

@Test
public void verifyServicesCache() throws Exception {
    val service1 = RegisteredServiceTestUtils.getRegisteredService(UUID.randomUUID().toString());
    val applicationContext = new StaticApplicationContext();
    applicationContext.refresh();
    val cache = Caffeine.newBuilder().initialCapacity(10).maximumSize(100).expireAfterWrite(1, TimeUnit.SECONDS).recordStats().build();
    val context = ServicesManagerConfigurationContext.builder().applicationContext(applicationContext).serviceRegistry(new InMemoryServiceRegistry(applicationContext, List.of(service1), List.of())).registeredServiceLocators(List.of(new DefaultServicesManagerRegisteredServiceLocator())).servicesCache((Cache) cache).build();
    val mgr = new DefaultServicesManager(context);
    assertFalse(mgr.getAllServices().isEmpty());
    assertEquals(1, mgr.load().size());
    assertEquals(1, mgr.getAllServices().size());
    Thread.sleep(1500);
    assertFalse(mgr.getAllServices().isEmpty());
    assertEquals(1, mgr.load().size());
    assertEquals(1, mgr.getAllServices().size());
}
Also used : lombok.val(lombok.val) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) Cache(com.github.benmanes.caffeine.cache.Cache) Test(org.junit.jupiter.api.Test)

Example 52 with StaticApplicationContext

use of org.springframework.context.support.StaticApplicationContext in project cas by apereo.

the class SimpleWebApplicationServiceImplTests method verifyResponseWithNoTicketAndNoParameterInServiceURL.

@Test
public void verifyResponseWithNoTicketAndNoParameterInServiceURL() {
    val applicationContext = new StaticApplicationContext();
    applicationContext.refresh();
    val request = new MockHttpServletRequest();
    request.setParameter(CasProtocolConstants.PARAMETER_SERVICE, "http://foo.com/");
    val impl = new WebApplicationServiceFactory().createService(request);
    val response = new WebApplicationServiceResponseBuilder(getServicesManager(applicationContext), SimpleUrlValidator.getInstance()).build(impl, null, RegisteredServiceTestUtils.getAuthentication());
    assertNotNull(response);
    assertEquals(Response.ResponseType.REDIRECT, response.getResponseType());
    assertFalse(response.getUrl().contains("ticket="));
    assertEquals("http://foo.com/", response.getUrl());
}
Also used : lombok.val(lombok.val) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.jupiter.api.Test)

Example 53 with StaticApplicationContext

use of org.springframework.context.support.StaticApplicationContext in project cas by apereo.

the class SimpleWebApplicationServiceImplTests method verifyResponseWithNoTicket.

@Test
public void verifyResponseWithNoTicket() {
    val request = new MockHttpServletRequest();
    request.setParameter(CasProtocolConstants.PARAMETER_SERVICE, RegisteredServiceTestUtils.CONST_TEST_URL);
    val impl = new WebApplicationServiceFactory().createService(request);
    val applicationContext = new StaticApplicationContext();
    applicationContext.refresh();
    val response = new WebApplicationServiceResponseBuilder(getServicesManager(applicationContext), SimpleUrlValidator.getInstance()).build(impl, null, RegisteredServiceTestUtils.getAuthentication());
    assertNotNull(response);
    assertEquals(Response.ResponseType.REDIRECT, response.getResponseType());
    assertFalse(response.getUrl().contains("ticket="));
}
Also used : lombok.val(lombok.val) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.jupiter.api.Test)

Example 54 with StaticApplicationContext

use of org.springframework.context.support.StaticApplicationContext in project cas by apereo.

the class AbstractServicesManagerTests method getConfigurationContext.

protected ServicesManagerConfigurationContext getConfigurationContext() {
    val applicationContext = new StaticApplicationContext();
    applicationContext.refresh();
    return ServicesManagerConfigurationContext.builder().serviceRegistry(serviceRegistry).applicationContext(applicationContext).environments(new HashSet<>(0)).registeredServiceLocators(List.of(new DefaultServicesManagerRegisteredServiceLocator())).servicesCache(Caffeine.newBuilder().expireAfterWrite(Duration.ofSeconds(2)).build()).build();
}
Also used : lombok.val(lombok.val) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) HashSet(java.util.HashSet)

Example 55 with StaticApplicationContext

use of org.springframework.context.support.StaticApplicationContext in project cas by apereo.

the class BaseResourceBasedServiceRegistryTests method verify.

@Test
public void verify() {
    val applicationContext = new StaticApplicationContext();
    applicationContext.refresh();
    val serializer = mock(StringSerializer.class);
    doThrow(new RuntimeException()).when(serializer).to(any(OutputStream.class), any());
    val registry = new AbstractResourceBasedServiceRegistry(FileUtils.getTempDirectory().toPath(), serializer, applicationContext, mock(RegisteredServiceReplicationStrategy.class), new DefaultRegisteredServiceResourceNamingStrategy(), List.of(), mock(WatcherService.class)) {

        @Override
        protected String[] getExtensions() {
            return new String[] { ".json" };
        }
    };
    val r = buildRegisteredServiceInstance(RandomUtils.nextInt(), RegexRegisteredService.class);
    assertThrows(IllegalArgumentException.class, () -> registry.save(r));
    registry.destroy();
}
Also used : lombok.val(lombok.val) AbstractResourceBasedServiceRegistry(org.apereo.cas.services.resource.AbstractResourceBasedServiceRegistry) RegisteredServiceReplicationStrategy(org.apereo.cas.services.replication.RegisteredServiceReplicationStrategy) DefaultRegisteredServiceResourceNamingStrategy(org.apereo.cas.services.resource.DefaultRegisteredServiceResourceNamingStrategy) WatcherService(org.apereo.cas.util.io.WatcherService) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) OutputStream(java.io.OutputStream) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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