use of org.springframework.web.context.support.StaticWebApplicationContext in project spring-framework by spring-projects.
the class ControllerTests method doTestServletForwardingController.
private void doTestServletForwardingController(ServletForwardingController sfc, boolean include) throws Exception {
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
ServletContext context = mock(ServletContext.class);
RequestDispatcher dispatcher = mock(RequestDispatcher.class);
given(request.getMethod()).willReturn("GET");
given(context.getNamedDispatcher("action")).willReturn(dispatcher);
if (include) {
given(request.getAttribute(WebUtils.INCLUDE_REQUEST_URI_ATTRIBUTE)).willReturn("somePath");
} else {
given(request.getAttribute(WebUtils.INCLUDE_REQUEST_URI_ATTRIBUTE)).willReturn(null);
}
StaticWebApplicationContext sac = new StaticWebApplicationContext();
sac.setServletContext(context);
sfc.setApplicationContext(sac);
assertNull(sfc.handleRequest(request, response));
if (include) {
verify(dispatcher).include(request, response);
} else {
verify(dispatcher).forward(request, response);
}
}
use of org.springframework.web.context.support.StaticWebApplicationContext in project spring-framework by spring-projects.
the class ResponseEntityExceptionHandlerTests method controllerAdvice.
@Test
public void controllerAdvice() throws Exception {
StaticWebApplicationContext cxt = new StaticWebApplicationContext();
cxt.registerSingleton("exceptionHandler", ApplicationExceptionHandler.class);
cxt.refresh();
ExceptionHandlerExceptionResolver resolver = new ExceptionHandlerExceptionResolver();
resolver.setApplicationContext(cxt);
resolver.afterPropertiesSet();
ServletRequestBindingException ex = new ServletRequestBindingException("message");
resolver.resolveException(this.servletRequest, this.servletResponse, null, ex);
assertEquals(400, this.servletResponse.getStatus());
assertEquals("error content", this.servletResponse.getContentAsString());
assertEquals("someHeaderValue", this.servletResponse.getHeader("someHeader"));
}
use of org.springframework.web.context.support.StaticWebApplicationContext in project spring-framework by spring-projects.
the class RequestMappingHandlerAdapterTests method modelAttributeAdviceInParentContext.
@Test
public void modelAttributeAdviceInParentContext() throws Exception {
StaticWebApplicationContext parent = new StaticWebApplicationContext();
parent.registerSingleton("maa", ModelAttributeAdvice.class);
parent.refresh();
this.webAppContext.setParent(parent);
this.webAppContext.refresh();
HandlerMethod handlerMethod = handlerMethod(new SimpleController(), "handle");
this.handlerAdapter.afterPropertiesSet();
ModelAndView mav = this.handlerAdapter.handle(this.request, this.response, handlerMethod);
assertEquals("lAttr1", mav.getModel().get("attr1"));
assertEquals("gAttr2", mav.getModel().get("attr2"));
}
use of org.springframework.web.context.support.StaticWebApplicationContext in project spring-framework by spring-projects.
the class RequestMappingHandlerAdapterTests method setupOnce.
@BeforeClass
public static void setupOnce() {
RequestMappingHandlerAdapter adapter = new RequestMappingHandlerAdapter();
adapter.setApplicationContext(new StaticWebApplicationContext());
adapter.afterPropertiesSet();
RESOLVER_COUNT = adapter.getArgumentResolvers().size();
INIT_BINDER_RESOLVER_COUNT = adapter.getInitBinderArgumentResolvers().size();
HANDLER_COUNT = adapter.getReturnValueHandlers().size();
}
use of org.springframework.web.context.support.StaticWebApplicationContext in project spring-framework by spring-projects.
the class AbstractHtmlElementTagTests method getMockRequestDataValueProcessor.
@SuppressWarnings("deprecation")
protected RequestDataValueProcessor getMockRequestDataValueProcessor() {
RequestDataValueProcessor mockProcessor = mock(RequestDataValueProcessor.class);
HttpServletRequest request = (HttpServletRequest) getPageContext().getRequest();
StaticWebApplicationContext wac = (StaticWebApplicationContext) RequestContextUtils.findWebApplicationContext(request);
wac.getBean(RequestDataValueProcessorWrapper.class).setRequestDataValueProcessor(mockProcessor);
return mockProcessor;
}
Aggregations