Polish formatting
This commit is contained in:
@@ -19,8 +19,8 @@ package org.springframework.boot.test.context;
|
||||
import org.springframework.test.context.MergedContextConfiguration;
|
||||
|
||||
/**
|
||||
* Encapsulates the <em>merged</em> context configuration declared on a test class and
|
||||
* all of its superclasses for a reactive web application.
|
||||
* Encapsulates the <em>merged</em> context configuration declared on a test class and all
|
||||
* of its superclasses for a reactive web application.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @since 2.0.0
|
||||
@@ -31,4 +31,5 @@ public class ReactiveWebMergedContextConfiguration extends MergedContextConfigur
|
||||
MergedContextConfiguration mergedConfig) {
|
||||
super(mergedConfig);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -115,8 +115,8 @@ public @interface SpringBootTest {
|
||||
|
||||
/**
|
||||
* Creates a {@link WebApplicationContext} with a mock servlet environment if
|
||||
* servlet APIs are on the classpath, a {@link ReactiveWebApplicationContext}
|
||||
* if Spring WebFlux is on the classpath or a regular {@link ApplicationContext}
|
||||
* servlet APIs are on the classpath, a {@link ReactiveWebApplicationContext} if
|
||||
* Spring WebFlux is on the classpath or a regular {@link ApplicationContext}
|
||||
* otherwise.
|
||||
*/
|
||||
MOCK(false),
|
||||
|
||||
@@ -93,7 +93,8 @@ public class SpringBootTestContextBootstrapper extends DefaultTestContextBootstr
|
||||
TestContext context = super.buildTestContext();
|
||||
verifyConfiguration(context.getTestClass());
|
||||
WebEnvironment webEnvironment = getWebEnvironment(context.getTestClass());
|
||||
if (webEnvironment == WebEnvironment.MOCK && deduceWebApplication() == WebApplicationType.SERVLET) {
|
||||
if (webEnvironment == WebEnvironment.MOCK
|
||||
&& deduceWebApplication() == WebApplicationType.SERVLET) {
|
||||
context.setAttribute(ACTIVATE_SERVLET_LISTENER, true);
|
||||
}
|
||||
else if (webEnvironment != null && webEnvironment.isEmbedded()) {
|
||||
@@ -154,8 +155,9 @@ public class SpringBootTestContextBootstrapper extends DefaultTestContextBootstr
|
||||
WebEnvironment webEnvironment = getWebEnvironment(mergedConfig.getTestClass());
|
||||
if (webEnvironment != null) {
|
||||
WebApplicationType webApplicationType = getWebApplicationType(mergedConfig);
|
||||
if (webApplicationType == WebApplicationType.SERVLET &&
|
||||
(webEnvironment.isEmbedded() || webEnvironment == WebEnvironment.MOCK)) {
|
||||
if (webApplicationType == WebApplicationType.SERVLET
|
||||
&& (webEnvironment.isEmbedded()
|
||||
|| webEnvironment == WebEnvironment.MOCK)) {
|
||||
WebAppConfiguration webAppConfiguration = AnnotatedElementUtils
|
||||
.findMergedAnnotation(mergedConfig.getTestClass(),
|
||||
WebAppConfiguration.class);
|
||||
@@ -164,8 +166,9 @@ public class SpringBootTestContextBootstrapper extends DefaultTestContextBootstr
|
||||
mergedConfig = new WebMergedContextConfiguration(mergedConfig,
|
||||
resourceBasePath);
|
||||
}
|
||||
else if (webApplicationType == WebApplicationType.REACTIVE &&
|
||||
(webEnvironment.isEmbedded() || webEnvironment == WebEnvironment.MOCK)) {
|
||||
else if (webApplicationType == WebApplicationType.REACTIVE
|
||||
&& (webEnvironment.isEmbedded()
|
||||
|| webEnvironment == WebEnvironment.MOCK)) {
|
||||
return new ReactiveWebMergedContextConfiguration(mergedConfig);
|
||||
}
|
||||
}
|
||||
@@ -174,8 +177,8 @@ public class SpringBootTestContextBootstrapper extends DefaultTestContextBootstr
|
||||
|
||||
private WebApplicationType getWebApplicationType(
|
||||
MergedContextConfiguration configuration) {
|
||||
WebApplicationType webApplicationType =
|
||||
getConfiguredWebApplicationType(configuration);
|
||||
WebApplicationType webApplicationType = getConfiguredWebApplicationType(
|
||||
configuration);
|
||||
if (webApplicationType != null) {
|
||||
return webApplicationType;
|
||||
}
|
||||
|
||||
@@ -42,8 +42,8 @@ class WebTestClientContextCustomizer implements ContextCustomizer {
|
||||
@Override
|
||||
public void customizeContext(ConfigurableApplicationContext context,
|
||||
MergedContextConfiguration mergedConfig) {
|
||||
SpringBootTest annotation = AnnotatedElementUtils.getMergedAnnotation(
|
||||
mergedConfig.getTestClass(), SpringBootTest.class);
|
||||
SpringBootTest annotation = AnnotatedElementUtils
|
||||
.getMergedAnnotation(mergedConfig.getTestClass(), SpringBootTest.class);
|
||||
if (annotation.webEnvironment().isEmbedded()) {
|
||||
registerWebTestClient(context);
|
||||
}
|
||||
|
||||
@@ -32,8 +32,7 @@ import org.springframework.util.ClassUtils;
|
||||
*/
|
||||
public class WebTestClientContextCustomizerFactory implements ContextCustomizerFactory {
|
||||
|
||||
private static final String WEB_TEST_CLIENT_CLASS =
|
||||
"org.springframework.web.reactive.function.client.WebClient";
|
||||
private static final String WEB_TEST_CLIENT_CLASS = "org.springframework.web.reactive.function.client.WebClient";
|
||||
|
||||
@Override
|
||||
public ContextCustomizer createContextCustomizer(Class<?> testClass,
|
||||
|
||||
@@ -62,19 +62,15 @@ public abstract class AbstractSpringBootTestEmbeddedReactiveWebEnvironmentTests
|
||||
@Test
|
||||
public void runAndTestHttpEndpoint() {
|
||||
assertThat(this.port).isNotEqualTo(8080).isNotEqualTo(0);
|
||||
WebTestClient.bindToServer()
|
||||
.baseUrl("http://localhost:" + this.port).build()
|
||||
.get().uri("/")
|
||||
.exchange()
|
||||
.expectBody(String.class).value().isEqualTo("Hello World");
|
||||
WebTestClient.bindToServer().baseUrl("http://localhost:" + this.port).build()
|
||||
.get().uri("/").exchange().expectBody(String.class).value()
|
||||
.isEqualTo("Hello World");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void injectWebTestClient() {
|
||||
this.webClient
|
||||
.get().uri("/")
|
||||
.exchange()
|
||||
.expectBody(String.class).value().isEqualTo("Hello World");
|
||||
this.webClient.get().uri("/").exchange().expectBody(String.class).value()
|
||||
.isEqualTo("Hello World");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user