接口的使用
cn.taketoday.test.web.servlet.ResultMatcher
使用ResultMatcher的程序包
程序包
说明
Contains server-side support for testing Web MVC applications.
Support for testing Web MVC applications via
WebTestClient
with MockMvc for server request
handling.Contains built-in
ResultMatcher and ResultHandler implementations.Contains built-in
MockMvcBuilder implementations.-
cn.taketoday.test.web.servlet中ResultMatcher的使用
类型参数类型为ResultMatcher的cn.taketoday.test.web.servlet中的字段修饰符和类型方法说明static ResultMatcherResultMatcher.matchAll(ResultMatcher... matchers) Static method for matching with an array of result matchers.修饰符和类型方法说明ResultActions.andExpect(ResultMatcher matcher) Perform an expectation.default ResultActionsResultActions.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 ResultMatcherResultMatcher.matchAll(ResultMatcher... matchers) Static method for matching with an array of result matchers.类型变量类型为ResultMatcher的cn.taketoday.test.web.servlet中的方法参数修饰符和类型方法说明protected final MockMvcMockMvcBuilderSupport.createMockMvc(jakarta.servlet.Filter[] filters, MockServletConfig servletConfig, cn.taketoday.web.servlet.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 theMockMvcinstance and configures that instance with the supplieddefaultResponseCharacterEncoding.protected final MockMvcMockMvcBuilderSupport.createMockMvc(jakarta.servlet.Filter[] filters, MockServletConfig servletConfig, cn.taketoday.web.servlet.WebApplicationContext webAppContext, RequestBuilder defaultRequestBuilder, List<ResultMatcher> globalResultMatchers, List<ResultHandler> globalResultHandlers, List<DispatcherServletCustomizer> dispatcherServletCustomizers) (专用程序包) voidMockMvc.setGlobalResultMatchers(List<ResultMatcher> resultMatchers) Expectations to assert after every performed request. -
cn.taketoday.test.web.servlet.client中ResultMatcher的使用
修饰符和类型方法说明<T extends B>
TAbstractMockMvcServerSpec.alwaysExpect(ResultMatcher resultMatcher) <T extends B>
TMockMvcWebTestClient.MockMvcServerSpec.alwaysExpect(ResultMatcher resultMatcher) Define a global expectation that should always be applied to every response. -
cn.taketoday.test.web.servlet.result中ResultMatcher的使用
修饰符和类型方法说明RequestResultMatchers.asyncNotStarted()Assert that asynchronous processing was not started.RequestResultMatchers.asyncResult(Object expectedResult) Assert the result from asynchronous processing.<T> ResultMatcherRequestResultMatchers.asyncResult(org.hamcrest.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 returningCallableorDeferredResult.Assert a flash attribute's value.<T> ResultMatcherAssert a flash attribute's value with the given HamcrestMatcher.Assert a model attribute value.<T> ResultMatcherAssert a model attribute value with the given HamcrestMatcher.Assert a request attribute value.<T> ResultMatcherAssert 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, org.hamcrest.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 theBooleanvalue found.ContentResultMatchers.bytes(byte[] expectedContent) Assert the response body content as a byte array.ContentResultMatchers.contentType(cn.taketoday.http.MediaType contentType) Assert the ServletResponse content type after parsing it as a MediaType.ContentResultMatchers.contentType(String contentType) Assert the ServletResponse content type.ContentResultMatchers.contentTypeCompatibleWith(cn.taketoday.http.MediaType contentType) Assert the ServletResponse content type is compatible with the given content type as defined byMediaType.isCompatibleWith(MediaType).ContentResultMatchers.contentTypeCompatibleWith(String 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 suppliedcontentand assert that a value, includingnullvalues, 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 ResultMatcherMockMvcResultMatchers.forwardedUrl(String expectedUrl) Asserts the request was forwarded to the given URL.static ResultMatcherMockMvcResultMatchers.forwardedUrlPattern(String urlPattern) Asserts the request was forwarded to the given URL.static ResultMatcherMockMvcResultMatchers.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()Assert the response status code isHttpStatus.CHECKPOINT(103).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()已过时。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()已过时。matching the deprecation ofHttpStatus.INSUFFICIENT_SPACE_ON_RESOURCEStatusResultMatchers.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()已过时。matching the deprecation ofHttpStatus.METHOD_FAILUREStatusResultMatchers.isMethodNotAllowed()Assert the response status code isHttpStatus.METHOD_NOT_ALLOWED(405).StatusResultMatchers.isMovedPermanently()Assert the response status code isHttpStatus.MOVED_PERMANENTLY(301).StatusResultMatchers.isMovedTemporarily()已过时。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()已过时。matching the deprecation ofHttpStatus.REQUEST_ENTITY_TOO_LARGEStatusResultMatchers.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()已过时。matching the deprecation ofHttpStatus.REQUEST_URI_TOO_LONGStatusResultMatchers.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()已过时。matching the deprecation ofHttpStatus.USE_PROXYStatusResultMatchers.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. they contain the same attribute-value pairs regardless of formatting with a lenient checking (extensible, and non-strict array ordering).Parse the response content and the given string as JSON and assert the two are "similar" - i.e. they contain the same attribute-value pairs regardless of formatting.static <T> ResultMatcherEvaluate the given JsonPath expression against the response body and assert the resulting value with the given HamcrestMatcher.static <T> ResultMatcherMockMvcResultMatchers.jsonPath(String expression, org.hamcrest.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.Assert the primary value of the named response header as along.private ResultMatcherStatusResultMatchers.matcher(cn.taketoday.http.HttpStatusCode status) Match the expected response status to that of the HttpServletResponse.Assert a cookie's maxAge.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(org.hamcrest.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.Parse the response content asNodeand apply the given HamcrestMatcher.Evaluate the XPath and assert theNodecontent found 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 theNodeListcontent found with the given HamcrestMatcher.Evaluate the XPath and assert theDoublevalue found.Evaluate the XPath and assert theDoublevalue found with the given HamcrestMatcher.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 ResultMatcherMockMvcResultMatchers.redirectedUrl(String expectedUrl) Asserts the request was redirected to the given URL.static ResultMatcherMockMvcResultMatchers.redirectedUrlPattern(String urlPattern) Asserts the request was redirected to the given URL.static ResultMatcherMockMvcResultMatchers.redirectedUrlTemplate(String urlTemplate, Object... uriVars) Asserts the request was redirected to the given URL template.Assert the given RequestContext.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> ResultMatcherRequestResultMatchers.sessionAttribute(String name, org.hamcrest.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.Parse the response content asDOMSourceand apply the given HamcrestMatcher.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 theStringvalue found.Apply the XPath and assert theStringvalue found with the given HamcrestMatcher.HeaderResultMatchers.stringValues(String name, String... values) Assert the values of the response header as String values.HeaderResultMatchers.stringValues(String name, org.hamcrest.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> ResultMatcherJsonPathResultMatchers.value(org.hamcrest.Matcher<? super T> matcher) Evaluate the JSON path expression against the response content and assert the resulting value with the given HamcrestMatcher.<T> ResultMatcherAn overloaded variant ofJsonPathResultMatchers.value(Matcher)that also accepts a target type for the resulting value that the matcher can work reliably against.Parse the response content and the given string as XML and assert the two are "similar" - i.e. they contain the same elements and attributes regardless of order. -
cn.taketoday.test.web.servlet.setup中ResultMatcher的使用
类型参数类型为ResultMatcher的cn.taketoday.test.web.servlet.setup中的字段修饰符和类型方法说明final <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.
HttpStatus.DESTINATION_LOCKED