Polish contribution

Closes gh-7905
This commit is contained in:
Stephane Nicoll 2017-01-16 11:23:35 +01:00
parent b2250f4ad8
commit 8bef0a1e60
4 changed files with 26 additions and 12 deletions

View File

@ -27,10 +27,13 @@ import org.springframework.util.Assert;
* {@link HealthIndicator} for configured LDAP server(s).
*
* @author Eddú Meléndez
* @author Stephane Nicoll
* @version 1.5.0
*/
public class LdapHealthIndicator extends AbstractHealthIndicator {
private static final ContextExecutor<String> versionContextExecutor = new VersionContextExecutor();
private final LdapOperations ldapOperations;
public LdapHealthIndicator(LdapOperations ldapOperations) {
@ -40,13 +43,20 @@ public class LdapHealthIndicator extends AbstractHealthIndicator {
@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {
String version = (String) this.ldapOperations.executeReadOnly(new ContextExecutor<Object>() {
@Override
public Object executeWithContext(DirContext ctx) throws NamingException {
return ctx.getEnvironment().get("java.naming.ldap.version");
}
});
String version = this.ldapOperations.executeReadOnly(versionContextExecutor);
builder.up().withDetail("version", version);
}
private static class VersionContextExecutor implements ContextExecutor<String> {
@Override
public String executeWithContext(DirContext ctx) throws NamingException {
Object version = ctx.getEnvironment().get("java.naming.ldap.version");
if (version != null) {
return (String) version;
}
return null;
}
}
}

View File

@ -641,8 +641,7 @@ public class HealthIndicatorAutoConfigurationTests {
@Bean
public LdapOperations ldapOperations() {
LdapOperations operations = mock(LdapOperations.class);
return operations;
return mock(LdapOperations.class);
}
}

View File

@ -59,13 +59,16 @@ public class LdapHealthIndicatorTests {
@Test
public void indicatorExist() {
this.context.register(LdapAutoConfiguration.class, LdapDataAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class, EndpointAutoConfiguration.class,
this.context.register(LdapAutoConfiguration.class,
LdapDataAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class,
EndpointAutoConfiguration.class,
HealthIndicatorAutoConfiguration.class);
this.context.refresh();
LdapTemplate ldapTemplate = this.context.getBean(LdapTemplate.class);
assertThat(ldapTemplate).isNotNull();
LdapHealthIndicator healthIndicator = this.context.getBean(LdapHealthIndicator.class);
LdapHealthIndicator healthIndicator = this.context.getBean(
LdapHealthIndicator.class);
assertThat(healthIndicator).isNotNull();
}
@ -84,7 +87,8 @@ public class LdapHealthIndicatorTests {
public void ldapIsDown() {
LdapTemplate ldapTemplate = mock(LdapTemplate.class);
given(ldapTemplate.executeReadOnly(any(ContextExecutor.class)))
.willThrow(new CommunicationException(new javax.naming.CommunicationException("Connection failed")));
.willThrow(new CommunicationException(
new javax.naming.CommunicationException("Connection failed")));
LdapHealthIndicator healthIndicator = new LdapHealthIndicator(ldapTemplate);
Health health = healthIndicator.health();
assertThat(health.getStatus()).isEqualTo(Status.DOWN);

View File

@ -1114,6 +1114,7 @@ content into your application; rather pick only the properties that you need.
management.health.elasticsearch.indices= # Comma-separated index names.
management.health.elasticsearch.response-timeout=100 # The time, in milliseconds, to wait for a response from the cluster.
management.health.jms.enabled=true # Enable JMS health check.
management.health.ldap.enabled=true # Enable LDAP health check.
management.health.mail.enabled=true # Enable Mail health check.
management.health.mongo.enabled=true # Enable MongoDB health check.
management.health.rabbit.enabled=true # Enable RabbitMQ health check.