public abstract class MockMvcResultMatchers extends Object
ResultMatcher
-based result actions.
Consider adding this class as a Java editor favorite. To navigate to this setting, open the Preferences and type "favorites".
Constructor and Description |
---|
MockMvcResultMatchers() |
Modifier and Type | Method and Description |
---|---|
static ContentResultMatchers |
content()
Access to response body assertions.
|
static CookieResultMatchers |
cookie()
Access to response cookie assertions.
|
static FlashAttributeResultMatchers |
flash()
Access to flash attribute assertions.
|
static ResultMatcher |
forwardedUrl(String expectedUrl)
Asserts the request was forwarded to the given URL.
|
static ResultMatcher |
forwardedUrlPattern(String urlPattern)
Asserts the request was forwarded to the given URL.
|
static ResultMatcher |
forwardedUrlTemplate(String urlTemplate,
Object... uriVars)
Asserts the request was forwarded to the given URL template.
|
static HandlerResultMatchers |
handler()
Access to assertions for the handler that handled the request.
|
static HeaderResultMatchers |
header()
Access to response header assertions.
|
static <T> ResultMatcher |
jsonPath(String expression,
Matcher<T> matcher)
|
static <T> ResultMatcher |
jsonPath(String expression,
Matcher<T> matcher,
Class<T> targetType)
|
static JsonPathResultMatchers |
jsonPath(String expression,
Object... args)
Access to response body assertions using a
JsonPath expression
to inspect a specific subset of the body.
|
static ModelResultMatchers |
model()
Access to model-related assertions.
|
static ResultMatcher |
redirectedUrl(String expectedUrl)
Asserts the request was redirected to the given URL.
|
static ResultMatcher |
redirectedUrlPattern(String urlPattern)
Asserts the request was redirected to the given URL.
|
static ResultMatcher |
redirectedUrlTemplate(String urlTemplate,
Object... uriVars)
Asserts the request was redirected to the given URL template.
|
static RequestResultMatchers |
request()
Access to request-related assertions.
|
static StatusResultMatchers |
status()
Access to response status assertions.
|
static ViewResultMatchers |
view()
Access to assertions on the selected view.
|
static XpathResultMatchers |
xpath(String expression,
Map<String,String> namespaces,
Object... args)
Access to response body assertions using an XPath expression to
inspect a specific subset of the body.
|
static XpathResultMatchers |
xpath(String expression,
Object... args)
Access to response body assertions using an XPath expression to
inspect a specific subset of the body.
|
public static RequestResultMatchers request()
public static HandlerResultMatchers handler()
public static ModelResultMatchers model()
public static ViewResultMatchers view()
public static FlashAttributeResultMatchers flash()
public static ResultMatcher forwardedUrl(@Nullable String expectedUrl)
This method accepts only exact matches.
expectedUrl
- the exact URL expectedpublic static ResultMatcher forwardedUrlTemplate(String urlTemplate, Object... uriVars)
This method accepts exact matches against the expanded and encoded URL template.
urlTemplate
- a URL template; the expanded URL will be encodeduriVars
- zero or more URI variables to populate the templateUriComponentsBuilder.fromUriString(String)
public static ResultMatcher forwardedUrlPattern(String urlPattern)
This method accepts AntPathMatcher
patterns.
urlPattern
- an Ant-style path pattern to match againstAntPathMatcher
public static ResultMatcher redirectedUrl(String expectedUrl)
This method accepts only exact matches.
expectedUrl
- the exact URL expectedpublic static ResultMatcher redirectedUrlTemplate(String urlTemplate, Object... uriVars)
This method accepts exact matches against the expanded and encoded URL template.
urlTemplate
- a URL template; the expanded URL will be encodeduriVars
- zero or more URI variables to populate the templateUriComponentsBuilder.fromUriString(String)
public static ResultMatcher redirectedUrlPattern(String urlPattern)
This method accepts AntPathMatcher
patterns.
urlPattern
- an Ant-style path pattern to match againstAntPathMatcher
public static StatusResultMatchers status()
public static HeaderResultMatchers header()
public static ContentResultMatchers content()
public static JsonPathResultMatchers jsonPath(String expression, Object... args)
The JSON path expression can be a parameterized string using
formatting specifiers as defined in
String.format(String, Object...)
.
expression
- the JSON path expression, optionally parameterized with argumentsargs
- arguments to parameterize the JSON path expression withjsonPath(String, Matcher)
,
jsonPath(String, Matcher, Class)
public static <T> ResultMatcher jsonPath(String expression, Matcher<T> matcher)
Matcher
.expression
- the JSON path expressionmatcher
- a matcher for the value expected at the JSON pathjsonPath(String, Object...)
,
jsonPath(String, Matcher, Class)
public static <T> ResultMatcher jsonPath(String expression, Matcher<T> matcher, Class<T> targetType)
Matcher
, coercing the resulting value into the
given target type before applying the matcher.
This can be useful for matching numbers reliably — for example, to coerce an integer into a double.
expression
- the JSON path expressionmatcher
- a matcher for the value expected at the JSON pathtargetType
- the target type to coerce the matching value intojsonPath(String, Object...)
,
jsonPath(String, Matcher)
public static XpathResultMatchers xpath(String expression, Object... args) throws XPathExpressionException
The XPath expression can be a parameterized string using formatting
specifiers as defined in String.format(String, Object...)
.
expression
- the XPath expression, optionally parameterized with argumentsargs
- arguments to parameterize the XPath expression withXPathExpressionException
public static XpathResultMatchers xpath(String expression, Map<String,String> namespaces, Object... args) throws XPathExpressionException
The XPath expression can be a parameterized string using formatting
specifiers as defined in String.format(String, Object...)
.
expression
- the XPath expression, optionally parameterized with argumentsnamespaces
- the namespaces referenced in the XPath expressionargs
- arguments to parameterize the XPath expression withXPathExpressionException
public static CookieResultMatchers cookie()