Interface RestTestClient.Builder<B extends RestTestClient.Builder<B>>
- Type Parameters:
B
- the type of builder
- All Known Subinterfaces:
RestTestClient.MockMvcSetupBuilder<S,
,M> RestTestClient.RouterFunctionSetupBuilder
,RestTestClient.StandaloneSetupBuilder
,RestTestClient.WebAppContextSetupBuilder
- Enclosing interface:
RestTestClient
public static interface RestTestClient.Builder<B extends RestTestClient.Builder<B>>
Steps to customize the underlying
RestClient
via RestClient.Builder
.- Since:
- 7.0
- Author:
- Rob Worsnop, Rossen Stoyanchev
-
Method Summary
Modifier and TypeMethodDescription<T extends B>
TapiVersionInserter
(ApiVersionInserter apiVersionInserter) Configure anApiVersionInserter
to abstract how an API version specified viaRestTestClient.RequestHeadersSpec.apiVersion(Object)
is inserted into the request.<T extends B>
TConfigure a base URI as described inRestClient.create(String)
.build()
Build theRestTestClient
instance.<T extends B>
TConfigure the message converters to use for the request and response body.<T extends B>
TdefaultApiVersion
(Object version) Global option to specify an API version to add to every request, if not already set.<T extends B>
TdefaultCookie
(String cookieName, String... cookieValues) Add the given cookie to all requests that have not already added it.<T extends B>
TdefaultCookies
(Consumer<MultiValueMap<String, String>> cookiesConsumer) Manipulate the default cookies with the given consumer.<T extends B>
TdefaultHeader
(String headerName, String... headerValues) Add the given header to all requests that have not added it.<T extends B>
TdefaultHeaders
(Consumer<HttpHeaders> headersConsumer) Manipulate the default headers with the given consumer.<T extends B>
TentityExchangeResultConsumer
(Consumer<EntityExchangeResult<?>> consumer) Configure anEntityExchangeResult
callback that is invoked every time after a response is fully decoded to a single entity, to a List of entities, or to a byte[].<T extends B>
TrequestInterceptor
(ClientHttpRequestInterceptor interceptor) Add the given request interceptor to the end of the interceptor chain.<T extends B>
TrequestInterceptors
(Consumer<List<ClientHttpRequestInterceptor>> interceptorsConsumer) Manipulate the interceptors with the given consumer.<T extends B>
TuriBuilderFactory
(UriBuilderFactory uriBuilderFactory) Provide a pre-configuredUriBuilderFactory
instance as an alternative to and effectively overridingbaseUrl(String)
.
-
Method Details
-
baseUrl
Configure a base URI as described inRestClient.create(String)
.- Returns:
- this builder
-
uriBuilderFactory
Provide a pre-configuredUriBuilderFactory
instance as an alternative to and effectively overridingbaseUrl(String)
.- Returns:
- this builder
-
defaultHeader
-
defaultHeaders
Manipulate the default headers with the given consumer. The headers provided to the consumer are "live", so that the consumer can be used to overwrite existing header values, remove values, or use any of the otherHttpHeaders
methods.- Parameters:
headersConsumer
- a function that consumes theHttpHeaders
- Returns:
- this builder
-
defaultCookie
-
defaultCookies
Manipulate the default cookies with the given consumer. The map provided to the consumer is "live", so that the consumer can be used to overwrite existing header values, remove values, or use any of the otherMultiValueMap
methods.- Parameters:
cookiesConsumer
- a function that consumes the cookies map- Returns:
- this builder
-
defaultApiVersion
-
apiVersionInserter
Configure anApiVersionInserter
to abstract how an API version specified viaRestTestClient.RequestHeadersSpec.apiVersion(Object)
is inserted into the request.- Parameters:
apiVersionInserter
- the inserter to use
-
requestInterceptor
Add the given request interceptor to the end of the interceptor chain.- Parameters:
interceptor
- the interceptor to be added to the chain
-
requestInterceptors
<T extends B> T requestInterceptors(Consumer<List<ClientHttpRequestInterceptor>> interceptorsConsumer) Manipulate the interceptors with the given consumer. The list provided to the consumer is "live", so that the consumer can be used to remove interceptors, change ordering, etc.- Parameters:
interceptorsConsumer
- a function that consumes the interceptors list- Returns:
- this builder
-
configureMessageConverters
<T extends B> T configureMessageConverters(Consumer<HttpMessageConverters.ClientBuilder> configurer) Configure the message converters to use for the request and response body.- Parameters:
configurer
- the configurer to apply on an emptyHttpMessageConverters.ClientBuilder
.- Returns:
- this builder
-
entityExchangeResultConsumer
Configure anEntityExchangeResult
callback that is invoked every time after a response is fully decoded to a single entity, to a List of entities, or to a byte[]. In effect, this is equivalent to each of the below but registered only once, globally.client.get().uri("/accounts/1") .exchange() .expectBody(Person.class).consumeWith(exchangeResult -> ... )); client.get().uri("/accounts") .exchange() .expectBodyList(Person.class).consumeWith(exchangeResult -> ... )); client.get().uri("/accounts/1") .exchange() .expectBody().consumeWith(exchangeResult -> ... ));
Note that the configured consumer does not apply to responses decoded to
Flux<T>
which can be consumed outside the workflow of the test client, for example viareactor.test.StepVerifier
.- Parameters:
consumer
- the consumer to apply to entity responses- Returns:
- the builder
-
build
RestTestClient build()Build theRestTestClient
instance.
-