Search in sources :

Example 1 with ContextConfigurationProperties

use of org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ContextConfigurationProperties in project spring-cloud-stream by spring-cloud.

the class BinderPropertiesTests method testSerializationWithNonStringValues.

@SuppressWarnings("unchecked")
@Test
public void testSerializationWithNonStringValues() {
    StaticApplicationContext context = new StaticApplicationContext();
    DefaultListableBeanFactory bf = (DefaultListableBeanFactory) context.getBeanFactory();
    BindingServiceProperties bindingServiceProperties = new BindingServiceProperties();
    bindingServiceProperties.setApplicationContext(context);
    bf.registerSingleton("bindingServiceProperties", bindingServiceProperties);
    BindingServiceProperties bsp = context.getBean(BindingServiceProperties.class);
    bsp.setApplicationContext(context);
    BinderProperties bp = new BinderProperties();
    bsp.setBinders(Collections.singletonMap("testBinder", bp));
    bp.getEnvironment().put("spring.rabbitmq.connection-timeout", 2345);
    bp.getEnvironment().put("foo", Collections.singletonMap("bar", "hello"));
    // using Spring Boot class to ensure that reliance on the same ObjectMapper configuration
    ConfigurationPropertiesReportEndpoint endpoint = new ConfigurationPropertiesReportEndpoint();
    endpoint.setApplicationContext(context);
    ContextConfigurationProperties configurationProperties = endpoint.configurationProperties().getContexts().values().iterator().next();
    Map<String, Object> properties = configurationProperties.getBeans().get("bindingServiceProperties").getProperties();
    assertFalse(properties.containsKey("error"));
    assertTrue(properties.containsKey("binders"));
    Map<String, Object> testBinder = (Map<String, Object>) ((Map<String, Object>) properties.get("binders")).get("testBinder");
    Map<String, Object> environment = (Map<String, Object>) testBinder.get("environment");
    assertTrue(environment.get("spring.rabbitmq.connection-timeout") instanceof Integer);
    assertTrue(environment.get("foo") instanceof Map);
}
Also used : ContextConfigurationProperties(org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ContextConfigurationProperties) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) ConfigurationPropertiesReportEndpoint(org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) Map(java.util.Map) Test(org.junit.Test)

Example 2 with ContextConfigurationProperties

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

the class ConfigurationPropertiesReportEndpointFilteringTests method filterByPrefixSingleMatch.

@Test
void filterByPrefixSingleMatch() {
    ApplicationContextRunner contextRunner = new ApplicationContextRunner().withUserConfiguration(Config.class).withPropertyValues("foo.primary.name:foo1", "foo.secondary.name:foo2", "only.bar.name:solo1");
    contextRunner.run((context) -> {
        ConfigurationPropertiesReportEndpoint endpoint = context.getBean(ConfigurationPropertiesReportEndpoint.class);
        ApplicationConfigurationProperties applicationProperties = endpoint.configurationPropertiesWithPrefix("only.bar");
        assertThat(applicationProperties.getContexts()).containsOnlyKeys(context.getId());
        ContextConfigurationProperties contextProperties = applicationProperties.getContexts().get(context.getId());
        assertThat(contextProperties.getBeans().values()).singleElement().hasFieldOrPropertyWithValue("prefix", "only.bar");
    });
}
Also used : ContextConfigurationProperties(org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ContextConfigurationProperties) ApplicationConfigurationProperties(org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ApplicationConfigurationProperties) ApplicationContextRunner(org.springframework.boot.test.context.runner.ApplicationContextRunner) Test(org.junit.jupiter.api.Test)

Example 3 with ContextConfigurationProperties

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

the class ConfigurationPropertiesReportEndpointFilteringTests method filterByPrefixMultipleMatches.

@Test
void filterByPrefixMultipleMatches() {
    ApplicationContextRunner contextRunner = new ApplicationContextRunner().withUserConfiguration(Config.class).withPropertyValues("foo.primary.name:foo1", "foo.secondary.name:foo2", "only.bar.name:solo1");
    contextRunner.run((context) -> {
        ConfigurationPropertiesReportEndpoint endpoint = context.getBean(ConfigurationPropertiesReportEndpoint.class);
        ApplicationConfigurationProperties applicationProperties = endpoint.configurationPropertiesWithPrefix("foo.");
        assertThat(applicationProperties.getContexts()).containsOnlyKeys(context.getId());
        ContextConfigurationProperties contextProperties = applicationProperties.getContexts().get(context.getId());
        assertThat(contextProperties.getBeans()).containsOnlyKeys("primaryFoo", "secondaryFoo");
    });
}
Also used : ContextConfigurationProperties(org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ContextConfigurationProperties) 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 ContextConfigurationProperties

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

the class ConfigurationPropertiesReportEndpointFilteringTests method filterByPrefixNoMatches.

@Test
void filterByPrefixNoMatches() {
    ApplicationContextRunner contextRunner = new ApplicationContextRunner().withUserConfiguration(Config.class).withPropertyValues("foo.primary.name:foo1", "foo.secondary.name:foo2", "only.bar.name:solo1");
    contextRunner.run((context) -> {
        ConfigurationPropertiesReportEndpoint endpoint = context.getBean(ConfigurationPropertiesReportEndpoint.class);
        ApplicationConfigurationProperties applicationProperties = endpoint.configurationPropertiesWithPrefix("foo.third");
        assertThat(applicationProperties.getContexts()).containsOnlyKeys(context.getId());
        ContextConfigurationProperties contextProperties = applicationProperties.getContexts().get(context.getId());
        assertThat(contextProperties.getBeans()).isEmpty();
    });
}
Also used : ContextConfigurationProperties(org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ContextConfigurationProperties) 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 ContextConfigurationProperties

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

the class ConfigurationPropertiesReportEndpointMethodAnnotationsTests method prefixFromBeanMethodConfigurationPropertiesCanOverridePrefixOnClass.

@Test
void prefixFromBeanMethodConfigurationPropertiesCanOverridePrefixOnClass() {
    ApplicationContextRunner contextRunner = new ApplicationContextRunner().withUserConfiguration(OverriddenPrefix.class).withPropertyValues("other.name:foo");
    contextRunner.run((context) -> {
        ConfigurationPropertiesReportEndpoint endpoint = context.getBean(ConfigurationPropertiesReportEndpoint.class);
        ApplicationConfigurationProperties applicationProperties = endpoint.configurationProperties();
        assertThat(applicationProperties.getContexts()).containsOnlyKeys(context.getId());
        ContextConfigurationProperties contextProperties = applicationProperties.getContexts().get(context.getId());
        ConfigurationPropertiesBeanDescriptor bar = contextProperties.getBeans().get("bar");
        assertThat(bar).isNotNull();
        assertThat(bar.getPrefix()).isEqualTo("other");
        assertThat(bar.getProperties()).isNotNull();
        assertThat(bar.getProperties()).isNotEmpty();
    });
}
Also used : ContextConfigurationProperties(org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ContextConfigurationProperties) 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

ContextConfigurationProperties (org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ContextConfigurationProperties)6 Test (org.junit.jupiter.api.Test)5 ApplicationConfigurationProperties (org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ApplicationConfigurationProperties)5 ApplicationContextRunner (org.springframework.boot.test.context.runner.ApplicationContextRunner)5 ConfigurationPropertiesBeanDescriptor (org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint.ConfigurationPropertiesBeanDescriptor)2 Map (java.util.Map)1 Test (org.junit.Test)1 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)1 ConfigurationPropertiesReportEndpoint (org.springframework.boot.actuate.context.properties.ConfigurationPropertiesReportEndpoint)1 StaticApplicationContext (org.springframework.context.support.StaticApplicationContext)1