use of org.springframework.web.testfixture.servlet.MockHttpServletResponse 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.MockHttpServletResponse in project spring-framework by spring-projects.
the class DispatcherServletTests method invalidRequest.
@Test
public void invalidRequest() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "GET", "/invalid.do");
MockHttpServletResponse response = new MockHttpServletResponse();
simpleDispatcherServlet.service(request, response);
assertThat(response.getForwardedUrl() == null).as("Not forwarded").isTrue();
assertThat(response.getStatus() == HttpServletResponse.SC_NOT_FOUND).as("correct error code").isTrue();
}
use of org.springframework.web.testfixture.servlet.MockHttpServletResponse in project spring-framework by spring-projects.
the class DispatcherServletTests method headMethodWithExplicitHandling.
@Test
public void headMethodWithExplicitHandling() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "HEAD", "/head.do");
MockHttpServletResponse response = new MockHttpServletResponse();
complexDispatcherServlet.service(request, response);
assertThat(response.getContentLength()).isEqualTo(5);
request = new MockHttpServletRequest(getServletContext(), "GET", "/head.do");
response = new MockHttpServletResponse();
complexDispatcherServlet.service(request, response);
assertThat(response.getContentAsString()).isEqualTo("");
}
use of org.springframework.web.testfixture.servlet.MockHttpServletResponse in project spring-framework by spring-projects.
the class DispatcherServletTests method existingMultipartRequestButWrapped.
@Test
public void existingMultipartRequestButWrapped() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "GET", "/locale.do;abc=def");
request.addPreferredLocale(Locale.CANADA);
request.addUserRole("role1");
MockHttpServletResponse response = new MockHttpServletResponse();
ComplexWebApplicationContext.MockMultipartResolver multipartResolver = (ComplexWebApplicationContext.MockMultipartResolver) complexDispatcherServlet.getWebApplicationContext().getBean("multipartResolver");
MultipartHttpServletRequest multipartRequest = multipartResolver.resolveMultipart(request);
complexDispatcherServlet.service(new HttpServletRequestWrapper(multipartRequest), response);
multipartResolver.cleanupMultipart(multipartRequest);
assertThat(request.getAttribute(SimpleMappingExceptionResolver.DEFAULT_EXCEPTION_ATTRIBUTE)).isNull();
assertThat(request.getAttribute("cleanedUp")).isNotNull();
}
use of org.springframework.web.testfixture.servlet.MockHttpServletResponse in project spring-framework by spring-projects.
the class DispatcherServletTests method simpleMappingExceptionResolverWithAllHandlers1.
@Test
public void simpleMappingExceptionResolverWithAllHandlers1() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "GET", "/loc.do");
request.addPreferredLocale(Locale.CANADA);
request.addUserRole("role1");
request.addParameter("access", "yes");
MockHttpServletResponse response = new MockHttpServletResponse();
complexDispatcherServlet.service(request, response);
assertThat(response.getStatus()).isEqualTo(500);
assertThat(response.getForwardedUrl()).as("forwarded to failed").isEqualTo("failed1.jsp");
assertThat(request.getAttribute("exception") instanceof IllegalAccessException).as("Exception exposed").isTrue();
}
Aggregations