org.springframework.test.web.servlet.result

Class MockMvcResultMatchers

  • java.lang.Object
    • org.springframework.test.web.servlet.result.MockMvcResultMatchers


  • public abstract class MockMvcResultMatchers
    extends java.lang.Object
    Static factory methods for 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 Detail

      • MockMvcResultMatchers

        public MockMvcResultMatchers()
    • Method Detail

      • handler

        public static HandlerResultMatchers handler()
        Access to assertions for the handler that handled the request.
      • view

        public static ViewResultMatchers view()
        Access to assertions on the selected view.
      • forwardedUrl

        public static ResultMatcher forwardedUrl(java.lang.String expectedUrl)
        Asserts the request was forwarded to the given URL.

        This method accepts only exact matches.

        Parameters:
        expectedUrl - the exact URL expected
      • forwardedUrlTemplate

        public static ResultMatcher forwardedUrlTemplate(java.lang.String urlTemplate,
                                                         java.lang.Object... uriVars)
        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 encoded
        uriVars - zero or more URI variables to populate the template
        See Also:
        UriComponentsBuilder.fromUriString(String)
      • forwardedUrlPattern

        public static ResultMatcher forwardedUrlPattern(java.lang.String urlPattern)
        Asserts the request was forwarded to the given URL.

        This method accepts AntPathMatcher patterns.

        Parameters:
        urlPattern - an AntPath pattern to match against
        Since:
        4.0
        See Also:
        AntPathMatcher
      • redirectedUrl

        public static ResultMatcher redirectedUrl(java.lang.String expectedUrl)
        Asserts the request was redirected to the given URL.

        This method accepts only exact matches.

        Parameters:
        expectedUrl - the exact URL expected
      • redirectedUrlTemplate

        public static ResultMatcher redirectedUrlTemplate(java.lang.String urlTemplate,
                                                          java.lang.Object... uriVars)
        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 encoded
        uriVars - zero or more URI variables to populate the template
        See Also:
        UriComponentsBuilder.fromUriString(String)
      • redirectedUrlPattern

        public static ResultMatcher redirectedUrlPattern(java.lang.String urlPattern)
        Asserts the request was redirected to the given URL.

        This method accepts AntPathMatcher patterns.

        Parameters:
        urlPattern - an AntPath pattern to match against
        Since:
        4.0
        See Also:
        AntPathMatcher
      • jsonPath

        public static JsonPathResultMatchers jsonPath(java.lang.String expression,
                                                      java.lang.Object... args)
        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 arguments
        args - arguments to parameterize the JSON path expression with
      • jsonPath

        public static <T> ResultMatcher jsonPath(java.lang.String expression,
                                                 org.hamcrest.Matcher<T> matcher)
        Access to response body assertions using a JsonPath expression to inspect a specific subset of the body and a Hamcrest matcher 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
      • xpath

        public static XpathResultMatchers xpath(java.lang.String expression,
                                                java.lang.Object... args)
                                         throws javax.xml.xpath.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:
        javax.xml.xpath.XPathExpressionException
      • xpath

        public static XpathResultMatchers xpath(java.lang.String expression,
                                                java.util.Map<java.lang.String,java.lang.String> namespaces,
                                                java.lang.Object... args)
                                         throws javax.xml.xpath.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
        namespaces - namespaces referenced in the XPath expression
        args - arguments to parameterize the XPath expression with
        Throws:
        javax.xml.xpath.XPathExpressionException