Class WebTestClientResponseAssert

java.lang.Object
org.assertj.core.api.AbstractAssert<WebTestClientResponseAssert, WebTestClientResponse>
org.assertj.core.api.AbstractObjectAssert<WebTestClientResponseAssert, WebTestClientResponse>
org.springframework.test.web.reactive.server.assertj.WebTestClientResponseAssert
All Implemented Interfaces:
org.assertj.core.api.Assert<WebTestClientResponseAssert, WebTestClientResponse>, org.assertj.core.api.Descriptable<WebTestClientResponseAssert>, org.assertj.core.api.ExtensionPoints<WebTestClientResponseAssert, WebTestClientResponse>

public class WebTestClientResponseAssert extends org.assertj.core.api.AbstractObjectAssert<WebTestClientResponseAssert, WebTestClientResponse>
AssertJ assertions for the result from a WebTestClient exchange.
Since:
7.0
Author:
Rossen Stoyanchev
  • Method Details

    • hasStatus

      public WebTestClientResponseAssert hasStatus(int status)
      Verify that the HTTP status is equal to the specified status code.
      Parameters:
      status - the expected HTTP status code
    • hasStatus

      public WebTestClientResponseAssert hasStatus(HttpStatus status)
      Verify that the HTTP status is equal to the specified status.
      Parameters:
      status - the expected HTTP status code
    • hasStatusOk

      public WebTestClientResponseAssert hasStatusOk()
      Verify that the HTTP status is equal to HttpStatus.OK.
      See Also:
    • hasStatus1xxInformational

      public WebTestClientResponseAssert hasStatus1xxInformational()
      Verify that the HTTP status code is in the 1xx range.
      See Also:
    • hasStatus2xxSuccessful

      public WebTestClientResponseAssert hasStatus2xxSuccessful()
      Verify that the HTTP status code is in the 2xx range.
      See Also:
    • hasStatus3xxRedirection

      public WebTestClientResponseAssert hasStatus3xxRedirection()
      Verify that the HTTP status code is in the 3xx range.
      See Also:
    • hasStatus4xxClientError

      public WebTestClientResponseAssert hasStatus4xxClientError()
      Verify that the HTTP status code is in the 4xx range.
      See Also:
    • hasStatus5xxServerError

      public WebTestClientResponseAssert hasStatus5xxServerError()
      Verify that the HTTP status code is in the 5xx range.
      See Also:
    • headers

      public HttpHeadersAssert headers()
      Return a new assertion object that uses HttpHeaders as the object to test. The returned assertion object provides all the regular map assertions, with headers mapped by header name. Examples:
      // Check for the presence of the Accept header:
      assertThat(response).headers().containsHeader(HttpHeaders.ACCEPT);
      
      // Check for the absence of the Content-Length header:
      assertThat(response).headers().doesNotContainsHeader(HttpHeaders.CONTENT_LENGTH);
      
    • containsHeader

      public WebTestClientResponseAssert containsHeader(String name)
      Verify that the response contains a header with the given name.
      Parameters:
      name - the name of an expected HTTP header
    • doesNotContainHeader

      public WebTestClientResponseAssert doesNotContainHeader(String name)
      Verify that the response does not contain a header with the given name.
      Parameters:
      name - the name of an HTTP header that should not be present
    • hasHeader

      public WebTestClientResponseAssert hasHeader(String name, String value)
      Verify that the response contains a header with the given name and primary value.
      Parameters:
      name - the name of an expected HTTP header
      value - the expected value of the header
    • contentType

      public MediaTypeAssert contentType()
      Return a new assertion object that uses the response's content type as the object to test.
    • hasContentType

      public WebTestClientResponseAssert hasContentType(MediaType contentType)
      Verify that the response's Content-Type is equal to the given value.
      Parameters:
      contentType - the expected content type
    • hasContentType

      public WebTestClientResponseAssert hasContentType(String contentType)
      Verify that the response's Content-Type is equal to the given string representation.
      Parameters:
      contentType - the expected content type
    • hasContentTypeCompatibleWith

      public WebTestClientResponseAssert hasContentTypeCompatibleWith(MediaType contentType)
      Verify that the response's Content-Type is compatible with the given value.
      Parameters:
      contentType - the expected compatible content type
    • hasContentTypeCompatibleWith

      public WebTestClientResponseAssert hasContentTypeCompatibleWith(String contentType)
      Verify that the response's Content-Type is compatible with the given string representation.
      Parameters:
      contentType - the expected compatible content type
    • cookies

      public ResponseCookieMapAssert cookies()
      Return a new assertion object that uses the response's cookies as the object to test.
    • body

      public org.assertj.core.api.AbstractByteArrayAssert<?> body()
      Return a new assertion object that uses the response body as the object to test.
      See Also:
    • bodyText

      public org.assertj.core.api.AbstractStringAssert<?> bodyText()
      Return a new assertion object that uses the response body converted to text as the object to test.

      Examples:

      // Check that the response body is equal to "Hello World":
      assertThat(response).bodyText().isEqualTo("Hello World");
      
    • hasBodyTextEqualTo

      public WebTestClientResponseAssert hasBodyTextEqualTo(String bodyText)
      Verify that the response body is equal to the given value.
    • bodyJson

      public AbstractJsonContentAssert<?> bodyJson()
      Return a new assertion object that uses the response body converted to text as the object to test. Compared to bodyText(), the assertion object provides dedicated JSON support.

      Examples:

      // Check that the response body is strictly equal to the content of
      // "/com/acme/sample/person-created.json":
      assertThat(response).bodyJson()
              .isStrictlyEqualToJson("/com/acme/sample/person-created.json");
      
      // Check that the response is strictly equal to the content of the
      // specified file located in the same package as the PersonController:
      assertThat(response).bodyJson().withResourceLoadClass(PersonController.class)
              .isStrictlyEqualToJson("person-created.json");
      
      The returned assert object also supports JSON path expressions.

      Examples:

      // Check that the JSON document does not have an "error" element
      assertThat(response).bodyJson().doesNotHavePath("$.error");
      
      // Check that the JSON document as a top level "message" element
      assertThat(response).bodyJson()
              .extractingPath("$.message").asString().isEqualTo("hello");