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:
committed by
Phillip Webb
parent
491a61d54a
commit
bf839e57a5
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user