org.springframework.test.web.servlet.result

Class RequestResultMatchers

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


  • public class RequestResultMatchers
    extends java.lang.Object
    Factory for assertions on the request.

    An instance of this class is typically accessed via MockMvcResultMatchers.request().

    Since:
    3.2
    Author:
    Rossen Stoyanchev, Sam Brannen
    • Constructor Summary

      Constructors 
      Modifier Constructor and Description
      protected RequestResultMatchers()
      Protected constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      ResultMatcher asyncNotStarted()
      Assert that asynchronous processing was not started.
      <T> ResultMatcher asyncResult(org.hamcrest.Matcher<T> matcher)
      Assert the result from asynchronous processing with the given matcher.
      <T> ResultMatcher asyncResult(java.lang.Object expectedResult)
      Assert the result from asynchronous processing.
      ResultMatcher asyncStarted()
      Assert whether asynchronous processing started, usually as a result of a controller method returning Callable or DeferredResult.
      <T> ResultMatcher attribute(java.lang.String name, org.hamcrest.Matcher<T> matcher)
      Assert a request attribute value with the given Hamcrest Matcher.
      <T> ResultMatcher attribute(java.lang.String name, java.lang.Object expectedValue)
      Assert a request attribute value.
      <T> ResultMatcher sessionAttribute(java.lang.String name, org.hamcrest.Matcher<T> matcher)
      Assert a session attribute value with the given Hamcrest Matcher.
      <T> ResultMatcher sessionAttribute(java.lang.String name, java.lang.Object value)
      Assert a session attribute value.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • asyncStarted

        public ResultMatcher asyncStarted()
        Assert whether asynchronous processing started, usually as a result of a controller method returning Callable or DeferredResult.

        The test will await the completion of a Callable so that asyncResult(Matcher) can be used to assert the resulting value. Neither a Callable nor a DeferredResult will complete processing all the way since a MockHttpServletRequest does not perform asynchronous dispatches.

      • asyncNotStarted

        public ResultMatcher asyncNotStarted()
        Assert that asynchronous processing was not started.
        See Also:
        asyncStarted()
      • asyncResult

        public <T> ResultMatcher asyncResult(org.hamcrest.Matcher<T> matcher)
        Assert the result from asynchronous processing with the given matcher.

        This method can be used when a controller method returns Callable or WebAsyncTask.

      • asyncResult

        public <T> ResultMatcher asyncResult(java.lang.Object expectedResult)
        Assert the result from asynchronous processing.

        This method can be used when a controller method returns Callable or WebAsyncTask. The value matched is the value returned from the Callable or the exception raised.

      • attribute

        public <T> ResultMatcher attribute(java.lang.String name,
                                           org.hamcrest.Matcher<T> matcher)
        Assert a request attribute value with the given Hamcrest Matcher.
      • attribute

        public <T> ResultMatcher attribute(java.lang.String name,
                                           java.lang.Object expectedValue)
        Assert a request attribute value.
      • sessionAttribute

        public <T> ResultMatcher sessionAttribute(java.lang.String name,
                                                  org.hamcrest.Matcher<T> matcher)
        Assert a session attribute value with the given Hamcrest Matcher.
      • sessionAttribute

        public <T> ResultMatcher sessionAttribute(java.lang.String name,
                                                  java.lang.Object value)
        Assert a session attribute value.