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 Details

    • baseUrl

      WebTestClient.Builder baseUrl(String baseUrl)
      Configure a base URI as described in WebClient.create(String).
    • uriBuilderFactory

      WebTestClient.Builder uriBuilderFactory(UriBuilderFactory uriBuilderFactory)
      Provide a pre-configured UriBuilderFactory instance as an alternative to and effectively overriding baseUrl(String).
    • defaultHeader

      WebTestClient.Builder defaultHeader(String headerName, String... headerValues)
      Add the given header to all requests that haven't added it.
      Parameters:
      headerName - the header name
      headerValues - 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 other HttpHeaders methods.
      Parameters:
      headersConsumer - a function that consumes the HttpHeaders
      Returns:
      this builder
    • defaultCookie

      WebTestClient.Builder defaultCookie(String cookieName, String... cookieValues)
      Add the given header to all requests that haven't added it.
      Parameters:
      cookieName - the cookie name
      cookieValues - 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 other MultiValueMap 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

      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[]. 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.

      Parameters:
      consumer - the consumer to apply to entity responses
      Returns:
      the builder
      Since:
      5.3.5
    • codecs

      Configure the codecs for the WebClient in the underlying ExchangeStrategies.
      Parameters:
      configurer - the configurer to apply
      Since:
      5.1.13
    • exchangeStrategies

      WebTestClient.Builder exchangeStrategies(ExchangeStrategies strategies)
      Configure the 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().

      Parameters:
      strategies - the strategies to use
    • exchangeStrategies

      Deprecated.
      as of 5.1.13 in favor of codecs(Consumer)
      Customize the strategies configured via exchangeStrategies(ExchangeStrategies). This method is designed for use in scenarios where multiple parties wish to update the ExchangeStrategies.
    • responseTimeout

      WebTestClient.Builder responseTimeout(Duration timeout)
      Max amount of time to wait for responses.

      By default 5 seconds.

      Parameters:
      timeout - the response timeout value
    • 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 the WebTestClient instance.