Search in sources :

Example 56 with MockHttpServletRequest

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");
}
Also used : MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) ModelAndView(org.springframework.web.servlet.ModelAndView) MockHttpServletResponse(org.springframework.web.testfixture.servlet.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 57 with MockHttpServletRequest

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());
}
Also used : MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) ModelAndView(org.springframework.web.servlet.ModelAndView) MockHttpServletResponse(org.springframework.web.testfixture.servlet.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 58 with MockHttpServletRequest

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);
}
Also used : MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) ModelAndView(org.springframework.web.servlet.ModelAndView) MockHttpServletResponse(org.springframework.web.testfixture.servlet.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 59 with MockHttpServletRequest

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");
}
Also used : MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) ModelAndView(org.springframework.web.servlet.ModelAndView) MockHttpServletResponse(org.springframework.web.testfixture.servlet.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 60 with MockHttpServletRequest

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");
}
Also used : MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) ModelAndView(org.springframework.web.servlet.ModelAndView) MockHttpServletResponse(org.springframework.web.testfixture.servlet.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Aggregations

MockHttpServletRequest (org.springframework.web.testfixture.servlet.MockHttpServletRequest)752 Test (org.junit.jupiter.api.Test)458 MockHttpServletResponse (org.springframework.web.testfixture.servlet.MockHttpServletResponse)359 PathPatternsParameterizedTest (org.springframework.web.servlet.handler.PathPatternsParameterizedTest)180 ServletWebRequest (org.springframework.web.context.request.ServletWebRequest)83 BeforeEach (org.junit.jupiter.api.BeforeEach)73 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)57 ModelAndView (org.springframework.web.servlet.ModelAndView)45 MockServletContext (org.springframework.web.testfixture.servlet.MockServletContext)45 ServletServerHttpRequest (org.springframework.http.server.ServletServerHttpRequest)39 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)38 HandlerExecutionChain (org.springframework.web.servlet.HandlerExecutionChain)38 TestBean (org.springframework.beans.testfixture.beans.TestBean)36 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)35 StaticWebApplicationContext (org.springframework.web.context.support.StaticWebApplicationContext)31 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)29 Cookie (jakarta.servlet.http.Cookie)27 HttpRequest (org.springframework.http.HttpRequest)27 HttpServletResponse (jakarta.servlet.http.HttpServletResponse)26 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)25