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 SummaryConstructorsModifierConstructorDescriptionprotectedClass constructor, not for direct instantiation.
- 
Method SummaryModifier 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- 
ContentRequestMatchersprotected ContentRequestMatchers()Class constructor, not for direct instantiation. UseMockRestRequestMatchers.content().
 
- 
- 
Method Details- 
contentTypeAssert the request content type as a String.
- 
contentTypeAssert the request content type as aMediaType.
- 
contentTypeCompatibleWithAssert the request content type is compatible with the given content type as defined byMediaType.isCompatibleWith(MediaType).
- 
contentTypeCompatibleWithAssert the request content type is compatible with the given content type as defined byMediaType.isCompatibleWith(MediaType).
- 
stringGet the body of the request as a UTF-8 string and apply the givenMatcher.
- 
stringGet the body of the request as a UTF-8 string and compare it to the given String.
- 
bytesCompare the body of the request to the given byte array.
- 
formDataParse the body as form data and compare to the givenMultiValueMap.- Since:
- 4.3
 
- 
formDataContainsVariant offormData(MultiValueMap)that matches the given subset of expected form parameters.- Since:
- 5.3
 
- 
multipartDataParse the body as multipart data and assert it contains exactly the values from the givenMultiValueMap. Values may be of type:- String- form field
- Resource- content from a file
- byte[]- 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
 
- 
multipartDataContainsVariant 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
 
- 
xmlParse 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:
 
- 
jsonParse 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
 
- 
jsonParse 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 content
- strict- enables strict checking
- Since:
- 5.0.5
 
 
-