public class ContentRequestMatchers extends Object
RequestMatcher
's. An instance of this
class is typically accessed via MockRestRequestMatchers.content()
.Modifier | Constructor and Description |
---|---|
protected |
ContentRequestMatchers()
Class constructor, not for direct instantiation.
|
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 |
formData(MultiValueMap<String,String> expected)
Parse the body as form data and compare to the given
MultiValueMap . |
RequestMatcher |
formDataContains(Map<String,String> expected)
Variant of
formData(MultiValueMap) that matches the given subset
of expected form parameters. |
RequestMatcher |
json(String expectedJsonContent)
Parse the expected and actual strings as JSON and assert the two
are "similar" - i.e.
|
RequestMatcher |
json(String expectedJsonContent,
boolean strict)
Parse the request body and the given string as JSON and assert the two
are "similar" - i.e.
|
RequestMatcher |
multipartData(MultiValueMap<String,?> expectedMap)
Parse the body as multipart data and assert it contains exactly the
values from the given
MultiValueMap . |
RequestMatcher |
multipartDataContains(Map<String,?> expectedMap)
Variant of
multipartData(MultiValueMap) that does the same but
only for a subset of the actual values. |
RequestMatcher |
node(Matcher<? super Node> matcher)
|
RequestMatcher |
source(Matcher<? super Source> matcher)
|
RequestMatcher |
string(Matcher<? super String> matcher)
Get the body of the request as a UTF-8 string and apply 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.
|
protected ContentRequestMatchers()
MockRestRequestMatchers.content()
.public RequestMatcher contentType(String expectedContentType)
public RequestMatcher contentType(MediaType expectedContentType)
MediaType
.public RequestMatcher contentTypeCompatibleWith(String contentType)
MediaType.isCompatibleWith(MediaType)
.public RequestMatcher contentTypeCompatibleWith(MediaType contentType)
MediaType.isCompatibleWith(MediaType)
.public RequestMatcher string(Matcher<? super String> matcher)
Matcher
.public RequestMatcher string(String expectedContent)
public RequestMatcher bytes(byte[] expectedContent)
public RequestMatcher formData(MultiValueMap<String,String> expected)
MultiValueMap
.public RequestMatcher formDataContains(Map<String,String> expected)
formData(MultiValueMap)
that matches the given subset
of expected form parameters.public RequestMatcher multipartData(MultiValueMap<String,?> expectedMap)
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 File Upload library to parse the multipart data and it must be on the test classpath.
expectedMap
- the expected multipart valuespublic RequestMatcher multipartDataContains(Map<String,?> expectedMap)
multipartData(MultiValueMap)
that does the same but
only for a subset of the actual values.expectedMap
- the expected multipart valuespublic RequestMatcher xml(String expectedXmlContent)
Use of this matcher assumes the XMLUnit library is available.
expectedXmlContent
- the expected XML contentpublic RequestMatcher node(Matcher<? super Node> matcher)
public RequestMatcher source(Matcher<? super Source> matcher)
public RequestMatcher json(String expectedJsonContent)
Use of this matcher requires the JSONassert library.
expectedJsonContent
- the expected JSON contentpublic RequestMatcher json(String expectedJsonContent, 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.
expectedJsonContent
- the expected JSON contentstrict
- enables strict checking