Search in sources :

Example 76 with MapPropertySource

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

the class AbstractWebEndpointIntegrationTests method load.

private void load(Consumer<T> contextCustomizer, String endpointPath, BiConsumer<ApplicationContext, WebTestClient> consumer) {
    T applicationContext = this.applicationContextSupplier.get();
    contextCustomizer.accept(applicationContext);
    Map<String, Object> properties = new HashMap<>();
    properties.put("endpointPath", endpointPath);
    properties.put("server.error.include-message", "always");
    applicationContext.getEnvironment().getPropertySources().addLast(new MapPropertySource("test", properties));
    applicationContext.refresh();
    try {
        InetSocketAddress address = new InetSocketAddress(getPort(applicationContext));
        String url = "http://" + address.getHostString() + ":" + address.getPort() + endpointPath;
        consumer.accept(applicationContext, WebTestClient.bindToServer().baseUrl(url).responseTimeout(TIMEOUT).build());
    } finally {
        applicationContext.close();
    }
}
Also used : HashMap(java.util.HashMap) MapPropertySource(org.springframework.core.env.MapPropertySource) InetSocketAddress(java.net.InetSocketAddress)

Example 77 with MapPropertySource

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

the class SpringApplicationTests method defaultPropertiesShouldBeMerged.

@Test
void defaultPropertiesShouldBeMerged() {
    MockEnvironment environment = new MockEnvironment();
    environment.getPropertySources().addFirst(new MapPropertySource(DefaultPropertiesPropertySource.NAME, Collections.singletonMap("bar", "foo")));
    SpringApplication application = new SpringApplicationBuilder(ExampleConfig.class).environment(environment).properties("baz=bing").web(WebApplicationType.NONE).build();
    this.context = application.run();
    assertThat(getEnvironment().getProperty("bar")).isEqualTo("foo");
    assertThat(getEnvironment().getProperty("baz")).isEqualTo("bing");
}
Also used : MockEnvironment(org.springframework.mock.env.MockEnvironment) MapPropertySource(org.springframework.core.env.MapPropertySource) SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) Test(org.junit.jupiter.api.Test)

Example 78 with MapPropertySource

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

the class ConfigDataActivationContextTests method createKubernetesEnvironment.

private MockEnvironment createKubernetesEnvironment() {
    MockEnvironment environment = new MockEnvironment();
    Map<String, Object> map = new LinkedHashMap<>();
    map.put("KUBERNETES_SERVICE_HOST", "host");
    map.put("KUBERNETES_SERVICE_PORT", "port");
    PropertySource<?> propertySource = new MapPropertySource(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, map);
    environment.getPropertySources().addLast(propertySource);
    return environment;
}
Also used : MockEnvironment(org.springframework.mock.env.MockEnvironment) MapPropertySource(org.springframework.core.env.MapPropertySource) LinkedHashMap(java.util.LinkedHashMap)

Example 79 with MapPropertySource

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

the class EnvironmentEndpointWebIntegrationTests method nestedPathMatchedByRegexWhenPlaceholderCannotBeResolvedShouldReturnUnresolvedProperty.

@WebEndpointTest
void nestedPathMatchedByRegexWhenPlaceholderCannotBeResolvedShouldReturnUnresolvedProperty() {
    Map<String, Object> map = new HashMap<>();
    map.put("my.foo", "${my.bar}");
    this.context.getEnvironment().getPropertySources().addFirst(new MapPropertySource("unresolved-placeholder", map));
    this.client.get().uri("/actuator/env?pattern=my.*").exchange().expectStatus().isOk().expectBody().jsonPath("propertySources[?(@.name=='unresolved-placeholder')].properties.['my.foo'].value").isEqualTo("${my.bar}");
}
Also used : HashMap(java.util.HashMap) MapPropertySource(org.springframework.core.env.MapPropertySource) WebEndpointTest(org.springframework.boot.actuate.endpoint.web.test.WebEndpointTest)

Example 80 with MapPropertySource

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

the class EnvironmentEndpointWebIntegrationTests method nestedPathWithSensitivePlaceholderShouldSanitize.

@WebEndpointTest
void nestedPathWithSensitivePlaceholderShouldSanitize() {
    Map<String, Object> map = new HashMap<>();
    map.put("my.foo", "${my.password}");
    map.put("my.password", "hello");
    this.context.getEnvironment().getPropertySources().addFirst(new MapPropertySource("placeholder", map));
    this.client.get().uri("/actuator/env/my.foo").exchange().expectStatus().isOk().expectBody().jsonPath("property.value").isEqualTo("******").jsonPath(forPropertyEntry("placeholder")).isEqualTo("******");
}
Also used : HashMap(java.util.HashMap) MapPropertySource(org.springframework.core.env.MapPropertySource) WebEndpointTest(org.springframework.boot.actuate.endpoint.web.test.WebEndpointTest)

Aggregations

MapPropertySource (org.springframework.core.env.MapPropertySource)213 HashMap (java.util.HashMap)103 Test (org.junit.jupiter.api.Test)80 MutablePropertySources (org.springframework.core.env.MutablePropertySources)66 Test (org.junit.Test)59 StandardEnvironment (org.springframework.core.env.StandardEnvironment)52 LinkedHashMap (java.util.LinkedHashMap)42 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)30 URI (java.net.URI)24 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)23 MessageSerDe (com.kixeye.chassis.transport.serde.MessageSerDe)21 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)21 ArrayList (java.util.ArrayList)18 Map (java.util.Map)16 RestTemplate (org.springframework.web.client.RestTemplate)16 ProtobufMessageSerDe (com.kixeye.chassis.transport.serde.converter.ProtobufMessageSerDe)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