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");
});
}
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));
}
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));
});
}
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));
}
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();
});
}
Aggregations