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 SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic ContentResultMatcherscontent()Access to response body assertions.static CookieResultMatcherscookie()Access to response cookie assertions.static FlashAttributeResultMatchersflash()Access to flash attribute assertions.static ResultMatcherforwardedUrl(@Nullable String expectedUrl) Asserts the request was forwarded to the given URL.static ResultMatcherforwardedUrlPattern(String urlPattern) Asserts the request was forwarded to the given URL.static ResultMatcherforwardedUrlTemplate(String urlTemplate, @Nullable Object... uriVars) Asserts the request was forwarded to the given URL template.static HandlerResultMatchershandler()Access to assertions for the handler that handled the request.static HeaderResultMatchersheader()Access to response header assertions.static JsonPathResultMatchersAccess to response body assertions using a JsonPath expression to inspect a specific subset of the body.static <T> ResultMatcherstatic <T> ResultMatcherstatic ModelResultMatchersmodel()Access to model-related assertions.static ResultMatcherredirectedUrl(String expectedUrl) Asserts the request was redirected to the given URL.static ResultMatcherredirectedUrlPattern(String urlPattern) Asserts the request was redirected to the given URL.static ResultMatcherredirectedUrlTemplate(String urlTemplate, @Nullable Object... uriVars) Asserts the request was redirected to the given URL template.static RequestResultMatchersrequest()Access to request-related assertions.static StatusResultMatchersstatus()Access to response status assertions.static ViewResultMatchersview()Access to assertions on the selected view.static XpathResultMatchersAccess to response body assertions using an XPath expression to inspect a specific subset of the body.static XpathResultMatchersAccess to response body assertions using an XPath expression to inspect a specific subset of the body.
- 
Constructor Details- 
MockMvcResultMatcherspublic MockMvcResultMatchers()
 
- 
- 
Method Details- 
requestAccess to request-related assertions.
- 
handlerAccess to assertions for the handler that handled the request.
- 
modelAccess to model-related assertions.
- 
viewAccess to assertions on the selected view.
- 
flashAccess to flash attribute assertions.
- 
forwardedUrlAsserts the request was forwarded to the given URL.This method accepts only exact matches. - Parameters:
- expectedUrl- the exact URL expected
 
- 
forwardedUrlTemplateAsserts 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 encoded
- uriVars- zero or more URI variables to populate the template
- See Also:
 
- 
forwardedUrlPatternAsserts the request was forwarded to the given URL.This method accepts AntPathMatcherpatterns.- Parameters:
- urlPattern- an Ant-style path pattern to match against
- Since:
- 4.0
- See Also:
 
- 
redirectedUrlAsserts the request was redirected to the given URL.This method accepts only exact matches. - Parameters:
- expectedUrl- the exact URL expected
 
- 
redirectedUrlTemplateAsserts 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 encoded
- uriVars- zero or more URI variables to populate the template
- See Also:
 
- 
redirectedUrlPatternAsserts the request was redirected to the given URL.This method accepts AntPathMatcherpatterns.- Parameters:
- urlPattern- an Ant-style path pattern to match against
- Since:
- 4.0
- See Also:
 
- 
statusAccess to response status assertions.
- 
headerAccess to response header assertions.
- 
contentAccess to response body assertions.
- 
jsonPathAccess 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 arguments
- args- arguments to parameterize the JSON path expression with
- See Also:
 
- 
jsonPathEvaluate the given JsonPath expression against the response body and assert the resulting value with the given HamcrestMatcher.- Parameters:
- expression- the JSON path expression
- matcher- a matcher for the value expected at the JSON path
- See Also:
 
- 
jsonPathpublic 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 expression
- matcher- a matcher for the value expected at the JSON path
- targetType- the target type to coerce the matching value into
- Since:
- 5.2
- See Also:
 
- 
xpathpublic 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 arguments
- args- arguments to parameterize the XPath expression with
- Throws:
- XPathExpressionException
 
- 
xpathpublic 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 arguments
- namespaces- the namespaces referenced in the XPath expression
- args- arguments to parameterize the XPath expression with
- Throws:
- XPathExpressionException
 
- 
cookieAccess to response cookie assertions.
 
-