mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Polish contribution
Closes gh-7905
This commit is contained in:
parent
b2250f4ad8
commit
8bef0a1e60
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -641,8 +641,7 @@ public class HealthIndicatorAutoConfigurationTests {
|
||||
|
||||
@Bean
|
||||
public LdapOperations ldapOperations() {
|
||||
LdapOperations operations = mock(LdapOperations.class);
|
||||
return operations;
|
||||
return mock(LdapOperations.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user