Polish "Add properties to control exceptions ignored by LdapTemplate"

See gh-21289
This commit is contained in:
Andy Wilkinson
2020-07-01 10:03:34 +01:00
parent 6853320661
commit 8c341df73b
4 changed files with 68 additions and 51 deletions

View File

@@ -122,10 +122,11 @@ class LdapAutoConfigurationTests {
}
@Test
void templateWithCustomConfigurationExists() {
void templateConfigurationCanBeCustomized() {
this.contextRunner.withPropertyValues("spring.ldap.urls:ldap://localhost:389",
"spring.ldap.ignorePartialResultException=true", "spring.ldap.ignoreNameNotFoundException=true",
"spring.ldap.ignoreSizeLimitExceededException=false").run((context) -> {
"spring.ldap.template.ignorePartialResultException=true",
"spring.ldap.template.ignoreNameNotFoundException=true",
"spring.ldap.template.ignoreSizeLimitExceededException=false").run((context) -> {
assertThat(context).hasSingleBean(LdapTemplate.class);
LdapTemplate ldapTemplate = context.getBean(LdapTemplate.class);
assertThat(ldapTemplate).hasFieldOrPropertyWithValue("ignorePartialResultException", true);

View File

@@ -18,6 +18,7 @@ package org.springframework.boot.autoconfigure.ldap;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.ldap.LdapProperties.Template;
import org.springframework.ldap.core.LdapTemplate;
import static org.assertj.core.api.Assertions.assertThat;
@@ -29,18 +30,16 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
class LdapPropertiesTests {
private final LdapProperties properties = new LdapProperties();
@Test
void ldapTemplatePropertiesUseConsistentLdapTemplateDefaultValues() {
Template templateProperties = new LdapProperties().getTemplate();
LdapTemplate ldapTemplate = new LdapTemplate();
assertThat(ldapTemplate).hasFieldOrPropertyWithValue("ignorePartialResultException",
this.properties.isIgnorePartialResultException());
templateProperties.isIgnorePartialResultException());
assertThat(ldapTemplate).hasFieldOrPropertyWithValue("ignoreNameNotFoundException",
this.properties.isIgnoreNameNotFoundException());
templateProperties.isIgnoreNameNotFoundException());
assertThat(ldapTemplate).hasFieldOrPropertyWithValue("ignoreSizeLimitExceededException",
this.properties.isIgnoreSizeLimitExceededException());
templateProperties.isIgnoreSizeLimitExceededException());
}
}