Interface RestTestClient.ResponseSpec
- Enclosing interface:
RestTestClient
public static interface RestTestClient.ResponseSpec
Chained API for applying assertions to a response.
- Since:
- 7.0
- Author:
- Rob Worsnop, Rossen Stoyanchev
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
-
Method Summary
Modifier and TypeMethodDescriptionexpectAll
(RestTestClient.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 (for example, isEmpty, JSONPath, etc.).<B> RestTestClient.BodySpec
<B, ?> expectBody
(Class<B> bodyType) Consume and decode the response body to a single object of type<B>
and then apply assertions.<B> RestTestClient.BodySpec
<B, ?> expectBody
(ParameterizedTypeReference<B> bodyType) Alternative toexpectBody(Class)
that accepts information about a target type with generics.Assertions on the cookies of the response.Assertions on the headers of the response.Assertions on the response status.<T> EntityExchangeResult
<T> returnResult
(Class<T> elementClass) Exit the chained flow in order to consume the response body externally.<T> EntityExchangeResult
<T> returnResult
(ParameterizedTypeReference<T> elementTypeRef) Alternative toreturnResult(Class)
that accepts information about a target type with generics.
-
Method Details
-
expectAll
RestTestClient.ResponseSpec expectAll(RestTestClient.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.If a single
Error
orRuntimeException
is thrown, it will be rethrown.If multiple exceptions are thrown, this method will throw an
AssertionError
whose 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
SoftAssertions
support in AssertJ and theassertAll()
support in JUnit Jupiter.Example
restTestClient.get().uri("/hello").exchange() .expectAll( responseSpec -> responseSpec.expectStatus().isOk(), responseSpec -> responseSpec.expectBody(String.class).isEqualTo("Hello, World!") );
- Parameters:
consumers
- the list ofResponseSpec
consumers
-
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.- Parameters:
bodyType
- the expected body type
-
expectBody
Alternative toexpectBody(Class)
that accepts information about a target type with generics. -
expectBody
RestTestClient.BodyContentSpec expectBody()Consume and decode the response body tobyte[]
and then apply assertions on the raw content (for example, isEmpty, JSONPath, etc.). -
returnResult
Exit the chained flow in order to consume the response body externally. -
returnResult
Alternative toreturnResult(Class)
that accepts information about a target type with generics.
-