Class MockMvcResultMatchers
ResultMatcher
-based result actions.
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:
- Rossen Stoyanchev, Brian Clozel, Sam Brannen
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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 JsonPathResultMatchers
Access to response body assertions using a JsonPath expression to inspect a specific subset of the body.static <T> ResultMatcher
static <T> ResultMatcher
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
Access to response body assertions using an XPath expression to inspect a specific subset of the body.static XpathResultMatchers
Access to response body assertions using an XPath expression to inspect a specific subset of the body.
-
Constructor Details
-
MockMvcResultMatchers
public MockMvcResultMatchers()
-
-
Method Details
-
request
Access to request-related assertions. -
handler
Access to assertions for the handler that handled the request. -
model
Access to model-related assertions. -
view
Access to assertions on the selected view. -
flash
Access to flash attribute assertions. -
forwardedUrl
Asserts the request was forwarded to the given URL.This method accepts only exact matches.
- Parameters:
expectedUrl
- the exact URL expected
-
forwardedUrlTemplate
Asserts the request was forwarded to the given URL template.This method accepts exact matches against the expanded and encoded URL template.
- Parameters:
urlTemplate
- a URL template; the expanded URL will be encodeduriVars
- zero or more URI variables to populate the template- See Also:
-
forwardedUrlPattern
Asserts the request was forwarded to the given URL.This method accepts
AntPathMatcher
patterns.- Parameters:
urlPattern
- an Ant-style path pattern to match against- Since:
- 4.0
- See Also:
-
redirectedUrl
Asserts the request was redirected to the given URL.This method accepts only exact matches.
- Parameters:
expectedUrl
- the exact URL expected
-
redirectedUrlTemplate
Asserts the request was redirected to the given URL template.This method accepts exact matches against the expanded and encoded URL template.
- Parameters:
urlTemplate
- a URL template; the expanded URL will be encodeduriVars
- zero or more URI variables to populate the template- See Also:
-
redirectedUrlPattern
Asserts the request was redirected to the given URL.This method accepts
AntPathMatcher
patterns.- Parameters:
urlPattern
- an Ant-style path pattern to match against- Since:
- 4.0
- See Also:
-
status
Access to response status assertions. -
header
Access to response header assertions. -
content
Access to response body assertions. -
jsonPath
Access to response body assertions 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 in
String.format(String, Object...)
.- Parameters:
expression
- the JSON path expression, optionally parameterized with argumentsargs
- arguments to parameterize the JSON path expression with- See Also:
-
jsonPath
Evaluate the given JsonPath expression against the response body and assert the resulting value with the given HamcrestMatcher
.- Parameters:
expression
- the JSON path expressionmatcher
- a matcher for the value expected at the JSON path- See Also:
-
jsonPath
public static <T> ResultMatcher jsonPath(String expression, Matcher<? super T> matcher, Class<T> targetType) Evaluate the given JsonPath expression against the response body and assert the resulting value with the given HamcrestMatcher
, 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.
- Parameters:
expression
- the JSON path expressionmatcher
- a matcher for the value expected at the JSON pathtargetType
- the target type to coerce the matching value into- Since:
- 5.2
- See Also:
-
xpath
public static XpathResultMatchers xpath(String expression, Object... args) throws XPathExpressionException Access to response body assertions using an XPath expression to inspect a specific subset of the body.The XPath expression can be a parameterized string using formatting specifiers as defined in
String.format(String, Object...)
.- Parameters:
expression
- the XPath expression, optionally parameterized with argumentsargs
- arguments to parameterize the XPath expression with- Throws:
XPathExpressionException
-
xpath
public static XpathResultMatchers xpath(String expression, Map<String, String> namespaces, Object... args) throws XPathExpressionExceptionAccess to response body assertions using an XPath expression to inspect a specific subset of the body.The XPath expression can be a parameterized string using formatting specifiers as defined in
String.format(String, Object...)
.- Parameters:
expression
- the XPath expression, optionally parameterized with argumentsnamespaces
- the namespaces referenced in the XPath expressionargs
- arguments to parameterize the XPath expression with- Throws:
XPathExpressionException
-
cookie
Access to response cookie assertions.
-