Search in sources :

Example 1 with UndertowBuilderCustomizer

use of org.springframework.boot.web.embedded.undertow.UndertowBuilderCustomizer in project spring-boot by spring-projects.

the class ServletWebServerFactoryAutoConfigurationTests method undertowBuilderCustomizerRegisteredAsBeanAndViaFactoryIsOnlyCalledOnce.

@Test
void undertowBuilderCustomizerRegisteredAsBeanAndViaFactoryIsOnlyCalledOnce() {
    WebApplicationContextRunner runner = new WebApplicationContextRunner(AnnotationConfigServletWebServerApplicationContext::new).withClassLoader(new FilteredClassLoader(Tomcat.class, HttpServer.class, Server.class)).withConfiguration(AutoConfigurations.of(ServletWebServerFactoryAutoConfiguration.class)).withUserConfiguration(DoubleRegistrationUndertowBuilderCustomizerConfiguration.class).withPropertyValues("server.port: 0");
    runner.run((context) -> {
        UndertowServletWebServerFactory factory = context.getBean(UndertowServletWebServerFactory.class);
        UndertowBuilderCustomizer customizer = context.getBean("builderCustomizer", UndertowBuilderCustomizer.class);
        assertThat(factory.getBuilderCustomizers()).contains(customizer);
        then(customizer).should().customize(any(Builder.class));
    });
}
Also used : WebApplicationContextRunner(org.springframework.boot.test.context.runner.WebApplicationContextRunner) UndertowBuilderCustomizer(org.springframework.boot.web.embedded.undertow.UndertowBuilderCustomizer) AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) UndertowServletWebServerFactory(org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory) Builder(io.undertow.Undertow.Builder) FilteredClassLoader(org.springframework.boot.test.context.FilteredClassLoader) Test(org.junit.jupiter.api.Test)

Example 2 with UndertowBuilderCustomizer

use of org.springframework.boot.web.embedded.undertow.UndertowBuilderCustomizer in project spring-boot by spring-projects.

the class UndertowWebServerFactoryCustomizerTests method mockFactory.

private ConfigurableUndertowWebServerFactory mockFactory(Builder builder) {
    ConfigurableUndertowWebServerFactory factory = mock(ConfigurableUndertowWebServerFactory.class);
    willAnswer((invocation) -> {
        Object argument = invocation.getArgument(0);
        Arrays.stream((argument instanceof UndertowBuilderCustomizer) ? new UndertowBuilderCustomizer[] { (UndertowBuilderCustomizer) argument } : (UndertowBuilderCustomizer[]) argument).forEach((customizer) -> customizer.customize(builder));
        return null;
    }).given(factory).addBuilderCustomizers(any());
    return factory;
}
Also used : UndertowBuilderCustomizer(org.springframework.boot.web.embedded.undertow.UndertowBuilderCustomizer) ConfigurableUndertowWebServerFactory(org.springframework.boot.web.embedded.undertow.ConfigurableUndertowWebServerFactory)

Example 3 with UndertowBuilderCustomizer

use of org.springframework.boot.web.embedded.undertow.UndertowBuilderCustomizer in project spring-boot by spring-projects.

the class ReactiveWebServerFactoryAutoConfigurationTests method undertowBuilderCustomizerRegisteredAsBeanAndViaFactoryIsOnlyCalledOnce.

@Test
void undertowBuilderCustomizerRegisteredAsBeanAndViaFactoryIsOnlyCalledOnce() {
    new ReactiveWebApplicationContextRunner(AnnotationConfigReactiveWebServerApplicationContext::new).withConfiguration(AutoConfigurations.of(ReactiveWebServerFactoryAutoConfiguration.class)).withClassLoader(new FilteredClassLoader(Tomcat.class, HttpServer.class, Server.class)).withUserConfiguration(DoubleRegistrationUndertowBuilderCustomizerConfiguration.class, HttpHandlerConfiguration.class).withPropertyValues("server.port: 0").run((context) -> {
        UndertowReactiveWebServerFactory factory = context.getBean(UndertowReactiveWebServerFactory.class);
        UndertowBuilderCustomizer customizer = context.getBean("builderCustomizer", UndertowBuilderCustomizer.class);
        assertThat(factory.getBuilderCustomizers()).contains(customizer);
        then(customizer).should().customize(any(Builder.class));
    });
}
Also used : UndertowBuilderCustomizer(org.springframework.boot.web.embedded.undertow.UndertowBuilderCustomizer) Builder(io.undertow.Undertow.Builder) UndertowReactiveWebServerFactory(org.springframework.boot.web.embedded.undertow.UndertowReactiveWebServerFactory) ReactiveWebApplicationContextRunner(org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner) FilteredClassLoader(org.springframework.boot.test.context.FilteredClassLoader) Test(org.junit.jupiter.api.Test)

Aggregations

UndertowBuilderCustomizer (org.springframework.boot.web.embedded.undertow.UndertowBuilderCustomizer)3 Builder (io.undertow.Undertow.Builder)2 Test (org.junit.jupiter.api.Test)2 FilteredClassLoader (org.springframework.boot.test.context.FilteredClassLoader)2 ReactiveWebApplicationContextRunner (org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner)1 WebApplicationContextRunner (org.springframework.boot.test.context.runner.WebApplicationContextRunner)1 ConfigurableUndertowWebServerFactory (org.springframework.boot.web.embedded.undertow.ConfigurableUndertowWebServerFactory)1 UndertowReactiveWebServerFactory (org.springframework.boot.web.embedded.undertow.UndertowReactiveWebServerFactory)1 UndertowServletWebServerFactory (org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory)1 AnnotationConfigServletWebServerApplicationContext (org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext)1