Search in sources :

Example 1 with FilteredClassLoader

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

the class AbstractApplicationContextRunnerTests method consecutiveRunWithFilteredClassLoaderShouldHaveBeanWithLazyProperties.

@Test
void consecutiveRunWithFilteredClassLoaderShouldHaveBeanWithLazyProperties() {
    get().withClassLoader(new FilteredClassLoader(Gson.class)).withUserConfiguration(LazyConfig.class).run((context) -> assertThat(context).hasSingleBean(ExampleBeanWithLazyProperties.class));
    get().withClassLoader(new FilteredClassLoader(Gson.class)).withUserConfiguration(LazyConfig.class).run((context) -> assertThat(context).hasSingleBean(ExampleBeanWithLazyProperties.class));
}
Also used : Gson(com.google.gson.Gson) FilteredClassLoader(org.springframework.boot.test.context.FilteredClassLoader) Test(org.junit.jupiter.api.Test)

Example 2 with FilteredClassLoader

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

the class XADataSourceAutoConfigurationTests method createNonEmbeddedFromXAProperties.

@Test
void createNonEmbeddedFromXAProperties() {
    new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(XADataSourceAutoConfiguration.class)).withUserConfiguration(FromProperties.class).withClassLoader(new FilteredClassLoader("org.h2.Driver", "org.hsqldb.jdbcDriver")).withPropertyValues("spring.datasource.xa.data-source-class-name:com.ibm.db2.jcc.DB2XADataSource", "spring.datasource.xa.properties.user:test", "spring.datasource.xa.properties.password:secret").run((context) -> {
        MockXADataSourceWrapper wrapper = context.getBean(MockXADataSourceWrapper.class);
        XADataSource xaDataSource = wrapper.getXaDataSource();
        assertThat(xaDataSource).isInstanceOf(DB2XADataSource.class);
    });
}
Also used : DB2XADataSource(com.ibm.db2.jcc.DB2XADataSource) XADataSource(javax.sql.XADataSource) JDBCXADataSource(org.hsqldb.jdbc.pool.JDBCXADataSource) ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) FilteredClassLoader(org.springframework.boot.test.context.FilteredClassLoader) Test(org.junit.jupiter.api.Test)

Example 3 with FilteredClassLoader

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

the class AopAutoConfigurationTests method whenGlobalMethodSecurityIsEnabledAndAspectJIsNotAvailableThenClassProxyingIsStillUsedByDefault.

@Test
void whenGlobalMethodSecurityIsEnabledAndAspectJIsNotAvailableThenClassProxyingIsStillUsedByDefault() {
    this.contextRunner.withClassLoader(new FilteredClassLoader(Advice.class)).withUserConfiguration(ExampleController.class, EnableGlobalMethodSecurityConfiguration.class).run((context) -> {
        ExampleController exampleController = context.getBean(ExampleController.class);
        assertThat(AopUtils.isCglibProxy(exampleController)).isTrue();
    });
}
Also used : Advice(org.aspectj.weaver.Advice) FilteredClassLoader(org.springframework.boot.test.context.FilteredClassLoader) Test(org.junit.jupiter.api.Test)

Example 4 with FilteredClassLoader

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

the class R2dbcRepositoriesAutoConfigurationTests method backsOffWithNoDatabaseClientOperations.

@Test
void backsOffWithNoDatabaseClientOperations() {
    this.contextRunner.withConfiguration(AutoConfigurations.of(R2dbcAutoConfiguration.class)).withClassLoader(new FilteredClassLoader("org.springframework.r2dbc")).withUserConfiguration(TestConfiguration.class).run((context) -> {
        assertThat(context).doesNotHaveBean(DatabaseClient.class);
        assertThat(context).doesNotHaveBean(R2dbcRepositoryConfigurationExtension.class);
    });
}
Also used : FilteredClassLoader(org.springframework.boot.test.context.FilteredClassLoader) Test(org.junit.jupiter.api.Test)

Example 5 with FilteredClassLoader

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

the class HazelcastAutoConfigurationServerTests method autoConfiguredConfigWithoutHazelcastSpringDoesNotUseSpringManagedContext.

@Test
void autoConfiguredConfigWithoutHazelcastSpringDoesNotUseSpringManagedContext() {
    this.contextRunner.withClassLoader(new FilteredClassLoader(SpringManagedContext.class)).run((context) -> {
        Config config = context.getBean(HazelcastInstance.class).getConfig();
        assertThat(config.getManagedContext()).isNull();
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) QueueConfig(com.hazelcast.config.QueueConfig) 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