Search in sources :

Example 46 with ApplicationContextRunner

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

the class ConfigurationPropertiesReportEndpointMethodAnnotationsTests method prefixFromBeanMethodConfigurationPropertiesCanOverridePrefixOnClass.

@Test
void prefixFromBeanMethodConfigurationPropertiesCanOverridePrefixOnClass() {
    ApplicationContextRunner contextRunner = new ApplicationContextRunner().withUserConfiguration(OverriddenPrefix.class).withPropertyValues("other.name:foo");
    contextRunner.run((context) -> {
        ConfigurationPropertiesReportEndpoint endpoint = context.getBean(ConfigurationPropertiesReportEndpoint.class);
        ApplicationConfigurationProperties applicationProperties = endpoint.configurationProperties();
        assertThat(applicationProperties.getContexts()).containsOnlyKeys(context.getId());
        ContextConfigurationProperties contextProperties = applicationProperties.getContexts().get(context.getId());
        ConfigurationPropertiesBeanDescriptor bar = contextProperties.getBeans().get("bar");
        assertThat(bar).isNotNull();
        assertThat(bar.getPrefix()).isEqualTo("other");
        assertThat(bar.getProperties()).isNotNull();
        assertThat(bar.getProperties()).isNotEmpty();
    });
}
Also used : ContextConfigurationProperties(org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ContextConfigurationProperties) ConfigurationPropertiesBeanDescriptor(org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ConfigurationPropertiesBeanDescriptor) ApplicationConfigurationProperties(org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ApplicationConfigurationProperties) ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) Test(org.junit.jupiter.api.Test)

Example 47 with ApplicationContextRunner

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

the class ConfigurationPropertiesReportEndpointMethodAnnotationsTests method testNaming.

@Test
void testNaming() {
    ApplicationContextRunner contextRunner = new ApplicationContextRunner().withUserConfiguration(Config.class).withPropertyValues("other.name:foo", "first.name:bar");
    contextRunner.run((context) -> {
        ConfigurationPropertiesReportEndpoint endpoint = context.getBean(ConfigurationPropertiesReportEndpoint.class);
        ApplicationConfigurationProperties applicationProperties = endpoint.configurationProperties();
        assertThat(applicationProperties.getContexts()).containsOnlyKeys(context.getId());
        ContextConfigurationProperties contextProperties = applicationProperties.getContexts().get(context.getId());
        ConfigurationPropertiesBeanDescriptor other = contextProperties.getBeans().get("other");
        assertThat(other).isNotNull();
        assertThat(other.getPrefix()).isEqualTo("other");
        assertThat(other.getProperties()).isNotNull();
        assertThat(other.getProperties()).isNotEmpty();
    });
}
Also used : ContextConfigurationProperties(org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ContextConfigurationProperties) ConfigurationPropertiesBeanDescriptor(org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ConfigurationPropertiesBeanDescriptor) ApplicationConfigurationProperties(org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ApplicationConfigurationProperties) ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) Test(org.junit.jupiter.api.Test)

Example 48 with ApplicationContextRunner

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

the class MeterRegistryConfigurerIntegrationTests method counterIsIncrementedOncePerEventWithCompositeMeterRegistry.

@Test
void counterIsIncrementedOncePerEventWithCompositeMeterRegistry() {
    new ApplicationContextRunner().with(MetricsRun.limitedTo(JmxMetricsExportAutoConfiguration.class, PrometheusMetricsExportAutoConfiguration.class)).withConfiguration(AutoConfigurations.of(LogbackMetricsAutoConfiguration.class)).run((context) -> {
        Logger logger = ((LoggerContext) StaticLoggerBinder.getSingleton().getLoggerFactory()).getLogger("test-logger");
        logger.error("Error.");
        Map<String, MeterRegistry> registriesByName = context.getBeansOfType(MeterRegistry.class);
        assertThat(registriesByName).hasSize(3);
        registriesByName.forEach((name, registry) -> assertThat(registry.get("logback.events").tag("level", "error").counter().count()).isEqualTo(1));
    });
}
Also used : PrometheusMetricsExportAutoConfiguration(org.springframework.boot.actuate.autoconfigure.metrics.export.prometheus.PrometheusMetricsExportAutoConfiguration) JmxMetricsExportAutoConfiguration(org.springframework.boot.actuate.autoconfigure.metrics.export.jmx.JmxMetricsExportAutoConfiguration) ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) Logger(ch.qos.logback.classic.Logger) LoggerContext(ch.qos.logback.classic.LoggerContext) CompositeMeterRegistry(io.micrometer.core.instrument.composite.CompositeMeterRegistry) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Test(org.junit.jupiter.api.Test)

Example 49 with ApplicationContextRunner

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

the class MeterRegistryConfigurerIntegrationTests method counterIsIncrementedOncePerEventWithoutCompositeMeterRegistry.

@Test
void counterIsIncrementedOncePerEventWithoutCompositeMeterRegistry() {
    new ApplicationContextRunner().with(MetricsRun.limitedTo(JmxMetricsExportAutoConfiguration.class)).withConfiguration(AutoConfigurations.of(LogbackMetricsAutoConfiguration.class)).run((context) -> {
        Logger logger = ((LoggerContext) StaticLoggerBinder.getSingleton().getLoggerFactory()).getLogger("test-logger");
        logger.error("Error.");
        Map<String, MeterRegistry> registriesByName = context.getBeansOfType(MeterRegistry.class);
        assertThat(registriesByName).hasSize(1);
        MeterRegistry registry = registriesByName.values().iterator().next();
        assertThat(registry.get("logback.events").tag("level", "error").counter().count()).isEqualTo(1);
    });
}
Also used : JmxMetricsExportAutoConfiguration(org.springframework.boot.actuate.autoconfigure.metrics.export.jmx.JmxMetricsExportAutoConfiguration) ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) Logger(ch.qos.logback.classic.Logger) LoggerContext(ch.qos.logback.classic.LoggerContext) CompositeMeterRegistry(io.micrometer.core.instrument.composite.CompositeMeterRegistry) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Test(org.junit.jupiter.api.Test)

Example 50 with ApplicationContextRunner

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

the class MetricsAutoConfigurationIntegrationTests method autoConfiguredCompositeDoesNotHaveMeterFiltersApplied.

@Test
void autoConfiguredCompositeDoesNotHaveMeterFiltersApplied() {
    new ApplicationContextRunner().with(MetricsRun.limitedTo(GraphiteMetricsExportAutoConfiguration.class, JmxMetricsExportAutoConfiguration.class)).run((context) -> {
        MeterRegistry composite = context.getBean(MeterRegistry.class);
        assertThat(composite).extracting("filters", InstanceOfAssertFactories.ARRAY).hasSize(0);
        assertThat(composite).isInstanceOf(CompositeMeterRegistry.class);
        Set<MeterRegistry> registries = ((CompositeMeterRegistry) composite).getRegistries();
        assertThat(registries).hasSize(2);
        assertThat(registries).hasAtLeastOneElementOfType(GraphiteMeterRegistry.class).hasAtLeastOneElementOfType(JmxMeterRegistry.class);
        assertThat(registries).allSatisfy((registry) -> assertThat(registry).extracting("filters", InstanceOfAssertFactories.ARRAY).hasSize(1));
    });
}
Also used : CompositeMeterRegistry(io.micrometer.core.instrument.composite.CompositeMeterRegistry) GraphiteMeterRegistry(io.micrometer.graphite.GraphiteMeterRegistry) ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) GraphiteMeterRegistry(io.micrometer.graphite.GraphiteMeterRegistry) CompositeMeterRegistry(io.micrometer.core.instrument.composite.CompositeMeterRegistry) JmxMeterRegistry(io.micrometer.jmx.JmxMeterRegistry) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Test(org.junit.jupiter.api.Test)

Aggregations

ApplicationContextRunner (org.springframework.boot.test.context.runner.ApplicationContextRunner)53 Test (org.junit.jupiter.api.Test)49 ApplicationConfigurationProperties (org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ApplicationConfigurationProperties)21 ConfigurationPropertiesBeanDescriptor (org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ConfigurationPropertiesBeanDescriptor)16 Map (java.util.Map)7 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)6 CompositeMeterRegistry (io.micrometer.core.instrument.composite.CompositeMeterRegistry)6 HashMap (java.util.HashMap)6 List (java.util.List)6 ArrayList (java.util.ArrayList)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 ContextConfigurationProperties (org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ContextConfigurationProperties)5 Bean (org.springframework.context.annotation.Bean)5 Configuration (org.springframework.context.annotation.Configuration)5 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)4 GraphiteMeterRegistry (io.micrometer.graphite.GraphiteMeterRegistry)4 JmxMeterRegistry (io.micrometer.jmx.JmxMeterRegistry)4 ApplicationBeans (org.springframework.boot.actuate.beans.BeansEndpoint.ApplicationBeans)4 Test (org.junit.Test)3 ContextBeans (org.springframework.boot.actuate.beans.BeansEndpoint.ContextBeans)3