Polish
This commit is contained in:
parent
5ec993bb8c
commit
533544d8fc
|
@ -18,13 +18,12 @@ package org.springframework.boot.test.web.reactive.client;
|
||||||
|
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||||
import org.springframework.test.web.reactive.server.WebTestClient.Builder;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A customizer that can be implemented by beans wishing to customize the {@link Builder}
|
* A customizer that can be implemented by beans wishing to customize the
|
||||||
* to fine-tune its auto-configuration before a {@link WebTestClient} is created.
|
* {@link WebTestClient.Builder} to fine-tune its auto-configuration before a
|
||||||
* Implementations can be registered in the {@link ApplicationContext} or
|
* {@link WebTestClient} is created. Implementations can be registered in the
|
||||||
* {@code spring.factories}.
|
* {@link ApplicationContext} or {@code spring.factories}.
|
||||||
*
|
*
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
* @since 4.0.0
|
* @since 4.0.0
|
||||||
|
@ -36,6 +35,6 @@ public interface WebTestClientBuilderCustomizer {
|
||||||
* Customize the given {@code builder}.
|
* Customize the given {@code builder}.
|
||||||
* @param builder the builder
|
* @param builder the builder
|
||||||
*/
|
*/
|
||||||
void customize(Builder builder);
|
void customize(WebTestClient.Builder builder);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,10 +123,6 @@ class WebTestClientContextCustomizer implements ContextCustomizer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -143,11 +139,6 @@ class WebTestClientContextCustomizer implements ContextCustomizer {
|
||||||
this.applicationContext = applicationContext;
|
this.applicationContext = applicationContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isSingleton() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<?> getObjectType() {
|
public Class<?> getObjectType() {
|
||||||
return WebTestClient.class;
|
return WebTestClient.class;
|
||||||
|
@ -164,7 +155,7 @@ class WebTestClientContextCustomizer implements ContextCustomizer {
|
||||||
private WebTestClient createWebTestClient() {
|
private WebTestClient createWebTestClient() {
|
||||||
Assert.state(this.applicationContext != null, "ApplicationContext not injected");
|
Assert.state(this.applicationContext != null, "ApplicationContext not injected");
|
||||||
WebTestClient.Builder builder = WebTestClient.bindToServer();
|
WebTestClient.Builder builder = WebTestClient.bindToServer();
|
||||||
customizeWebTestClientBuilder(builder, this.applicationContext);
|
customizeWebTestClientBuilder(builder);
|
||||||
BaseUrl baseUrl = new BaseUrlProviders(this.applicationContext).getBaseUrl();
|
BaseUrl baseUrl = new BaseUrlProviders(this.applicationContext).getBaseUrl();
|
||||||
if (baseUrl != null) {
|
if (baseUrl != null) {
|
||||||
builder.baseUrl(baseUrl.resolve());
|
builder.baseUrl(baseUrl.resolve());
|
||||||
|
@ -172,7 +163,7 @@ class WebTestClientContextCustomizer implements ContextCustomizer {
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void customizeWebTestClientBuilder(WebTestClient.Builder clientBuilder, ApplicationContext context) {
|
private void customizeWebTestClientBuilder(WebTestClient.Builder clientBuilder) {
|
||||||
Assert.state(this.applicationContext != null, "ApplicationContext not injected");
|
Assert.state(this.applicationContext != null, "ApplicationContext not injected");
|
||||||
getWebTestClientBuilderCustomizers(this.applicationContext)
|
getWebTestClientBuilderCustomizers(this.applicationContext)
|
||||||
.forEach((customizer) -> customizer.customize(clientBuilder));
|
.forEach((customizer) -> customizer.customize(clientBuilder));
|
||||||
|
@ -180,10 +171,9 @@ class WebTestClientContextCustomizer implements ContextCustomizer {
|
||||||
|
|
||||||
private List<WebTestClientBuilderCustomizer> getWebTestClientBuilderCustomizers(ApplicationContext context) {
|
private List<WebTestClientBuilderCustomizer> getWebTestClientBuilderCustomizers(ApplicationContext context) {
|
||||||
List<WebTestClientBuilderCustomizer> customizers = new ArrayList<>();
|
List<WebTestClientBuilderCustomizer> customizers = new ArrayList<>();
|
||||||
SpringFactoriesLoader.forDefaultResourceLocation(context.getClassLoader())
|
customizers.addAll(SpringFactoriesLoader.forDefaultResourceLocation(context.getClassLoader())
|
||||||
.load(WebTestClientBuilderCustomizer.class, ArgumentResolver.of(ApplicationContext.class, context))
|
.load(WebTestClientBuilderCustomizer.class, ArgumentResolver.of(ApplicationContext.class, context)));
|
||||||
.forEach(customizers::add);
|
customizers.addAll(context.getBeansOfType(WebTestClientBuilderCustomizer.class).values());
|
||||||
context.getBeansOfType(WebTestClientBuilderCustomizer.class).values().forEach(customizers::add);
|
|
||||||
return customizers;
|
return customizers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,13 +18,12 @@ package org.springframework.boot.test.web.servlet.client;
|
||||||
|
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.test.web.servlet.client.RestTestClient;
|
import org.springframework.test.web.servlet.client.RestTestClient;
|
||||||
import org.springframework.test.web.servlet.client.RestTestClient.Builder;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A customizer that can be implemented by beans wishing to customize the {@link Builder}
|
* A customizer that can be implemented by beans wishing to customize the
|
||||||
* to fine-tune its auto-configuration before a {@link RestTestClient} is created.
|
* {@link RestTestClient.Builder} to fine-tune its auto-configuration before a
|
||||||
* Implementations can be registered in the {@link ApplicationContext} or
|
* {@link RestTestClient} is created. Implementations can be registered in the
|
||||||
* {@code spring.factories}.
|
* {@link ApplicationContext} or {@code spring.factories}.
|
||||||
*
|
*
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
* @since 4.0.0
|
* @since 4.0.0
|
||||||
|
@ -33,9 +32,9 @@ import org.springframework.test.web.servlet.client.RestTestClient.Builder;
|
||||||
public interface RestTestClientBuilderCustomizer {
|
public interface RestTestClientBuilderCustomizer {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Customize the given {@link Builder Builder}.
|
* Customize the given {@link RestTestClient.Builder Builder}.
|
||||||
* @param builder the builder
|
* @param builder the builder
|
||||||
*/
|
*/
|
||||||
void customize(Builder<?> builder);
|
void customize(RestTestClient.Builder<?> builder);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,10 +125,6 @@ class RestTestClientContextCustomizer implements ContextCustomizer {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -145,11 +141,6 @@ class RestTestClientContextCustomizer implements ContextCustomizer {
|
||||||
this.applicationContext = applicationContext;
|
this.applicationContext = applicationContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isSingleton() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<?> getObjectType() {
|
public Class<?> getObjectType() {
|
||||||
return RestTestClient.class;
|
return RestTestClient.class;
|
||||||
|
@ -166,13 +157,12 @@ class RestTestClientContextCustomizer implements ContextCustomizer {
|
||||||
private RestTestClient createRestTestClient() {
|
private RestTestClient createRestTestClient() {
|
||||||
Assert.state(this.applicationContext != null, "ApplicationContext not injected");
|
Assert.state(this.applicationContext != null, "ApplicationContext not injected");
|
||||||
RestTestClient.Builder<?> builder = RestTestClient.bindToServer();
|
RestTestClient.Builder<?> builder = RestTestClient.bindToServer();
|
||||||
customizeRestTestClientBuilder(builder, this.applicationContext);
|
customizeRestTestClientBuilder(builder);
|
||||||
BaseUrl baseUrl = new BaseUrlProviders(this.applicationContext).getBaseUrl();
|
BaseUrl baseUrl = new BaseUrlProviders(this.applicationContext).getBaseUrl();
|
||||||
return builder.uriBuilderFactory(BaseUrlUriBuilderFactory.get(baseUrl)).build();
|
return builder.uriBuilderFactory(BaseUrlUriBuilderFactory.get(baseUrl)).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void customizeRestTestClientBuilder(RestTestClient.Builder<?> clientBuilder,
|
private void customizeRestTestClientBuilder(RestTestClient.Builder<?> clientBuilder) {
|
||||||
ApplicationContext context) {
|
|
||||||
Assert.state(this.applicationContext != null, "ApplicationContext not injected");
|
Assert.state(this.applicationContext != null, "ApplicationContext not injected");
|
||||||
getRestTestClientBuilderCustomizers(this.applicationContext)
|
getRestTestClientBuilderCustomizers(this.applicationContext)
|
||||||
.forEach((customizer) -> customizer.customize(clientBuilder));
|
.forEach((customizer) -> customizer.customize(clientBuilder));
|
||||||
|
@ -180,10 +170,9 @@ class RestTestClientContextCustomizer implements ContextCustomizer {
|
||||||
|
|
||||||
private List<RestTestClientBuilderCustomizer> getRestTestClientBuilderCustomizers(ApplicationContext context) {
|
private List<RestTestClientBuilderCustomizer> getRestTestClientBuilderCustomizers(ApplicationContext context) {
|
||||||
List<RestTestClientBuilderCustomizer> customizers = new ArrayList<>();
|
List<RestTestClientBuilderCustomizer> customizers = new ArrayList<>();
|
||||||
SpringFactoriesLoader.forDefaultResourceLocation(context.getClassLoader())
|
customizers.addAll(SpringFactoriesLoader.forDefaultResourceLocation(context.getClassLoader())
|
||||||
.load(RestTestClientBuilderCustomizer.class, ArgumentResolver.of(ApplicationContext.class, context))
|
.load(RestTestClientBuilderCustomizer.class, ArgumentResolver.of(ApplicationContext.class, context)));
|
||||||
.forEach(customizers::add);
|
customizers.addAll(context.getBeansOfType(RestTestClientBuilderCustomizer.class).values());
|
||||||
context.getBeansOfType(RestTestClientBuilderCustomizer.class).values().forEach(customizers::add);
|
|
||||||
return customizers;
|
return customizers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue