Search in sources :

Example 1 with ApplicationConfigurationProperties

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

the class ConfigurationPropertiesReportEndpointWebExtension method configurationPropertiesWithPrefix.

@ReadOperation
public WebEndpointResponse<ApplicationConfigurationProperties> configurationPropertiesWithPrefix(@Selector String prefix) {
    ApplicationConfigurationProperties configurationProperties = this.delegate.configurationPropertiesWithPrefix(prefix);
    boolean foundMatchingBeans = configurationProperties.getContexts().values().stream().anyMatch((context) -> !context.getBeans().isEmpty());
    return (foundMatchingBeans) ? new WebEndpointResponse<>(configurationProperties, WebEndpointResponse.STATUS_OK) : new WebEndpointResponse<>(WebEndpointResponse.STATUS_NOT_FOUND);
}
Also used : ApplicationConfigurationProperties(org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ApplicationConfigurationProperties) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation)

Example 2 with ApplicationConfigurationProperties

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

the class ConfigurationPropertiesReportEndpointSerializationTests method testInitializedMapAndList.

@Test
@SuppressWarnings("unchecked")
void testInitializedMapAndList() {
    ApplicationContextRunner contextRunner = new ApplicationContextRunner().withUserConfiguration(InitializedMapAndListPropertiesConfig.class).withPropertyValues("foo.map.entryOne:true", "foo.list[0]:abc");
    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.getPrefix()).isEqualTo("foo");
        Map<String, Object> propertiesMap = foo.getProperties();
        assertThat(propertiesMap).containsOnlyKeys("bar", "name", "map", "list");
        Map<String, Object> map = (Map<String, Object>) propertiesMap.get("map");
        assertThat(map).containsOnly(entry("entryOne", true));
        List<String> list = (List<String>) propertiesMap.get("list");
        assertThat(list).containsExactly("abc");
    });
}
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) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 3 with ApplicationConfigurationProperties

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

the class ConfigurationPropertiesReportEndpointSerializationTests method testNaming.

@Test
void testNaming() {
    ApplicationContextRunner contextRunner = new ApplicationContextRunner().withUserConfiguration(FooConfig.class).withPropertyValues("foo.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();
        assertThat(foo.getPrefix()).isEqualTo("foo");
        Map<String, Object> map = foo.getProperties();
        assertThat(map).isNotNull();
        assertThat(map).hasSize(2);
        assertThat(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) Test(org.junit.jupiter.api.Test)

Example 4 with ApplicationConfigurationProperties

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

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

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