Search in sources :

Example 16 with ApplicationContextRunner

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

the class MongoDataAutoConfigurationTests method backsOffIfMongoClientBeanIsNotPresent.

@Test
void backsOffIfMongoClientBeanIsNotPresent() {
    ApplicationContextRunner runner = new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(MongoDataAutoConfiguration.class));
    runner.run((context) -> assertThat(context).doesNotHaveBean(MongoTemplate.class));
}
Also used : ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) MongoTemplate(org.springframework.data.mongodb.core.MongoTemplate) Test(org.junit.jupiter.api.Test)

Example 17 with ApplicationContextRunner

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

the class MongoReactiveDataAutoConfigurationTests method backsOffIfMongoClientBeanIsNotPresent.

@Test
void backsOffIfMongoClientBeanIsNotPresent() {
    ApplicationContextRunner runner = new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class, MongoReactiveDataAutoConfiguration.class));
    runner.run((context) -> assertThat(context).doesNotHaveBean(MongoReactiveDataAutoConfiguration.class));
}
Also used : ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) PropertyPlaceholderAutoConfiguration(org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration) Test(org.junit.jupiter.api.Test)

Example 18 with ApplicationContextRunner

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

the class ConfigurationPropertiesReportEndpointProxyTests method testWithProxyClass.

@Test
void testWithProxyClass() {
    ApplicationContextRunner contextRunner = new ApplicationContextRunner().withUserConfiguration(Config.class, SqlExecutor.class);
    contextRunner.run((context) -> {
        ApplicationConfigurationProperties applicationProperties = context.getBean(ConfigurationPropertiesReportEndpoint.class).configurationProperties();
        assertThat(applicationProperties.getContexts().get(context.getId()).getBeans().values().stream().map(ConfigurationPropertiesBeanDescriptor::getPrefix).filter("executor.sql"::equals).findFirst()).isNotEmpty();
    });
}
Also used : 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 19 with ApplicationContextRunner

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

the class ConfigurationPropertiesReportEndpointProxyTests method proxiedConstructorBoundPropertiesShouldBeAvailableInReport.

@Test
void proxiedConstructorBoundPropertiesShouldBeAvailableInReport() {
    ApplicationContextRunner contextRunner = new ApplicationContextRunner().withUserConfiguration(ValidatedConfiguration.class).withPropertyValues("validated.name=baz");
    contextRunner.run((context) -> {
        ApplicationConfigurationProperties applicationProperties = context.getBean(ConfigurationPropertiesReportEndpoint.class).configurationProperties();
        Map<String, Object> properties = applicationProperties.getContexts().get(context.getId()).getBeans().values().stream().map(ConfigurationPropertiesBeanDescriptor::getProperties).findFirst().get();
        assertThat(properties.get("name")).isEqualTo("baz");
    });
}
Also used : 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 20 with ApplicationContextRunner

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

the class ConfigurationPropertiesReportEndpointFilteringTests method filterByPrefixSingleMatch.

@Test
void filterByPrefixSingleMatch() {
    ApplicationContextRunner contextRunner = new ApplicationContextRunner().withUserConfiguration(Config.class).withPropertyValues("foo.primary.name:foo1", "foo.secondary.name:foo2", "only.bar.name:solo1");
    contextRunner.run((context) -> {
        ConfigurationPropertiesReportEndpoint endpoint = context.getBean(ConfigurationPropertiesReportEndpoint.class);
        ApplicationConfigurationProperties applicationProperties = endpoint.configurationPropertiesWithPrefix("only.bar");
        assertThat(applicationProperties.getContexts()).containsOnlyKeys(context.getId());
        ContextConfigurationProperties contextProperties = applicationProperties.getContexts().get(context.getId());
        assertThat(contextProperties.getBeans().values()).singleElement().hasFieldOrPropertyWithValue("prefix", "only.bar");
    });
}
Also used : ContextConfigurationProperties(org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ContextConfigurationProperties) ApplicationConfigurationProperties(org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ApplicationConfigurationProperties) ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) 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