类 ContentRequestMatchers

java.lang.Object
cn.taketoday.test.web.client.match.ContentRequestMatchers

public class ContentRequestMatchers extends Object
Factory for request content RequestMatcher's. An instance of this class is typically accessed via MockRestRequestMatchers.content().
从以下版本开始:
4.0
作者:
Rossen Stoyanchev
  • 字段详细资料

  • 构造器详细资料

  • 方法详细资料

    • contentType

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

      public RequestMatcher contentType(cn.taketoday.http.MediaType expectedContentType)
      Assert the request content type as a MediaType.
    • contentTypeCompatibleWith

      public RequestMatcher contentTypeCompatibleWith(String contentType)
      Assert the request content type is compatible with the given content type as defined by MediaType.isCompatibleWith(MediaType).
    • contentTypeCompatibleWith

      public RequestMatcher contentTypeCompatibleWith(cn.taketoday.http.MediaType contentType)
      Assert the request content type is compatible with the given content type as defined by MediaType.isCompatibleWith(MediaType).
    • string

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

      public RequestMatcher string(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(cn.taketoday.util.MultiValueMap<String,String> expected)
      Parse the body as form data and compare to the given MultiValueMap.
    • formDataContains

      public RequestMatcher formDataContains(Map<String,String> expected)
      Variant of formData(MultiValueMap) that matches the given subset of expected form parameters.
    • formData

      private RequestMatcher formData(cn.taketoday.util.MultiValueMap<String,String> expectedMap, boolean containsExactly)
    • multipartData

      public RequestMatcher multipartData(cn.taketoday.util.MultiValueMap<String,?> expectedMap)
      Parse the body as multipart data and assert it contains exactly the values from the given MultiValueMap. Values may be of type:
      • String - form field
      • Resource - content from a file
      • byte[] - other raw content

      Note: This method uses the Apache Commons FileUpload library to parse the multipart data and it must be on the test classpath.

      参数:
      expectedMap - the expected multipart values
    • multipartDataContains

      public RequestMatcher multipartDataContains(Map<String,?> expectedMap)
      Variant of multipartData(MultiValueMap) that does the same but only for a subset of the actual values.
      参数:
      expectedMap - the expected multipart values
    • multipartData

      private RequestMatcher multipartData(cn.taketoday.util.MultiValueMap<String,?> expectedMap, boolean containsExactly)
    • xml

      public RequestMatcher xml(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.

      参数:
      expectedXmlContent - the expected XML content
    • node

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

      public RequestMatcher source(org.hamcrest.Matcher<? super Source> matcher)
      Parse the request content as DOMSource and apply the given Matcher.
      另请参阅:
    • json

      public RequestMatcher json(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.

      参数:
      expectedJsonContent - the expected JSON content
    • json

      public RequestMatcher json(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.

      参数:
      expectedJsonContent - the expected JSON content
      strict - enables strict checking