Class MockRestRequestMatchers
java.lang.Object
org.springframework.test.web.client.match.MockRestRequestMatchers
Static factory methods for
RequestMatcher
classes. Typically used to
provide input for MockRestServiceServer.expect(RequestMatcher)
.
Eclipse Users
Consider adding this class as a Java editor favorite. To navigate to this setting, open the Preferences and type "favorites".
- Since:
- 3.2
- Author:
- Craig Walls, Rossen Stoyanchev, Sam Brannen
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic RequestMatcher
anything()
Match to any request.static ContentRequestMatchers
content()
Access to request body matchers.static RequestMatcher
Assert request header values.static RequestMatcher
Assert request header values with the given Hamcrest matcher(s).static RequestMatcher
headerDoesNotExist
(String name) Assert that the given request header does not exist.static JsonPathRequestMatchers
Access to request body matchers using a JsonPath expression to inspect a specific subset of the body.static <T> RequestMatcher
Access to request body matchers using a JsonPath expression to inspect a specific subset of the body and a Hamcrest match for asserting the value found at the JSON path.static RequestMatcher
method
(HttpMethod method) Assert theHttpMethod
of the request.static RequestMatcher
queryParam
(String name, String... expectedValues) Assert request query parameter values.static RequestMatcher
queryParam
(String name, Matcher<? super String>... matchers) Assert request query parameter values with the given Hamcrest matcher(s).static RequestMatcher
Assert the request URI matches the given string.static RequestMatcher
Expect a request to the given URI.static RequestMatcher
Assert the request URI string with the given Hamcrest matcher.static RequestMatcher
requestToUriTemplate
(String expectedUri, Object... uriVars) Variant ofrequestTo(URI)
that prepares the URI from a URI template plus optional variables viaUriComponentsBuilder
including encoding.static XpathRequestMatchers
Access to request body matchers using an XPath to inspect a specific subset of the body.static XpathRequestMatchers
Access to response body matchers using an XPath to inspect a specific subset of the body.
-
Constructor Details
-
MockRestRequestMatchers
public MockRestRequestMatchers()
-
-
Method Details
-
anything
Match to any request. -
method
Assert theHttpMethod
of the request.- Parameters:
method
- the HTTP method- Returns:
- the request matcher
-
requestTo
Assert the request URI string with the given Hamcrest matcher.- Parameters:
matcher
- the String matcher for the expected URI- Returns:
- the request matcher
-
requestTo
Assert the request URI matches the given string.- Parameters:
expectedUri
- the expected URI- Returns:
- the request matcher
-
requestToUriTemplate
Variant ofrequestTo(URI)
that prepares the URI from a URI template plus optional variables viaUriComponentsBuilder
including encoding.- Parameters:
expectedUri
- the expected URI templateuriVars
- zero or more URI variables to populate the expected URI- Returns:
- the request matcher
-
requestTo
Expect a request to the given URI.- Parameters:
uri
- the expected URI- Returns:
- the request matcher
-
queryParam
@SafeVarargs public static RequestMatcher queryParam(String name, Matcher<? super String>... matchers) Assert request query parameter values with the given Hamcrest matcher(s). -
queryParam
Assert request query parameter values. -
header
Assert request header values with the given Hamcrest matcher(s). -
header
Assert request header values. -
headerDoesNotExist
Assert that the given request header does not exist.- Since:
- 5.2
-
content
Access to request body matchers. -
jsonPath
Access to request body matchers using a JsonPath expression to inspect a specific subset of the body. The JSON path expression can be a parameterized string using formatting specifiers as defined inString.format(String, Object...)
.- Parameters:
expression
- the JSON path optionally parameterized with argumentsargs
- arguments to parameterize the JSON path expression with
-
jsonPath
Access to request body matchers using a JsonPath expression to inspect a specific subset of the body and a Hamcrest match for asserting the value found at the JSON path.- Parameters:
expression
- the JSON path expressionmatcher
- a matcher for the value expected at the JSON path
-
xpath
public static XpathRequestMatchers xpath(String expression, Object... args) throws XPathExpressionException Access to request body matchers using an XPath to inspect a specific subset of the body. The XPath expression can be a parameterized string using formatting specifiers as defined inString.format(String, Object...)
.- Parameters:
expression
- the XPath optionally parameterized with argumentsargs
- arguments to parameterize the XPath expression with- Throws:
XPathExpressionException
-
xpath
public static XpathRequestMatchers xpath(String expression, Map<String, String> namespaces, Object... args) throws XPathExpressionExceptionAccess to response body matchers using an XPath to inspect a specific subset of the body. The XPath expression can be a parameterized string using formatting specifiers as defined inString.format(String, Object...)
.- Parameters:
expression
- the XPath optionally parameterized with argumentsnamespaces
- the namespaces referenced in the XPath expressionargs
- arguments to parameterize the XPath expression with- Throws:
XPathExpressionException
-