use of org.springframework.web.context.ConfigurableWebApplicationContext in project Gemma by PavlidisLab.
the class WebContextLoader method loadContext.
@Override
public ApplicationContext loadContext(String... locations) {
if (WebContextLoader.logger.isDebugEnabled()) {
WebContextLoader.logger.debug("Loading WebApplicationContext for locations [" + StringUtils.arrayToCommaDelimitedString(locations) + "].");
}
ConfigurableWebApplicationContext context = new XmlWebApplicationContext();
context.setConfigLocations(locations);
context.setServletContext(new MockServletContext(""));
context.refresh();
AnnotationConfigUtils.registerAnnotationConfigProcessors((BeanDefinitionRegistry) context.getBeanFactory());
context.registerShutdownHook();
return context;
}
use of org.springframework.web.context.ConfigurableWebApplicationContext in project spring-security by spring-projects.
the class InterceptUrlConfigTests method requestWhenUsingMvcMatchersAndServletPathThenAuthorizesRequestsAccordingly.
@Test
public void requestWhenUsingMvcMatchersAndServletPathThenAuthorizesRequestsAccordingly() throws Exception {
this.spring.configLocations(this.xml("MvcMatchersServletPath")).autowire();
MockServletContext servletContext = mockServletContext("/spring");
ConfigurableWebApplicationContext context = this.spring.getContext();
context.setServletContext(servletContext);
// @formatter:off
this.mvc.perform(get("/spring/path").servletPath("/spring")).andExpect(status().isUnauthorized());
this.mvc.perform(get("/spring/path.html").servletPath("/spring")).andExpect(status().isUnauthorized());
this.mvc.perform(get("/spring/path/").servletPath("/spring")).andExpect(status().isUnauthorized());
// @formatter:on
}
use of org.springframework.web.context.ConfigurableWebApplicationContext in project spring-security by spring-projects.
the class ServletApiConfigurerTests method logoutServletApiWhenCsrfDisabled.
@Test
public void logoutServletApiWhenCsrfDisabled() throws Exception {
ConfigurableWebApplicationContext context = this.spring.register(CsrfDisabledConfig.class).getContext();
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(context).apply(springSecurity()).build();
MvcResult mvcResult = mockMvc.perform(get("/")).andReturn();
assertThat(mvcResult.getRequest().getSession(false)).isNull();
}
use of org.springframework.web.context.ConfigurableWebApplicationContext in project spring-framework by spring-projects.
the class PathMatchingUrlHandlerMappingTests method initConfig.
private static WebApplicationContext initConfig(String... configLocations) {
MockServletContext sc = new MockServletContext("");
ConfigurableWebApplicationContext context = new XmlWebApplicationContext();
context.setServletContext(sc);
context.setConfigLocations(configLocations);
context.refresh();
return context;
}
use of org.springframework.web.context.ConfigurableWebApplicationContext in project spring-boot by spring-projects.
the class WebApplicationContextRunner method withMockServletContext.
/**
* Decorate the specified {@code contextFactory} to set a {@link MockServletContext}
* on each newly created {@link WebApplicationContext}.
* @param contextFactory the context factory to decorate
* @return an updated supplier that will set the {@link MockServletContext}
*/
public static Supplier<ConfigurableWebApplicationContext> withMockServletContext(Supplier<ConfigurableWebApplicationContext> contextFactory) {
return (contextFactory != null) ? () -> {
ConfigurableWebApplicationContext context = contextFactory.get();
context.setServletContext(new MockServletContext());
return context;
} : null;
}
Aggregations