ContentRequestMatchers (Spring Framework 3.2.1.RELEASE API)
Date: 2013-01-24

org.springframework.test.web.client.match

## Class ContentRequestMatchers

- java.lang.Object
- - org.springframework.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()`.
  Since:
    3.2
  Author:
    Rossen Stoyanchev

- - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `ContentRequestMatchers()` Class constructor, not for direct instantiation.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `RequestMatcher` | `bytes(byte[] expectedContent)` Compare the body of the request to the given byte array.
    `RequestMatcher` | `contentType(MediaType expectedContentType)` Assert the request content type as a `MediaType`.
    `RequestMatcher` | `contentType(String expectedContentType)` Assert the request content type as a String.
    `RequestMatcher` | `contentTypeCompatibleWith(MediaType contentType)` Assert the request content type is compatible with the given content type as defined by `MediaType.isCompatibleWith(MediaType)`.
    `RequestMatcher` | `contentTypeCompatibleWith(String contentType)` Assert the request content type is compatible with the given content type as defined by `MediaType.isCompatibleWith(MediaType)`.
    `RequestMatcher` | `node(org.hamcrest.Matcher<? super Node> matcher)` Parse the request content as `Node` and apply the given `Matcher`.
    `RequestMatcher` | `source(org.hamcrest.Matcher<? super Source> matcher)` Parse the request content as `DOMSource` and apply the given `Matcher`.
    `RequestMatcher` | `string(org.hamcrest.Matcher<? super String> matcher)` Get the body of the request as a UTF-8 string and appply the given `Matcher`.
    `RequestMatcher` | `string(String expectedContent)` Get the body of the request as a UTF-8 string and compare it to the given String.
    `RequestMatcher` | `xml(String expectedXmlContent)` Parse the request body and the given String as XML and assert that the two are "similar" - i.e.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ContentRequestMatchers

          protected ContentRequestMatchers()

      Class constructor, not for direct instantiation. Use `MockRestRequestMatchers.content()`.

  - ### Method Detail

    - #### contentType

          public RequestMatcher contentType(String expectedContentType)

      Assert the request content type as a String.

    - #### contentType

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

    - #### 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.

      Parameters:
        `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`.
      See Also:
        http://code.google.com/p/xml-matchers/