public abstract class MockRestRequestMatchers extends Object
RequestMatcher
classes. Typically used to
provide input for MockRestServiceServer.expect(RequestMatcher)
.
Consider adding this class as a Java editor favorite. To navigate to this setting, open the Preferences and type "favorites".
Constructor and Description |
---|
MockRestRequestMatchers() |
Modifier and Type | Method and Description |
---|---|
static RequestMatcher |
anything()
Match to any request.
|
static ContentRequestMatchers |
content()
Access to request body matchers.
|
static RequestMatcher |
header(String name,
Matcher<? super List<String>> matcher)
Assert request header values with the given Hamcrest matcher, matching on
the entire
List of values. |
static RequestMatcher |
header(String name,
Matcher<? super String>... matchers)
Assert request header values with the given Hamcrest matcher(s).
|
static RequestMatcher |
header(String name,
String... expectedValues)
Assert request header values.
|
static RequestMatcher |
headerDoesNotExist(String name)
Assert that the given request header does not exist.
|
static <T> RequestMatcher |
jsonPath(String expression,
Matcher<? super T> matcher)
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 JsonPathRequestMatchers |
jsonPath(String expression,
Object... args)
Access to request body matchers using a
JsonPath expression to
inspect a specific subset of the body.
|
static RequestMatcher |
method(HttpMethod method)
Assert the
HttpMethod of the request. |
static RequestMatcher |
queryParam(String name,
Matcher<? super List<String>> matcher)
Assert request query parameter values with the given Hamcrest matcher,
matching on the entire
List of values. |
static RequestMatcher |
queryParam(String name,
Matcher<? super String>... matchers)
Assert request query parameter values with the given Hamcrest matcher(s).
|
static RequestMatcher |
queryParam(String name,
String... expectedValues)
Assert request query parameter values.
|
static RequestMatcher |
requestTo(Matcher<? super String> matcher)
Assert the request URI string with the given Hamcrest matcher.
|
static RequestMatcher |
requestTo(String expectedUri)
Assert the request URI matches the given string.
|
static RequestMatcher |
requestTo(URI uri)
Expect a request to the given URI.
|
static RequestMatcher |
requestToUriTemplate(String expectedUri,
Object... uriVars)
Variant of
requestTo(URI) that prepares the URI from a URI
template plus optional variables via UriComponentsBuilder
including encoding. |
static XpathRequestMatchers |
xpath(String expression,
Map<String,String> namespaces,
Object... args)
Access to response body matchers using an XPath to inspect a specific
subset of the body.
|
static XpathRequestMatchers |
xpath(String expression,
Object... args)
Access to request body matchers using an XPath to inspect a specific
subset of the body.
|
public static RequestMatcher anything()
public static RequestMatcher method(HttpMethod method)
HttpMethod
of the request.method
- the HTTP methodpublic static RequestMatcher requestTo(Matcher<? super String> matcher)
matcher
- the String matcher for the expected URIpublic static RequestMatcher requestTo(String expectedUri)
expectedUri
- the expected URIpublic static RequestMatcher requestToUriTemplate(String expectedUri, Object... uriVars)
requestTo(URI)
that prepares the URI from a URI
template plus optional variables via UriComponentsBuilder
including encoding.expectedUri
- the expected URI templateuriVars
- zero or more URI variables to populate the expected URIpublic static RequestMatcher requestTo(URI uri)
uri
- the expected URIpublic static RequestMatcher queryParam(String name, Matcher<? super List<String>> matcher)
List
of 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 as Matchers.everyItem(Matcher)
),
that each value in the list matches corresponding dedicated criteria
(such as Matchers.contains(Matcher[])
), etc.
name
- the name of the query parameter whose value(s) will be assertedmatcher
- the Hamcrest matcher to apply to the entire list of values
for the given query parameterqueryParam(String, Matcher...)
,
queryParam(String, String...)
@SafeVarargs public static RequestMatcher queryParam(String name, Matcher<? super String>... matchers)
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 provided matchers
exceeds the number of query parameter values,
an AssertionError
will be thrown to signal the mismatch.
See queryParam(String, Matcher)
for a variant which accepts a
Matcher
that applies to the entire list of values as opposed to
applying only to individual values.
name
- the name of the query parameter whose value(s) will be assertedmatchers
- the Hamcrest matchers to apply to individual query parameter
values; the nth matcher is applied to the nth query
parameter valuequeryParam(String, Matcher)
,
queryParam(String, String...)
public static RequestMatcher queryParam(String name, String... expectedValues)
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 of expectedValues
exceeds the number of query parameter
values, an AssertionError
will be thrown to signal the mismatch.
See queryParam(String, Matcher)
for a variant which accepts a
Hamcrest Matcher
that applies to the entire list of values as opposed
to asserting only individual values.
name
- the name of the query parameter whose value(s) will be assertedexpectedValues
- the expected values of individual query parameter values;
the nth expected value is compared to the nth query
parameter valuequeryParam(String, Matcher)
,
queryParam(String, Matcher...)
public static RequestMatcher header(String name, Matcher<? super List<String>> matcher)
List
of 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 as Matchers.everyItem(Matcher)
),
that each value in the list matches corresponding dedicated criteria
(such as Matchers.contains(Matcher[])
), etc.
name
- the name of the header whose value(s) will be assertedmatcher
- the Hamcrest matcher to apply to the entire list of values
for the given headerheader(String, Matcher...)
,
header(String, String...)
@SafeVarargs public static RequestMatcher header(String name, Matcher<? super String>... matchers)
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
provided matchers
exceeds the number of header values, an
AssertionError
will be thrown to signal the mismatch.
See header(String, Matcher)
for a variant which accepts a
Hamcrest Matcher
that applies to the entire list of values as
opposed to applying only to individual values.
name
- the name of the header whose value(s) will be assertedmatchers
- the Hamcrest matchers to apply to individual header values;
the nth matcher is applied to the nth header valueheader(String, Matcher)
,
header(String, String...)
public static RequestMatcher header(String name, String... expectedValues)
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 of expectedValues
exceeds the
number of header values, an AssertionError
will be thrown to signal the
mismatch.
See header(String, Matcher)
for a variant which accepts a
Hamcrest Matcher
that applies to the entire list of values as
opposed to applying only to individual values.
name
- the name of the header whose value(s) will be assertedexpectedValues
- the expected values of individual header values; the
nth expected value is compared to the nth header valueheader(String, Matcher)
,
header(String, Matcher...)
public static RequestMatcher headerDoesNotExist(String name)
public static ContentRequestMatchers content()
public static JsonPathRequestMatchers jsonPath(String expression, Object... args)
String.format(String, Object...)
.expression
- the JSON path optionally parameterized with argumentsargs
- arguments to parameterize the JSON path expression withpublic static <T> RequestMatcher jsonPath(String expression, Matcher<? super T> matcher)
expression
- the JSON path expressionmatcher
- a matcher for the value expected at the JSON pathpublic static XpathRequestMatchers xpath(String expression, Object... args) throws XPathExpressionException
String.format(String, Object...)
.expression
- the XPath optionally parameterized with argumentsargs
- arguments to parameterize the XPath expression withXPathExpressionException
public static XpathRequestMatchers xpath(String expression, Map<String,String> namespaces, Object... args) throws XPathExpressionException
String.format(String, Object...)
.expression
- the XPath optionally parameterized with argumentsnamespaces
- the namespaces referenced in the XPath expressionargs
- arguments to parameterize the XPath expression withXPathExpressionException