Search in sources :

Example 11 with FilteredClassLoader

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

the class ServletWebServerFactoryAutoConfigurationTests method jettyServerCustomizerRegisteredAsBeanAndViaFactoryIsOnlyCalledOnce.

@Test
void jettyServerCustomizerRegisteredAsBeanAndViaFactoryIsOnlyCalledOnce() {
    WebApplicationContextRunner runner = new WebApplicationContextRunner(AnnotationConfigServletWebServerApplicationContext::new).withClassLoader(new FilteredClassLoader(Tomcat.class, HttpServer.class)).withConfiguration(AutoConfigurations.of(ServletWebServerFactoryAutoConfiguration.class)).withUserConfiguration(DoubleRegistrationJettyServerCustomizerConfiguration.class).withPropertyValues("server.port: 0");
    runner.run((context) -> {
        JettyServletWebServerFactory factory = context.getBean(JettyServletWebServerFactory.class);
        JettyServerCustomizer customizer = context.getBean("serverCustomizer", JettyServerCustomizer.class);
        assertThat(factory.getServerCustomizers()).contains(customizer);
        then(customizer).should().customize(any(Server.class));
    });
}
Also used : JettyServerCustomizer(org.springframework.boot.web.embedded.jetty.JettyServerCustomizer) WebApplicationContextRunner(org.springframework.boot.test.context.runner.WebApplicationContextRunner) Server(org.eclipse.jetty.server.Server) HttpServer(reactor.netty.http.server.HttpServer) 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 12 with FilteredClassLoader

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

the class ClientHttpConnectorAutoConfigurationTests method whenReactorIsUnavailableThenJettyBeansAreDefined.

@Test
void whenReactorIsUnavailableThenJettyBeansAreDefined() {
    this.contextRunner.withClassLoader(new FilteredClassLoader(HttpClient.class)).run((context) -> {
        BeanDefinition customizerDefinition = context.getBeanFactory().getBeanDefinition("clientConnectorCustomizer");
        assertThat(customizerDefinition.isLazyInit()).isTrue();
        BeanDefinition connectorDefinition = context.getBeanFactory().getBeanDefinition("jettyClientHttpConnector");
        assertThat(connectorDefinition.isLazyInit()).isTrue();
        assertThat(context).hasBean("jettyClientResourceFactory");
    });
}
Also used : BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) FilteredClassLoader(org.springframework.boot.test.context.FilteredClassLoader) Test(org.junit.jupiter.api.Test)

Example 13 with FilteredClassLoader

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

the class ClientHttpConnectorAutoConfigurationTests method whenReactorAndJettyAreUnavailableThenHttpClientBeansAreDefined.

@Test
void whenReactorAndJettyAreUnavailableThenHttpClientBeansAreDefined() {
    this.contextRunner.withClassLoader(new FilteredClassLoader(HttpClient.class, ReactiveRequest.class)).run((context) -> {
        BeanDefinition customizerDefinition = context.getBeanFactory().getBeanDefinition("clientConnectorCustomizer");
        assertThat(customizerDefinition.isLazyInit()).isTrue();
        BeanDefinition connectorDefinition = context.getBeanFactory().getBeanDefinition("httpComponentsClientHttpConnector");
        assertThat(connectorDefinition.isLazyInit()).isTrue();
    });
}
Also used : BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) FilteredClassLoader(org.springframework.boot.test.context.FilteredClassLoader) Test(org.junit.jupiter.api.Test)

Example 14 with FilteredClassLoader

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

Example 15 with FilteredClassLoader

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

the class ReactiveWebServerFactoryAutoConfigurationTests method nettyServerCustomizerBeanIsAddedToFactory.

@Test
void nettyServerCustomizerBeanIsAddedToFactory() {
    new ReactiveWebApplicationContextRunner(AnnotationConfigReactiveWebApplicationContext::new).withConfiguration(AutoConfigurations.of(ReactiveWebServerFactoryAutoConfiguration.class)).withClassLoader(new FilteredClassLoader(Tomcat.class, Server.class, Undertow.class)).withUserConfiguration(NettyServerCustomizerConfiguration.class, HttpHandlerConfiguration.class).run((context) -> {
        NettyReactiveWebServerFactory factory = context.getBean(NettyReactiveWebServerFactory.class);
        assertThat(factory.getServerCustomizers()).hasSize(1);
    });
}
Also used : NettyReactiveWebServerFactory(org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory) Tomcat(org.apache.catalina.startup.Tomcat) Server(org.eclipse.jetty.server.Server) HttpServer(reactor.netty.http.server.HttpServer) Undertow(io.undertow.Undertow) ReactiveWebApplicationContextRunner(org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner) AnnotationConfigReactiveWebApplicationContext(org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebApplicationContext) FilteredClassLoader(org.springframework.boot.test.context.FilteredClassLoader) 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