@@ -89,6 +89,8 @@ class DefaultWebTestClient implements WebTestClient {
89
89
90
90
private final @ Nullable MultiValueMap <String , String > defaultCookies ;
91
91
92
+ private final @ Nullable Object defaultApiVersion ;
93
+
92
94
private final @ Nullable ApiVersionInserter apiVersionInserter ;
93
95
94
96
private final Consumer <EntityExchangeResult <?>> entityResultConsumer ;
@@ -104,7 +106,8 @@ class DefaultWebTestClient implements WebTestClient {
104
106
ClientHttpConnector connector , ExchangeStrategies exchangeStrategies ,
105
107
Function <ClientHttpConnector , ExchangeFunction > exchangeFactory , UriBuilderFactory uriBuilderFactory ,
106
108
@ Nullable HttpHeaders headers , @ Nullable MultiValueMap <String , String > cookies ,
107
- @ Nullable ApiVersionInserter apiVersionInserter , Consumer <EntityExchangeResult <?>> entityResultConsumer ,
109
+ @ Nullable Object defaultApiVersion , @ Nullable ApiVersionInserter apiVersionInserter ,
110
+ Consumer <EntityExchangeResult <?>> entityResultConsumer ,
108
111
@ Nullable Duration responseTimeout , DefaultWebTestClientBuilder clientBuilder ) {
109
112
110
113
this .wiretapConnector = new WiretapConnector (connector );
@@ -114,6 +117,7 @@ class DefaultWebTestClient implements WebTestClient {
114
117
this .uriBuilderFactory = uriBuilderFactory ;
115
118
this .defaultHeaders = headers ;
116
119
this .defaultCookies = cookies ;
120
+ this .defaultApiVersion = defaultApiVersion ;
117
121
this .apiVersionInserter = apiVersionInserter ;
118
122
this .entityResultConsumer = entityResultConsumer ;
119
123
this .responseTimeout = (responseTimeout != null ? responseTimeout : Duration .ofSeconds (5 ));
@@ -386,9 +390,10 @@ private ClientRequest.Builder initRequestBuilder() {
386
390
if (!this .headers .isEmpty ()) {
387
391
headersToUse .putAll (this .headers );
388
392
}
389
- if (this .apiVersion != null ) {
393
+ Object version = getApiVersionOrDefault ();
394
+ if (version != null ) {
390
395
Assert .state (apiVersionInserter != null , "No ApiVersionInserter configured" );
391
- apiVersionInserter .insertVersion (this . apiVersion , headersToUse );
396
+ apiVersionInserter .insertVersion (version , headersToUse );
392
397
}
393
398
})
394
399
.cookies (cookiesToUse -> {
@@ -404,13 +409,18 @@ private ClientRequest.Builder initRequestBuilder() {
404
409
405
410
private URI initUri () {
406
411
URI uriToUse = this .uri != null ? this .uri : DefaultWebTestClient .this .uriBuilderFactory .expand ("" );
407
- if (this .apiVersion != null ) {
412
+ Object version = getApiVersionOrDefault ();
413
+ if (version != null ) {
408
414
Assert .state (apiVersionInserter != null , "No ApiVersionInserter configured" );
409
- uriToUse = apiVersionInserter .insertVersion (this . apiVersion , uriToUse );
415
+ uriToUse = apiVersionInserter .insertVersion (version , uriToUse );
410
416
}
411
417
return uriToUse ;
412
418
}
413
419
420
+ private @ Nullable Object getApiVersionOrDefault () {
421
+ return (this .apiVersion != null ? this .apiVersion : DefaultWebTestClient .this .defaultApiVersion );
422
+ }
423
+
414
424
}
415
425
416
426
0 commit comments