public class ContentResultMatchers
extends java.lang.Object
An instance of this class is typically accessed via
MockMvcResultMatchers.content()
.
Modifier | Constructor and Description |
---|---|
protected |
ContentResultMatchers()
Protected constructor.
|
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(java.lang.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(java.lang.String contentType)
Assert the ServletResponse content type is compatible with the given
content type as defined by
MediaType.isCompatibleWith(MediaType) . |
ResultMatcher |
encoding(java.lang.String characterEncoding)
Assert the character encoding in the ServletResponse.
|
ResultMatcher |
json(java.lang.String jsonContent)
Parse the expected and actual strings as JSON and assert the two
are "similar" - i.e.
|
ResultMatcher |
json(java.lang.String jsonContent,
boolean strict)
Parse the response content and the given string as JSON and assert the two are "similar" -
i.e.
|
ResultMatcher |
node(Matcher<? super org.w3c.dom.Node> matcher)
Parse the response content as
Node and apply the given Hamcrest
Matcher . |
ResultMatcher |
source(Matcher<? super javax.xml.transform.Source> matcher)
Parse the response content as
DOMSource and apply the given
Hamcrest Matcher . |
ResultMatcher |
string(Matcher<? super java.lang.String> matcher)
Assert the response body content with a Hamcrest
Matcher . |
ResultMatcher |
string(java.lang.String expectedContent)
Assert the response body content as a String.
|
ResultMatcher |
xml(java.lang.String xmlContent)
Parse the response content and the given string as XML and assert the two
are "similar" - i.e.
|
protected ContentResultMatchers()
MockMvcResultMatchers.content()
.public ResultMatcher contentType(java.lang.String contentType)
contentTypeCompatibleWith(String)
.public ResultMatcher contentType(MediaType contentType)
contentTypeCompatibleWith(MediaType)
.public ResultMatcher contentTypeCompatibleWith(java.lang.String contentType)
MediaType.isCompatibleWith(MediaType)
.public ResultMatcher contentTypeCompatibleWith(MediaType contentType)
MediaType.isCompatibleWith(MediaType)
.public ResultMatcher encoding(java.lang.String characterEncoding)
ServletResponse.getCharacterEncoding()
public ResultMatcher string(Matcher<? super java.lang.String> matcher)
Matcher
.
mockMvc.perform(get("/path")) .andExpect(content().string(containsString("text")));
public ResultMatcher string(java.lang.String expectedContent)
public ResultMatcher bytes(byte[] expectedContent)
public ResultMatcher xml(java.lang.String xmlContent)
Use of this matcher requires the XMLUnit library.
xmlContent
- the expected XML contentMockMvcResultMatchers.xpath(String, Object...)
,
MockMvcResultMatchers.xpath(String, Map, Object...)
public ResultMatcher node(Matcher<? super org.w3c.dom.Node> matcher)
Node
and apply the given Hamcrest
Matcher
.public ResultMatcher source(Matcher<? super javax.xml.transform.Source> matcher)
DOMSource
and apply the given
Hamcrest Matcher
.public ResultMatcher json(java.lang.String jsonContent)
jsonContent
- the expected JSON contentpublic ResultMatcher json(java.lang.String jsonContent, boolean strict)
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.
jsonContent
- the expected JSON contentstrict
- enables strict checking