Interface WebTestClient.Builder
- Enclosing interface:
- WebTestClient
public static interface WebTestClient.Builder
Steps for customizing the 
WebClient used to test with,
 internally delegating to a
 WebClient.Builder.- 
Method SummaryModifier and TypeMethodDescriptionapply(WebTestClientConfigurer configurer) Apply the given configurer to this builder instance.Configure a base URI as described inWebClient.create(String).build()Build theWebTestClientinstance.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 anEntityExchangeResultcallback 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 theExchangeStrategiesto 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-configuredUriBuilderFactoryinstance as an alternative to and effectively overridingbaseUrl(String).
- 
Method Details- 
baseUrlConfigure a base URI as described inWebClient.create(String).
- 
uriBuilderFactoryProvide a pre-configuredUriBuilderFactoryinstance as an alternative to and effectively overridingbaseUrl(String).
- 
defaultHeaderAdd the given header to all requests that haven't added it.- Parameters:
- headerName- the header name
- headerValues- the header values
 
- 
defaultHeadersManipulate 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 otherHttpHeadersmethods.- Parameters:
- headersConsumer- a function that consumes the- HttpHeaders
- Returns:
- this builder
 
- 
defaultCookieAdd the given header to all requests that haven't added it.- Parameters:
- cookieName- the cookie name
- cookieValues- the cookie values
 
- 
defaultCookiesManipulate 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 otherMultiValueMapmethods.- Parameters:
- cookiesConsumer- a function that consumes the cookies map
- Returns:
- this builder
 
- 
filterAdd the given filter to the filter chain.- Parameters:
- filter- the filter to be added to the chain
 
- 
filtersManipulate 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
 
- 
entityExchangeResultConsumerConfigure anEntityExchangeResultcallback 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
 
- 
exchangeStrategiesConfigure theExchangeStrategiesto use.For most cases, prefer using codecs(Consumer)which allows customizing the codecs in theExchangeStrategiesrather 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.
- 
responseTimeoutMax amount of time to wait for responses.By default 5 seconds. - Parameters:
- timeout- the response timeout value
 
- 
applyApply the given configurer to this builder instance.This can be useful for applying pre-packaged customizations. - Parameters:
- configurer- the configurer to apply
 
- 
buildWebTestClient build()Build theWebTestClientinstance.
 
- 
codecs(Consumer)