Search in sources :

Example 16 with ApplicationConfigurationProperties

use of org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ApplicationConfigurationProperties 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 17 with ApplicationConfigurationProperties

use of org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ApplicationConfigurationProperties 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 18 with ApplicationConfigurationProperties

use of org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ApplicationConfigurationProperties 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 19 with ApplicationConfigurationProperties

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

Example 20 with ApplicationConfigurationProperties

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

the class ConfigurationPropertiesReportEndpointSerializationTests method testInetAddress.

@Test
void testInetAddress() {
    ApplicationContextRunner contextRunner = new ApplicationContextRunner().withUserConfiguration(AddressedConfig.class).withPropertyValues("foo.address:192.168.1.10");
    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(map.get("address")).isEqualTo("192.168.1.10");
    });
}
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

ApplicationConfigurationProperties (org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ApplicationConfigurationProperties)22 Test (org.junit.jupiter.api.Test)21 ApplicationContextRunner (org.springframework.boot.test.context.runner.ApplicationContextRunner)21 ConfigurationPropertiesBeanDescriptor (org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ConfigurationPropertiesBeanDescriptor)16 HashMap (java.util.HashMap)6 Map (java.util.Map)6 ContextConfigurationProperties (org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ContextConfigurationProperties)5 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 ConfigurationProperties (org.springframework.boot.context.properties.ConfigurationProperties)2 ConfigurationPropertiesBinding (org.springframework.boot.context.properties.ConfigurationPropertiesBinding)2 EnableConfigurationProperties (org.springframework.boot.context.properties.EnableConfigurationProperties)2