接口 WebTestClient.Builder
- 封闭接口:
- WebTestClient
public static interface WebTestClient.Builder
Steps for customizing theWebClientused to test with, internally delegating to aWebClient.Builder.
方法概要
所有方法 实例方法 抽象方法 已过时的方法 修饰符和类型 方法 说明 WebTestClient.Builderapply(WebTestClientConfigurer configurer)Apply the given configurer to this builder instance.WebTestClient.BuilderbaseUrl(String baseUrl)Configure a base URI as described inWebClient.create(String).WebTestClientbuild()Build theWebTestClientinstance.WebTestClient.Buildercodecs(Consumer<ClientCodecConfigurer> configurer)WebTestClient.BuilderdefaultCookie(String cookieName, String... cookieValues)Add the given header to all requests that haven't added it.WebTestClient.BuilderdefaultCookies(Consumer<MultiValueMap<String,String>> cookiesConsumer)Manipulate the default cookies with the given consumer.WebTestClient.BuilderdefaultHeader(String headerName, String... headerValues)Add the given header to all requests that haven't added it.WebTestClient.BuilderdefaultHeaders(Consumer<HttpHeaders> headersConsumer)Manipulate the default headers with the given consumer.WebTestClient.BuilderexchangeStrategies(Consumer<ExchangeStrategies.Builder> configurer)已过时。as of 5.1.13 in favor ofcodecs(Consumer)WebTestClient.BuilderexchangeStrategies(ExchangeStrategies strategies)Configure theExchangeStrategiesto use.WebTestClient.Builderfilter(ExchangeFilterFunction filter)Add the given filter to the filter chain.WebTestClient.Builderfilters(Consumer<List<ExchangeFilterFunction>> filtersConsumer)Manipulate the filters with the given consumer.WebTestClient.BuilderresponseTimeout(Duration timeout)Max amount of time to wait for responses.WebTestClient.BuilderuriBuilderFactory(UriBuilderFactory uriBuilderFactory)Provide a pre-configuredUriBuilderFactoryinstance as an alternative to and effectively overridingbaseUrl(String).
方法详细资料
baseUrl
WebTestClient.Builder baseUrl(String baseUrl)
Configure a base URI as described inWebClient.create(String).
uriBuilderFactory
WebTestClient.Builder uriBuilderFactory(UriBuilderFactory uriBuilderFactory)
Provide a pre-configuredUriBuilderFactoryinstance as an alternative to and effectively overridingbaseUrl(String).
defaultHeader
WebTestClient.Builder defaultHeader(String headerName, String... headerValues)
Add the given header to all requests that haven't added it.- 参数:
headerName- the header nameheaderValues- the header values
defaultHeaders
WebTestClient.Builder defaultHeaders(Consumer<HttpHeaders> headersConsumer)
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 otherHttpHeadersmethods.- 参数:
headersConsumer- a function that consumes theHttpHeaders- 返回:
- this builder
defaultCookie
WebTestClient.Builder defaultCookie(String cookieName, String... cookieValues)
Add the given header to all requests that haven't added it.- 参数:
cookieName- the cookie namecookieValues- the cookie values
defaultCookies
WebTestClient.Builder defaultCookies(Consumer<MultiValueMap<String,String>> cookiesConsumer)
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 otherMultiValueMapmethods.- 参数:
cookiesConsumer- a function that consumes the cookies map- 返回:
- this builder
filter
WebTestClient.Builder filter(ExchangeFilterFunction filter)
Add the given filter to the filter chain.- 参数:
filter- the filter to be added to the chain
filters
WebTestClient.Builder filters(Consumer<List<ExchangeFilterFunction>> filtersConsumer)
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.- 参数:
filtersConsumer- a function that consumes the filter list- 返回:
- this builder
codecs
WebTestClient.Builder codecs(Consumer<ClientCodecConfigurer> configurer)
- 参数:
configurer- the configurer to apply- 从以下版本开始:
- 5.1.13
exchangeStrategies
WebTestClient.Builder exchangeStrategies(ExchangeStrategies strategies)
Configure 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().- 参数:
strategies- the strategies to use
exchangeStrategies
@Deprecated WebTestClient.Builder exchangeStrategies(Consumer<ExchangeStrategies.Builder> configurer)
已过时。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.
apply
WebTestClient.Builder apply(WebTestClientConfigurer configurer)
Apply the given configurer to this builder instance.This can be useful for applying pre-packaged customizations.
- 参数:
configurer- the configurer to apply
build
WebTestClient build()
Build theWebTestClientinstance.