use of org.springframework.boot.test.context.FilteredClassLoader in project spring-boot by spring-projects.
the class ConditionalOnJavaTests method getJavaVersion.
private String getJavaVersion(Class<?>... hiddenClasses) throws Exception {
FilteredClassLoader classLoader = new FilteredClassLoader(hiddenClasses);
Class<?> javaVersionClass = Class.forName(JavaVersion.class.getName(), false, classLoader);
Method getJavaVersionMethod = ReflectionUtils.findMethod(javaVersionClass, "getJavaVersion");
Object javaVersion = ReflectionUtils.invokeMethod(getJavaVersionMethod, null);
classLoader.close();
return javaVersion.toString();
}
use of org.springframework.boot.test.context.FilteredClassLoader in project spring-boot by spring-projects.
the class DataSourcePropertiesTests method determineUrlWithNoEmbeddedSupport.
@Test
void determineUrlWithNoEmbeddedSupport() throws Exception {
DataSourceProperties properties = new DataSourceProperties();
properties.setBeanClassLoader(new FilteredClassLoader("org.h2", "org.apache.derby", "org.hsqldb"));
properties.afterPropertiesSet();
assertThatExceptionOfType(DataSourceProperties.DataSourceBeanCreationException.class).isThrownBy(properties::determineUrl).withMessageContaining("Failed to determine suitable jdbc url");
}
use of org.springframework.boot.test.context.FilteredClassLoader in project spring-boot by spring-projects.
the class DataSourceAutoConfigurationTests method assertDataSource.
private <T extends DataSource> void assertDataSource(Class<T> expectedType, List<String> hiddenPackages, Consumer<T> consumer) {
FilteredClassLoader classLoader = new FilteredClassLoader(StringUtils.toStringArray(hiddenPackages));
this.contextRunner.withClassLoader(classLoader).run((context) -> {
DataSource bean = context.getBean(DataSource.class);
assertThat(bean).isInstanceOf(expectedType);
consumer.accept(expectedType.cast(bean));
});
}
use of org.springframework.boot.test.context.FilteredClassLoader in project spring-boot by spring-projects.
the class ValidatorAdapterTests method wrapperWhenValidationProviderNotPresentShouldNotThrowException.
@Test
void wrapperWhenValidationProviderNotPresentShouldNotThrowException() {
ClassPathResource hibernateValidator = new ClassPathResource("META-INF/services/jakarta.validation.spi.ValidationProvider");
this.contextRunner.withClassLoader(new FilteredClassLoader(FilteredClassLoader.ClassPathResourceFilter.of(hibernateValidator), FilteredClassLoader.PackageFilter.of("org.hibernate.validator"))).run((context) -> ValidatorAdapter.get(context, null));
}
use of org.springframework.boot.test.context.FilteredClassLoader in project spring-boot by spring-projects.
the class ReactiveWebServerFactoryAutoConfigurationTests method nettyServerCustomizerRegisteredAsBeanAndViaFactoryIsOnlyCalledOnce.
@Test
void nettyServerCustomizerRegisteredAsBeanAndViaFactoryIsOnlyCalledOnce() {
new ReactiveWebApplicationContextRunner(AnnotationConfigReactiveWebServerApplicationContext::new).withConfiguration(AutoConfigurations.of(ReactiveWebServerFactoryAutoConfiguration.class)).withClassLoader(new FilteredClassLoader(Tomcat.class, Server.class, Undertow.class)).withUserConfiguration(DoubleRegistrationNettyServerCustomizerConfiguration.class, HttpHandlerConfiguration.class).withPropertyValues("server.port: 0").run((context) -> {
NettyReactiveWebServerFactory factory = context.getBean(NettyReactiveWebServerFactory.class);
NettyServerCustomizer customizer = context.getBean("serverCustomizer", NettyServerCustomizer.class);
assertThat(factory.getServerCustomizers()).contains(customizer);
then(customizer).should().apply(any(HttpServer.class));
});
}
Aggregations