Class ContentRequestMatchers
- java.lang.Object
- org.springframework.test.web.client.match.ContentRequestMatchers
public class ContentRequestMatchers extends Object
Factory for request contentRequestMatcher
's. An instance of this class is typically accessed viaMockRestRequestMatchers.content()
.- Since:
- 3.2
- Author:
- Rossen Stoyanchev
Constructor Summary
Constructors Modifier Constructor Description protected
ContentRequestMatchers()
Class constructor, not for direct instantiation.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RequestMatcher
bytes(byte[] expectedContent)
Compare the body of the request to the given byte array.RequestMatcher
contentType(String expectedContentType)
Assert the request content type as a String.RequestMatcher
contentType(MediaType expectedContentType)
Assert the request content type as aMediaType
.RequestMatcher
contentTypeCompatibleWith(String contentType)
Assert the request content type is compatible with the given content type as defined byMediaType.isCompatibleWith(MediaType)
.RequestMatcher
contentTypeCompatibleWith(MediaType contentType)
Assert the request content type is compatible with the given content type as defined byMediaType.isCompatibleWith(MediaType)
.RequestMatcher
formData(MultiValueMap<String,String> expectedContent)
Parse the body as form data and compare to the givenMultiValueMap
.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
node(Matcher<? super Node> matcher)
RequestMatcher
source(Matcher<? super Source> matcher)
RequestMatcher
string(String expectedContent)
Get the body of the request as a UTF-8 string and compare it to the given String.RequestMatcher
string(Matcher<? super String> matcher)
Get the body of the request as a UTF-8 string and apply the givenMatcher
.RequestMatcher
xml(String expectedXmlContent)
Parse the request body and the given String as XML and assert that the two are "similar" - i.e.
Constructor Detail
ContentRequestMatchers
protected ContentRequestMatchers()
Class constructor, not for direct instantiation. UseMockRestRequestMatchers.content()
.
Method Detail
contentType
public RequestMatcher contentType(String expectedContentType)
Assert the request content type as a String.
contentType
public RequestMatcher contentType(MediaType expectedContentType)
Assert the request content type as aMediaType
.
contentTypeCompatibleWith
public RequestMatcher contentTypeCompatibleWith(String contentType)
Assert the request content type is compatible with the given content type as defined byMediaType.isCompatibleWith(MediaType)
.
contentTypeCompatibleWith
public RequestMatcher contentTypeCompatibleWith(MediaType contentType)
Assert the request content type is compatible with the given content type as defined byMediaType.isCompatibleWith(MediaType)
.
string
public RequestMatcher string(Matcher<? super String> matcher)
Get the body of the request as a UTF-8 string and apply the givenMatcher
.
string
public RequestMatcher string(String expectedContent)
Get the body of the request as a UTF-8 string and compare it to the given String.
bytes
public RequestMatcher bytes(byte[] expectedContent)
Compare the body of the request to the given byte array.
formData
public RequestMatcher formData(MultiValueMap<String,String> expectedContent)
Parse the body as form data and compare to the givenMultiValueMap
.- Since:
- 4.3
xml
public RequestMatcher xml(String expectedXmlContent)
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
public RequestMatcher node(Matcher<? super Node> matcher)
source
public RequestMatcher source(Matcher<? super Source> matcher)
json
public RequestMatcher json(String expectedJsonContent)
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
public RequestMatcher json(String expectedJsonContent, boolean strict)
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