Class ContentRequestMatchers
RequestMatcher
's. An instance of this
class is typically accessed via MockRestRequestMatchers.content()
.- Since:
- 3.2
- Author:
- Rossen Stoyanchev
-
Constructor Summary
ModifierConstructorDescriptionprotected
Class constructor, not for direct instantiation. -
Method Summary
Modifier and TypeMethodDescriptionbytes
(byte[] expectedContent) Compare the body of the request to the given byte array.contentType
(String expectedContentType) Assert the request content type as a String.contentType
(MediaType expectedContentType) Assert the request content type as aMediaType
.contentTypeCompatibleWith
(String contentType) Assert the request content type is compatible with the given content type as defined byMediaType.isCompatibleWith(MediaType)
.contentTypeCompatibleWith
(MediaType contentType) Assert the request content type is compatible with the given content type as defined byMediaType.isCompatibleWith(MediaType)
.formData
(MultiValueMap<String, String> expected) Parse the body as form data and compare to the givenMultiValueMap
.formDataContains
(Map<String, String> expected) Variant offormData(MultiValueMap)
that matches the given subset of expected form parameters.Parse the expected and actual strings as JSON and assert the two are "similar" - i.e.Deprecated.json
(String expectedJsonContent, JsonComparator comparator) Parse the request body and the given string as JSON and assert the two using the givenJsonComparator
.json
(String expectedJsonContent, JsonCompareMode compareMode) Parse the request body and the given string as JSON and assert the two using the given mode.multipartData
(MultiValueMap<String, ?> expectedMap) Parse the body as multipart data and assert it contains exactly the values from the givenMultiValueMap
.multipartData
(MultiValueMap<String, ?> expectedMap, Charset defaultCharset) Variant ofmultipartData(MultiValueMap)
with a defaultCharset.multipartDataContains
(Map<String, ?> expectedMap) Variant ofmultipartData(MultiValueMap)
that does the same but only for a subset of the actual values.Get the body of the request as a UTF-8 string and compare it to the given String.Get the body of the request as a UTF-8 string and apply the givenMatcher
.Parse the request body and the given String as XML and assert that the two are "similar" - i.e.
-
Constructor Details
-
ContentRequestMatchers
protected ContentRequestMatchers()Class constructor, not for direct instantiation. UseMockRestRequestMatchers.content()
.
-
-
Method Details
-
contentType
Assert the request content type as a String. -
contentType
Assert the request content type as aMediaType
. -
contentTypeCompatibleWith
Assert the request content type is compatible with the given content type as defined byMediaType.isCompatibleWith(MediaType)
. -
contentTypeCompatibleWith
Assert the request content type is compatible with the given content type as defined byMediaType.isCompatibleWith(MediaType)
. -
string
Get the body of the request as a UTF-8 string and apply the givenMatcher
. -
string
Get the body of the request as a UTF-8 string and compare it to the given String. -
bytes
Compare the body of the request to the given byte array. -
formData
Parse the body as form data and compare to the givenMultiValueMap
.- Since:
- 4.3
-
formDataContains
Variant offormData(MultiValueMap)
that matches the given subset of expected form parameters.- Since:
- 5.3
-
multipartData
Parse the body as multipart data and assert it contains exactly the values from the givenMultiValueMap
. Values may be of type:String
- form fieldResource
- content from a filebyte[]
- other raw content
Note: This method uses the fork of Commons FileUpload library packaged with Apache Tomcat in the
org.apache.tomcat.util.http.fileupload
package to parse the multipart data and it must be on the test classpath.- Parameters:
expectedMap
- the expected multipart values- Since:
- 5.3
-
multipartData
Variant ofmultipartData(MultiValueMap)
with a defaultCharset.- Since:
- 6.2
-
multipartDataContains
Variant ofmultipartData(MultiValueMap)
that does the same but only for a subset of the actual values.Note: This method uses the fork of Commons FileUpload library packaged with Apache Tomcat in the
org.apache.tomcat.util.http.fileupload
package to parse the multipart data and it must be on the test classpath.- Parameters:
expectedMap
- the expected multipart values- Since:
- 5.3
-
xml
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
-
source
- See Also:
-
json
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.
- Parameters:
expectedJsonContent
- the expected JSON content- Since:
- 5.0.5
-
json
Deprecated.in favor ofjson(String, JsonCompareMode)
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.
- Parameters:
expectedJsonContent
- the expected JSON contentstrict
- enables strict checking- Since:
- 5.0.5
-
json
Parse the request body and the given string as JSON and assert the two using the given mode. If the comparison failed, throws anAssertionError
with the message of theJsonComparison
.Use of this matcher requires the JSONassert library.
- Parameters:
expectedJsonContent
- the expected JSON contentcompareMode
- the compare mode- Since:
- 6.2
-
json
Parse the request body and the given string as JSON and assert the two using the givenJsonComparator
. If the comparison failed, throws anAssertionError
with the message of theJsonComparison
.Use this matcher if you require a custom JSONAssert configuration or if you desire to use another assertion library.
- Parameters:
expectedJsonContent
- the expected JSON contentcomparator
- the comparator to use- Since:
- 6.2
-
json(String, JsonCompareMode)