use of org.springframework.web.testfixture.servlet.MockHttpServletRequest in project spring-framework by spring-projects.
the class DefaultRenderingResponseTests method modelAttributeConventions.
@Test
public void modelAttributeConventions() throws Exception {
RenderingResponse result = RenderingResponse.create("foo").modelAttribute("bar").build();
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
ModelAndView mav = result.writeTo(request, response, EMPTY_CONTEXT);
assertThat(mav).isNotNull();
assertThat(mav.getModel().get("string")).isEqualTo("bar");
}
use of org.springframework.web.testfixture.servlet.MockHttpServletRequest in project spring-framework by spring-projects.
the class DefaultRenderingResponseTests method notModifiedEtag.
@Test
public void notModifiedEtag() throws Exception {
String etag = "\"foo\"";
RenderingResponse result = RenderingResponse.create("bar").header(HttpHeaders.ETAG, etag).build();
MockHttpServletRequest request = new MockHttpServletRequest("GET", "https://example.com");
request.addHeader(HttpHeaders.IF_NONE_MATCH, etag);
MockHttpServletResponse response = new MockHttpServletResponse();
ModelAndView mav = result.writeTo(request, response, EMPTY_CONTEXT);
assertThat(mav).isNull();
assertThat(response.getStatus()).isEqualTo(HttpStatus.NOT_MODIFIED.value());
}
use of org.springframework.web.testfixture.servlet.MockHttpServletRequest in project spring-framework by spring-projects.
the class DefaultRenderingResponseTests method create.
@Test
public void create() throws Exception {
String name = "foo";
RenderingResponse result = RenderingResponse.create(name).build();
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
ModelAndView mav = result.writeTo(request, response, EMPTY_CONTEXT);
assertThat(mav.getViewName()).isEqualTo(name);
}
use of org.springframework.web.testfixture.servlet.MockHttpServletRequest in project spring-framework by spring-projects.
the class DefaultRenderingResponseTests method modelAttributes.
@Test
public void modelAttributes() throws Exception {
Map<String, String> model = Collections.singletonMap("foo", "bar");
RenderingResponse result = RenderingResponse.create("foo").modelAttributes(model).build();
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
ModelAndView mav = result.writeTo(request, response, EMPTY_CONTEXT);
assertThat(mav).isNotNull();
assertThat(mav.getModel().get("foo")).isEqualTo("bar");
}
use of org.springframework.web.testfixture.servlet.MockHttpServletRequest in project spring-framework by spring-projects.
the class DefaultRenderingResponseTests method modelAttribute.
@Test
public void modelAttribute() throws Exception {
RenderingResponse result = RenderingResponse.create("foo").modelAttribute("foo", "bar").build();
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
ModelAndView mav = result.writeTo(request, response, EMPTY_CONTEXT);
assertThat(mav).isNotNull();
assertThat(mav.getModel().get("foo")).isEqualTo("bar");
}
Aggregations