Support values other than String in /env
Fixes gh-9079
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package org.springframework.boot.actuate.endpoint;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.After;
|
||||
@@ -29,6 +30,7 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.CompositePropertySource;
|
||||
import org.springframework.core.env.MapPropertySource;
|
||||
import org.springframework.core.env.MutablePropertySources;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -255,6 +257,24 @@ public class EnvironmentEndpointTests extends AbstractEndpointTests<EnvironmentE
|
||||
assertThat(testProperties.get("my.foo")).isEqualTo("http://${bar.password}://hello");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void propertyWithTypeOtherThanStringShouldNotFail() throws Exception {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
MutablePropertySources propertySources = this.context.getEnvironment().getPropertySources();
|
||||
Map<String, Object> source = new HashMap<String, Object>();
|
||||
source.put("foo", Collections.singletonMap("bar", "baz"));
|
||||
propertySources.addFirst(new MapPropertySource("test", source));
|
||||
this.context.register(Config.class);
|
||||
this.context.refresh();
|
||||
EnvironmentEndpoint report = getEndpointBean();
|
||||
Map<String, Object> env = report.invoke();
|
||||
Map<String, Object> testProperties = (Map<String, Object>) env
|
||||
.get("test");
|
||||
Map<String, String> foo = (Map<String, String>) testProperties.get("foo");
|
||||
assertThat(foo.get("bar")).isEqualTo("baz");
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties
|
||||
public static class Config {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.boot.actuate.endpoint.mvc;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -39,6 +40,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.MapPropertySource;
|
||||
import org.springframework.core.env.MutablePropertySources;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
@@ -160,6 +162,18 @@ public class EnvironmentMvcEndpointTests {
|
||||
.andExpect(content().string(containsString("\"my.foo\":\"******\"")));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void propertyWithTypeOtherThanStringShouldNotFail() throws Exception {
|
||||
ConfigurableEnvironment environment = (ConfigurableEnvironment) this.context.getEnvironment();
|
||||
MutablePropertySources propertySources = environment.getPropertySources();
|
||||
Map<String, Object> source = new HashMap<String, Object>();
|
||||
source.put("foo", Collections.singletonMap("bar", "baz"));
|
||||
propertySources.addFirst(new MapPropertySource("test", source));
|
||||
this.mvc.perform(get("/env/foo.*")).andExpect(status().isOk())
|
||||
.andExpect(content().string("{\"foo\":{\"bar\":\"baz\"}}"));
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@Import({ JacksonAutoConfiguration.class,
|
||||
HttpMessageConvertersAutoConfiguration.class, WebMvcAutoConfiguration.class,
|
||||
|
||||
Reference in New Issue
Block a user