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
ConstructorsModifierConstructorDescriptionprotectedClass 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.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.fileuploadpackage 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.fileuploadpackage 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
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
strictparameter 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
-