use of org.springframework.web.context.WebApplicationContext in project spring-framework by spring-projects.
the class DefaultMockMvcBuilderTests method rootWacServletContainerAttributeNotPreviouslySet.
/**
* See SPR-12553 and SPR-13075.
*/
@Test
public void rootWacServletContainerAttributeNotPreviouslySet() {
StubWebApplicationContext root = new StubWebApplicationContext(this.servletContext);
DefaultMockMvcBuilder builder = webAppContextSetup(root);
WebApplicationContext wac = builder.initWebAppContext();
assertSame(root, wac);
assertSame(root, WebApplicationContextUtils.getRequiredWebApplicationContext(this.servletContext));
}
use of org.springframework.web.context.WebApplicationContext in project spring-framework by spring-projects.
the class DefaultMockMvcBuilderTests method rootWacServletContainerAttributeNotPreviouslySetWithContextHierarchy.
/**
* See SPR-12553 and SPR-13075.
*/
@Test
public void rootWacServletContainerAttributeNotPreviouslySetWithContextHierarchy() {
StaticApplicationContext ear = new StaticApplicationContext();
StaticWebApplicationContext root = new StaticWebApplicationContext();
root.setParent(ear);
root.setServletContext(this.servletContext);
StaticWebApplicationContext dispatcher = new StaticWebApplicationContext();
dispatcher.setParent(root);
dispatcher.setServletContext(this.servletContext);
DefaultMockMvcBuilder builder = webAppContextSetup(dispatcher);
WebApplicationContext wac = builder.initWebAppContext();
assertSame(dispatcher, wac);
assertSame(root, wac.getParent());
assertSame(ear, wac.getParent().getParent());
assertSame(root, WebApplicationContextUtils.getRequiredWebApplicationContext(this.servletContext));
}
use of org.springframework.web.context.WebApplicationContext in project spring-framework by spring-projects.
the class AbstractMockMvcBuilder method build.
/**
* Build a {@link org.springframework.test.web.servlet.MockMvc} instance.
*/
@Override
@SuppressWarnings("rawtypes")
public final MockMvc build() {
WebApplicationContext wac = initWebAppContext();
ServletContext servletContext = wac.getServletContext();
MockServletConfig mockServletConfig = new MockServletConfig(servletContext);
for (MockMvcConfigurer configurer : this.configurers) {
RequestPostProcessor processor = configurer.beforeMockMvcCreated(this, wac);
if (processor != null) {
if (this.defaultRequestBuilder == null) {
this.defaultRequestBuilder = MockMvcRequestBuilders.get("/");
}
if (this.defaultRequestBuilder instanceof ConfigurableSmartRequestBuilder) {
((ConfigurableSmartRequestBuilder) this.defaultRequestBuilder).with(processor);
}
}
}
Filter[] filterArray = this.filters.toArray(new Filter[this.filters.size()]);
return super.createMockMvc(filterArray, mockServletConfig, wac, this.defaultRequestBuilder, this.globalResultMatchers, this.globalResultHandlers, this.dispatcherServletCustomizers);
}
use of org.springframework.web.context.WebApplicationContext in project spring-framework by spring-projects.
the class ControllerIntegrationTests method verifyRootWacSupport.
@Test
public void verifyRootWacSupport() {
assertEquals("foo", foo);
assertEquals("bar", bar);
ApplicationContext parent = wac.getParent();
assertNotNull(parent);
assertTrue(parent instanceof WebApplicationContext);
WebApplicationContext root = (WebApplicationContext) parent;
assertFalse(root.getBeansOfType(String.class).containsKey("bar"));
ServletContext childServletContext = wac.getServletContext();
assertNotNull(childServletContext);
ServletContext rootServletContext = root.getServletContext();
assertNotNull(rootServletContext);
assertSame(childServletContext, rootServletContext);
assertSame(root, rootServletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE));
assertSame(root, childServletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE));
}
use of org.springframework.web.context.WebApplicationContext in project spring-framework by spring-projects.
the class DispatcherWacRootWacEarTests method verifyDispatcherWacConfig.
@Test
public void verifyDispatcherWacConfig() {
ApplicationContext parent = wac.getParent();
assertNotNull(parent);
assertTrue(parent instanceof WebApplicationContext);
ApplicationContext grandParent = parent.getParent();
assertNotNull(grandParent);
assertFalse(grandParent instanceof WebApplicationContext);
ServletContext dispatcherServletContext = wac.getServletContext();
assertNotNull(dispatcherServletContext);
ServletContext rootServletContext = ((WebApplicationContext) parent).getServletContext();
assertNotNull(rootServletContext);
assertSame(dispatcherServletContext, rootServletContext);
assertSame(parent, rootServletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE));
assertSame(parent, dispatcherServletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE));
assertEquals("ear", ear);
assertEquals("root", root);
assertEquals("dispatcher", dispatcher);
}
Aggregations