Search in sources :

Example 6 with FilteredClassLoader

use of org.springframework.boot.test.context.FilteredClassLoader in project spring-boot by spring-projects.

the class ServletWebServerFactoryAutoConfigurationTests method undertowBuilderCustomizerBeanIsAddedToFactory.

@Test
void undertowBuilderCustomizerBeanIsAddedToFactory() {
    WebApplicationContextRunner runner = new WebApplicationContextRunner(AnnotationConfigServletWebServerApplicationContext::new).withClassLoader(new FilteredClassLoader(Tomcat.class, HttpServer.class, Server.class)).withConfiguration(AutoConfigurations.of(ServletWebServerFactoryAutoConfiguration.class)).withUserConfiguration(UndertowBuilderCustomizerConfiguration.class).withPropertyValues("server.port:0");
    runner.run((context) -> {
        UndertowServletWebServerFactory factory = context.getBean(UndertowServletWebServerFactory.class);
        assertThat(factory.getBuilderCustomizers()).hasSize(1);
    });
}
Also used : WebApplicationContextRunner(org.springframework.boot.test.context.runner.WebApplicationContextRunner) AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) UndertowServletWebServerFactory(org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory) FilteredClassLoader(org.springframework.boot.test.context.FilteredClassLoader) Test(org.junit.jupiter.api.Test)

Example 7 with FilteredClassLoader

use of org.springframework.boot.test.context.FilteredClassLoader 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 8 with FilteredClassLoader

use of org.springframework.boot.test.context.FilteredClassLoader in project spring-boot by spring-projects.

the class ServletWebServerFactoryAutoConfigurationTests method undertowDeploymentInfoCustomizerBeanIsAddedToFactory.

@Test
void undertowDeploymentInfoCustomizerBeanIsAddedToFactory() {
    WebApplicationContextRunner runner = new WebApplicationContextRunner(AnnotationConfigServletWebServerApplicationContext::new).withClassLoader(new FilteredClassLoader(Tomcat.class, HttpServer.class, Server.class)).withConfiguration(AutoConfigurations.of(ServletWebServerFactoryAutoConfiguration.class)).withUserConfiguration(UndertowDeploymentInfoCustomizerConfiguration.class).withPropertyValues("server.port:0");
    runner.run((context) -> {
        UndertowServletWebServerFactory factory = context.getBean(UndertowServletWebServerFactory.class);
        assertThat(factory.getDeploymentInfoCustomizers()).hasSize(1);
    });
}
Also used : WebApplicationContextRunner(org.springframework.boot.test.context.runner.WebApplicationContextRunner) AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) UndertowServletWebServerFactory(org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory) FilteredClassLoader(org.springframework.boot.test.context.FilteredClassLoader) Test(org.junit.jupiter.api.Test)

Example 9 with FilteredClassLoader

use of org.springframework.boot.test.context.FilteredClassLoader in project spring-boot by spring-projects.

the class ServletWebServerFactoryAutoConfigurationTests method jettyServerCustomizerBeanIsAddedToFactory.

@Test
void jettyServerCustomizerBeanIsAddedToFactory() {
    WebApplicationContextRunner runner = new WebApplicationContextRunner(AnnotationConfigServletWebServerApplicationContext::new).withClassLoader(new FilteredClassLoader(Tomcat.class, HttpServer.class)).withConfiguration(AutoConfigurations.of(ServletWebServerFactoryAutoConfiguration.class)).withUserConfiguration(JettyServerCustomizerConfiguration.class).withPropertyValues("server.port:0");
    runner.run((context) -> {
        JettyServletWebServerFactory factory = context.getBean(JettyServletWebServerFactory.class);
        assertThat(factory.getServerCustomizers()).hasSize(1);
    });
}
Also used : WebApplicationContextRunner(org.springframework.boot.test.context.runner.WebApplicationContextRunner) AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) JettyServletWebServerFactory(org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory) FilteredClassLoader(org.springframework.boot.test.context.FilteredClassLoader) Test(org.junit.jupiter.api.Test)

Example 10 with FilteredClassLoader

use of org.springframework.boot.test.context.FilteredClassLoader in project spring-boot by spring-projects.

the class ServletWebServerFactoryAutoConfigurationTests method relativeRedirectsShouldNotBeEnabledWhenNotUsingTomcatContainer.

@Test
void relativeRedirectsShouldNotBeEnabledWhenNotUsingTomcatContainer() {
    WebApplicationContextRunner runner = new WebApplicationContextRunner(AnnotationConfigServletWebServerApplicationContext::new).withClassLoader(new FilteredClassLoader(Tomcat.class)).withConfiguration(AutoConfigurations.of(ServletWebServerFactoryAutoConfiguration.class)).withPropertyValues("server.forward-headers-strategy=framework", "server.port=0");
    runner.run((context) -> {
        Filter filter = context.getBean(FilterRegistrationBean.class).getFilter();
        assertThat(filter).isInstanceOf(ForwardedHeaderFilter.class);
        assertThat(filter).extracting("relativeRedirects").isEqualTo(false);
    });
}
Also used : Tomcat(org.apache.catalina.startup.Tomcat) WebApplicationContextRunner(org.springframework.boot.test.context.runner.WebApplicationContextRunner) Filter(jakarta.servlet.Filter) ForwardedHeaderFilter(org.springframework.web.filter.ForwardedHeaderFilter) FilteredClassLoader(org.springframework.boot.test.context.FilteredClassLoader) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) Test(org.junit.jupiter.api.Test)

Aggregations

FilteredClassLoader (org.springframework.boot.test.context.FilteredClassLoader)31 Test (org.junit.jupiter.api.Test)27 WebApplicationContextRunner (org.springframework.boot.test.context.runner.WebApplicationContextRunner)8 AnnotationConfigServletWebServerApplicationContext (org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext)7 ReactiveWebApplicationContextRunner (org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner)6 HttpServer (reactor.netty.http.server.HttpServer)6 Tomcat (org.apache.catalina.startup.Tomcat)4 Server (org.eclipse.jetty.server.Server)4 UndertowServletWebServerFactory (org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory)4 AnnotationConfigReactiveWebApplicationContext (org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebApplicationContext)3 Builder (io.undertow.Undertow.Builder)2 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)2 JettyReactiveWebServerFactory (org.springframework.boot.web.embedded.jetty.JettyReactiveWebServerFactory)2 JettyServerCustomizer (org.springframework.boot.web.embedded.jetty.JettyServerCustomizer)2 JettyServletWebServerFactory (org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory)2 NettyReactiveWebServerFactory (org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory)2 UndertowBuilderCustomizer (org.springframework.boot.web.embedded.undertow.UndertowBuilderCustomizer)2 UndertowReactiveWebServerFactory (org.springframework.boot.web.embedded.undertow.UndertowReactiveWebServerFactory)2 Gson (com.google.gson.Gson)1 Config (com.hazelcast.config.Config)1