接口 WebTestClient.ResponseSpec
- 封闭接口:
- WebTestClient
public static interface WebTestClient.ResponseSpec
Chained API for applying assertions to a response.
方法概要
所有方法 实例方法 抽象方法 修饰符和类型 方法 说明 WebTestClient.BodyContentSpec
expectBody()
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(Class<B> bodyType)
Consume and decode the response body to a single object of type<B>
and then apply assertions.<B> WebTestClient.BodySpec<B,?>
expectBody(ParameterizedTypeReference<B> bodyType)
Alternative toexpectBody(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.<E> WebTestClient.ListBodySpec<E>
expectBodyList(ParameterizedTypeReference<E> elementType)
Alternative toexpectBodyList(Class)
that accepts information about a target type with generics.HeaderAssertions
expectHeader()
Assertions on the headers of the response.StatusAssertions
expectStatus()
Assertions on the response status.<T> FluxExchangeResult<T>
returnResult(Class<T> elementClass)
Exit the chained API and consume the response body externally.<T> FluxExchangeResult<T>
returnResult(ParameterizedTypeReference<T> elementTypeRef)
Alternative toreturnResult(Class)
that accepts information about a target type with generics.
方法详细资料
expectStatus
StatusAssertions expectStatus()
Assertions on the response status.
expectHeader
HeaderAssertions expectHeader()
Assertions on the headers of the response.
expectBody
<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.- 参数:
bodyType
- the expected body type
expectBody
<B> WebTestClient.BodySpec<B,?> expectBody(ParameterizedTypeReference<B> bodyType)
Alternative toexpectBody(Class)
that accepts information about a target type with generics.
expectBodyList
<E> WebTestClient.ListBodySpec<E> expectBodyList(Class<E> elementType)
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(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
<T> FluxExchangeResult<T> returnResult(Class<T> elementClass)
Exit the chained API and consume the response body externally. This is useful for testing infinite streams (e.g. SSE) where you need to to assert decoded objects as they come and then cancel at some point when test objectives are met. Consider usingStepVerifier
from "reactor-test" to assert theFlux<T>
stream of decoded objects.Note: Do not use this option for cases where there is no content (e.g. 204, 4xx) or you're not interested in the content. For such cases you can use
expectBody().isEmpty()
orexpectBody(Void.class)
which ensures that resources are released regardless of whether the response has content or not.
returnResult
<T> FluxExchangeResult<T> returnResult(ParameterizedTypeReference<T> elementTypeRef)
Alternative toreturnResult(Class)
that accepts information about a target type with generics.