Search in sources :

Example 1 with ApplicationBeans

use of org.springframework.boot.actuate.beans.BeansEndpoint.ApplicationBeans 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)

Example 2 with ApplicationBeans

use of org.springframework.boot.actuate.beans.BeansEndpoint.ApplicationBeans in project spring-boot by spring-projects.

the class BeansEndpointTests method beansInParentContextAreFound.

@Test
void beansInParentContextAreFound() {
    ApplicationContextRunner parentRunner = new ApplicationContextRunner().withUserConfiguration(BeanConfiguration.class);
    parentRunner.run((parent) -> {
        new ApplicationContextRunner().withUserConfiguration(EndpointConfiguration.class).withParent(parent).run((child) -> {
            ApplicationBeans result = child.getBean(BeansEndpoint.class).beans();
            assertThat(result.getContexts().get(parent.getId()).getBeans()).containsKey("bean");
            assertThat(result.getContexts().get(child.getId()).getBeans()).containsKey("endpoint");
        });
    });
}
Also used : ApplicationBeans(org.springframework.boot.actuate.beans.BeansEndpoint.ApplicationBeans) ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) Test(org.junit.jupiter.api.Test)

Example 3 with ApplicationBeans

use of org.springframework.boot.actuate.beans.BeansEndpoint.ApplicationBeans in project spring-boot by spring-projects.

the class BeansEndpointTests method lazyBeansAreOmitted.

@Test
void lazyBeansAreOmitted() {
    ApplicationContextRunner contextRunner = new ApplicationContextRunner().withUserConfiguration(EndpointConfiguration.class, LazyBeanConfiguration.class);
    contextRunner.run((context) -> {
        ApplicationBeans result = context.getBean(BeansEndpoint.class).beans();
        ContextBeans contextDescriptor = result.getContexts().get(context.getId());
        assertThat(context).hasBean("lazyBean");
        assertThat(contextDescriptor.getBeans()).doesNotContainKey("lazyBean");
    });
}
Also used : ApplicationBeans(org.springframework.boot.actuate.beans.BeansEndpoint.ApplicationBeans) ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) ContextBeans(org.springframework.boot.actuate.beans.BeansEndpoint.ContextBeans) Test(org.junit.jupiter.api.Test)

Example 4 with ApplicationBeans

use of org.springframework.boot.actuate.beans.BeansEndpoint.ApplicationBeans in project spring-boot by spring-projects.

the class BeansEndpointTests method beansAreFound.

@Test
void beansAreFound() {
    ApplicationContextRunner contextRunner = new ApplicationContextRunner().withUserConfiguration(EndpointConfiguration.class);
    contextRunner.run((context) -> {
        ApplicationBeans result = context.getBean(BeansEndpoint.class).beans();
        ContextBeans descriptor = result.getContexts().get(context.getId());
        assertThat(descriptor.getParentId()).isNull();
        Map<String, BeanDescriptor> beans = descriptor.getBeans();
        assertThat(beans.size()).isLessThanOrEqualTo(context.getBeanDefinitionCount());
        assertThat(beans).containsKey("endpoint");
    });
}
Also used : 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) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)4 ApplicationBeans (org.springframework.boot.actuate.beans.BeansEndpoint.ApplicationBeans)4 ApplicationContextRunner (org.springframework.boot.test.context.runner.ApplicationContextRunner)4 ContextBeans (org.springframework.boot.actuate.beans.BeansEndpoint.ContextBeans)3 BeanDescriptor (org.springframework.boot.actuate.beans.BeansEndpoint.BeanDescriptor)2 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)1 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1 Bean (org.springframework.context.annotation.Bean)1 Configuration (org.springframework.context.annotation.Configuration)1 Lazy (org.springframework.context.annotation.Lazy)1