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();
});
}
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();
});
}
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));
});
}
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);
});
}
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));
});
}
Aggregations