|
|
@ -40,34 +40,31 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class ReactiveWebServerFactoryAutoConfigurationTests {
|
|
|
|
public class ReactiveWebServerFactoryAutoConfigurationTests {
|
|
|
|
|
|
|
|
|
|
|
|
private ReactiveWebApplicationContextRunner contextRunner =
|
|
|
|
private ReactiveWebApplicationContextRunner contextRunner = new ReactiveWebApplicationContextRunner(
|
|
|
|
new ReactiveWebApplicationContextRunner(AnnotationConfigReactiveWebServerApplicationContext::new)
|
|
|
|
AnnotationConfigReactiveWebServerApplicationContext::new)
|
|
|
|
.withConfiguration(AutoConfigurations.of(ReactiveWebServerFactoryAutoConfiguration.class));
|
|
|
|
.withConfiguration(AutoConfigurations
|
|
|
|
|
|
|
|
.of(ReactiveWebServerFactoryAutoConfiguration.class));
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void createFromConfigClass() {
|
|
|
|
public void createFromConfigClass() {
|
|
|
|
this.contextRunner
|
|
|
|
this.contextRunner.withUserConfiguration(MockWebServerAutoConfiguration.class,
|
|
|
|
.withUserConfiguration(MockWebServerAutoConfiguration.class,
|
|
|
|
HttpHandlerConfiguration.class).run((context) -> {
|
|
|
|
HttpHandlerConfiguration.class)
|
|
|
|
|
|
|
|
.run(context -> {
|
|
|
|
|
|
|
|
assertThat(context.getBeansOfType(ReactiveWebServerFactory.class))
|
|
|
|
assertThat(context.getBeansOfType(ReactiveWebServerFactory.class))
|
|
|
|
.hasSize(1);
|
|
|
|
.hasSize(1);
|
|
|
|
assertThat(context.getBeansOfType(WebServerFactoryCustomizer.class))
|
|
|
|
assertThat(context.getBeansOfType(WebServerFactoryCustomizer.class))
|
|
|
|
.hasSize(1);
|
|
|
|
.hasSize(1);
|
|
|
|
assertThat(context.getBeansOfType(ReactiveWebServerFactoryCustomizer.class))
|
|
|
|
assertThat(context
|
|
|
|
.hasSize(1);
|
|
|
|
.getBeansOfType(ReactiveWebServerFactoryCustomizer.class))
|
|
|
|
|
|
|
|
.hasSize(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void missingHttpHandler() {
|
|
|
|
public void missingHttpHandler() {
|
|
|
|
this.contextRunner
|
|
|
|
this.contextRunner.withUserConfiguration(MockWebServerAutoConfiguration.class)
|
|
|
|
.withUserConfiguration(MockWebServerAutoConfiguration.class)
|
|
|
|
.run((context) -> assertThat(context.getStartupFailure())
|
|
|
|
.run(context -> {
|
|
|
|
.isInstanceOf(ApplicationContextException.class)
|
|
|
|
assertThat(context.getStartupFailure())
|
|
|
|
.hasMessageContaining("missing HttpHandler bean"));
|
|
|
|
.isInstanceOf(ApplicationContextException.class)
|
|
|
|
|
|
|
|
.hasMessageContaining("missing HttpHandler bean");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -75,34 +72,27 @@ public class ReactiveWebServerFactoryAutoConfigurationTests {
|
|
|
|
this.contextRunner
|
|
|
|
this.contextRunner
|
|
|
|
.withUserConfiguration(MockWebServerAutoConfiguration.class,
|
|
|
|
.withUserConfiguration(MockWebServerAutoConfiguration.class,
|
|
|
|
HttpHandlerConfiguration.class, TooManyHttpHandlers.class)
|
|
|
|
HttpHandlerConfiguration.class, TooManyHttpHandlers.class)
|
|
|
|
.run(context -> {
|
|
|
|
.run((context) -> assertThat(context.getStartupFailure())
|
|
|
|
assertThat(context.getStartupFailure())
|
|
|
|
.isInstanceOf(ApplicationContextException.class)
|
|
|
|
.isInstanceOf(ApplicationContextException.class)
|
|
|
|
.hasMessageContaining("multiple HttpHandler beans : "
|
|
|
|
.hasMessageContaining("multiple HttpHandler beans : " +
|
|
|
|
+ "httpHandler,additionalHttpHandler"));
|
|
|
|
"httpHandler,additionalHttpHandler");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void customizeReactiveWebServer() {
|
|
|
|
public void customizeReactiveWebServer() {
|
|
|
|
this.contextRunner
|
|
|
|
this.contextRunner.withUserConfiguration(MockWebServerAutoConfiguration.class,
|
|
|
|
.withUserConfiguration(MockWebServerAutoConfiguration.class,
|
|
|
|
HttpHandlerConfiguration.class, ReactiveWebServerCustomization.class)
|
|
|
|
HttpHandlerConfiguration.class, ReactiveWebServerCustomization.class)
|
|
|
|
.run((context) -> assertThat(
|
|
|
|
.run(context -> {
|
|
|
|
context.getBean(MockReactiveWebServerFactory.class).getPort())
|
|
|
|
assertThat(context.getBean(MockReactiveWebServerFactory.class).getPort())
|
|
|
|
.isEqualTo(9000));
|
|
|
|
.isEqualTo(9000);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void defaultWebServerIsTomcat() {
|
|
|
|
public void defaultWebServerIsTomcat() {
|
|
|
|
// Tomcat should be chosen over Netty if the Tomcat library is present.
|
|
|
|
// Tomcat should be chosen over Netty if the Tomcat library is present.
|
|
|
|
this.contextRunner
|
|
|
|
this.contextRunner.withUserConfiguration(HttpHandlerConfiguration.class).run(
|
|
|
|
.withUserConfiguration(HttpHandlerConfiguration.class)
|
|
|
|
(context) -> assertThat(context.getBean(ReactiveWebServerFactory.class))
|
|
|
|
.run(context -> {
|
|
|
|
.isInstanceOf(TomcatReactiveWebServerFactory.class));
|
|
|
|
assertThat(context.getBean(ReactiveWebServerFactory.class))
|
|
|
|
|
|
|
|
.isInstanceOf(TomcatReactiveWebServerFactory.class);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
@Configuration
|
|
|
|