Interface RestTestClient.Builder<B extends RestTestClient.Builder<B>>

Type Parameters:
B - the type of builder
All Known Subinterfaces:
RestTestClient.MockMvcSetupBuilder<S,M>, RestTestClient.RouterFunctionSetupBuilder, RestTestClient.StandaloneSetupBuilder, RestTestClient.WebAppContextSetupBuilder
Enclosing interface:
RestTestClient

public static interface RestTestClient.Builder<B extends RestTestClient.Builder<B>>
Steps to customize the underlying RestClient via RestClient.Builder.
Since:
7.0
Author:
Rob Worsnop, Rossen Stoyanchev
  • Method Details

    • baseUrl

      <T extends B> T baseUrl(String baseUrl)
      Configure a base URI as described in RestClient.create(String).
      Returns:
      this builder
    • uriBuilderFactory

      <T extends B> T uriBuilderFactory(UriBuilderFactory uriBuilderFactory)
      Provide a pre-configured UriBuilderFactory instance as an alternative to and effectively overriding baseUrl(String).
      Returns:
      this builder
    • defaultHeader

      <T extends B> T defaultHeader(String headerName, String... headerValues)
      Add the given header to all requests that have not added it.
      Parameters:
      headerName - the header name
      headerValues - the header values
      Returns:
      this builder
    • defaultHeaders

      <T extends B> T 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

      <T extends B> T defaultCookie(String cookieName, String... cookieValues)
      Add the given cookie to all requests that have not already added it.
      Parameters:
      cookieName - the cookie name
      cookieValues - the cookie values
      Returns:
      this builder
    • defaultCookies

      <T extends B> T 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
    • defaultApiVersion

      <T extends B> T defaultApiVersion(Object version)
      Global option to specify an API version to add to every request, if not already set.
      Parameters:
      version - the version to use
      Returns:
      this builder
    • apiVersionInserter

      <T extends B> T apiVersionInserter(ApiVersionInserter apiVersionInserter)
      Configure an ApiVersionInserter to abstract how an API version specified via RestTestClient.RequestHeadersSpec.apiVersion(Object) is inserted into the request.
      Parameters:
      apiVersionInserter - the inserter to use
    • requestInterceptor

      <T extends B> T requestInterceptor(ClientHttpRequestInterceptor interceptor)
      Add the given request interceptor to the end of the interceptor chain.
      Parameters:
      interceptor - the interceptor to be added to the chain
    • requestInterceptors

      <T extends B> T requestInterceptors(Consumer<List<ClientHttpRequestInterceptor>> interceptorsConsumer)
      Manipulate the interceptors with the given consumer. The list provided to the consumer is "live", so that the consumer can be used to remove interceptors, change ordering, etc.
      Parameters:
      interceptorsConsumer - a function that consumes the interceptors list
      Returns:
      this builder
    • configureMessageConverters

      <T extends B> T configureMessageConverters(Consumer<HttpMessageConverters.ClientBuilder> configurer)
      Configure the message converters to use for the request and response body.
      Parameters:
      configurer - the configurer to apply on an empty HttpMessageConverters.ClientBuilder.
      Returns:
      this builder
    • entityExchangeResultConsumer

      <T extends B> T 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, this is equivalent to each of the below but registered only 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
    • build

      Build the RestTestClient instance.