Search in sources :

Example 11 with ConfigurationPropertiesBeanDescriptor

use of org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ConfigurationPropertiesBeanDescriptor 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)

Example 12 with ConfigurationPropertiesBeanDescriptor

use of org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ConfigurationPropertiesBeanDescriptor in project spring-boot by spring-projects.

the class ConfigurationPropertiesReportEndpointSerializationTests method endpointResponseUsesPlaceholderForComplexValueAsPropertyValue.

@Test
@SuppressWarnings("unchecked")
void endpointResponseUsesPlaceholderForComplexValueAsPropertyValue() throws IOException {
    ApplicationContextRunner contextRunner = new ApplicationContextRunner().withInitializer((context) -> {
        ConfigurableEnvironment environment = context.getEnvironment();
        environment.getPropertySources().addFirst(new MapPropertySource("test", Collections.singletonMap("foo.name", new ComplexProperty("Spring Boot"))));
    }).withUserConfiguration(ComplexPropertyToStringConverter.class, FooConfig.class);
    contextRunner.run((context) -> {
        ConfigurationPropertiesReportEndpoint endpoint = context.getBean(ConfigurationPropertiesReportEndpoint.class);
        ApplicationConfigurationProperties applicationProperties = endpoint.configurationProperties();
        ConfigurationPropertiesBeanDescriptor descriptor = applicationProperties.getContexts().get(context.getId()).getBeans().get("foo");
        assertThat((Map<String, Object>) descriptor.getInputs().get("name")).containsEntry("value", "Complex property value " + ComplexProperty.class.getName());
    });
}
Also used : Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashMap(java.util.HashMap) ConfigurationProperties(org.springframework.boot.context.properties.ConfigurationProperties) ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) ArrayList(java.util.ArrayList) InetAddress(java.net.InetAddress) ByteArrayInputStream(java.io.ByteArrayInputStream) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) Map(java.util.Map) EnableConfigurationProperties(org.springframework.boot.context.properties.EnableConfigurationProperties) Converter(org.springframework.core.convert.converter.Converter) ApplicationConfigurationProperties(org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ApplicationConfigurationProperties) Import(org.springframework.context.annotation.Import) IOException(java.io.IOException) Assertions.entry(org.assertj.core.api.Assertions.entry) Test(org.junit.jupiter.api.Test) ConfigurationPropertiesBinding(org.springframework.boot.context.properties.ConfigurationPropertiesBinding) Configuration(org.springframework.context.annotation.Configuration) List(java.util.List) ConfigurationPropertiesBeanDescriptor(org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ConfigurationPropertiesBeanDescriptor) MapPropertySource(org.springframework.core.env.MapPropertySource) HikariDataSource(com.zaxxer.hikari.HikariDataSource) InputStreamSource(org.springframework.core.io.InputStreamSource) Bean(org.springframework.context.annotation.Bean) Collections(java.util.Collections) InputStream(java.io.InputStream) ConfigurationPropertiesBeanDescriptor(org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ConfigurationPropertiesBeanDescriptor) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) ApplicationConfigurationProperties(org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ApplicationConfigurationProperties) MapPropertySource(org.springframework.core.env.MapPropertySource) ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 13 with ConfigurationPropertiesBeanDescriptor

use of org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ConfigurationPropertiesBeanDescriptor in project spring-boot by spring-projects.

the class ConfigurationPropertiesReportEndpointSerializationTests method endpointResponseUsesToStringOfCharSequenceAsPropertyValue.

@Test
@SuppressWarnings("unchecked")
void endpointResponseUsesToStringOfCharSequenceAsPropertyValue() throws IOException {
    ApplicationContextRunner contextRunner = new ApplicationContextRunner().withInitializer((context) -> {
        ConfigurableEnvironment environment = context.getEnvironment();
        environment.getPropertySources().addFirst(new MapPropertySource("test", Collections.singletonMap("foo.name", new CharSequenceProperty("Spring Boot"))));
    }).withUserConfiguration(FooConfig.class);
    contextRunner.run((context) -> {
        ConfigurationPropertiesReportEndpoint endpoint = context.getBean(ConfigurationPropertiesReportEndpoint.class);
        ApplicationConfigurationProperties applicationProperties = endpoint.configurationProperties();
        ConfigurationPropertiesBeanDescriptor descriptor = applicationProperties.getContexts().get(context.getId()).getBeans().get("foo");
        assertThat((Map<String, Object>) descriptor.getInputs().get("name")).containsEntry("value", "Spring Boot");
    });
}
Also used : Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashMap(java.util.HashMap) ConfigurationProperties(org.springframework.boot.context.properties.ConfigurationProperties) ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) ArrayList(java.util.ArrayList) InetAddress(java.net.InetAddress) ByteArrayInputStream(java.io.ByteArrayInputStream) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) Map(java.util.Map) EnableConfigurationProperties(org.springframework.boot.context.properties.EnableConfigurationProperties) Converter(org.springframework.core.convert.converter.Converter) ApplicationConfigurationProperties(org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ApplicationConfigurationProperties) Import(org.springframework.context.annotation.Import) IOException(java.io.IOException) Assertions.entry(org.assertj.core.api.Assertions.entry) Test(org.junit.jupiter.api.Test) ConfigurationPropertiesBinding(org.springframework.boot.context.properties.ConfigurationPropertiesBinding) Configuration(org.springframework.context.annotation.Configuration) List(java.util.List) ConfigurationPropertiesBeanDescriptor(org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ConfigurationPropertiesBeanDescriptor) MapPropertySource(org.springframework.core.env.MapPropertySource) HikariDataSource(com.zaxxer.hikari.HikariDataSource) InputStreamSource(org.springframework.core.io.InputStreamSource) Bean(org.springframework.context.annotation.Bean) Collections(java.util.Collections) InputStream(java.io.InputStream) ConfigurationPropertiesBeanDescriptor(org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ConfigurationPropertiesBeanDescriptor) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) ApplicationConfigurationProperties(org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ApplicationConfigurationProperties) MapPropertySource(org.springframework.core.env.MapPropertySource) ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 14 with ConfigurationPropertiesBeanDescriptor

use of org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ConfigurationPropertiesBeanDescriptor in project spring-boot by spring-projects.

the class ConfigurationPropertiesReportEndpointSerializationTests method testNestedNaming.

@Test
@SuppressWarnings("unchecked")
void testNestedNaming() {
    ApplicationContextRunner contextRunner = new ApplicationContextRunner().withUserConfiguration(FooConfig.class).withPropertyValues("foo.bar.name: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();
        Map<String, Object> map = foo.getProperties();
        assertThat(map).isNotNull();
        assertThat(map).hasSize(2);
        assertThat(((Map<String, Object>) map.get("bar")).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 15 with ConfigurationPropertiesBeanDescriptor

use of org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ConfigurationPropertiesBeanDescriptor in project spring-boot by spring-projects.

the class ConfigurationPropertiesReportEndpointSerializationTests method testCycle.

@Test
void testCycle() {
    ApplicationContextRunner contextRunner = new ApplicationContextRunner().withUserConfiguration(CycleConfig.class);
    contextRunner.run((context) -> {
        ConfigurationPropertiesReportEndpoint endpoint = context.getBean(ConfigurationPropertiesReportEndpoint.class);
        ApplicationConfigurationProperties applicationProperties = endpoint.configurationProperties();
        ConfigurationPropertiesBeanDescriptor cycle = applicationProperties.getContexts().get(context.getId()).getBeans().get("cycle");
        assertThat(cycle.getPrefix()).isEqualTo("cycle");
        Map<String, Object> map = cycle.getProperties();
        assertThat(map).isNotNull();
        assertThat(map).containsOnlyKeys("error");
        assertThat(map).containsEntry("error", "Cannot serialize 'cycle'");
    });
}
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

Test (org.junit.jupiter.api.Test)16 ApplicationConfigurationProperties (org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ApplicationConfigurationProperties)16 ConfigurationPropertiesBeanDescriptor (org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ConfigurationPropertiesBeanDescriptor)16 ApplicationContextRunner (org.springframework.boot.test.context.runner.ApplicationContextRunner)16 HashMap (java.util.HashMap)6 Map (java.util.Map)6 ArrayList (java.util.ArrayList)4 List (java.util.List)4 HikariDataSource (com.zaxxer.hikari.HikariDataSource)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 InetAddress (java.net.InetAddress)2 Collections (java.util.Collections)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assertions.entry (org.assertj.core.api.Assertions.entry)2 ContextConfigurationProperties (org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ContextConfigurationProperties)2 ConfigurationProperties (org.springframework.boot.context.properties.ConfigurationProperties)2 ConfigurationPropertiesBinding (org.springframework.boot.context.properties.ConfigurationPropertiesBinding)2 EnableConfigurationProperties (org.springframework.boot.context.properties.EnableConfigurationProperties)2