use of org.springframework.web.testfixture.servlet.MockServletContext in project spring-framework by spring-projects.
the class DelegatingWebMvcConfigurationIntegrationTests method load.
private void load(Consumer<GenericWebApplicationContext> context) {
GenericWebApplicationContext webContext = new GenericWebApplicationContext();
AnnotationConfigUtils.registerAnnotationConfigProcessors(webContext);
webContext.setServletContext(new MockServletContext());
context.accept(webContext);
webContext.registerBean(DelegatingWebMvcConfiguration.class);
webContext.refresh();
this.context = webContext;
}
use of org.springframework.web.testfixture.servlet.MockServletContext in project spring-framework by spring-projects.
the class DispatcherServletTests method withNoView.
@Test
public void withNoView() throws Exception {
MockServletContext servletContext = new MockServletContext();
MockHttpServletRequest request = new MockHttpServletRequest(servletContext, "GET", "/noview.do");
MockHttpServletResponse response = new MockHttpServletResponse();
complexDispatcherServlet.service(request, response);
assertThat(response.getForwardedUrl()).isEqualTo("noview.jsp");
}
use of org.springframework.web.testfixture.servlet.MockServletContext in project spring-framework by spring-projects.
the class DispatcherServletTests method dispatcherServletContextRefresh.
@Test
public void dispatcherServletContextRefresh() throws ServletException {
MockServletContext servletContext = new MockServletContext("org/springframework/web/context");
DispatcherServlet servlet = new DispatcherServlet();
servlet.init(new MockServletConfig(servletContext, "empty"));
ServletContextAwareBean contextBean = (ServletContextAwareBean) servlet.getWebApplicationContext().getBean("servletContextAwareBean");
ServletConfigAwareBean configBean = (ServletConfigAwareBean) servlet.getWebApplicationContext().getBean("servletConfigAwareBean");
assertThat(contextBean.getServletContext()).isSameAs(servletContext);
assertThat(configBean.getServletConfig()).isSameAs(servlet.getServletConfig());
MultipartResolver multipartResolver = servlet.getMultipartResolver();
assertThat(multipartResolver).isNotNull();
((ConfigurableApplicationContext) servlet.getWebApplicationContext()).refresh();
ServletContextAwareBean contextBean2 = (ServletContextAwareBean) servlet.getWebApplicationContext().getBean("servletContextAwareBean");
ServletConfigAwareBean configBean2 = (ServletConfigAwareBean) servlet.getWebApplicationContext().getBean("servletConfigAwareBean");
assertThat(contextBean2.getServletContext()).isSameAs(servletContext);
assertThat(configBean2.getServletConfig()).isSameAs(servlet.getServletConfig());
assertThat(contextBean != contextBean2).isTrue();
assertThat(configBean != configBean2).isTrue();
MultipartResolver multipartResolver2 = servlet.getMultipartResolver();
assertThat(multipartResolver != multipartResolver2).isTrue();
servlet.destroy();
}
use of org.springframework.web.testfixture.servlet.MockServletContext in project spring-framework by spring-projects.
the class DispatcherServletTests method withNoViewNested.
@Test
public void withNoViewNested() throws Exception {
MockServletContext servletContext = new MockServletContext();
MockHttpServletRequest request = new MockHttpServletRequest(servletContext, "GET", "/noview/simple.do");
MockHttpServletResponse response = new MockHttpServletResponse();
complexDispatcherServlet.service(request, response);
assertThat(response.getForwardedUrl()).isEqualTo("noview/simple.jsp");
}
use of org.springframework.web.testfixture.servlet.MockServletContext in project spring-framework by spring-projects.
the class ResourceHttpRequestHandlerTests method getMediaTypeWithFavorPathExtensionOff.
// SPR-14577
@Test
@SuppressWarnings("deprecation")
public void getMediaTypeWithFavorPathExtensionOff() throws Exception {
ContentNegotiationManagerFactoryBean factory = new ContentNegotiationManagerFactoryBean();
factory.setFavorPathExtension(false);
factory.afterPropertiesSet();
ContentNegotiationManager manager = factory.getObject();
List<Resource> paths = Collections.singletonList(new ClassPathResource("test/", getClass()));
ResourceHttpRequestHandler handler = new ResourceHttpRequestHandler();
handler.setServletContext(new MockServletContext());
handler.setLocations(paths);
handler.setContentNegotiationManager(manager);
handler.afterPropertiesSet();
this.request.addHeader("Accept", "application/json,text/plain,*/*");
this.request.setAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, "foo.html");
handler.handleRequest(this.request, this.response);
assertThat(this.response.getContentType()).isEqualTo("text/html");
}
Aggregations