Search in sources :

Example 21 with FilteredClassLoader

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

the class HealthEndpointAutoConfigurationTests method runWhenNoReactorCreatesHealthContributorRegistryContainingHealthBeans.

@Test
void runWhenNoReactorCreatesHealthContributorRegistryContainingHealthBeans() {
    ClassLoader classLoader = new FilteredClassLoader(Mono.class, Flux.class);
    this.contextRunner.withClassLoader(classLoader).run((context) -> {
        HealthContributorRegistry registry = context.getBean(HealthContributorRegistry.class);
        Object[] names = registry.stream().map(NamedContributor::getName).toArray();
        assertThat(names).containsExactlyInAnyOrder("simple", "additional", "ping");
    });
}
Also used : HealthContributorRegistry(org.springframework.boot.actuate.health.HealthContributorRegistry) ReactiveHealthContributorRegistry(org.springframework.boot.actuate.health.ReactiveHealthContributorRegistry) DefaultReactiveHealthContributorRegistry(org.springframework.boot.actuate.health.DefaultReactiveHealthContributorRegistry) DefaultHealthContributorRegistry(org.springframework.boot.actuate.health.DefaultHealthContributorRegistry) FilteredClassLoader(org.springframework.boot.test.context.FilteredClassLoader) FilteredClassLoader(org.springframework.boot.test.context.FilteredClassLoader) Test(org.junit.jupiter.api.Test)

Example 22 with FilteredClassLoader

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

the class ServletWebServerFactoryAutoConfigurationTests method undertowServletWebServerFactoryCustomizerIsAutoConfigured.

@Test
void undertowServletWebServerFactoryCustomizerIsAutoConfigured() {
    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) -> assertThat(context).hasSingleBean(UndertowServletWebServerFactoryCustomizer.class));
}
Also used : WebApplicationContextRunner(org.springframework.boot.test.context.runner.WebApplicationContextRunner) AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) FilteredClassLoader(org.springframework.boot.test.context.FilteredClassLoader) Test(org.junit.jupiter.api.Test)

Example 23 with FilteredClassLoader

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

the class ServletWebServerFactoryAutoConfigurationTests method undertowDeploymentInfoCustomizerRegisteredAsBeanAndViaFactoryIsOnlyCalledOnce.

@Test
void undertowDeploymentInfoCustomizerRegisteredAsBeanAndViaFactoryIsOnlyCalledOnce() {
    WebApplicationContextRunner runner = new WebApplicationContextRunner(AnnotationConfigServletWebServerApplicationContext::new).withClassLoader(new FilteredClassLoader(Tomcat.class, HttpServer.class, Server.class)).withConfiguration(AutoConfigurations.of(ServletWebServerFactoryAutoConfiguration.class)).withUserConfiguration(DoubleRegistrationUndertowDeploymentInfoCustomizerConfiguration.class).withPropertyValues("server.port: 0");
    runner.run((context) -> {
        UndertowServletWebServerFactory factory = context.getBean(UndertowServletWebServerFactory.class);
        UndertowDeploymentInfoCustomizer customizer = context.getBean("deploymentInfoCustomizer", UndertowDeploymentInfoCustomizer.class);
        assertThat(factory.getDeploymentInfoCustomizers()).contains(customizer);
        then(customizer).should().customize(any(DeploymentInfo.class));
    });
}
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) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) UndertowDeploymentInfoCustomizer(org.springframework.boot.web.embedded.undertow.UndertowDeploymentInfoCustomizer) FilteredClassLoader(org.springframework.boot.test.context.FilteredClassLoader) Test(org.junit.jupiter.api.Test)

Example 24 with FilteredClassLoader

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

the class MockWebServiceClientAutoConfigurationTests method shouldNotRegisterMockWebServiceClientWhenItIsNotOnTheClasspath.

@Test
void shouldNotRegisterMockWebServiceClientWhenItIsNotOnTheClasspath() {
    FilteredClassLoader classLoader = new FilteredClassLoader(MockWebServiceClient.class);
    this.contextRunner.withClassLoader(classLoader).run((context) -> assertThat(context).doesNotHaveBean(MockWebServiceClient.class));
}
Also used : MockWebServiceClient(org.springframework.ws.test.server.MockWebServiceClient) FilteredClassLoader(org.springframework.boot.test.context.FilteredClassLoader) Test(org.junit.jupiter.api.Test)

Example 25 with FilteredClassLoader

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

the class WebTestClientAutoConfigurationTests method shouldNotApplySpringSecurityConfigurerWhenSpringSecurityNotOnClassPath.

@Test
@SuppressWarnings("unchecked")
void shouldNotApplySpringSecurityConfigurerWhenSpringSecurityNotOnClassPath() {
    FilteredClassLoader classLoader = new FilteredClassLoader(SecurityMockServerConfigurers.class);
    this.contextRunner.withUserConfiguration(BaseConfiguration.class).withClassLoader(classLoader).run((context) -> {
        WebTestClient webTestClient = context.getBean(WebTestClient.class);
        WebTestClient.Builder builder = (WebTestClient.Builder) ReflectionTestUtils.getField(webTestClient, "builder");
        WebHttpHandlerBuilder httpHandlerBuilder = (WebHttpHandlerBuilder) ReflectionTestUtils.getField(builder, "httpHandlerBuilder");
        List<WebFilter> filters = (List<WebFilter>) ReflectionTestUtils.getField(httpHandlerBuilder, "filters");
        assertThat(filters).isEmpty();
    });
}
Also used : WebFilter(org.springframework.web.server.WebFilter) WebTestClient(org.springframework.test.web.reactive.server.WebTestClient) WebHttpHandlerBuilder(org.springframework.web.server.adapter.WebHttpHandlerBuilder) WebHttpHandlerBuilder(org.springframework.web.server.adapter.WebHttpHandlerBuilder) List(java.util.List) 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