This commit is contained in:
Andy Wilkinson
2017-08-11 18:46:05 +01:00
parent cf2bf0c2b9
commit e7a3b3c4e2
9 changed files with 123 additions and 104 deletions

View File

@@ -44,8 +44,7 @@ class ServletWebManagementContextFactory implements ManagementContextFactory {
ApplicationContext parent, Class<?>... configClasses) {
AnnotationConfigServletWebServerApplicationContext child = new AnnotationConfigServletWebServerApplicationContext();
child.setParent(parent);
List<Class<?>> combinedClasses = new ArrayList<Class<?>>(
Arrays.asList(configClasses));
List<Class<?>> combinedClasses = new ArrayList<>(Arrays.asList(configClasses));
combinedClasses.add(ServletWebServerFactoryAutoConfiguration.class);
child.register(combinedClasses.toArray(new Class<?>[combinedClasses.size()]));
registerServletWebServerFactory(parent, child);

View File

@@ -22,13 +22,12 @@ import org.springframework.boot.endpoint.CachingConfiguration;
import org.springframework.core.env.Environment;
/**
* A {@link CachingConfiguration} factory that use the {@link Environment} to extract
* the caching settings of each endpoint.
* A {@link CachingConfiguration} factory that use the {@link Environment} to extract the
* caching settings of each endpoint.
*
* @author Stephane Nicoll
*/
class CachingConfigurationFactory
implements Function<String, CachingConfiguration> {
class CachingConfigurationFactory implements Function<String, CachingConfiguration> {
private final Environment environment;

View File

@@ -53,8 +53,7 @@ class JmxEndpointExporter implements InitializingBean, DisposableBean {
private Collection<ObjectName> registeredObjectNames;
JmxEndpointExporter(EndpointProvider<JmxEndpointOperation> endpointProvider,
EndpointMBeanRegistrar endpointMBeanRegistrar,
ObjectMapper objectMapper) {
EndpointMBeanRegistrar endpointMBeanRegistrar, ObjectMapper objectMapper) {
this.endpointProvider = endpointProvider;
this.endpointMBeanRegistrar = endpointMBeanRegistrar;
DataConverter dataConverter = new DataConverter(objectMapper);
@@ -73,8 +72,8 @@ class JmxEndpointExporter implements InitializingBean, DisposableBean {
private Collection<ObjectName> registerEndpointMBeans() {
List<ObjectName> objectNames = new ArrayList<>();
Collection<EndpointMBean> mBeans = this.mBeanFactory.createMBeans(
this.endpointProvider.getEndpoints());
Collection<EndpointMBean> mBeans = this.mBeanFactory
.createMBeans(this.endpointProvider.getEndpoints());
for (EndpointMBean mBean : mBeans) {
objectNames.add(this.endpointMBeanRegistrar.registerEndpointMBean(mBean));
}
@@ -122,13 +121,13 @@ class JmxEndpointExporter implements InitializingBean, DisposableBean {
if (responseType.equals(String.class)) {
return String.class;
}
if (responseType.isArray() || Collection.class.isAssignableFrom(responseType)) {
if (responseType.isArray()
|| Collection.class.isAssignableFrom(responseType)) {
return List.class;
}
return Map.class;
}
}
}

View File

@@ -55,7 +55,8 @@ public class EndpointEnablementProvider {
* @param endpointId the id of the endpoint
* @param enabledByDefault whether the endpoint is enabled by default or not
* @param endpointType the requested {@link EndpointType}
* @return the {@link EndpointEnablement} of that endpoint for the specified {@link EndpointType}
* @return the {@link EndpointEnablement} of that endpoint for the specified
* {@link EndpointType}
*/
public EndpointEnablement getEndpointEnablement(String endpointId,
boolean enabledByDefault, EndpointType endpointType) {
@@ -92,9 +93,8 @@ public class EndpointEnablementProvider {
// All endpoints specific attributes have been looked at. Checking default value
// for the endpoint
if (!enabledByDefault) {
return new EndpointEnablement(false,
createDefaultEnablementMessage(endpointId, enabledByDefault,
endpointType));
return new EndpointEnablement(false, createDefaultEnablementMessage(
endpointId, enabledByDefault, endpointType));
}
if (endpointType != null) {
@@ -106,7 +106,8 @@ public class EndpointEnablementProvider {
}
else {
// Check if there is a global tech required
EndpointEnablement anyTechGeneralOutcome = getAnyTechSpecificOutcomeFor("all");
EndpointEnablement anyTechGeneralOutcome = getAnyTechSpecificOutcomeFor(
"all");
if (anyTechGeneralOutcome != null) {
return anyTechGeneralOutcome;
}

View File

@@ -100,7 +100,7 @@ public class HealthWebEndpointExtension {
public WebEndpointResponse<Health> getHealth() {
Health health = this.delegate.health();
Integer status = getStatus(health);
return new WebEndpointResponse<Health>(health, status);
return new WebEndpointResponse<>(health, status);
}
private int getStatus(Health health) {

View File

@@ -23,7 +23,6 @@ import org.springframework.mock.env.MockEnvironment;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link CachingConfigurationFactory}.
*

View File

@@ -72,23 +72,26 @@ public class EndpointEnablementProviderTests {
@Test
public void generalEnabledOverrideViaSpecificProperty() {
validate(determineEnablement("foo", true, "endpoints.all.enabled=false",
"endpoints.foo.enabled=true"), true,
"found property endpoints.foo.enabled");
validate(
determineEnablement("foo", true, "endpoints.all.enabled=false",
"endpoints.foo.enabled=true"),
true, "found property endpoints.foo.enabled");
}
@Test
public void generalEnabledOverrideViaSpecificWebProperty() {
validate(determineEnablement("foo", true, "endpoints.foo.enabled=false",
"endpoints.foo.web.enabled=true"), true,
"found property endpoints.foo.web.enabled");
validate(
determineEnablement("foo", true, "endpoints.foo.enabled=false",
"endpoints.foo.web.enabled=true"),
true, "found property endpoints.foo.web.enabled");
}
@Test
public void generalEnabledOverrideViaSpecificJmxProperty() {
validate(determineEnablement("foo", true, "endpoints.foo.enabled=false",
"endpoints.foo.jmx.enabled=true"), true,
"found property endpoints.foo.jmx.enabled");
validate(
determineEnablement("foo", true, "endpoints.foo.enabled=false",
"endpoints.foo.jmx.enabled=true"),
true, "found property endpoints.foo.jmx.enabled");
}
@Test
@@ -100,16 +103,18 @@ public class EndpointEnablementProviderTests {
@Test
public void generalEnabledOverrideViaGeneralWebProperty() {
validate(determineEnablement("foo", true, "endpoints.all.enabled=false",
"endpoints.all.web.enabled=true"), true,
"found property endpoints.all.web.enabled");
validate(
determineEnablement("foo", true, "endpoints.all.enabled=false",
"endpoints.all.web.enabled=true"),
true, "found property endpoints.all.web.enabled");
}
@Test
public void generalEnabledOverrideViaGeneralJmxProperty() {
validate(determineEnablement("foo", true, "endpoints.all.enabled=false",
"endpoints.all.jmx.enabled=true"), true,
"found property endpoints.all.jmx.enabled");
validate(
determineEnablement("foo", true, "endpoints.all.enabled=false",
"endpoints.all.jmx.enabled=true"),
true, "found property endpoints.all.jmx.enabled");
}
@Test
@@ -121,10 +126,11 @@ public class EndpointEnablementProviderTests {
@Test
public void generalDisabledEvenWithEnabledGeneralProperties() {
validate(determineEnablement("foo", true, "endpoints.all.enabled=true",
"endpoints.all.web.enabled=true", "endpoints.all.jmx.enabled=true",
"endpoints.foo.enabled=false"), false,
"found property endpoints.foo.enabled");
validate(
determineEnablement("foo", true, "endpoints.all.enabled=true",
"endpoints.all.web.enabled=true",
"endpoints.all.jmx.enabled=true", "endpoints.foo.enabled=false"),
false, "found property endpoints.foo.enabled");
}
@Test
@@ -153,8 +159,8 @@ public class EndpointEnablementProviderTests {
@Test
public void generalEnabledOverrideWithAndAnnotationFlagAndSpecificProperty() {
validate(determineEnablement("bar", false, "endpoints.bar.enabled=true"),
true, "found property endpoints.bar.enabled");
validate(determineEnablement("bar", false, "endpoints.bar.enabled=true"), true,
"found property endpoints.bar.enabled");
}
@Test
@@ -171,12 +177,12 @@ public class EndpointEnablementProviderTests {
@Test
public void generalEnabledOverrideWithAndAnnotationFlagAndAnyProperty() {
validate(determineEnablement("bar", false, "endpoints.bar.web.enabled=false",
"endpoints.bar.jmx.enabled=true"), true,
"found property endpoints.bar.jmx.enabled");
validate(
determineEnablement("bar", false, "endpoints.bar.web.enabled=false",
"endpoints.bar.jmx.enabled=true"),
true, "found property endpoints.bar.jmx.enabled");
}
@Test
public void specificEnabledByDefault() {
validate(determineEnablement("foo", true, EndpointType.WEB), true,
@@ -185,82 +191,93 @@ public class EndpointEnablementProviderTests {
@Test
public void specificDisabledViaEndpointProperty() {
validate(determineEnablement("foo", true, EndpointType.WEB,
"endpoints.foo.enabled=false"), false,
"found property endpoints.foo.enabled");
validate(
determineEnablement("foo", true, EndpointType.WEB,
"endpoints.foo.enabled=false"),
false, "found property endpoints.foo.enabled");
}
@Test
public void specificDisabledViaTechProperty() {
validate(determineEnablement("foo", true, EndpointType.WEB,
"endpoints.foo.web.enabled=false"), false,
"found property endpoints.foo.web.enabled");
validate(
determineEnablement("foo", true, EndpointType.WEB,
"endpoints.foo.web.enabled=false"),
false, "found property endpoints.foo.web.enabled");
}
@Test
public void specificNotDisabledViaUnrelatedTechProperty() {
validate(determineEnablement("foo", true, EndpointType.WEB,
"endpoints.foo.jmx.enabled=false"), true,
"endpoint 'foo' (web) is enabled by default");
validate(
determineEnablement("foo", true, EndpointType.WEB,
"endpoints.foo.jmx.enabled=false"),
true, "endpoint 'foo' (web) is enabled by default");
}
@Test
public void specificDisabledViaGeneralProperty() {
validate(determineEnablement("foo", true, EndpointType.WEB,
"endpoints.all.enabled=false"), false,
"found property endpoints.all.enabled");
validate(
determineEnablement("foo", true, EndpointType.WEB,
"endpoints.all.enabled=false"),
false, "found property endpoints.all.enabled");
}
@Test
public void specificEnabledOverrideViaEndpointProperty() {
validate(determineEnablement("foo", true, EndpointType.WEB,
"endpoints.all.enabled=false", "endpoints.foo.enabled=true"), true,
"found property endpoints.foo.enabled");
validate(
determineEnablement("foo", true, EndpointType.WEB,
"endpoints.all.enabled=false", "endpoints.foo.enabled=true"),
true, "found property endpoints.foo.enabled");
}
@Test
public void specificEnabledOverrideViaTechProperty() {
validate(determineEnablement("foo", true, EndpointType.WEB,
"endpoints.foo.enabled=false", "endpoints.foo.web.enabled=true"), true,
"found property endpoints.foo.web.enabled");
validate(
determineEnablement("foo", true, EndpointType.WEB,
"endpoints.foo.enabled=false", "endpoints.foo.web.enabled=true"),
true, "found property endpoints.foo.web.enabled");
}
@Test
public void specificEnabledOverrideHasNotEffectWithUnrelatedTechProperty() {
validate(determineEnablement("foo", true, EndpointType.WEB,
"endpoints.foo.enabled=false", "endpoints.foo.jmx.enabled=true"), false,
"found property endpoints.foo.enabled");
validate(
determineEnablement("foo", true, EndpointType.WEB,
"endpoints.foo.enabled=false", "endpoints.foo.jmx.enabled=true"),
false, "found property endpoints.foo.enabled");
}
@Test
public void specificEnabledOverrideViaGeneralWebProperty() {
validate(determineEnablement("foo", true, EndpointType.WEB,
"endpoints.all.enabled=false", "endpoints.all.web.enabled=true"), true,
"found property endpoints.all.web.enabled");
validate(
determineEnablement("foo", true, EndpointType.WEB,
"endpoints.all.enabled=false", "endpoints.all.web.enabled=true"),
true, "found property endpoints.all.web.enabled");
}
@Test
public void specificEnabledOverrideHasNoEffectWithUnrelatedTechProperty() {
validate(determineEnablement("foo", true, EndpointType.WEB,
"endpoints.all.enabled=false", "endpoints.all.jmx.enabled=true"), false,
"found property endpoints.all.enabled");
validate(
determineEnablement("foo", true, EndpointType.WEB,
"endpoints.all.enabled=false", "endpoints.all.jmx.enabled=true"),
false, "found property endpoints.all.enabled");
}
@Test
public void specificDisabledWithEndpointPropertyEvenWithEnabledGeneralProperties() {
validate(determineEnablement("foo", true, EndpointType.WEB,
"endpoints.all.enabled=true", "endpoints.all.web.enabled=true",
"endpoints.all.jmx.enabled=true", "endpoints.foo.enabled=false"), false,
"found property endpoints.foo.enabled");
validate(
determineEnablement("foo", true, EndpointType.WEB,
"endpoints.all.enabled=true", "endpoints.all.web.enabled=true",
"endpoints.all.jmx.enabled=true", "endpoints.foo.enabled=false"),
false, "found property endpoints.foo.enabled");
}
@Test
public void specificDisabledWithTechPropertyEvenWithEnabledGeneralProperties() {
validate(determineEnablement("foo", true, EndpointType.WEB,
"endpoints.all.enabled=true", "endpoints.all.web.enabled=true",
"endpoints.all.jmx.enabled=true", "endpoints.foo.enabled=true",
"endpoints.foo.web.enabled=false"), false,
"found property endpoints.foo.web.enabled");
validate(
determineEnablement("foo", true, EndpointType.WEB,
"endpoints.all.enabled=true", "endpoints.all.web.enabled=true",
"endpoints.all.jmx.enabled=true", "endpoints.foo.enabled=true",
"endpoints.foo.web.enabled=false"),
false, "found property endpoints.foo.web.enabled");
}
@Test
@@ -271,47 +288,52 @@ public class EndpointEnablementProviderTests {
@Test
public void specificDisabledByDefaultWithAnnotationFlagEvenWithGeneralProperty() {
validate(determineEnablement("bar", false, EndpointType.WEB,
"endpoints.all.enabled=true"), false,
"endpoint 'bar' (web) is disabled by default");
validate(
determineEnablement("bar", false, EndpointType.WEB,
"endpoints.all.enabled=true"),
false, "endpoint 'bar' (web) is disabled by default");
}
@Test
public void specificDisabledByDefaultWithAnnotationFlagEvenWithGeneralWebProperty() {
validate(determineEnablement("bar", false, EndpointType.WEB,
"endpoints.all.web.enabled=true"), false,
"endpoint 'bar' (web) is disabled by default");
validate(
determineEnablement("bar", false, EndpointType.WEB,
"endpoints.all.web.enabled=true"),
false, "endpoint 'bar' (web) is disabled by default");
}
@Test
public void specificDisabledByDefaultWithAnnotationFlagEvenWithGeneralJmxProperty() {
validate(determineEnablement("bar", false, EndpointType.WEB,
"endpoints.all.jmx.enabled=true"), false,
"endpoint 'bar' (web) is disabled by default");
validate(
determineEnablement("bar", false, EndpointType.WEB,
"endpoints.all.jmx.enabled=true"),
false, "endpoint 'bar' (web) is disabled by default");
}
@Test
public void specificEnabledOverrideWithAndAnnotationFlagAndEndpointProperty() {
validate(determineEnablement("bar", false, EndpointType.WEB,
"endpoints.bar.enabled=true"), true,
"found property endpoints.bar.enabled");
validate(
determineEnablement("bar", false, EndpointType.WEB,
"endpoints.bar.enabled=true"),
true, "found property endpoints.bar.enabled");
}
@Test
public void specificEnabledOverrideWithAndAnnotationFlagAndTechProperty() {
validate(determineEnablement("bar", false, EndpointType.WEB,
"endpoints.bar.web.enabled=true"), true,
"found property endpoints.bar.web.enabled");
validate(
determineEnablement("bar", false, EndpointType.WEB,
"endpoints.bar.web.enabled=true"),
true, "found property endpoints.bar.web.enabled");
}
@Test
public void specificEnabledOverrideWithAndAnnotationFlagHasNoEffectWithUnrelatedTechProperty() {
validate(determineEnablement("bar", false, EndpointType.WEB,
"endpoints.bar.jmx.enabled=true"), false,
"endpoint 'bar' (web) is disabled by default");
validate(
determineEnablement("bar", false, EndpointType.WEB,
"endpoints.bar.jmx.enabled=true"),
false, "endpoint 'bar' (web) is disabled by default");
}
private void validate(EndpointEnablement enablement, boolean enabled,
String... messages) {
assertThat(enablement).isNotNull();

View File

@@ -196,7 +196,7 @@ public class EnvironmentEndpointTests {
public void propertyWithTypeOtherThanStringShouldNotFail() {
StandardEnvironment environment = new StandardEnvironment();
MutablePropertySources propertySources = environment.getPropertySources();
Map<String, Object> source = new HashMap<String, Object>();
Map<String, Object> source = new HashMap<>();
source.put("foo", Collections.singletonMap("bar", "baz"));
propertySources.addFirst(new MapPropertySource("test", source));
EnvironmentDescriptor env = new EnvironmentEndpoint(environment)

View File

@@ -70,7 +70,7 @@ public class EnvironmentEndpointWebIntegrationTests {
@Test
public void nestedPathWhenPlaceholderCannotBeResolvedShouldReturnUnresolvedProperty()
throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
Map<String, Object> map = new HashMap<>();
map.put("my.foo", "${my.bar}");
context.getEnvironment().getPropertySources()
.addFirst(new MapPropertySource("unresolved-placeholder", map));
@@ -81,7 +81,7 @@ public class EnvironmentEndpointWebIntegrationTests {
@Test
public void nestedPathWithSensitivePlaceholderShouldSanitize() throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
Map<String, Object> map = new HashMap<>();
map.put("my.foo", "${my.password}");
map.put("my.password", "hello");
context.getEnvironment().getPropertySources()
@@ -94,7 +94,7 @@ public class EnvironmentEndpointWebIntegrationTests {
@Test
public void nestedPathMatchedByRegexWhenPlaceholderCannotBeResolvedShouldReturnUnresolvedProperty()
throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
Map<String, Object> map = new HashMap<>();
map.put("my.foo", "${my.bar}");
context.getEnvironment().getPropertySources()
.addFirst(new MapPropertySource("unresolved-placeholder", map));
@@ -108,7 +108,7 @@ public class EnvironmentEndpointWebIntegrationTests {
@Test
public void nestedPathMatchedByRegexWithSensitivePlaceholderShouldSanitize()
throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
Map<String, Object> map = new HashMap<>();
map.put("my.foo", "${my.password}");
map.put("my.password", "hello");
context.getEnvironment().getPropertySources()