Search in sources :

Example 96 with StandardEnvironment

use of org.springframework.core.env.StandardEnvironment in project spring-boot by spring-projects.

the class EnvironmentEndpointTests method emptyEnvironment.

private static ConfigurableEnvironment emptyEnvironment() {
    StandardEnvironment environment = new StandardEnvironment();
    environment.getPropertySources().remove(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME);
    environment.getPropertySources().remove(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME);
    return environment;
}
Also used : StandardEnvironment(org.springframework.core.env.StandardEnvironment)

Example 97 with StandardEnvironment

use of org.springframework.core.env.StandardEnvironment in project spring-boot by spring-projects.

the class EnvironmentEndpointTests method sensitiveKeysHaveTheirValuesSanitized.

@Test
void sensitiveKeysHaveTheirValuesSanitized() {
    TestPropertyValues.of("dbPassword=123456", "apiKey=123456", "mySecret=123456", "myCredentials=123456", "VCAP_SERVICES=123456").applyToSystemProperties(() -> {
        EnvironmentDescriptor descriptor = new EnvironmentEndpoint(new StandardEnvironment()).environment(null);
        Map<String, PropertyValueDescriptor> systemProperties = propertySources(descriptor).get("systemProperties").getProperties();
        assertThat(systemProperties.get("dbPassword").getValue()).isEqualTo("******");
        assertThat(systemProperties.get("apiKey").getValue()).isEqualTo("******");
        assertThat(systemProperties.get("mySecret").getValue()).isEqualTo("******");
        assertThat(systemProperties.get("myCredentials").getValue()).isEqualTo("******");
        assertThat(systemProperties.get("VCAP_SERVICES").getValue()).isEqualTo("******");
        PropertyValueDescriptor command = systemProperties.get("sun.java.command");
        if (command != null) {
            assertThat(command.getValue()).isEqualTo("******");
        }
        return null;
    });
}
Also used : 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 98 with StandardEnvironment

use of org.springframework.core.env.StandardEnvironment in project spring-boot by spring-projects.

the class EnvironmentEndpointTests method sensitiveKeysMatchingCustomNameHaveTheirValuesSanitized.

@Test
void sensitiveKeysMatchingCustomNameHaveTheirValuesSanitized() {
    TestPropertyValues.of("dbPassword=123456", "apiKey=123456").applyToSystemProperties(() -> {
        EnvironmentEndpoint endpoint = new EnvironmentEndpoint(new StandardEnvironment());
        endpoint.setKeysToSanitize("key");
        EnvironmentDescriptor descriptor = endpoint.environment(null);
        Map<String, PropertyValueDescriptor> systemProperties = propertySources(descriptor).get("systemProperties").getProperties();
        assertThat(systemProperties.get("dbPassword").getValue()).isEqualTo("123456");
        assertThat(systemProperties.get("apiKey").getValue()).isEqualTo("******");
        return null;
    });
}
Also used : 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 99 with StandardEnvironment

use of org.springframework.core.env.StandardEnvironment in project spring-boot by spring-projects.

the class EnvironmentEndpointTests method originAndOriginParents.

@Test
void originAndOriginParents() {
    StandardEnvironment environment = new StandardEnvironment();
    OriginParentMockPropertySource propertySource = new OriginParentMockPropertySource();
    propertySource.setProperty("name", "test");
    environment.getPropertySources().addFirst(propertySource);
    EnvironmentEntryDescriptor descriptor = new EnvironmentEndpoint(environment).environmentEntry("name");
    PropertySourceEntryDescriptor entryDescriptor = propertySources(descriptor).get("mockProperties");
    assertThat(entryDescriptor.getProperty().getOrigin()).isEqualTo("name");
    assertThat(entryDescriptor.getProperty().getOriginParents()).containsExactly("spring", "boot");
}
Also used : PropertySourceEntryDescriptor(org.springframework.boot.actuate.env.EnvironmentEndpoint.PropertySourceEntryDescriptor) EnvironmentEntryDescriptor(org.springframework.boot.actuate.env.EnvironmentEndpoint.EnvironmentEntryDescriptor) StandardEnvironment(org.springframework.core.env.StandardEnvironment) Test(org.junit.jupiter.api.Test)

Example 100 with StandardEnvironment

use of org.springframework.core.env.StandardEnvironment in project spring-boot by spring-projects.

the class SpringApplicationTests method propertiesFileEnhancesEnvironment.

@Test
void propertiesFileEnhancesEnvironment() {
    SpringApplication application = new SpringApplication(ExampleConfig.class);
    application.setWebApplicationType(WebApplicationType.NONE);
    ConfigurableEnvironment environment = new StandardEnvironment();
    application.setEnvironment(environment);
    this.context = application.run();
    assertThat(environment.getProperty("foo")).isEqualTo("bucket");
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) StandardEnvironment(org.springframework.core.env.StandardEnvironment) Test(org.junit.jupiter.api.Test)

Aggregations

StandardEnvironment (org.springframework.core.env.StandardEnvironment)146 Test (org.junit.jupiter.api.Test)63 MapPropertySource (org.springframework.core.env.MapPropertySource)52 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)42 Test (org.junit.Test)39 HashMap (java.util.HashMap)37 URI (java.net.URI)23 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)23 MessageSerDe (com.kixeye.chassis.transport.serde.MessageSerDe)21 MutablePropertySources (org.springframework.core.env.MutablePropertySources)18 ProtobufMessageSerDe (com.kixeye.chassis.transport.serde.converter.ProtobufMessageSerDe)15 RestTemplate (org.springframework.web.client.RestTemplate)15 ServiceError (com.kixeye.chassis.transport.dto.ServiceError)14 JsonJacksonMessageSerDe (com.kixeye.chassis.transport.serde.converter.JsonJacksonMessageSerDe)14 XmlMessageSerDe (com.kixeye.chassis.transport.serde.converter.XmlMessageSerDe)14 YamlJacksonMessageSerDe (com.kixeye.chassis.transport.serde.converter.YamlJacksonMessageSerDe)14 SerDeHttpMessageConverter (com.kixeye.chassis.transport.http.SerDeHttpMessageConverter)13 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)13 QueuingWebSocketListener (com.kixeye.chassis.transport.websocket.QueuingWebSocketListener)9 WebSocketMessageRegistry (com.kixeye.chassis.transport.websocket.WebSocketMessageRegistry)9