Interface WebTestClient.Builder
- Enclosing interface:
- WebTestClient
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.clientConnector(ClientHttpConnector connector) Set theClientHttpConnectorto 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 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(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
 
- 
responseTimeoutMax amount of time to wait for responses.By default 5 seconds. - Parameters:
- timeout- the response timeout value
 
- 
clientConnectorSet theClientHttpConnectorto 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 forMockMvcWebTestClienttests, and in that case you can use this fromWebTestClient.mutateWith(WebTestClientConfigurer)to replace it.- Parameters:
- connector- the connector to use
- Since:
- 6.1
 
- 
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.
 
-