Interface WebTestClient.BodyContentSpec

Enclosing interface:
WebTestClient

public static interface WebTestClient.BodyContentSpec
Spec for expectations on the response body content.
  • Method Details

    • isEmpty

      Assert the response body is empty and return the exchange result.
    • json

      default WebTestClient.BodyContentSpec json(String expectedJson)
      Parse the expected and actual response content as JSON and perform a comparison verifying that they contain the same attribute-value pairs regardless of formatting with lenient checking (extensible and non-strict array ordering).

      Use of this method requires the JSONassert library to be on the classpath.

      Parameters:
      expectedJson - the expected JSON content
      See Also:
    • json

      @Deprecated(since="6.2") WebTestClient.BodyContentSpec json(String expectedJson, boolean strict)
      Deprecated.
      Parse the expected and actual response content as JSON and perform a comparison verifying that they contain the same attribute-value pairs regardless of formatting.

      Can compare in two modes, depending on the strict parameter value:

      • true: strict checking. Not extensible and strict array ordering.
      • false: lenient checking. Extensible and non-strict array ordering.

      Use of this method requires the JSONassert library to be on the classpath.

      Parameters:
      expectedJson - the expected JSON content
      strict - enables strict checking if true
      Since:
      5.3.16
      See Also:
    • json

      WebTestClient.BodyContentSpec json(String expectedJson, JsonCompareMode compareMode)
      Parse the expected and actual response content as JSON and perform a comparison using the given mode. If the comparison failed, throws an AssertionError with the message of the JsonComparison.

      Use of this method requires the JSONassert library to be on the classpath.

      Parameters:
      expectedJson - the expected JSON content
      compareMode - the compare mode
      Since:
      6.2
      See Also:
    • json

      WebTestClient.BodyContentSpec json(String expectedJson, JsonComparator comparator)
      Parse the expected and actual response content as JSON and perform a comparison using the given JsonComparator. If the comparison failed, throws an AssertionError with the message of the JsonComparison.
      Parameters:
      expectedJson - the expected JSON content
      comparator - the comparator to use
      Since:
      6.2
    • xml

      Parse expected and actual response content as XML and assert that the two are "similar", i.e. they contain the same elements and attributes regardless of order.

      Use of this method requires the XMLUnit library on the classpath.

      Parameters:
      expectedXml - the expected XML content.
      Since:
      5.1
      See Also:
    • jsonPath

      JsonPathAssertions jsonPath(String expression)
      Access to response body assertions using a JsonPath expression to inspect a specific subset of the body.
      Parameters:
      expression - the JsonPath expression
      Since:
      6.2
    • jsonPath

      @Deprecated(since="6.2", forRemoval=true) JsonPathAssertions jsonPath(String expression, Object... args)
      Deprecated, for removal: This API element is subject to removal in a future version.
      in favor of calling String.formatted(Object...) upfront
      Access to response body assertions using a JsonPath expression to inspect a specific subset of the body.

      The JSON path expression can be a parameterized string using formatting specifiers as defined in String.format(java.lang.String, java.lang.Object...).

      Parameters:
      expression - the JsonPath expression
      args - arguments to parameterize the expression
    • xpath

      default XpathAssertions xpath(String expression, Object... args)
      Access to response body assertions using an XPath expression to inspect a specific subset of the body.

      The XPath expression can be a parameterized string using formatting specifiers as defined in String.format(java.lang.String, java.lang.Object...).

      Parameters:
      expression - the XPath expression
      args - arguments to parameterize the expression
      Since:
      5.1
      See Also:
    • xpath

      XpathAssertions xpath(String expression, @Nullable Map<String,String> namespaces, Object... args)
      Access to response body assertions with specific namespaces using an XPath expression to inspect a specific subset of the body.

      The XPath expression can be a parameterized string using formatting specifiers as defined in String.format(java.lang.String, java.lang.Object...).

      Parameters:
      expression - the XPath expression
      namespaces - the namespaces to use
      args - arguments to parameterize the expression
      Since:
      5.1
    • consumeWith

      Assert the response body content with the given Consumer.
      Parameters:
      consumer - the consumer for the response body; the input byte[] may be null if there was no response body.
    • returnResult

      EntityExchangeResult<byte[]> returnResult()
      Exit the chained API and return an ExchangeResult with the raw response content.