Add bindToHttpHandler to WebTestClient

Issue: SPR-15499
This commit is contained in:
Rossen Stoyanchev
2017-05-02 18:13:27 -04:00
parent 4db1eb1e4e
commit 16901b1497
3 changed files with 73 additions and 5 deletions

View File

@@ -77,13 +77,13 @@ class DefaultWebTestClient implements WebTestClient {
DefaultWebTestClient(WebClient.Builder webClientBuilder, ClientHttpConnector connector,
ExchangeMutatingWebFilter exchangeMutatingWebFilter, Duration timeout) {
ExchangeMutatingWebFilter filter, Duration timeout) {
Assert.notNull(webClientBuilder, "WebClient.Builder is required");
this.wiretapConnector = new WiretapConnector(connector);
this.webClient = webClientBuilder.clientConnector(this.wiretapConnector).build();
this.exchangeMutatingWebFilter = exchangeMutatingWebFilter;
this.exchangeMutatingWebFilter = (filter != null ? filter : new ExchangeMutatingWebFilter());
this.timeout = (timeout != null ? timeout : Duration.ofSeconds(5));
}

View File

@@ -35,6 +35,7 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.client.reactive.ClientHttpRequest;
import org.springframework.http.codec.ServerCodecConfigurer;
import org.springframework.http.server.reactive.HttpHandler;
import org.springframework.util.MultiValueMap;
import org.springframework.validation.Validator;
import org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder;
@@ -140,7 +141,7 @@ public interface WebTestClient {
// Static, factory methods
/**
* Integration testing without a server, targeting specific annotated,
* Integration testing without a server targeting specific annotated,
* WebFlux controllers. The default configuration is the same as for
* {@link org.springframework.web.reactive.config.EnableWebFlux @EnableWebFlux}
* but can also be further customized through the returned spec.
@@ -152,7 +153,7 @@ public interface WebTestClient {
}
/**
* Integration testing without a server, with WebFlux infrastructure detected
* Integration testing without a server with WebFlux infrastructure detected
* from an {@link ApplicationContext} such as {@code @EnableWebFlux}
* Java config and annotated controller Spring beans.
* @param applicationContext the context
@@ -164,7 +165,7 @@ public interface WebTestClient {
}
/**
* Integration testing without a server, targeting WebFlux functional endpoints.
* Integration testing without a server targeting WebFlux functional endpoints.
* @param routerFunction the RouterFunction to test
* @return the {@link WebTestClient} builder
*/
@@ -172,6 +173,15 @@ public interface WebTestClient {
return new RouterFunctionSpec(routerFunction);
}
/**
* Integration testing without a server targeting the given HttpHandler.
* @param httpHandler the handler to test
* @return the {@link WebTestClient} builder
*/
static Builder bindToHttpHandler(HttpHandler httpHandler) {
return new DefaultWebTestClientBuilder(httpHandler, null);
}
/**
* Complete end-to-end integration tests with actual requests to a running server.
* @return the {@link WebTestClient} builder