Search in sources :

Example 36 with ConfigurableListableBeanFactory

use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory in project spring-boot by spring-projects.

the class BatchAutoConfigurationTests method jobRepositoryBeansDependOnBatchDataSourceInitializer.

@Test
void jobRepositoryBeansDependOnBatchDataSourceInitializer() {
    this.contextRunner.withUserConfiguration(TestConfiguration.class, EmbeddedDataSourceConfiguration.class).run((context) -> {
        ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
        String[] jobRepositoryNames = beanFactory.getBeanNamesForType(JobRepository.class);
        assertThat(jobRepositoryNames).isNotEmpty();
        for (String jobRepositoryName : jobRepositoryNames) {
            assertThat(beanFactory.getBeanDefinition(jobRepositoryName).getDependsOn()).contains("batchDataSourceInitializer");
        }
    });
}
Also used : EmbeddedDataSourceConfiguration(org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) Test(org.junit.jupiter.api.Test)

Example 37 with ConfigurableListableBeanFactory

use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory in project spring-boot by spring-projects.

the class BatchAutoConfigurationTests method jobRepositoryBeansDependOnFlyway.

@Test
void jobRepositoryBeansDependOnFlyway() {
    this.contextRunner.withUserConfiguration(TestConfiguration.class, EmbeddedDataSourceConfiguration.class).withUserConfiguration(FlywayAutoConfiguration.class).withPropertyValues("spring.batch.initialize-schema=never").run((context) -> {
        ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
        String[] jobRepositoryNames = beanFactory.getBeanNamesForType(JobRepository.class);
        assertThat(jobRepositoryNames).isNotEmpty();
        for (String jobRepositoryName : jobRepositoryNames) {
            assertThat(beanFactory.getBeanDefinition(jobRepositoryName).getDependsOn()).contains("flyway", "flywayInitializer");
        }
    });
}
Also used : EmbeddedDataSourceConfiguration(org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) Test(org.junit.jupiter.api.Test)

Example 38 with ConfigurableListableBeanFactory

use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory in project spring-boot by spring-projects.

the class BatchAutoConfigurationTests method jobRepositoryBeansDependOnLiquibase.

@Test
void jobRepositoryBeansDependOnLiquibase() {
    this.contextRunner.withUserConfiguration(TestConfiguration.class, EmbeddedDataSourceConfiguration.class).withUserConfiguration(LiquibaseAutoConfiguration.class).withPropertyValues("spring.batch.initialize-schema=never").run((context) -> {
        ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
        String[] jobRepositoryNames = beanFactory.getBeanNamesForType(JobRepository.class);
        assertThat(jobRepositoryNames).isNotEmpty();
        for (String jobRepositoryName : jobRepositoryNames) {
            assertThat(beanFactory.getBeanDefinition(jobRepositoryName).getDependsOn()).contains("liquibase");
        }
    });
}
Also used : EmbeddedDataSourceConfiguration(org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) Test(org.junit.jupiter.api.Test)

Example 39 with ConfigurableListableBeanFactory

use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory in project spring-boot by spring-projects.

the class ConditionEvaluationReportTests method parent.

@Test
void parent() {
    this.beanFactory.setParentBeanFactory(new DefaultListableBeanFactory());
    ConditionEvaluationReport.get((ConfigurableListableBeanFactory) this.beanFactory.getParentBeanFactory());
    assertThat(this.report).isSameAs(ConditionEvaluationReport.get(this.beanFactory));
    assertThat(this.report).isNotNull();
    assertThat(this.report.getParent()).isNotNull();
    ConditionEvaluationReport.get((ConfigurableListableBeanFactory) this.beanFactory.getParentBeanFactory());
    assertThat(this.report).isSameAs(ConditionEvaluationReport.get(this.beanFactory));
    assertThat(this.report.getParent()).isSameAs(ConditionEvaluationReport.get((ConfigurableListableBeanFactory) this.beanFactory.getParentBeanFactory()));
}
Also used : DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) Test(org.junit.jupiter.api.Test)

Example 40 with ConfigurableListableBeanFactory

use of org.springframework.beans.factory.config.ConfigurableListableBeanFactory in project spring-boot by spring-projects.

the class BeansEndpointTests method infrastructureBeansAreOmitted.

@Test
void infrastructureBeansAreOmitted() {
    ApplicationContextRunner contextRunner = new ApplicationContextRunner().withUserConfiguration(EndpointConfiguration.class);
    contextRunner.run((context) -> {
        ConfigurableListableBeanFactory factory = (ConfigurableListableBeanFactory) context.getAutowireCapableBeanFactory();
        List<String> infrastructureBeans = Stream.of(context.getBeanDefinitionNames()).filter((name) -> BeanDefinition.ROLE_INFRASTRUCTURE == factory.getBeanDefinition(name).getRole()).collect(Collectors.toList());
        ApplicationBeans result = context.getBean(BeansEndpoint.class).beans();
        ContextBeans contextDescriptor = result.getContexts().get(context.getId());
        Map<String, BeanDescriptor> beans = contextDescriptor.getBeans();
        for (String infrastructureBean : infrastructureBeans) {
            assertThat(beans).doesNotContainKey(infrastructureBean);
        }
    });
}
Also used : Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ContextBeans(org.springframework.boot.actuate.beans.BeansEndpoint.ContextBeans) ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) Collectors(java.util.stream.Collectors) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) Test(org.junit.jupiter.api.Test) Configuration(org.springframework.context.annotation.Configuration) BeanDescriptor(org.springframework.boot.actuate.beans.BeansEndpoint.BeanDescriptor) List(java.util.List) Stream(java.util.stream.Stream) Map(java.util.Map) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) Lazy(org.springframework.context.annotation.Lazy) Bean(org.springframework.context.annotation.Bean) ApplicationBeans(org.springframework.boot.actuate.beans.BeansEndpoint.ApplicationBeans) ApplicationBeans(org.springframework.boot.actuate.beans.BeansEndpoint.ApplicationBeans) BeanDescriptor(org.springframework.boot.actuate.beans.BeansEndpoint.BeanDescriptor) ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) ContextBeans(org.springframework.boot.actuate.beans.BeansEndpoint.ContextBeans) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) Test(org.junit.jupiter.api.Test)

Aggregations

ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)104 Test (org.junit.Test)16 Test (org.junit.jupiter.api.Test)15 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)13 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)12 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)10 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)10 ApplicationContext (org.springframework.context.ApplicationContext)9 BeanDefinitionRegistry (org.springframework.beans.factory.support.BeanDefinitionRegistry)8 GenericBeanDefinition (org.springframework.beans.factory.support.GenericBeanDefinition)7 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)7 XmlWebApplicationContext (org.springframework.web.context.support.XmlWebApplicationContext)7 Map (java.util.Map)6 BeanFactory (org.springframework.beans.factory.BeanFactory)6 ListableBeanFactory (org.springframework.beans.factory.ListableBeanFactory)6 Collectors (java.util.stream.Collectors)5 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)5 HashMap (java.util.HashMap)4 BeanFactoryPostProcessor (org.springframework.beans.factory.config.BeanFactoryPostProcessor)4 SimpleApplicationEventMulticaster (org.springframework.context.event.SimpleApplicationEventMulticaster)4