use of org.springframework.web.context.support.StaticWebApplicationContext 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();
assertThat(wac).isSameAs(dispatcher);
assertThat(wac.getParent()).isSameAs(root);
assertThat(wac.getParent().getParent()).isSameAs(ear);
assertThat(WebApplicationContextUtils.getRequiredWebApplicationContext(this.servletContext)).isSameAs(root);
}
use of org.springframework.web.context.support.StaticWebApplicationContext in project spring-framework by spring-projects.
the class DelegatingFilterProxyTests method testDelegatingFilterProxy.
@Test
public void testDelegatingFilterProxy() throws ServletException, IOException {
ServletContext sc = new MockServletContext();
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.setServletContext(sc);
wac.registerSingleton("targetFilter", MockFilter.class);
wac.refresh();
sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
MockFilter targetFilter = (MockFilter) wac.getBean("targetFilter");
MockFilterConfig proxyConfig = new MockFilterConfig(sc);
proxyConfig.addInitParameter("targetBeanName", "targetFilter");
DelegatingFilterProxy filterProxy = new DelegatingFilterProxy();
filterProxy.init(proxyConfig);
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
filterProxy.doFilter(request, response, null);
assertThat(targetFilter.filterConfig).isNull();
assertThat(request.getAttribute("called")).isEqualTo(Boolean.TRUE);
filterProxy.destroy();
assertThat(targetFilter.filterConfig).isNull();
}
use of org.springframework.web.context.support.StaticWebApplicationContext in project spring-framework by spring-projects.
the class DelegatingFilterProxyTests method testDelegatingFilterProxyWithTargetBeanName.
@Test
public void testDelegatingFilterProxyWithTargetBeanName() throws ServletException, IOException {
MockServletContext sc = new MockServletContext();
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.setServletContext(sc);
wac.registerSingleton("targetFilter", MockFilter.class);
wac.refresh();
sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
MockFilter targetFilter = (MockFilter) wac.getBean("targetFilter");
DelegatingFilterProxy filterProxy = new DelegatingFilterProxy("targetFilter");
filterProxy.init(new MockFilterConfig(sc));
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
filterProxy.doFilter(request, response, null);
assertThat(targetFilter.filterConfig).isNull();
assertThat(request.getAttribute("called")).isEqualTo(Boolean.TRUE);
filterProxy.destroy();
assertThat(targetFilter.filterConfig).isNull();
}
use of org.springframework.web.context.support.StaticWebApplicationContext in project spring-framework by spring-projects.
the class DelegatingFilterProxyTests method testDelegatingFilterProxyWithLazyContextStartup.
@Test
public void testDelegatingFilterProxyWithLazyContextStartup() throws ServletException, IOException {
ServletContext sc = new MockServletContext();
MockFilterConfig proxyConfig = new MockFilterConfig(sc);
proxyConfig.addInitParameter("targetBeanName", "targetFilter");
DelegatingFilterProxy filterProxy = new DelegatingFilterProxy();
filterProxy.init(proxyConfig);
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.setServletContext(sc);
wac.registerSingleton("targetFilter", MockFilter.class);
wac.refresh();
sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
MockFilter targetFilter = (MockFilter) wac.getBean("targetFilter");
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
filterProxy.doFilter(request, response, null);
assertThat(targetFilter.filterConfig).isNull();
assertThat(request.getAttribute("called")).isEqualTo(Boolean.TRUE);
filterProxy.destroy();
assertThat(targetFilter.filterConfig).isNull();
}
use of org.springframework.web.context.support.StaticWebApplicationContext in project spring-framework by spring-projects.
the class DelegatingFilterProxyTests method testDelegatingFilterProxyAndCustomContextAttribute.
@Test
public void testDelegatingFilterProxyAndCustomContextAttribute() throws ServletException, IOException {
ServletContext sc = new MockServletContext();
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.setServletContext(sc);
wac.registerSingleton("targetFilter", MockFilter.class);
wac.refresh();
sc.setAttribute("CUSTOM_ATTR", wac);
MockFilter targetFilter = (MockFilter) wac.getBean("targetFilter");
MockFilterConfig proxyConfig = new MockFilterConfig(sc);
proxyConfig.addInitParameter("targetBeanName", "targetFilter");
proxyConfig.addInitParameter("contextAttribute", "CUSTOM_ATTR");
DelegatingFilterProxy filterProxy = new DelegatingFilterProxy();
filterProxy.init(proxyConfig);
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
filterProxy.doFilter(request, response, null);
assertThat(targetFilter.filterConfig).isNull();
assertThat(request.getAttribute("called")).isEqualTo(Boolean.TRUE);
filterProxy.destroy();
assertThat(targetFilter.filterConfig).isNull();
}
Aggregations