WebTestClient can be configured with connector
Issue: SPR-16168
This commit is contained in:
		
							parent
							
								
									1a246c0a67
								
							
						
					
					
						commit
						263da1535b
					
				|  | @ -52,20 +52,28 @@ class DefaultWebTestClientBuilder implements WebTestClient.Builder { | |||
| 	private Duration responseTimeout; | ||||
| 
 | ||||
| 
 | ||||
| 	/** Connect to server via Reactor Netty */ | ||||
| 	DefaultWebTestClientBuilder() { | ||||
| 		this(null, null, new ReactorClientHttpConnector(), null); | ||||
| 		this(new ReactorClientHttpConnector()); | ||||
| 	} | ||||
| 
 | ||||
| 	/** Connect to server through the given connector */ | ||||
| 	DefaultWebTestClientBuilder(ClientHttpConnector connector) { | ||||
| 		this(null, null, connector, null); | ||||
| 	} | ||||
| 
 | ||||
| 	/** Connect to given mock server with mock request and response */ | ||||
| 	DefaultWebTestClientBuilder(WebHttpHandlerBuilder httpHandlerBuilder) { | ||||
| 		this(null, httpHandlerBuilder, null, null); | ||||
| 	} | ||||
| 
 | ||||
| 	/** Copy constructor */ | ||||
| 	DefaultWebTestClientBuilder(DefaultWebTestClientBuilder other) { | ||||
| 		this(other.webClientBuilder.clone(), other.httpHandlerBuilder, other.connector, | ||||
| 				other.responseTimeout); | ||||
| 	} | ||||
| 
 | ||||
| 	DefaultWebTestClientBuilder(@Nullable WebClient.Builder webClientBuilder, | ||||
| 	private DefaultWebTestClientBuilder(@Nullable WebClient.Builder webClientBuilder, | ||||
| 			@Nullable WebHttpHandlerBuilder httpHandlerBuilder, @Nullable ClientHttpConnector connector, | ||||
| 			@Nullable Duration responseTimeout) { | ||||
| 
 | ||||
|  |  | |||
|  | @ -33,6 +33,7 @@ import org.springframework.format.FormatterRegistry; | |||
| import org.springframework.http.HttpHeaders; | ||||
| import org.springframework.http.HttpMethod; | ||||
| import org.springframework.http.MediaType; | ||||
| import org.springframework.http.client.reactive.ClientHttpConnector; | ||||
| import org.springframework.http.client.reactive.ClientHttpRequest; | ||||
| import org.springframework.http.codec.ServerCodecConfigurer; | ||||
| import org.springframework.util.MultiValueMap; | ||||
|  | @ -216,7 +217,8 @@ public interface WebTestClient { | |||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * This server setup option allows you to connect to a running server. | ||||
| 	 * This server setup option allows you to connect to a running server via | ||||
| 	 * Reactor Netty. | ||||
| 	 * <p><pre class="code"> | ||||
| 	 * WebTestClient client = WebTestClient.bindToServer() | ||||
| 	 *         .baseUrl("http://localhost:8080") | ||||
|  | @ -228,6 +230,20 @@ public interface WebTestClient { | |||
| 		return new DefaultWebTestClientBuilder(); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * A variant of {@link #bindToServer()} with a pre-configured connector. | ||||
| 	 * <p><pre class="code"> | ||||
| 	 * WebTestClient client = WebTestClient.bindToServer() | ||||
| 	 *         .baseUrl("http://localhost:8080") | ||||
| 	 *         .build(); | ||||
| 	 * </pre> | ||||
| 	 * @return chained API to customize client config | ||||
| 	 * @since 5.0.2 | ||||
| 	 */ | ||||
| 	static Builder bindToServer(ClientHttpConnector connector) { | ||||
| 		return new DefaultWebTestClientBuilder(connector); | ||||
| 	} | ||||
| 
 | ||||
| 
 | ||||
| 	/** | ||||
| 	 * Base specification for setting up tests without a server. | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue