Search in sources :

Example 6 with EnvironmentDescriptor

use of org.springframework.boot.actuate.env.EnvironmentEndpoint.EnvironmentDescriptor in project spring-boot by spring-projects.

the class EnvironmentEndpointTests method keysMatchingCustomSanitizingFunctionHaveTheirValuesSanitized.

@Test
void keysMatchingCustomSanitizingFunctionHaveTheirValuesSanitized() {
    ConfigurableEnvironment environment = new StandardEnvironment();
    TestPropertyValues.of("other.service=abcde").applyTo(environment);
    TestPropertyValues.of("system.service=123456").applyToSystemProperties(() -> {
        EnvironmentDescriptor descriptor = new EnvironmentEndpoint(environment, Collections.singletonList((data) -> {
            String name = data.getPropertySource().getName();
            if (name.equals(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME)) {
                return data.withValue("******");
            }
            return data;
        })).environment(null);
        assertThat(propertySources(descriptor).get("test").getProperties().get("other.service").getValue()).isEqualTo("abcde");
        Map<String, PropertyValueDescriptor> systemProperties = propertySources(descriptor).get("systemProperties").getProperties();
        assertThat(systemProperties.get("system.service").getValue()).isEqualTo("******");
        return null;
    });
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) PropertyValueDescriptor(org.springframework.boot.actuate.env.EnvironmentEndpoint.PropertyValueDescriptor) EnvironmentDescriptor(org.springframework.boot.actuate.env.EnvironmentEndpoint.EnvironmentDescriptor) StandardEnvironment(org.springframework.core.env.StandardEnvironment) Test(org.junit.jupiter.api.Test)

Example 7 with EnvironmentDescriptor

use of org.springframework.boot.actuate.env.EnvironmentEndpoint.EnvironmentDescriptor in project spring-boot by spring-projects.

the class EnvironmentEndpointTests method compositeSourceIsHandledCorrectly.

@Test
void compositeSourceIsHandledCorrectly() {
    ConfigurableEnvironment environment = emptyEnvironment();
    CompositePropertySource source = new CompositePropertySource("composite");
    source.addPropertySource(new MapPropertySource("one", Collections.singletonMap("foo", "bar")));
    source.addPropertySource(new MapPropertySource("two", Collections.singletonMap("foo", "spam")));
    environment.getPropertySources().addFirst(source);
    EnvironmentDescriptor descriptor = new EnvironmentEndpoint(environment).environment(null);
    Map<String, PropertySourceDescriptor> sources = propertySources(descriptor);
    assertThat(sources.keySet()).containsExactly("composite:one", "composite:two");
    assertThat(sources.get("composite:one").getProperties().get("foo").getValue()).isEqualTo("bar");
    assertThat(sources.get("composite:two").getProperties().get("foo").getValue()).isEqualTo("spam");
}
Also used : PropertySourceDescriptor(org.springframework.boot.actuate.env.EnvironmentEndpoint.PropertySourceDescriptor) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) CompositePropertySource(org.springframework.core.env.CompositePropertySource) MapPropertySource(org.springframework.core.env.MapPropertySource) EnvironmentDescriptor(org.springframework.boot.actuate.env.EnvironmentEndpoint.EnvironmentDescriptor) Test(org.junit.jupiter.api.Test)

Example 8 with EnvironmentDescriptor

use of org.springframework.boot.actuate.env.EnvironmentEndpoint.EnvironmentDescriptor in project spring-boot by spring-projects.

the class EnvironmentEndpointTests method propertyWithPlaceholderNotResolved.

@Test
void propertyWithPlaceholderNotResolved() {
    ConfigurableEnvironment environment = emptyEnvironment();
    TestPropertyValues.of("my.foo: ${bar.blah}").applyTo(environment);
    EnvironmentDescriptor descriptor = new EnvironmentEndpoint(environment).environment(null);
    assertThat(propertySources(descriptor).get("test").getProperties().get("my.foo").getValue()).isEqualTo("${bar.blah}");
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) EnvironmentDescriptor(org.springframework.boot.actuate.env.EnvironmentEndpoint.EnvironmentDescriptor) Test(org.junit.jupiter.api.Test)

Example 9 with EnvironmentDescriptor

use of org.springframework.boot.actuate.env.EnvironmentEndpoint.EnvironmentDescriptor in project spring-boot by spring-projects.

the class EnvironmentEndpointTests method propertyWithSensitivePlaceholderResolved.

@Test
void propertyWithSensitivePlaceholderResolved() {
    ConfigurableEnvironment environment = emptyEnvironment();
    TestPropertyValues.of("my.foo: http://${bar.password}://hello", "bar.password: hello").applyTo(environment);
    EnvironmentDescriptor descriptor = new EnvironmentEndpoint(environment).environment(null);
    assertThat(propertySources(descriptor).get("test").getProperties().get("my.foo").getValue()).isEqualTo("http://******://hello");
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) EnvironmentDescriptor(org.springframework.boot.actuate.env.EnvironmentEndpoint.EnvironmentDescriptor) Test(org.junit.jupiter.api.Test)

Example 10 with EnvironmentDescriptor

use of org.springframework.boot.actuate.env.EnvironmentEndpoint.EnvironmentDescriptor in project spring-boot by spring-projects.

the class EnvironmentEndpointTests method propertyWithCharSequenceTypeIsConvertedToString.

@Test
void propertyWithCharSequenceTypeIsConvertedToString() {
    ConfigurableEnvironment environment = emptyEnvironment();
    environment.getPropertySources().addFirst(singleKeyPropertySource("test", "foo", new CharSequenceProperty()));
    EnvironmentDescriptor descriptor = new EnvironmentEndpoint(environment).environment(null);
    String value = (String) propertySources(descriptor).get("test").getProperties().get("foo").getValue();
    assertThat(value).isEqualTo("test value");
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) EnvironmentDescriptor(org.springframework.boot.actuate.env.EnvironmentEndpoint.EnvironmentDescriptor) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)17 EnvironmentDescriptor (org.springframework.boot.actuate.env.EnvironmentEndpoint.EnvironmentDescriptor)17 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)12 PropertyValueDescriptor (org.springframework.boot.actuate.env.EnvironmentEndpoint.PropertyValueDescriptor)7 StandardEnvironment (org.springframework.core.env.StandardEnvironment)5 PropertySourceDescriptor (org.springframework.boot.actuate.env.EnvironmentEndpoint.PropertySourceDescriptor)3 MapPropertySource (org.springframework.core.env.MapPropertySource)2 LinkedHashMap (java.util.LinkedHashMap)1 EnvironmentEndpoint (org.springframework.boot.actuate.env.EnvironmentEndpoint)1 CompositePropertySource (org.springframework.core.env.CompositePropertySource)1