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();
}
}
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");
}
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;
}
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}");
}
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("******");
}
Aggregations