use of org.springframework.web.context.support.StaticWebApplicationContext in project spring-framework by spring-projects.
the class ScriptTemplateViewTests method setup.
@BeforeEach
public void setup() {
this.configurer = new ScriptTemplateConfigurer();
this.wac = new StaticWebApplicationContext();
this.wac.getBeanFactory().registerSingleton("scriptTemplateConfigurer", this.configurer);
this.view = new ScriptTemplateView();
}
use of org.springframework.web.context.support.StaticWebApplicationContext in project spring-framework by spring-projects.
the class DispatcherServletTests method detectHandlerMappingFromParent.
@Test
public void detectHandlerMappingFromParent() throws ServletException, IOException {
// create a parent context that includes a mapping
StaticWebApplicationContext parent = new StaticWebApplicationContext();
parent.setServletContext(getServletContext());
parent.registerSingleton("parentHandler", ControllerFromParent.class, new MutablePropertyValues());
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.addPropertyValue(new PropertyValue("mappings", URL_KNOWN_ONLY_PARENT + "=parentHandler"));
parent.registerSingleton("parentMapping", SimpleUrlHandlerMapping.class, pvs);
parent.refresh();
DispatcherServlet complexDispatcherServlet = new DispatcherServlet();
// will have parent
complexDispatcherServlet.setContextClass(ComplexWebApplicationContext.class);
complexDispatcherServlet.setNamespace("test");
ServletConfig config = new MockServletConfig(getServletContext(), "complex");
config.getServletContext().setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, parent);
complexDispatcherServlet.init(config);
MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "GET", URL_KNOWN_ONLY_PARENT);
MockHttpServletResponse response = new MockHttpServletResponse();
complexDispatcherServlet.service(request, response);
assertThat(response.getStatus() == HttpServletResponse.SC_NOT_FOUND).as("Matched through parent controller/handler pair: not response=" + response.getStatus()).isFalse();
}
use of org.springframework.web.context.support.StaticWebApplicationContext in project spring-framework by spring-projects.
the class DispatcherServletTests method cleanupAfterIncludeWithRestore.
@Test
public void cleanupAfterIncludeWithRestore() throws ServletException, IOException {
MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "GET", "/main.do");
MockHttpServletResponse response = new MockHttpServletResponse();
request.setAttribute("test1", "value1");
request.setAttribute("test2", "value2");
WebApplicationContext wac = new StaticWebApplicationContext();
request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
TestBean command = new TestBean();
request.setAttribute("command", command);
request.setAttribute(WebUtils.INCLUDE_REQUEST_URI_ATTRIBUTE, "/form.do");
simpleDispatcherServlet.service(request, response);
assertThat(request.getAttribute("test1")).isEqualTo("value1");
assertThat(request.getAttribute("test2")).isEqualTo("value2");
assertThat(request.getAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE)).isSameAs(wac);
}
use of org.springframework.web.context.support.StaticWebApplicationContext in project spring-framework by spring-projects.
the class WebMvcConfigurationSupportExtensionTests method setUp.
@BeforeEach
public void setUp() {
this.context = new StaticWebApplicationContext();
this.context.setServletContext(new MockServletContext(new FileSystemResourceLoader()));
this.context.registerSingleton("controller", TestController.class);
this.context.registerSingleton("userController", UserController.class);
this.config = new TestWebMvcConfigurationSupport();
this.config.setApplicationContext(this.context);
this.config.setServletContext(this.context.getServletContext());
}
use of org.springframework.web.context.support.StaticWebApplicationContext in project spring-security by spring-projects.
the class HttpSessionEventPublisherTests method publishedEventIsReceivedbyListener.
/**
* It's not that complicated so we'll just run it straight through here.
*/
@Test
public void publishedEventIsReceivedbyListener() {
HttpSessionEventPublisher publisher = new HttpSessionEventPublisher();
StaticWebApplicationContext context = new StaticWebApplicationContext();
MockServletContext servletContext = new MockServletContext();
servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, context);
context.setServletContext(servletContext);
context.registerSingleton("listener", MockApplicationListener.class, null);
context.refresh();
MockHttpSession session = new MockHttpSession(servletContext);
MockApplicationListener listener = (MockApplicationListener) context.getBean("listener");
HttpSessionEvent event = new HttpSessionEvent(session);
publisher.sessionCreated(event);
assertThat(listener.getCreatedEvent()).isNotNull();
assertThat(listener.getDestroyedEvent()).isNull();
assertThat(listener.getCreatedEvent().getSession()).isEqualTo(session);
listener.setCreatedEvent(null);
listener.setDestroyedEvent(null);
publisher.sessionDestroyed(event);
assertThat(listener.getDestroyedEvent()).isNotNull();
assertThat(listener.getCreatedEvent()).isNull();
assertThat(listener.getDestroyedEvent().getSession()).isEqualTo(session);
publisher.sessionIdChanged(event, "oldSessionId");
assertThat(listener.getSessionIdChangedEvent()).isNotNull();
assertThat(listener.getSessionIdChangedEvent().getOldSessionId()).isEqualTo("oldSessionId");
listener.setSessionIdChangedEvent(null);
}
Aggregations