Fix global endpoints.enabled property support

Update AbstractEndpoint to correctly support the `endpoints.enabled`
property. Also fix EnvironmentEnpoint which would previously prevent
the Environment from being set.

Fixes gh-2264
Closes gh-2265
This commit is contained in:
Mathieu Bernatet
2014-12-31 17:15:16 +01:00
committed by Phillip Webb
parent 491a61d54a
commit bf839e57a5
3 changed files with 37 additions and 15 deletions

View File

@@ -17,6 +17,8 @@
package org.springframework.boot.actuate.endpoint;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.junit.After;
import org.junit.Before;
@@ -133,6 +135,30 @@ public abstract class AbstractEndpointTests<T extends Endpoint<?>> {
assertThat(getEndpointBean().isEnabled(), equalTo(true));
}
@Test
public void isAllEndpointsDisabled() throws Exception {
this.context = new AnnotationConfigApplicationContext();
PropertySource<?> propertySource = new MapPropertySource("test",
Collections.<String, Object> singletonMap("endpoints.enabled", false));
this.context.getEnvironment().getPropertySources().addFirst(propertySource);
this.context.register(this.configClass);
this.context.refresh();
assertThat(getEndpointBean().isEnabled(), equalTo(false));
}
@Test
public void isOptIn() throws Exception {
this.context = new AnnotationConfigApplicationContext();
Map<String, Object> source = new HashMap<String, Object>();
source.put("endpoints.enabled", false);
source.put(this.property + ".enabled", true);
PropertySource<?> propertySource = new MapPropertySource("test", source);
this.context.getEnvironment().getPropertySources().addFirst(propertySource);
this.context.register(this.configClass);
this.context.refresh();
assertThat(getEndpointBean().isEnabled(), equalTo(true));
}
@SuppressWarnings("unchecked")
protected T getEndpointBean() {
return (T) this.context.getBean(this.type);