diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java index 34f0909721..1fe573acb4 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java @@ -74,7 +74,8 @@ class DefaultWebTestClient implements WebTestClient { private final AtomicLong requestIndex = new AtomicLong(); - DefaultWebTestClient(WebClient.Builder clientBuilder, ClientHttpConnector connector, @Nullable Duration timeout) { + DefaultWebTestClient(WebClient.Builder clientBuilder, ClientHttpConnector connector, + @Nullable Duration timeout) { Assert.notNull(clientBuilder, "WebClient.Builder is required"); this.wiretapConnector = new WiretapConnector(connector); this.webClient = clientBuilder.clientConnector(this.wiretapConnector).build(); @@ -122,6 +123,12 @@ class DefaultWebTestClient implements WebTestClient { return toUriSpec(wc -> wc.method(HttpMethod.OPTIONS)); } + @Override + public Builder mutate() { + return new DefaultWebTestClientBuilder(this.wiretapConnector.getDelegate(), + this.webClient.mutate(), this.timeout); + } + private > UriSpec toUriSpec( Function> function) { diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClientBuilder.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClientBuilder.java index edddbe8ba1..b02194c862 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClientBuilder.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClientBuilder.java @@ -24,6 +24,7 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.client.reactive.ClientHttpConnector; import org.springframework.http.client.reactive.ReactorClientHttpConnector; import org.springframework.http.server.reactive.HttpHandler; +import org.springframework.lang.Nullable; import org.springframework.util.MultiValueMap; import org.springframework.web.reactive.function.client.ExchangeFilterFunction; import org.springframework.web.reactive.function.client.ExchangeStrategies; @@ -38,7 +39,7 @@ import org.springframework.web.util.UriBuilderFactory; */ class DefaultWebTestClientBuilder implements WebTestClient.Builder { - private final WebClient.Builder webClientBuilder = WebClient.builder(); + private final WebClient.Builder webClientBuilder; private final ClientHttpConnector connector; @@ -49,12 +50,21 @@ class DefaultWebTestClientBuilder implements WebTestClient.Builder { this(new ReactorClientHttpConnector()); } + DefaultWebTestClientBuilder(HttpHandler httpHandler) { + this(new HttpHandlerConnector(httpHandler)); + } + DefaultWebTestClientBuilder(ClientHttpConnector connector) { - this.connector = connector; + this(connector, null, null); } - DefaultWebTestClientBuilder(HttpHandler httpHandler) { - this.connector = new HttpHandlerConnector(httpHandler); + DefaultWebTestClientBuilder(ClientHttpConnector connector, + @Nullable WebClient.Builder webClientBuilder, + @Nullable Duration responseTimeout) { + + this.connector = connector; + this.webClientBuilder = (webClientBuilder != null ? webClientBuilder : WebClient.builder()); + this.responseTimeout = responseTimeout; } diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/WebTestClient.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/WebTestClient.java index 043c8eae32..b72fa0dfc3 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/WebTestClient.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/WebTestClient.java @@ -127,6 +127,11 @@ public interface WebTestClient { UriSpec> options(); + /** + * Return a builder to mutate properties of this web test client. + */ + Builder mutate(); + // Static, factory methods /** diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/WiretapConnector.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/WiretapConnector.java index a99154639a..95dbb8f4b4 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/WiretapConnector.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/WiretapConnector.java @@ -50,6 +50,9 @@ class WiretapConnector implements ClientHttpConnector { this.delegate = delegate; } + public ClientHttpConnector getDelegate() { + return this.delegate; + } @Override public Mono connect(HttpMethod method, URI uri,