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());
}
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());
}
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="));
}
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();
}
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();
}
Aggregations