接口 WebTestClient.ResponseSpec
- 封闭接口:
- WebTestClient
public static interface WebTestClient.ResponseSpec
Chained API for applying assertions to a response.
-
嵌套类概要
嵌套类修饰符和类型接口说明static interface -
方法概要
修饰符和类型方法说明expectAll(WebTestClient.ResponseSpec.ResponseSpecConsumer... consumers) Apply multiple assertions to a response with the given consumers, with the guarantee that all assertions will be applied even if one or more assertions fails with an exception.Consume and decode the response body tobyte[]and then apply assertions on the raw content (e.g. isEmpty, JSONPath, etc.)<B> WebTestClient.BodySpec<B,?> expectBody(cn.taketoday.core.ParameterizedTypeReference<B> bodyType) Alternative toexpectBody(Class)that accepts information about a target type with generics.<B> WebTestClient.BodySpec<B,?> expectBody(Class<B> bodyType) Consume and decode the response body to a single object of type<B>and then apply assertions.<E> WebTestClient.ListBodySpec<E>expectBodyList(cn.taketoday.core.ParameterizedTypeReference<E> elementType) Alternative toexpectBodyList(Class)that accepts information about a target type with generics.<E> WebTestClient.ListBodySpec<E>expectBodyList(Class<E> elementType) Consume and decode the response body toList<E>and then apply List-specific assertions.Assertions on the cookies of the response.Assertions on the headers of the response.Assertions on the response status.<T> FluxExchangeResult<T>returnResult(cn.taketoday.core.ParameterizedTypeReference<T> elementTypeRef) Alternative toreturnResult(Class)that accepts information about a target type with generics.<T> FluxExchangeResult<T>returnResult(Class<T> elementClass) Exit the chained flow in order to consume the response body externally, e.g. viaStepVerifier.
-
方法详细资料
-
expectAll
Apply multiple assertions to a response with the given consumers, with the guarantee that all assertions will be applied even if one or more assertions fails with an exception.If a single
ErrororRuntimeExceptionis thrown, it will be rethrown.If multiple exceptions are thrown, this method will throw an
AssertionErrorwhose error message is a summary of all the exceptions. In addition, each exception will be added as a suppressed exception to theAssertionError.This feature is similar to the
SoftAssertionssupport in AssertJ and theassertAll()support in JUnit Jupiter.Example
webTestClient.get().uri("/hello").exchange() .expectAll( responseSpec -> responseSpec.expectStatus().isOk(), responseSpec -> responseSpec.expectBody(String.class).isEqualTo("Hello, World!") );- 参数:
consumers- the list ofResponseSpecconsumers
-
expectStatus
StatusAssertions expectStatus()Assertions on the response status. -
expectHeader
HeaderAssertions expectHeader()Assertions on the headers of the response. -
expectCookie
CookieAssertions expectCookie()Assertions on the cookies of the response. -
expectBody
Consume and decode the response body to a single object of type<B>and then apply assertions.- 参数:
bodyType- the expected body type
-
expectBody
<B> WebTestClient.BodySpec<B,?> expectBody(cn.taketoday.core.ParameterizedTypeReference<B> bodyType) Alternative toexpectBody(Class)that accepts information about a target type with generics. -
expectBodyList
Consume and decode the response body toList<E>and then apply List-specific assertions.- 参数:
elementType- the expected List element type
-
expectBodyList
<E> WebTestClient.ListBodySpec<E> expectBodyList(cn.taketoday.core.ParameterizedTypeReference<E> elementType) Alternative toexpectBodyList(Class)that accepts information about a target type with generics. -
expectBody
WebTestClient.BodyContentSpec expectBody()Consume and decode the response body tobyte[]and then apply assertions on the raw content (e.g. isEmpty, JSONPath, etc.) -
returnResult
Exit the chained flow in order to consume the response body externally, e.g. viaStepVerifier.Note that when
Void.classis passed in, the response body is consumed and released. If no content is expected, then consider using.expectBody().isEmpty()instead which asserts that there is no content. -
returnResult
<T> FluxExchangeResult<T> returnResult(cn.taketoday.core.ParameterizedTypeReference<T> elementTypeRef) Alternative toreturnResult(Class)that accepts information about a target type with generics.
-