Uses of Interface
org.springframework.test.web.servlet.ResultMatcher
Package
Description
Contains server-side support for testing Spring MVC applications.
AssertJ support for MockMvc.
Support for testing Spring MVC applications via
WebTestClient
with MockMvc
for server request
handling.Contains built-in
ResultMatcher
and ResultHandler
implementations.Contains built-in
MockMvcBuilder
implementations.-
Uses of ResultMatcher in org.springframework.test.web.servlet
Modifier and TypeMethodDescriptionstatic ResultMatcher
ResultMatcher.matchAll
(ResultMatcher... matchers) Deprecated.Modifier and TypeMethodDescriptionResultActions.andExpect
(ResultMatcher matcher) Perform an expectation.default ResultActions
ResultActions.andExpectAll
(ResultMatcher... matchers) Perform multiple expectations, with the guarantee that all expectations will be asserted even if one or more expectations fail with an exception.static ResultMatcher
ResultMatcher.matchAll
(ResultMatcher... matchers) Deprecated.as of Spring Framework 5.3.10, in favor ofResultActions.andExpectAll(ResultMatcher...)
Modifier and TypeMethodDescriptionprotected final MockMvc
MockMvcBuilderSupport.createMockMvc
(Filter[] filters, MockServletConfig servletConfig, WebApplicationContext webAppContext, RequestBuilder defaultRequestBuilder, Charset defaultResponseCharacterEncoding, List<ResultMatcher> globalResultMatchers, List<ResultHandler> globalResultHandlers, List<DispatcherServletCustomizer> dispatcherServletCustomizers) Delegates toMockMvcBuilderSupport.createMockMvc(Filter[], MockServletConfig, WebApplicationContext, RequestBuilder, List, List, List)
for creation of theMockMvc
instance and configures that instance with the supplieddefaultResponseCharacterEncoding
.protected final MockMvc
MockMvcBuilderSupport.createMockMvc
(Filter[] filters, MockServletConfig servletConfig, WebApplicationContext webAppContext, RequestBuilder defaultRequestBuilder, List<ResultMatcher> globalResultMatchers, List<ResultHandler> globalResultHandlers, List<DispatcherServletCustomizer> dispatcherServletCustomizers) -
Uses of ResultMatcher in org.springframework.test.web.servlet.assertj
Modifier and TypeMethodDescriptionMvcTestResultAssert.matches
(ResultMatcher resultMatcher) Verify that the actual MVC result matches the givenResultMatcher
. -
Uses of ResultMatcher in org.springframework.test.web.servlet.client
Modifier and TypeMethodDescription<T extends B>
TMockMvcWebTestClient.MockMvcServerSpec.alwaysExpect
(ResultMatcher resultMatcher) Define a global expectation that should always be applied to every response. -
Uses of ResultMatcher in org.springframework.test.web.servlet.result
Modifier and TypeMethodDescriptionRequestResultMatchers.asyncNotStarted()
Assert that asynchronous processing was not started.RequestResultMatchers.asyncResult
(Object expectedResult) Assert the result from asynchronous processing.<T> ResultMatcher
RequestResultMatchers.asyncResult
(Matcher<? super T> matcher) Assert the result from asynchronous processing with the given matcher.RequestResultMatchers.asyncStarted()
Assert whether asynchronous processing started, usually as a result of a controller method returningCallable
orDeferredResult
.Assert a cookie's specified attribute.CookieResultMatchers.attribute
(String cookieName, String cookieAttribute, Matcher<? super String> matcher) Assert a cookie's specified attribute with a HamcrestMatcher
.Assert a flash attribute's value.<T> ResultMatcher
Assert a flash attribute's value with the given HamcrestMatcher
.Assert a model attribute value.<T> ResultMatcher
Assert a model attribute value with the given HamcrestMatcher
.Assert a request attribute value.<T> ResultMatcher
Assert a request attribute value with the given HamcrestMatcher
.FlashAttributeResultMatchers.attributeCount
(int count) Assert the number of flash attributes.ModelResultMatchers.attributeDoesNotExist
(String... names) Assert the given model attributes do not exist.ModelResultMatchers.attributeErrorCount
(String name, int expectedCount) Assert the given model attribute(s) have errors.FlashAttributeResultMatchers.attributeExists
(String... names) Assert the existence of the given flash attributes.ModelResultMatchers.attributeExists
(String... names) Assert the given model attributes exist.ModelResultMatchers.attributeHasErrors
(String... names) Assert the given model attribute(s) have errors.ModelResultMatchers.attributeHasFieldErrorCode
(String name, String fieldName, String error) Assert a field error code for a model attribute using exact String match.ModelResultMatchers.attributeHasFieldErrorCode
(String name, String fieldName, Matcher<? super String> matcher) Assert a field error code for a model attribute using aMatcher
.ModelResultMatchers.attributeHasFieldErrors
(String name, String... fieldNames) Assert the given model attribute field(s) have errors.ModelResultMatchers.attributeHasNoErrors
(String... names) Assert the given model attribute(s) do not have errors.XpathResultMatchers.booleanValue
(Boolean value) Evaluate the XPath and assert theBoolean
value found.ContentResultMatchers.bytes
(byte[] expectedContent) Assert the response body content as a byte array.Assert a cookie's comment.Assert a cookie's comment with a HamcrestMatcher
.ContentResultMatchers.contentType
(String contentType) Assert the ServletResponse content type.ContentResultMatchers.contentType
(MediaType contentType) Assert the ServletResponse content type after parsing it as a MediaType.ContentResultMatchers.contentTypeCompatibleWith
(String contentType) Assert the ServletResponse content type is compatible with the given content type as defined byMediaType.isCompatibleWith(MediaType)
.ContentResultMatchers.contentTypeCompatibleWith
(MediaType contentType) Assert the ServletResponse content type is compatible with the given content type as defined byMediaType.isCompatibleWith(MediaType)
.Assert the primary value of the named response header parsed into a date using the preferred date format described in RFC 7231.CookieResultMatchers.doesNotExist
(String name) Assert a cookie does not exist.HeaderResultMatchers.doesNotExist
(String name) Assert that the named response header does not exist.JsonPathResultMatchers.doesNotExist()
Evaluate the JSON path expression against the response content and assert that a non-null value does not exist at the given path.XpathResultMatchers.doesNotExist()
Evaluate the XPath and assert that content doesn't exist.JsonPathResultMatchers.doesNotHaveJsonPath()
Evaluate the JSON path expression against the suppliedcontent
and assert that a value, includingnull
values, does not exist at the given path.Assert a cookie's domain.Assert a cookie's domain with a HamcrestMatcher
.Assert the character encoding in the ServletResponse.Assert the character encoding in the ServletResponse.ModelResultMatchers.errorCount
(int expectedCount) Assert the total number of errors in the model.Assert a cookie exists.Assert that the named response header exists.JsonPathResultMatchers.exists()
Evaluate the JSON path expression against the response content and assert that a non-null value, possibly an empty array or map, exists at the given path.XpathResultMatchers.exists()
Evaluate the XPath and assert that content exists.static ResultMatcher
MockMvcResultMatchers.forwardedUrl
(String expectedUrl) Asserts the request was forwarded to the given URL.static ResultMatcher
MockMvcResultMatchers.forwardedUrlPattern
(String urlPattern) Asserts the request was forwarded to the given URL.static ResultMatcher
MockMvcResultMatchers.forwardedUrlTemplate
(String urlTemplate, Object... uriVars) Asserts the request was forwarded to the given URL template.HandlerResultMatchers.handlerType
(Class<?> type) Assert the type of the handler that processed the request.ModelResultMatchers.hasErrors()
Assert the model has errors.JsonPathResultMatchers.hasJsonPath()
Evaluate the JSON path expression against the response content and assert that a value, possiblynull
, exists.ModelResultMatchers.hasNoErrors()
Assert the model has no errors.Assert whether the cookie must be HTTP only.StatusResultMatchers.is
(int status) Assert the response status code is equal to an integer value.Assert the response status code with the given HamcrestMatcher
.StatusResultMatchers.is1xxInformational()
Assert the response status code is in the 1xx range.StatusResultMatchers.is2xxSuccessful()
Assert the response status code is in the 2xx range.StatusResultMatchers.is3xxRedirection()
Assert the response status code is in the 3xx range.StatusResultMatchers.is4xxClientError()
Assert the response status code is in the 4xx range.StatusResultMatchers.is5xxServerError()
Assert the response status code is in the 5xx range.StatusResultMatchers.isAccepted()
Assert the response status code isHttpStatus.ACCEPTED
(202).StatusResultMatchers.isAlreadyReported()
Assert the response status code isHttpStatus.ALREADY_REPORTED
(208).JsonPathResultMatchers.isArray()
Evaluate the JSON path expression against the response content and assert that the result is an array.StatusResultMatchers.isBadGateway()
Assert the response status code isHttpStatus.BAD_GATEWAY
(502).StatusResultMatchers.isBadRequest()
Assert the response status code isHttpStatus.BAD_REQUEST
(400).StatusResultMatchers.isBandwidthLimitExceeded()
Assert the response status code isHttpStatus.BANDWIDTH_LIMIT_EXCEEDED
(509).JsonPathResultMatchers.isBoolean()
Evaluate the JSON path expression against the response content and assert that the result is aBoolean
.StatusResultMatchers.isCheckpoint()
Deprecated.in favor ofStatusResultMatchers.isEarlyHints()
StatusResultMatchers.isConflict()
Assert the response status code isHttpStatus.CONFLICT
(409).StatusResultMatchers.isContinue()
Assert the response status code isHttpStatus.CONTINUE
(100).StatusResultMatchers.isCreated()
Assert the response status code isHttpStatus.CREATED
(201).StatusResultMatchers.isDestinationLocked()
Deprecated.matching the deprecation ofHttpStatus.DESTINATION_LOCKED
StatusResultMatchers.isEarlyHints()
Assert the response status code isHttpStatus.EARLY_HINTS
(103).JsonPathResultMatchers.isEmpty()
Evaluate the JSON path expression against the response content and assert that an empty value exists at the given path.StatusResultMatchers.isExpectationFailed()
Assert the response status code isHttpStatus.EXPECTATION_FAILED
(417).StatusResultMatchers.isFailedDependency()
Assert the response status code isHttpStatus.FAILED_DEPENDENCY
(424).StatusResultMatchers.isForbidden()
Assert the response status code isHttpStatus.FORBIDDEN
(403).StatusResultMatchers.isFound()
Assert the response status code isHttpStatus.FOUND
(302).StatusResultMatchers.isGatewayTimeout()
Assert the response status code isHttpStatus.GATEWAY_TIMEOUT
(504).StatusResultMatchers.isGone()
Assert the response status code isHttpStatus.GONE
(410).StatusResultMatchers.isHttpVersionNotSupported()
Assert the response status code isHttpStatus.HTTP_VERSION_NOT_SUPPORTED
(505).StatusResultMatchers.isIAmATeapot()
Assert the response status code isHttpStatus.I_AM_A_TEAPOT
(418).StatusResultMatchers.isImUsed()
Assert the response status code isHttpStatus.IM_USED
(226).StatusResultMatchers.isInsufficientSpaceOnResource()
Deprecated.matching the deprecation ofHttpStatus.INSUFFICIENT_SPACE_ON_RESOURCE
StatusResultMatchers.isInsufficientStorage()
Assert the response status code isHttpStatus.INSUFFICIENT_STORAGE
(507).StatusResultMatchers.isInternalServerError()
Assert the response status code isHttpStatus.INTERNAL_SERVER_ERROR
(500).StatusResultMatchers.isLengthRequired()
Assert the response status code isHttpStatus.LENGTH_REQUIRED
(411).StatusResultMatchers.isLocked()
Assert the response status code isHttpStatus.LOCKED
(423).StatusResultMatchers.isLoopDetected()
Assert the response status code isHttpStatus.LOOP_DETECTED
(508).JsonPathResultMatchers.isMap()
Evaluate the JSON path expression against the response content and assert that the result is aMap
.StatusResultMatchers.isMethodFailure()
Deprecated.matching the deprecation ofHttpStatus.METHOD_FAILURE
StatusResultMatchers.isMethodNotAllowed()
Assert the response status code isHttpStatus.METHOD_NOT_ALLOWED
(405).StatusResultMatchers.isMovedPermanently()
Assert the response status code isHttpStatus.MOVED_PERMANENTLY
(301).StatusResultMatchers.isMovedTemporarily()
Deprecated.in favor ofStatusResultMatchers.isFound()
StatusResultMatchers.isMultipleChoices()
Assert the response status code isHttpStatus.MULTIPLE_CHOICES
(300).StatusResultMatchers.isMultiStatus()
Assert the response status code isHttpStatus.MULTI_STATUS
(207).StatusResultMatchers.isNetworkAuthenticationRequired()
Assert the response status code isHttpStatus.NETWORK_AUTHENTICATION_REQUIRED
(511).StatusResultMatchers.isNoContent()
Assert the response status code isHttpStatus.NO_CONTENT
(204).StatusResultMatchers.isNonAuthoritativeInformation()
Assert the response status code isHttpStatus.NON_AUTHORITATIVE_INFORMATION
(203).StatusResultMatchers.isNotAcceptable()
Assert the response status code isHttpStatus.NOT_ACCEPTABLE
(406).JsonPathResultMatchers.isNotEmpty()
Evaluate the JSON path expression against the response content and assert that a non-empty value exists at the given path.StatusResultMatchers.isNotExtended()
Assert the response status code isHttpStatus.NOT_EXTENDED
(510).StatusResultMatchers.isNotFound()
Assert the response status code isHttpStatus.NOT_FOUND
(404).StatusResultMatchers.isNotImplemented()
Assert the response status code isHttpStatus.NOT_IMPLEMENTED
(501).StatusResultMatchers.isNotModified()
Assert the response status code isHttpStatus.NOT_MODIFIED
(304).JsonPathResultMatchers.isNumber()
Evaluate the JSON path expression against the response content and assert that the result is aNumber
.StatusResultMatchers.isOk()
Assert the response status code isHttpStatus.OK
(200).StatusResultMatchers.isPartialContent()
Assert the response status code isHttpStatus.PARTIAL_CONTENT
(206).StatusResultMatchers.isPayloadTooLarge()
Assert the response status code isHttpStatus.PAYLOAD_TOO_LARGE
(413).StatusResultMatchers.isPaymentRequired()
Assert the response status code isHttpStatus.PAYMENT_REQUIRED
(402).StatusResultMatchers.isPermanentRedirect()
Assert the response status code isHttpStatus.PERMANENT_REDIRECT
(308).StatusResultMatchers.isPreconditionFailed()
Assert the response status code isHttpStatus.PRECONDITION_FAILED
(412).StatusResultMatchers.isPreconditionRequired()
Assert the response status code isHttpStatus.PRECONDITION_REQUIRED
(428).StatusResultMatchers.isProcessing()
Assert the response status code isHttpStatus.PROCESSING
(102).StatusResultMatchers.isProxyAuthenticationRequired()
Assert the response status code isHttpStatus.PROXY_AUTHENTICATION_REQUIRED
(407).StatusResultMatchers.isRequestedRangeNotSatisfiable()
Assert the response status code isHttpStatus.REQUESTED_RANGE_NOT_SATISFIABLE
(416).StatusResultMatchers.isRequestEntityTooLarge()
Deprecated.matching the deprecation ofHttpStatus.REQUEST_ENTITY_TOO_LARGE
StatusResultMatchers.isRequestHeaderFieldsTooLarge()
Assert the response status code isHttpStatus.REQUEST_HEADER_FIELDS_TOO_LARGE
(431).StatusResultMatchers.isRequestTimeout()
Assert the response status code isHttpStatus.REQUEST_TIMEOUT
(408).StatusResultMatchers.isRequestUriTooLong()
Deprecated.matching the deprecation ofHttpStatus.REQUEST_URI_TOO_LONG
StatusResultMatchers.isResetContent()
Assert the response status code isHttpStatus.RESET_CONTENT
(205).StatusResultMatchers.isSeeOther()
Assert the response status code isHttpStatus.SEE_OTHER
(303).StatusResultMatchers.isServiceUnavailable()
Assert the response status code isHttpStatus.SERVICE_UNAVAILABLE
(503).JsonPathResultMatchers.isString()
Evaluate the JSON path expression against the response content and assert that the result is aString
.StatusResultMatchers.isSwitchingProtocols()
Assert the response status code isHttpStatus.SWITCHING_PROTOCOLS
(101).StatusResultMatchers.isTemporaryRedirect()
Assert the response status code isHttpStatus.TEMPORARY_REDIRECT
(307).StatusResultMatchers.isTooEarly()
Assert the response status code isHttpStatus.TOO_EARLY
(425).StatusResultMatchers.isTooManyRequests()
Assert the response status code isHttpStatus.TOO_MANY_REQUESTS
(429).StatusResultMatchers.isUnauthorized()
Assert the response status code isHttpStatus.UNAUTHORIZED
(401).StatusResultMatchers.isUnavailableForLegalReasons()
Assert the response status code isHttpStatus.UNAVAILABLE_FOR_LEGAL_REASONS
(451).StatusResultMatchers.isUnprocessableEntity()
Assert the response status code isHttpStatus.UNPROCESSABLE_ENTITY
(422).StatusResultMatchers.isUnsupportedMediaType()
Assert the response status code isHttpStatus.UNSUPPORTED_MEDIA_TYPE
(415).StatusResultMatchers.isUpgradeRequired()
Assert the response status code isHttpStatus.UPGRADE_REQUIRED
(426).StatusResultMatchers.isUriTooLong()
Assert the response status code isHttpStatus.REQUEST_URI_TOO_LONG
(414).StatusResultMatchers.isUseProxy()
Deprecated.matching the deprecation ofHttpStatus.USE_PROXY
StatusResultMatchers.isVariantAlsoNegotiates()
Assert the response status code isHttpStatus.VARIANT_ALSO_NEGOTIATES
(506).Parse the expected and actual strings as JSON and assert the two are "similar" - i.e.Deprecated.ContentResultMatchers.json
(String jsonContent, JsonComparator comparator) Parse the response content and the given string as JSON and assert the two using the givenJsonComparator
.ContentResultMatchers.json
(String jsonContent, JsonCompareMode compareMode) Parse the response content and the given string as JSON and assert the two using the given mode.static <T> ResultMatcher
static <T> ResultMatcher
Assert the primary value of the named response header as along
.Assert a cookie's maxAge.Assert a cookie's maxAge with a HamcrestMatcher
.Assert the controller method used to process the request.HandlerResultMatchers.methodCall
(Object obj) Assert the controller method used to process the request.HandlerResultMatchers.methodName
(String name) Assert the name of the controller method used to process the request.HandlerResultMatchers.methodName
(Matcher<? super String> matcher) Assert the name of the controller method used to process the request using the given HamcrestMatcher
.Assert the selected view name.Assert the selected view name with the given HamcrestMatcher
.XpathResultMatchers.nodeCount
(int expectedCount) Evaluate the XPath and assert the number of nodes found.Evaluate the XPath and assert the number of nodes found with the given HamcrestMatcher
.Evaluate the XPath and assert theDouble
value found.CookieResultMatchers.partitioned
(String name, boolean partitioned) Assert whether the cookie is partitioned.Assert a cookie's path.Assert a cookie's path with a HamcrestMatcher
.Assert the Servlet response error message.Assert the Servlet response error message with the given HamcrestMatcher
.static ResultMatcher
MockMvcResultMatchers.redirectedUrl
(String expectedUrl) Asserts the request was redirected to the given URL.static ResultMatcher
MockMvcResultMatchers.redirectedUrlPattern
(String urlPattern) Asserts the request was redirected to the given URL.static ResultMatcher
MockMvcResultMatchers.redirectedUrlTemplate
(String urlTemplate, Object... uriVars) Asserts the request was redirected to the given URL template.Assert a cookie's SameSite attribute.Assert a cookie's SameSite attribute with a HamcrestMatcher
.Assert whether the cookie must be sent over a secure protocol or not.RequestResultMatchers.sessionAttribute
(String name, Object value) Assert a session attribute value.<T> ResultMatcher
RequestResultMatchers.sessionAttribute
(String name, Matcher<? super T> matcher) Assert a session attribute value with the given HamcrestMatcher
.RequestResultMatchers.sessionAttributeDoesNotExist
(String... names) Assert the given session attributes do not exist.ModelResultMatchers.size
(int size) Assert the number of model attributes.Assert the response body content as a String.Assert the response body content with a HamcrestMatcher
.Assert the primary value of the response header as a String value.Assert the primary value of the response header with the given Hamcrest StringMatcher
.Apply the XPath and assert theString
value found.HeaderResultMatchers.stringValues
(String name, String... values) Assert the values of the response header as String values.HeaderResultMatchers.stringValues
(String name, Matcher<? super Iterable<String>> matcher) Assert the values of the response header with the given Hamcrest IterableMatcher
.Assert a cookie value.Assert a cookie value with the given HamcrestMatcher
.Evaluate the JSON path expression against the response content and assert that the result is equal to the supplied value.<T> ResultMatcher
Evaluate the JSON path expression against the response content and assert the resulting value with the given HamcrestMatcher
.<T> ResultMatcher
An overloaded variant ofJsonPathResultMatchers.value(Matcher)
that also accepts a target type for the resulting value that the matcher can work reliably against.Assert a cookie's version.Assert a cookie's version with a HamcrestMatcher
.Parse the response content and the given string as XML and assert the two are "similar" - i.e. -
Uses of ResultMatcher in org.springframework.test.web.servlet.setup
Modifier and TypeMethodDescriptionfinal <T extends B>
TAbstractMockMvcBuilder.alwaysExpect
(ResultMatcher resultMatcher) <T extends B>
TConfigurableMockMvcBuilder.alwaysExpect
(ResultMatcher resultMatcher) Define a global expectation that should always be applied to every response.
ResultActions.andExpectAll(ResultMatcher...)