public static interface WebTestClient.Builder
WebClient
used to test with,
internally delegating to a
WebClient.Builder
.Modifier and Type | Method and Description |
---|---|
WebTestClient.Builder |
apply(WebTestClientConfigurer configurer)
Apply the given configurer to this builder instance.
|
WebTestClient.Builder |
baseUrl(String baseUrl)
Configure a base URI as described in
WebClient.create(String) . |
WebTestClient |
build()
Build the
WebTestClient instance. |
WebTestClient.Builder |
codecs(Consumer<ClientCodecConfigurer> configurer)
|
WebTestClient.Builder |
defaultCookie(String cookieName,
String... cookieValues)
Add the given header to all requests that haven't added it.
|
WebTestClient.Builder |
defaultCookies(Consumer<MultiValueMap<String,String>> cookiesConsumer)
Manipulate the default cookies with the given consumer.
|
WebTestClient.Builder |
defaultHeader(String headerName,
String... headerValues)
Add the given header to all requests that haven't added it.
|
WebTestClient.Builder |
defaultHeaders(Consumer<HttpHeaders> headersConsumer)
Manipulate the default headers with the given consumer.
|
WebTestClient.Builder |
entityExchangeResultConsumer(Consumer<EntityExchangeResult<?>> consumer)
Configure an
EntityExchangeResult 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[]. |
WebTestClient.Builder |
exchangeStrategies(Consumer<ExchangeStrategies.Builder> configurer)
Deprecated.
as of 5.1.13 in favor of
codecs(Consumer) |
WebTestClient.Builder |
exchangeStrategies(ExchangeStrategies strategies)
Configure the
ExchangeStrategies to use. |
WebTestClient.Builder |
filter(ExchangeFilterFunction filter)
Add the given filter to the filter chain.
|
WebTestClient.Builder |
filters(Consumer<List<ExchangeFilterFunction>> filtersConsumer)
Manipulate the filters with the given consumer.
|
WebTestClient.Builder |
responseTimeout(Duration timeout)
Max amount of time to wait for responses.
|
WebTestClient.Builder |
uriBuilderFactory(UriBuilderFactory uriBuilderFactory)
Provide a pre-configured
UriBuilderFactory instance as an
alternative to and effectively overriding baseUrl(String) . |
WebTestClient.Builder baseUrl(String baseUrl)
WebClient.create(String)
.WebTestClient.Builder uriBuilderFactory(UriBuilderFactory uriBuilderFactory)
UriBuilderFactory
instance as an
alternative to and effectively overriding baseUrl(String)
.WebTestClient.Builder defaultHeader(String headerName, String... headerValues)
headerName
- the header nameheaderValues
- the header valuesWebTestClient.Builder defaultHeaders(Consumer<HttpHeaders> headersConsumer)
HttpHeaders
methods.headersConsumer
- a function that consumes the HttpHeaders
WebTestClient.Builder defaultCookie(String cookieName, String... cookieValues)
cookieName
- the cookie namecookieValues
- the cookie valuesWebTestClient.Builder defaultCookies(Consumer<MultiValueMap<String,String>> cookiesConsumer)
MultiValueMap
methods.cookiesConsumer
- a function that consumes the cookies mapWebTestClient.Builder filter(ExchangeFilterFunction filter)
filter
- the filter to be added to the chainWebTestClient.Builder filters(Consumer<List<ExchangeFilterFunction>> filtersConsumer)
filtersConsumer
- a function that consumes the filter listWebTestClient.Builder entityExchangeResultConsumer(Consumer<EntityExchangeResult<?>> consumer)
EntityExchangeResult
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, equivalent to each and
all of the below but registered 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 via reactor.test.StepVerifier
.
consumer
- the consumer to apply to entity responsesWebTestClient.Builder codecs(Consumer<ClientCodecConfigurer> configurer)
configurer
- the configurer to applyWebTestClient.Builder exchangeStrategies(ExchangeStrategies strategies)
ExchangeStrategies
to use.
For most cases, prefer using codecs(Consumer)
which allows
customizing the codecs in the ExchangeStrategies
rather than
replace them. That ensures multiple parties can contribute to codecs
configuration.
By default this is set to ExchangeStrategies.withDefaults()
.
strategies
- the strategies to use@Deprecated WebTestClient.Builder exchangeStrategies(Consumer<ExchangeStrategies.Builder> configurer)
codecs(Consumer)
exchangeStrategies(ExchangeStrategies)
. This method is
designed for use in scenarios where multiple parties wish to update
the ExchangeStrategies
.WebTestClient.Builder responseTimeout(Duration timeout)
By default 5 seconds.
timeout
- the response timeout valueWebTestClient.Builder apply(WebTestClientConfigurer configurer)
This can be useful for applying pre-packaged customizations.
configurer
- the configurer to applyWebTestClient build()
WebTestClient
instance.