Search in sources :

Example 36 with ApplicationContextRunner

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

the class ConfigurationPropertiesReportEndpointParentTests method configurationPropertiesBeanMethod.

@Test
void configurationPropertiesBeanMethod() {
    new ApplicationContextRunner().withUserConfiguration(Parent.class).run((parent) -> {
        new ApplicationContextRunner().withUserConfiguration(BeanMethodConfigurationProperties.class).withParent(parent).run((child) -> {
            ConfigurationPropertiesReportEndpoint endpoint = child.getBean(ConfigurationPropertiesReportEndpoint.class);
            ApplicationConfigurationProperties applicationProperties = endpoint.configurationProperties();
            assertThat(applicationProperties.getContexts().get(child.getId()).getBeans().keySet()).containsExactlyInAnyOrder("otherProperties");
            assertThat((applicationProperties.getContexts().get(parent.getId()).getBeans().keySet())).containsExactly("testProperties");
        });
    });
}
Also used : ApplicationConfigurationProperties(org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ApplicationConfigurationProperties) ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) Test(org.junit.jupiter.api.Test)

Example 37 with ApplicationContextRunner

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

the class ConfigurationPropertiesReportEndpointSerializationTests method testMap.

@Test
@SuppressWarnings("unchecked")
void testMap() {
    ApplicationContextRunner contextRunner = new ApplicationContextRunner().withUserConfiguration(MapConfig.class).withPropertyValues("foo.map.name:foo");
    contextRunner.run((context) -> {
        ConfigurationPropertiesReportEndpoint endpoint = context.getBean(ConfigurationPropertiesReportEndpoint.class);
        ApplicationConfigurationProperties applicationProperties = endpoint.configurationProperties();
        ConfigurationPropertiesBeanDescriptor fooProperties = applicationProperties.getContexts().get(context.getId()).getBeans().get("foo");
        assertThat(fooProperties).isNotNull();
        assertThat(fooProperties.getPrefix()).isEqualTo("foo");
        Map<String, Object> map = fooProperties.getProperties();
        assertThat(map).isNotNull();
        assertThat(map).hasSize(3);
        assertThat(((Map<String, Object>) map.get("map")).get("name")).isEqualTo("foo");
    });
}
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) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 38 with ApplicationContextRunner

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

the class ConfigurationPropertiesReportEndpointSerializationTests method testList.

@Test
@SuppressWarnings("unchecked")
void testList() {
    ApplicationContextRunner contextRunner = new ApplicationContextRunner().withUserConfiguration(ListConfig.class).withPropertyValues("foo.list[0]:foo");
    contextRunner.run((context) -> {
        ConfigurationPropertiesReportEndpoint endpoint = context.getBean(ConfigurationPropertiesReportEndpoint.class);
        ApplicationConfigurationProperties applicationProperties = endpoint.configurationProperties();
        ConfigurationPropertiesBeanDescriptor foo = applicationProperties.getContexts().get(context.getId()).getBeans().get("foo");
        assertThat(foo).isNotNull();
        assertThat(foo.getPrefix()).isEqualTo("foo");
        Map<String, Object> map = foo.getProperties();
        assertThat(map).isNotNull();
        assertThat(map).hasSize(3);
        assertThat(((List<String>) map.get("list")).get(0)).isEqualTo("foo");
    });
}
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) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 39 with ApplicationContextRunner

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

the class ConfigurationPropertiesReportEndpointSerializationTests method hikariDataSourceConfigurationPropertiesBeanCanBeSerialized.

@Test
void hikariDataSourceConfigurationPropertiesBeanCanBeSerialized() {
    ApplicationContextRunner contextRunner = new ApplicationContextRunner().withUserConfiguration(HikariDataSourceConfig.class);
    contextRunner.run((context) -> {
        ConfigurationPropertiesReportEndpoint endpoint = context.getBean(ConfigurationPropertiesReportEndpoint.class);
        ApplicationConfigurationProperties applicationProperties = endpoint.configurationProperties();
        ConfigurationPropertiesBeanDescriptor hikariDataSource = applicationProperties.getContexts().get(context.getId()).getBeans().get("hikariDataSource");
        Map<String, Object> nestedProperties = hikariDataSource.getProperties();
        assertThat(nestedProperties).doesNotContainKey("error");
    });
}
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 40 with ApplicationContextRunner

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

the class ConfigurationPropertiesReportEndpointSerializationTests method testEmptyMapIsNotAdded.

@Test
void testEmptyMapIsNotAdded() {
    ApplicationContextRunner contextRunner = new ApplicationContextRunner().withUserConfiguration(MapConfig.class);
    contextRunner.run((context) -> {
        ConfigurationPropertiesReportEndpoint endpoint = context.getBean(ConfigurationPropertiesReportEndpoint.class);
        ApplicationConfigurationProperties applicationProperties = endpoint.configurationProperties();
        ConfigurationPropertiesBeanDescriptor foo = applicationProperties.getContexts().get(context.getId()).getBeans().get("foo");
        assertThat(foo).isNotNull();
        assertThat(foo.getPrefix()).isEqualTo("foo");
        Map<String, Object> map = foo.getProperties();
        assertThat(map).isNotNull();
        assertThat(map).hasSize(2);
        assertThat(map).doesNotContainKey("map");
    });
}
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)

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