use of org.springframework.web.testfixture.servlet.MockHttpServletResponse in project spring-framework by spring-projects.
the class ViewResolutionIntegrationTests method freemarker.
@Test
public void freemarker() throws Exception {
MockHttpServletResponse response = runTest(FreeMarkerWebConfig.class);
assertThat(response.getContentAsString()).isEqualTo("<html><body>Hello World!</body></html>");
}
use of org.springframework.web.testfixture.servlet.MockHttpServletResponse in project spring-framework by spring-projects.
the class DefaultEntityResponseBuilderTests method notModifiedLastModified.
@Test
public void notModifiedLastModified() throws ServletException, IOException {
ZonedDateTime now = ZonedDateTime.now();
ZonedDateTime oneMinuteBeforeNow = now.minus(1, ChronoUnit.MINUTES);
EntityResponse<String> entityResponse = EntityResponse.fromObject("bar").lastModified(oneMinuteBeforeNow).build();
MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", "https://example.com");
mockRequest.addHeader(HttpHeaders.IF_MODIFIED_SINCE, DateTimeFormatter.RFC_1123_DATE_TIME.format(now));
MockHttpServletResponse mockResponse = new MockHttpServletResponse();
ModelAndView mav = entityResponse.writeTo(mockRequest, mockResponse, EMPTY_CONTEXT);
assertThat(mav).isNull();
assertThat(mockResponse.getStatus()).isEqualTo(HttpStatus.NOT_MODIFIED.value());
}
use of org.springframework.web.testfixture.servlet.MockHttpServletResponse in project spring-framework by spring-projects.
the class DefaultEntityResponseBuilderTests method notModifiedEtag.
@Test
public void notModifiedEtag() throws Exception {
String etag = "\"foo\"";
EntityResponse<String> entityResponse = EntityResponse.fromObject("bar").eTag(etag).build();
MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", "https://example.com");
mockRequest.addHeader(HttpHeaders.IF_NONE_MATCH, etag);
MockHttpServletResponse mockResponse = new MockHttpServletResponse();
ModelAndView mav = entityResponse.writeTo(mockRequest, mockResponse, EMPTY_CONTEXT);
assertThat(mav).isNull();
assertThat(mockResponse.getStatus()).isEqualTo(HttpStatus.NOT_MODIFIED.value());
}
use of org.springframework.web.testfixture.servlet.MockHttpServletResponse in project spring-framework by spring-projects.
the class DispatcherServletTests method anotherLocaleRequest.
@Test
public void anotherLocaleRequest() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "GET", "/locale.do;abc=def");
request.addPreferredLocale(Locale.CANADA);
request.addUserRole("role1");
MockHttpServletResponse response = new MockHttpServletResponse();
complexDispatcherServlet.service(request, response);
assertThat(response.getForwardedUrl() == null).as("Not forwarded").isTrue();
assertThat(request.getAttribute("test1") != null).isTrue();
assertThat(request.getAttribute("test1x") == null).isTrue();
assertThat(request.getAttribute("test1y") == null).isTrue();
assertThat(request.getAttribute("test2") != null).isTrue();
assertThat(request.getAttribute("test2x") == null).isTrue();
assertThat(request.getAttribute("test2y") == null).isTrue();
assertThat(request.getAttribute("test3") != null).isTrue();
assertThat(request.getAttribute("test3x") != null).isTrue();
assertThat(request.getAttribute("test3y") != null).isTrue();
assertThat(response.getHeader("Last-Modified")).isEqualTo("Wed, 01 Apr 2015 00:00:01 GMT");
}
use of org.springframework.web.testfixture.servlet.MockHttpServletResponse in project spring-framework by spring-projects.
the class DispatcherServletTests method noCleanupAfterInclude.
@Test
public void noCleanupAfterInclude() 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.setCleanupAfterInclude(false);
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);
}
Aggregations