Interface WebTestClient.Builder
- Enclosing interface:
- WebTestClient
WebClient
used to test with,
internally delegating to a
WebClient.Builder
.-
Method Summary
Modifier and TypeMethodDescriptionapply
(WebTestClientConfigurer configurer) Apply the given configurer to this builder instance.Configure a base URI as described inWebClient.create(String)
.build()
Build theWebTestClient
instance.clientConnector
(ClientHttpConnector connector) Set theClientHttpConnector
to use.codecs
(Consumer<ClientCodecConfigurer> configurer) defaultCookie
(String cookieName, String... cookieValues) Add the given header to all requests that haven't added it.defaultCookies
(Consumer<MultiValueMap<String, String>> cookiesConsumer) Manipulate the default cookies with the given consumer.defaultHeader
(String headerName, String... headerValues) Add the given header to all requests that haven't added it.defaultHeaders
(Consumer<HttpHeaders> headersConsumer) Manipulate the default headers with the given consumer.entityExchangeResultConsumer
(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[].exchangeStrategies
(Consumer<ExchangeStrategies.Builder> configurer) Deprecated.exchangeStrategies
(ExchangeStrategies strategies) Configure theExchangeStrategies
to use.filter
(ExchangeFilterFunction filter) Add the given filter to the filter chain.filters
(Consumer<List<ExchangeFilterFunction>> filtersConsumer) Manipulate the filters with the given consumer.responseTimeout
(Duration timeout) Max amount of time to wait for responses.uriBuilderFactory
(UriBuilderFactory uriBuilderFactory) Provide a pre-configuredUriBuilderFactory
instance as an alternative to and effectively overridingbaseUrl(String)
.
-
Method Details
-
baseUrl
Configure a base URI as described inWebClient.create(String)
. -
uriBuilderFactory
Provide a pre-configuredUriBuilderFactory
instance as an alternative to and effectively overridingbaseUrl(String)
. -
defaultHeader
Add the given header to all requests that haven't added it.- Parameters:
headerName
- the header nameheaderValues
- the header values
-
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
Add the given header to all requests that haven't added it.- Parameters:
cookieName
- the cookie namecookieValues
- the cookie values
-
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
-
filter
Add the given filter to the filter chain.- Parameters:
filter
- the filter to be added to the chain
-
filters
Manipulate the filters with the given consumer. The list provided to the consumer is "live", so that the consumer can be used to remove filters, change ordering, etc.- Parameters:
filtersConsumer
- a function that consumes the filter list- 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, 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 viareactor.test.StepVerifier
.- Parameters:
consumer
- the consumer to apply to entity responses- Returns:
- the builder
- Since:
- 5.3.5
-
codecs
- Parameters:
configurer
- the configurer to apply- Since:
- 5.1.13
-
exchangeStrategies
Configure theExchangeStrategies
to use.For most cases, prefer using
codecs(Consumer)
which allows customizing the codecs in theExchangeStrategies
rather than replace them. That ensures multiple parties can contribute to codecs configuration.By default this is set to
ExchangeStrategies.withDefaults()
.- Parameters:
strategies
- the strategies to use
-
exchangeStrategies
@Deprecated WebTestClient.Builder exchangeStrategies(Consumer<ExchangeStrategies.Builder> configurer) Deprecated.as of 5.1.13 in favor ofcodecs(Consumer)
Customize the strategies configured viaexchangeStrategies(ExchangeStrategies)
. This method is designed for use in scenarios where multiple parties wish to update theExchangeStrategies
. -
responseTimeout
Max amount of time to wait for responses.By default 5 seconds.
- Parameters:
timeout
- the response timeout value
-
clientConnector
Set theClientHttpConnector
to use.By default, this is initialized and set internally. However, the connector may also be prepared externally and passed via
WebTestClient.bindToServer(ClientHttpConnector)
such as forMockMvcWebTestClient
tests, and in that case you can use this fromWebTestClient.mutateWith(WebTestClientConfigurer)
to replace it.- Parameters:
connector
- the connector to use- Since:
- 6.1
-
apply
Apply the given configurer to this builder instance.This can be useful for applying pre-packaged customizations.
- Parameters:
configurer
- the configurer to apply
-
build
WebTestClient build()Build theWebTestClient
instance.
-
codecs(Consumer)