Class MockRestRequestMatchers
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, Simon Baslé
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic RequestMatcheranything()Match to any request.static ContentRequestMatcherscontent()Access to request body matchers.static RequestMatcherAssert request header values.static RequestMatcherAssert request header values with the given Hamcrest matcher(s).static RequestMatcherheaderDoesNotExist(String name) Assert that the given request header does not exist.static RequestMatcherheaderList(String name, Matcher<? super List<String>> matcher) Assert request header values with the given Hamcrest matcher, matching on the entireListof values.static JsonPathRequestMatchersAccess to request body matchers using a JsonPath expression to inspect a specific subset of the body.static <T> RequestMatcherAccess 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 RequestMatchermethod(HttpMethod method) Assert theHttpMethodof the request.static RequestMatcherqueryParam(String name, String... expectedValues) Assert request query parameter values.static RequestMatcherqueryParam(String name, Matcher<? super String>... matchers) Assert request query parameter values with the given Hamcrest matcher(s).static RequestMatcherqueryParamList(String name, Matcher<? super List<String>> matcher) Assert request query parameter values with the given Hamcrest matcher, matching on the entireListof values.static RequestMatcherAssert the request URI matches the given string.static RequestMatcherExpect a request to the given URI.static RequestMatcherAssert the request URI string with the given Hamcrest matcher.static RequestMatcherrequestToUriTemplate(String expectedUri, @Nullable Object... uriVars) Variant ofrequestTo(URI)that prepares the URI from a URI template plus optional variables viaUriComponentsBuilderincluding encoding.static XpathRequestMatchersAccess to request body matchers using an XPath to inspect a specific subset of the body.static XpathRequestMatchersAccess to response body matchers using an XPath to inspect a specific subset of the body.
- 
Constructor Details- 
MockRestRequestMatcherspublic MockRestRequestMatchers()
 
- 
- 
Method Details- 
anythingMatch to any request.
- 
methodAssert theHttpMethodof the request.- Parameters:
- method- the HTTP method
- Returns:
- the request matcher
 
- 
requestToAssert the request URI string with the given Hamcrest matcher.- Parameters:
- matcher- the String matcher for the expected URI
- Returns:
- the request matcher
 
- 
requestToAssert the request URI matches the given string.- Parameters:
- expectedUri- the expected URI
- Returns:
- the request matcher
 
- 
requestToUriTemplateVariant ofrequestTo(URI)that prepares the URI from a URI template plus optional variables viaUriComponentsBuilderincluding encoding.- Parameters:
- expectedUri- the expected URI template
- uriVars- zero or more URI variables to populate the expected URI
- Returns:
- the request matcher
 
- 
requestToExpect a request to the given URI.- Parameters:
- uri- the expected URI
- Returns:
- the request matcher
 
- 
queryParamListAssert request query parameter values with the given Hamcrest matcher, matching on the entireListof values.For example, this can be used to check that the list of query parameter values has at least one value matching a given Hamcrest matcher (such as Matchers.hasItem(Matcher)), that every value in the list matches common criteria (such asMatchers.everyItem(Matcher)), that each value in the list matches corresponding dedicated criteria (such asMatchers.contains(Matcher[])), etc.- Parameters:
- name- the name of the query parameter whose value(s) will be asserted
- matcher- the Hamcrest matcher to apply to the entire list of values for the given query parameter
- Since:
- 5.3.27
- See Also:
 
- 
queryParam@SafeVarargs public static RequestMatcher queryParam(String name, Matcher<? super String>... matchers) Assert request query parameter values with the given Hamcrest matcher(s).If the query parameter value list is larger than the number of provided matchers, no matchers will be applied to the extra query parameter values, effectively ignoring the additional parameter values. If the number of providedmatchersexceeds the number of query parameter values, anAssertionErrorwill be thrown to signal the mismatch.See queryParamList(String, Matcher)for a variant which accepts aMatcherthat applies to the entire list of values as opposed to applying only to individual values.- Parameters:
- name- the name of the query parameter whose value(s) will be asserted
- matchers- the Hamcrest matchers to apply to individual query parameter values; the nth matcher is applied to the nth query parameter value
- See Also:
 
- 
queryParamAssert request query parameter values.If the query parameter value list is larger than the number of expectedValues, no assertions will be applied to the extra query parameter values, effectively ignoring the additional parameter values. If the number ofexpectedValuesexceeds the number of query parameter values, anAssertionErrorwill be thrown to signal the mismatch.See queryParamList(String, Matcher)for a variant which accepts a HamcrestMatcherthat applies to the entire list of values as opposed to asserting only individual values.- Parameters:
- name- the name of the query parameter whose value(s) will be asserted
- expectedValues- the expected values of individual query parameter values; the nth expected value is compared to the nth query parameter value
- See Also:
 
- 
headerListAssert request header values with the given Hamcrest matcher, matching on the entireListof values.For example, this can be used to check that the list of header values has at least one value matching a given Hamcrest matcher (such as Matchers.hasItem(Matcher)), that every value in the list matches common criteria (such asMatchers.everyItem(Matcher)), that each value in the list matches corresponding dedicated criteria (such asMatchers.contains(Matcher[])), etc.- Parameters:
- name- the name of the header whose value(s) will be asserted
- matcher- the Hamcrest matcher to apply to the entire list of values for the given header
- Since:
- 5.3.27
- See Also:
 
- 
headerAssert request header values with the given Hamcrest matcher(s).If the header value list is larger than the number of provided matchers, no matchers will be applied to the extra header values, effectively ignoring the additional header values. If the number of providedmatchersexceeds the number of header values, anAssertionErrorwill be thrown to signal the mismatch.See headerList(String, Matcher)for a variant which accepts a HamcrestMatcherthat applies to the entire list of values as opposed to applying only to individual values.- Parameters:
- name- the name of the header whose value(s) will be asserted
- matchers- the Hamcrest matchers to apply to individual header values; the nth matcher is applied to the nth header value
- See Also:
 
- 
headerAssert request header values.If the header value list is larger than the number of expectedValues, no matchers will be applied to the extra header values, effectively ignoring the additional header values. If the number ofexpectedValuesexceeds the number of header values, anAssertionErrorwill be thrown to signal the mismatch.See headerList(String, Matcher)for a variant which accepts a HamcrestMatcherthat applies to the entire list of values as opposed to applying only to individual values.- Parameters:
- name- the name of the header whose value(s) will be asserted
- expectedValues- the expected values of individual header values; the nth expected value is compared to the nth header value
- See Also:
 
- 
headerDoesNotExistAssert that the given request header does not exist.- Since:
- 5.2
 
- 
contentAccess to request body matchers.
- 
jsonPathAccess 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 arguments
- args- arguments to parameterize the JSON path expression with
 
- 
jsonPathAccess 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 expression
- matcher- a matcher for the value expected at the JSON path
 
- 
xpathpublic 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 arguments
- args- arguments to parameterize the XPath expression with
- Throws:
- XPathExpressionException
 
- 
xpathpublic 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 arguments
- namespaces- the namespaces referenced in the XPath expression
- args- arguments to parameterize the XPath expression with
- Throws:
- XPathExpressionException
 
 
-