org.springframework.test.web.client.match

Class ContentRequestMatchers

  • java.lang.Object
    • org.springframework.test.web.client.match.ContentRequestMatchers


  • public class ContentRequestMatchers
    extends java.lang.Object
    Factory for request content RequestMatcher's. An instance of this class is typically accessed via MockRestRequestMatchers.content().
    Since:
    3.2
    Author:
    Rossen Stoyanchev
    • Method Detail

      • contentType

        public RequestMatcher contentType(java.lang.String expectedContentType)
        Assert the request content type as a String.
      • string

        public RequestMatcher string(org.hamcrest.Matcher<? super java.lang.String> matcher)
        Get the body of the request as a UTF-8 string and appply the given Matcher.
      • string

        public RequestMatcher string(java.lang.String expectedContent)
        Get the body of the request as a UTF-8 string and compare it to the given String.
      • bytes

        public RequestMatcher bytes(byte[] expectedContent)
        Compare the body of the request to the given byte array.
      • formData

        public RequestMatcher formData(MultiValueMap<java.lang.String,java.lang.String> expectedContent)
        Parse the body as form data and compare to the given MultiValueMap.
        Since:
        4.3
      • xml

        public RequestMatcher xml(java.lang.String expectedXmlContent)
        Parse the request body and the given String as XML and assert that the two are "similar" - i.e. they contain the same elements and attributes regardless of order.

        Use of this matcher assumes the XMLUnit library is available.

        Parameters:
        expectedXmlContent - the expected XML content
      • node

        public RequestMatcher node(org.hamcrest.Matcher<? super org.w3c.dom.Node> matcher)
        Parse the request content as Node and apply the given Matcher.
      • json

        public RequestMatcher json(java.lang.String expectedJsonContent)
        Parse the expected and actual strings as JSON and assert the two are "similar" - i.e. they contain the same attribute-value pairs regardless of formatting with a lenient checking (extensible, and non-strict array ordering).

        Use of this matcher requires the JSONassert library.

        Parameters:
        expectedJsonContent - the expected JSON content
        Since:
        5.0.5
      • json

        public RequestMatcher json(java.lang.String expectedJsonContent,
                                   boolean strict)
        Parse the request body and the given string as JSON and assert the two are "similar" - i.e. they contain the same attribute-value pairs regardless of formatting.

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

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

        Use of this matcher requires the JSONassert library.

        Parameters:
        expectedJsonContent - the expected JSON content
        strict - enables strict checking
        Since:
        5.0.5