pull/10168/merge
Stephane Nicoll 7 years ago
parent e244d75bd2
commit 8b88c6e884

@ -73,17 +73,18 @@ public class EnvironmentEndpoint {
@ReadOperation
public EnvironmentDescriptor environment(String pattern) {
if (StringUtils.hasText(pattern)) {
return environment(Pattern.compile(pattern).asPredicate());
return getEnvironmentDescriptor(Pattern.compile(pattern).asPredicate());
}
return environment((name) -> true);
return getEnvironmentDescriptor((name) -> true);
}
@ReadOperation
public Object getEnvironmentEntry(@Selector String toMatch) {
return environment((name) -> toMatch.equals(name));
public EnvironmentDescriptor environmentEntry(@Selector String toMatch) {
return getEnvironmentDescriptor(toMatch::equals);
}
private EnvironmentDescriptor environment(Predicate<String> propertyNamePredicate) {
private EnvironmentDescriptor getEnvironmentDescriptor(
Predicate<String> propertyNamePredicate) {
PropertyResolver resolver = getResolver();
List<PropertySourceDescriptor> propertySources = new ArrayList<>();
getPropertySourcesAsMap().forEach((sourceName, source) -> {

@ -69,9 +69,9 @@ public class EnvironmentEndpointTests {
StandardEnvironment environment = new StandardEnvironment();
CompositePropertySource source = new CompositePropertySource("composite");
source.addPropertySource(new MapPropertySource("one",
Collections.singletonMap("foo", (Object) "bar")));
Collections.singletonMap("foo", "bar")));
source.addPropertySource(new MapPropertySource("two",
Collections.singletonMap("foo", (Object) "spam")));
Collections.singletonMap("foo", "spam")));
environment.getPropertySources().addFirst(source);
EnvironmentDescriptor env = new EnvironmentEndpoint(environment)
.environment(null);
@ -230,6 +230,25 @@ public class EnvironmentEndpointTests {
assertThat(foo.get("bar")).isEqualTo("baz");
}
@Test
public void propertyEntry() {
StandardEnvironment environment = new StandardEnvironment();
TestPropertyValues.of("my.foo=bar", "my.foo2=bar2")
.applyTo(environment);
EnvironmentDescriptor env = new EnvironmentEndpoint(environment)
.environmentEntry("my.foo");
assertThat(env).isNotNull();
assertThat(getSource("test", env).getProperties().get("my.foo").getValue())
.isEqualTo("bar");
}
@Test
public void propertyEntryNoMatchReturnNull() {
EnvironmentDescriptor env = new EnvironmentEndpoint(new StandardEnvironment())
.environmentEntry("this.property.does-not-exist");
assertThat(env).isNull();
}
private void clearSystemProperties(String... properties) {
for (String property : properties) {
System.clearProperty(property);
@ -254,5 +273,4 @@ public class EnvironmentEndpointTests {
}
}

Loading…
Cancel
Save