Class ContentRequestMatchers
java.lang.Object
org.springframework.test.web.client.match.ContentRequestMatchers
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
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.Parse the request body and the given string as JSON and assert the two are "similar" - i.e.multipartData
(MultiValueMap<String, ?> expectedMap) Parse the body as multipart data and assert it contains exactly the values from the givenMultiValueMap
.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 Apache Commons FileUpload library to parse the multipart data and it must be on the test classpath.
- Parameters:
expectedMap
- the expected multipart values- Since:
- 5.3
-
multipartDataContains
Variant ofmultipartData(MultiValueMap)
that does the same but only for a subset of the actual values.- 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
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
-