Search in sources :

Example 41 with ApplicationContextRunner

use of org.springframework.boot.test.context.runner.ApplicationContextRunner 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 42 with ApplicationContextRunner

use of org.springframework.boot.test.context.runner.ApplicationContextRunner 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 43 with ApplicationContextRunner

use of org.springframework.boot.test.context.runner.ApplicationContextRunner 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 44 with ApplicationContextRunner

use of org.springframework.boot.test.context.runner.ApplicationContextRunner 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 45 with ApplicationContextRunner

use of org.springframework.boot.test.context.runner.ApplicationContextRunner 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

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