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

org.springframework.test.web.servlet.result

## Class ContentResultMatchers

- java.lang.Object
- - org.springframework.test.web.servlet.result.ContentResultMatchers

-     public class ContentResultMatchers
      extends Object

  Factory for response content assertions. An instance of this class is typically accessed via `MockMvcResultMatchers.content()`.
  Since:
    3.2
  Author:
    Rossen Stoyanchev

- - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `ContentResultMatchers()` Protected constructor.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `ResultMatcher` | `bytes(byte[] expectedContent)` Assert the response body content as a byte array.
    `ResultMatcher` | `contentType(MediaType contentType)` Assert the ServletResponse content type after parsing it as a MediaType.
    `ResultMatcher` | `contentType(String contentType)` Assert the ServletResponse content type.
    `ResultMatcher` | `contentTypeCompatibleWith(MediaType contentType)` Assert the ServletResponse content type is compatible with the given content type as defined by `MediaType.isCompatibleWith(MediaType)`.
    `ResultMatcher` | `contentTypeCompatibleWith(String contentType)` Assert the ServletResponse content type is compatible with the given content type as defined by `MediaType.isCompatibleWith(MediaType)`.
    `ResultMatcher` | `encoding(String characterEncoding)` Assert the character encoding in the ServletResponse.
    `ResultMatcher` | `node(org.hamcrest.Matcher<? super Node> matcher)` Parse the response content as `Node` and apply the given Hamcrest `Matcher`.
    `ResultMatcher` | `source(org.hamcrest.Matcher<? super Source> matcher)` Parse the response content as `DOMSource` and apply the given Hamcrest `Matcher`.
    `ResultMatcher` | `string(org.hamcrest.Matcher<? super String> matcher)` Assert the response body content with a Hamcrest `Matcher`.
    `ResultMatcher` | `string(String expectedContent)` Assert the response body content as a String.
    `ResultMatcher` | `xml(String xmlContent)` Parse the response content and the given string as XML and assert 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

    - #### ContentResultMatchers

          protected ContentResultMatchers()

      Protected constructor. Use `MockMvcResultMatchers.content()`.

  - ### Method Detail

    - #### contentType

          public ResultMatcher contentType(String contentType)

      Assert the ServletResponse content type. The given content type must fully match including type, sub-type, and parameters. For checking only the type and sub-type see `contentTypeCompatibleWith(String)`.

    - #### contentType

          public ResultMatcher contentType(MediaType contentType)

      Assert the ServletResponse content type after parsing it as a MediaType. The given content type must fully match including type, sub-type, and parameters. For checking only the type and sub-type see `contentTypeCompatibleWith(MediaType)`.

    - #### contentTypeCompatibleWith

          public ResultMatcher contentTypeCompatibleWith(String contentType)

      Assert the ServletResponse content type is compatible with the given content type as defined by `MediaType.isCompatibleWith(MediaType)`.

    - #### contentTypeCompatibleWith

          public ResultMatcher contentTypeCompatibleWith(MediaType contentType)

      Assert the ServletResponse content type is compatible with the given content type as defined by `MediaType.isCompatibleWith(MediaType)`.

    - #### encoding

          public ResultMatcher encoding(String characterEncoding)

      Assert the character encoding in the ServletResponse.
      See Also:
        `ServletResponse.getCharacterEncoding()`

    - #### string

          public ResultMatcher string(org.hamcrest.Matcher<? super String> matcher)

      Assert the response body content with a Hamcrest `Matcher`.

           mockMvc.perform(get("/path"))
             .andExpect(content(containsString("text")));

    - #### string

          public ResultMatcher string(String expectedContent)

      Assert the response body content as a String.

    - #### bytes

          public ResultMatcher bytes(byte[] expectedContent)

      Assert the response body content as a byte array.

    - #### xml

          public ResultMatcher xml(String xmlContent)

      Parse the response content and the given string as XML and assert the two are "similar" - i.e. they contain the same elements and attributes regardless of order.

      Use of this matcher requires the XMLUnit library.

      Parameters:
        `xmlContent` - the expected XML content
      See Also:
        `MockMvcResultMatchers.xpath(String, Object...)`, `MockMvcResultMatchers.xpath(String, Map, Object...)`

    - #### node

          public ResultMatcher node(org.hamcrest.Matcher<? super Node> matcher)

      Parse the response content as `Node` and apply the given Hamcrest `Matcher`.

    - #### source

          public ResultMatcher source(org.hamcrest.Matcher<? super Source> matcher)

      Parse the response content as `DOMSource` and apply the given Hamcrest `Matcher`.
      See Also:
        xml-matchers