From c16ed5a440afebdda26287af87c26b753be011fb Mon Sep 17 00:00:00 2001 From: Josh Cummings Date: Tue, 9 May 2023 16:01:15 -0600 Subject: [PATCH] Address JavaFormat Violations in Integration Tests Issue gh-743 --- .../LdapConditionallyFilteredTestRunner.java | 2 +- ...DefaultLdapClientAuthenticationITests.java | 8 +- .../itest/DefaultLdapClientListITests.java | 4 +- .../itest/DefaultLdapClientLookupITests.java | 48 ++--- ...DefaultLdapClientLookupMultiRdnITests.java | 3 +- .../DefaultLdapClientSearchResultITests.java | 166 ++++++++++-------- .../LdapTemplateAuthenticationITests.java | 19 +- .../LdapTemplateContextExecutorTests.java | 1 + .../ldap/itest/LdapTemplateListITests.java | 1 + .../ldap/itest/LdapTemplateLookupITests.java | 57 +++--- .../LdapTemplateLookupMultiRdnITests.java | 6 +- .../itest/LdapTemplateNoBaseSuffixITests.java | 3 +- .../LdapTemplateRecursiveDeleteITests.java | 2 +- .../itest/LdapTemplateSearchResultITests.java | 135 +++++++------- ...lateSearchResultNamespaceConfigITests.java | 118 +++++++------ .../core/DistinguishedNameEditorITests.java | 1 + .../core/simple/SimpleLdapTemplateITests.java | 1 + .../LdapContextSourceIntegrationTests.java | 8 +- ...textSourceMultiServerIntegrationTests.java | 1 + .../HardcodedFilterIntegrationTests.java | 1 + .../ldap/itest/ldap321/Ldap321Tests.java | 1 + .../ldap/itest/ldap321/RoleRepo.java | 1 + ...rceTransactionManagerIntegrationTests.java | 4 +- ...urceTransactionManagerNamespaceITests.java | 3 +- ...rceTransactionManagerIntegrationTests.java | 4 +- ...ctionManagerNamespaceIntegrationTests.java | 4 +- ...ateTransactionManagerIntegrationTests.java | 1 + ...nateTransactionManagerNamespaceITests.java | 1 + ...dapTemplateOdmGroupManipulationITests.java | 28 +-- ...dapTemplateOdmWithDnAnnotationsITests.java | 19 +- ...pTemplateOdmWithNoDnAnnotationsITests.java | 36 ++-- 31 files changed, 381 insertions(+), 306 deletions(-) diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/LdapConditionallyFilteredTestRunner.java b/test/integration-tests/src/test/java/org/springframework/ldap/LdapConditionallyFilteredTestRunner.java index 61cfa069..7b88fb29 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/LdapConditionallyFilteredTestRunner.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/LdapConditionallyFilteredTestRunner.java @@ -43,7 +43,7 @@ public class LdapConditionallyFilteredTestRunner extends SpringJUnit4ClassRunner try { filter(Categories.CategoryFilter.exclude(NoAdTests.class)); } - catch (NoTestsRemainException e) { + catch (NoTestsRemainException ex) { // Nothing to do here. } } diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/DefaultLdapClientAuthenticationITests.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/DefaultLdapClientAuthenticationITests.java index 27f36cbb..c6af1928 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/DefaultLdapClientAuthenticationITests.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/DefaultLdapClientAuthenticationITests.java @@ -100,8 +100,8 @@ public class DefaultLdapClientAuthenticationITests extends AbstractLdapTemplateI DirContextAdapter adapter = (DirContextAdapter) ctx.lookup(entry.getRelativeDn()); assertThat(adapter.getStringAttribute("cn")).isEqualTo("Some Person3"); } - catch (NamingException e) { - throw new RuntimeException("Failed to lookup " + entry.getRelativeDn(), e); + catch (NamingException ex) { + throw new RuntimeException("Failed to lookup " + entry.getRelativeDn(), ex); } }; this.tested.authenticate().query(query).password("password").execute((ctx, entry) -> { @@ -125,8 +125,8 @@ public class DefaultLdapClientAuthenticationITests extends AbstractLdapTemplateI @Category(NoAdTests.class) public void testAuthenticateWithLdapQueryAndMapperAndInvalidPassword() { LdapQuery query = LdapQueryBuilder.query().where("objectclass").is("person").and("uid").is("some.person3"); - assertThatExceptionOfType(AuthenticationException.class).isThrownBy(() -> this.tested.authenticate().query(query) - .password("invalidpassword").execute(new LookupAttemptingCallback())); + assertThatExceptionOfType(AuthenticationException.class).isThrownBy(() -> this.tested.authenticate() + .query(query).password("invalidpassword").execute(new LookupAttemptingCallback())); } @Test diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/DefaultLdapClientListITests.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/DefaultLdapClientListITests.java index fbf57998..858fc70f 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/DefaultLdapClientListITests.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/DefaultLdapClientListITests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ldap.itest; import java.util.LinkedList; @@ -71,7 +72,8 @@ public class DefaultLdapClientListITests extends AbstractLdapTemplateIntegration public void testListBindings_ContextMapper() { this.contextMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.contextMapper.setExpectedValues(ALL_VALUES); - List list = this.tested.listBindings("ou=company2,ou=Sweden" + BASE_STRING).toList(this.contextMapper); + List list = this.tested.listBindings("ou=company2,ou=Sweden" + BASE_STRING) + .toList(this.contextMapper); assertThat(list).hasSize(1); } diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/DefaultLdapClientLookupITests.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/DefaultLdapClientLookupITests.java index 36850c03..ad9c9a6c 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/DefaultLdapClientLookupITests.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/DefaultLdapClientLookupITests.java @@ -90,30 +90,6 @@ public class DefaultLdapClientLookupITests extends AbstractLdapTemplateIntegrati assertThat(person.getDescription()).isEqualTo("Sweden, Company1, Some Person2"); } - /** - * An {@link AttributesMapper} that only maps a subset of the full attributes list. - * Used in tests where the return attributes list has been limited. - * - * @author Ulrik Sandberg - */ - private static final class SubsetPersonAttributesMapper implements AttributesMapper { - - /** - * Maps the cn attribute into a {@link Person} object. Also verifies - * that the other attributes haven't been set. - * - * @see AttributesMapper#mapFromAttributes(Attributes) - */ - public Person mapFromAttributes(Attributes attributes) throws NamingException { - Person person = new Person(); - person.setFullname((String) attributes.get("cn").get()); - assertThat(attributes.get("sn")).as("sn should be null").isNull(); - assertThat(attributes.get("description")).as("description should be null").isNull(); - return person; - } - - } - /** * Verifies that only the subset is used when specifying a subset of the available * attributes as return attributes. @@ -190,4 +166,28 @@ public class DefaultLdapClientLookupITests extends AbstractLdapTemplateIntegrati assertThat(result.getNameInNamespace()).isEqualTo("cn=Some Person2,ou=company1,ou=Sweden," + base); } + /** + * An {@link AttributesMapper} that only maps a subset of the full attributes list. + * Used in tests where the return attributes list has been limited. + * + * @author Ulrik Sandberg + */ + private static final class SubsetPersonAttributesMapper implements AttributesMapper { + + /** + * Maps the cn attribute into a {@link Person} object. Also verifies + * that the other attributes haven't been set. + * + * @see AttributesMapper#mapFromAttributes(Attributes) + */ + public Person mapFromAttributes(Attributes attributes) throws NamingException { + Person person = new Person(); + person.setFullname((String) attributes.get("cn").get()); + assertThat(attributes.get("sn")).as("sn should be null").isNull(); + assertThat(attributes.get("description")).as("description should be null").isNull(); + return person; + } + + } + } diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/DefaultLdapClientLookupMultiRdnITests.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/DefaultLdapClientLookupMultiRdnITests.java index ac63fedd..ef4b7fb9 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/DefaultLdapClientLookupMultiRdnITests.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/DefaultLdapClientLookupMultiRdnITests.java @@ -76,7 +76,8 @@ public class DefaultLdapClientLookupMultiRdnITests extends AbstractLdapTemplateI @Test @Category(NoAdTests.class) public void testLookup_GetNameInNamespace_MultiRdn() { - DirContextOperations result = this.tested.search().name("cn=Some Person+sn=Person,ou=company1,ou=Norway").toEntry(); + DirContextOperations result = this.tested.search().name("cn=Some Person+sn=Person,ou=company1,ou=Norway") + .toEntry(); assertThat(result.getDn().toString()).isEqualTo("cn=Some Person+sn=Person,ou=company1,ou=Norway"); assertThat(result.getNameInNamespace()).isEqualTo("cn=Some Person+sn=Person,ou=company1,ou=Norway," + base); } diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/DefaultLdapClientSearchResultITests.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/DefaultLdapClientSearchResultITests.java index e4ecf714..bf2bf6fa 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/DefaultLdapClientSearchResultITests.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/DefaultLdapClientSearchResultITests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ldap.itest; import java.util.List; @@ -45,7 +46,6 @@ import org.springframework.test.util.ReflectionTestUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; -import static org.springframework.ldap.query.LdapQueryBuilder.query; /** * Tests for {@link LdapClient}'s search methods. @@ -106,8 +106,8 @@ public class DefaultLdapClientSearchResultITests extends AbstractLdapTemplateInt this.attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.attributesMapper.setExpectedValues(ALL_VALUES); - List list = this.tested.search() - .query(query().base(BASE_STRING).where("objectclass").is("person").and("sn").is("Person2")) + List list = this.tested.search().query( + LdapQueryBuilder.query().base(BASE_STRING).where("objectclass").is("person").and("sn").is("Person2")) .toList(this.attributesMapper); assertThat(list).hasSize(1); } @@ -117,8 +117,8 @@ public class DefaultLdapClientSearchResultITests extends AbstractLdapTemplateInt this.attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.attributesMapper.setExpectedValues(ALL_VALUES); - List list = this.tested.search() - .query(query().base(BASE_STRING).where("objectclass").is("person").and("sn").is("Person2")) + List list = this.tested.search().query( + LdapQueryBuilder.query().base(BASE_STRING).where("objectclass").is("person").and("sn").is("Person2")) .toStream(this.attributesMapper).collect(Collectors.toList()); assertThat(list).hasSize(1); } @@ -128,9 +128,8 @@ public class DefaultLdapClientSearchResultITests extends AbstractLdapTemplateInt this.attributesMapper.setExpectedAttributes(new String[] { "cn" }); this.attributesMapper.setExpectedValues(new String[] { "Some Person2" }); - List list = this.tested.search().query( - query().base(BASE_STRING).attributes("cn").where("objectclass").is("person").and("sn").is("Person2")) - .toList(this.attributesMapper); + List list = this.tested.search().query(LdapQueryBuilder.query().base(BASE_STRING).attributes("cn") + .where("objectclass").is("person").and("sn").is("Person2")).toList(this.attributesMapper); assertThat(list).hasSize(1); } @@ -139,8 +138,9 @@ public class DefaultLdapClientSearchResultITests extends AbstractLdapTemplateInt this.attributesMapper.setExpectedAttributes(new String[] { "cn" }); this.attributesMapper.setExpectedValues(new String[] { "Some Person2" }); - List list = this.tested.search().query( - query().base(BASE_STRING).attributes("cn").where("objectclass").is("person").and("sn").is("Person2")) + List list = this.tested + .search().query(LdapQueryBuilder.query().base(BASE_STRING).attributes("cn").where("objectclass") + .is("person").and("sn").is("Person2")) .toStream(this.attributesMapper).collect(Collectors.toList()); assertThat(list).hasSize(1); } @@ -150,8 +150,9 @@ public class DefaultLdapClientSearchResultITests extends AbstractLdapTemplateInt this.attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.attributesMapper.setExpectedValues(ALL_VALUES); - List list = this.tested.search().query(query().base(BASE_STRING).searchScope(SearchScope.ONELEVEL) - .where("objectclass").is("person").and("sn").is("Person2")).toList(this.attributesMapper); + List list = this.tested.search().query(LdapQueryBuilder.query().base(BASE_STRING) + .searchScope(SearchScope.ONELEVEL).where("objectclass").is("person").and("sn").is("Person2")) + .toList(this.attributesMapper); assertThat(list).isEmpty(); } @@ -160,9 +161,10 @@ public class DefaultLdapClientSearchResultITests extends AbstractLdapTemplateInt this.attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.attributesMapper.setExpectedValues(ALL_VALUES); - List list = this.tested.search().query(query().base(BASE_STRING).searchScope(SearchScope.ONELEVEL) - .where("objectclass").is("person").and("sn").is("Person2")).toStream(this.attributesMapper) - .collect(Collectors.toList()); + List list = this.tested.search() + .query(LdapQueryBuilder.query().base(BASE_STRING).searchScope(SearchScope.ONELEVEL).where("objectclass") + .is("person").and("sn").is("Person2")) + .toStream(this.attributesMapper).collect(Collectors.toList()); assertThat(list).isEmpty(); } @@ -171,7 +173,7 @@ public class DefaultLdapClientSearchResultITests extends AbstractLdapTemplateInt this.attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.attributesMapper.setExpectedValues(ALL_VALUES); - List list = this.tested.search().query(query().base("ou=company1,ou=Sweden") + List list = this.tested.search().query(LdapQueryBuilder.query().base("ou=company1,ou=Sweden") .searchScope(SearchScope.ONELEVEL).where("objectclass").is("person").and("sn").is("Person2")) .toList(this.attributesMapper); assertThat(list).hasSize(1); @@ -182,8 +184,8 @@ public class DefaultLdapClientSearchResultITests extends AbstractLdapTemplateInt this.attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.attributesMapper.setExpectedValues(ALL_VALUES); - List list = this.tested - .search().query(query().base("ou=company1,ou=Sweden").searchScope(SearchScope.ONELEVEL) + List list = this.tested.search() + .query(LdapQueryBuilder.query().base("ou=company1,ou=Sweden").searchScope(SearchScope.ONELEVEL) .where("objectclass").is("person").and("sn").is("Person2")) .toStream(this.attributesMapper).collect(Collectors.toList()); assertThat(list).hasSize(1); @@ -194,7 +196,8 @@ public class DefaultLdapClientSearchResultITests extends AbstractLdapTemplateInt this.attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.attributesMapper.setExpectedValues(ALL_VALUES); - List list = this.tested.search().query(query().where("objectclass").is("person").and("sn").is("Person2")) + List list = this.tested.search() + .query(LdapQueryBuilder.query().where("objectclass").is("person").and("sn").is("Person2")) .toList(this.attributesMapper); assertThat(list).hasSize(1); } @@ -204,7 +207,8 @@ public class DefaultLdapClientSearchResultITests extends AbstractLdapTemplateInt this.attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.attributesMapper.setExpectedValues(ALL_VALUES); - List list = this.tested.search().query(query().where("objectclass").is("person").and("sn").is("Person2")) + List list = this.tested.search() + .query(LdapQueryBuilder.query().where("objectclass").is("person").and("sn").is("Person2")) .toStream(this.attributesMapper).collect(Collectors.toList()); assertThat(list).hasSize(1); } @@ -214,8 +218,8 @@ public class DefaultLdapClientSearchResultITests extends AbstractLdapTemplateInt this.attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.attributesMapper.setExpectedValues(ALL_VALUES); - List list = this.tested.search() - .query(query().base("ou=Norway").where("objectclass").is("person").and("sn").is("Person2")) + List list = this.tested.search().query( + LdapQueryBuilder.query().base("ou=Norway").where("objectclass").is("person").and("sn").is("Person2")) .toList(this.attributesMapper); assertThat(list).isEmpty(); } @@ -225,8 +229,8 @@ public class DefaultLdapClientSearchResultITests extends AbstractLdapTemplateInt this.attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.attributesMapper.setExpectedValues(ALL_VALUES); - List list = this.tested.search() - .query(query().base("ou=Norway").where("objectclass").is("person").and("sn").is("Person2")) + List list = this.tested.search().query( + LdapQueryBuilder.query().base("ou=Norway").where("objectclass").is("person").and("sn").is("Person2")) .toStream(this.attributesMapper).collect(Collectors.toList()); assertThat(list).isEmpty(); } @@ -235,8 +239,8 @@ public class DefaultLdapClientSearchResultITests extends AbstractLdapTemplateInt public void testSearch_SearchScope_AttributesMapper() { this.attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.attributesMapper.setExpectedValues(ALL_VALUES); - List list = this.tested.search() - .query(query().base(BASE_STRING).searchScope(SearchScope.SUBTREE).filter(FILTER_STRING)) + List list = this.tested.search().query( + LdapQueryBuilder.query().base(BASE_STRING).searchScope(SearchScope.SUBTREE).filter(FILTER_STRING)) .toList(this.attributesMapper); assertThat(list).hasSize(1); } @@ -246,8 +250,9 @@ public class DefaultLdapClientSearchResultITests extends AbstractLdapTemplateInt this.attributesMapper.setExpectedAttributes(CN_SN_ATTRS); this.attributesMapper.setExpectedValues(CN_SN_VALUES); this.attributesMapper.setAbsentAttributes(ABSENT_ATTRIBUTES); - List list = this.tested.search().query(query().base(BASE_STRING).searchScope(SearchScope.SUBTREE) - .attributes(CN_SN_ATTRS).filter(FILTER_STRING)).toList(this.attributesMapper); + List list = this.tested.search().query(LdapQueryBuilder.query().base(BASE_STRING) + .searchScope(SearchScope.SUBTREE).attributes(CN_SN_ATTRS).filter(FILTER_STRING)) + .toList(this.attributesMapper); assertThat(list).hasSize(1); } @@ -255,7 +260,7 @@ public class DefaultLdapClientSearchResultITests extends AbstractLdapTemplateInt public void testSearch_AttributesMapper_Name() { this.attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.attributesMapper.setExpectedValues(ALL_VALUES); - List list = this.tested.search().query(query().base(BASE_NAME).filter(FILTER_STRING)) + List list = this.tested.search().query(LdapQueryBuilder.query().base(BASE_NAME).filter(FILTER_STRING)) .toList(this.attributesMapper); assertThat(list).hasSize(1); } @@ -265,7 +270,7 @@ public class DefaultLdapClientSearchResultITests extends AbstractLdapTemplateInt this.attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.attributesMapper.setExpectedValues(ALL_VALUES); List list = this.tested.search() - .query(query().base(BASE_NAME).searchScope(SearchScope.SUBTREE).filter(FILTER_STRING)) + .query(LdapQueryBuilder.query().base(BASE_NAME).searchScope(SearchScope.SUBTREE).filter(FILTER_STRING)) .toList(this.attributesMapper); assertThat(list).hasSize(1); } @@ -275,8 +280,8 @@ public class DefaultLdapClientSearchResultITests extends AbstractLdapTemplateInt this.attributesMapper.setExpectedAttributes(CN_SN_ATTRS); this.attributesMapper.setExpectedValues(CN_SN_VALUES); this.attributesMapper.setAbsentAttributes(ABSENT_ATTRIBUTES); - List list = this.tested.search().query( - query().base(BASE_NAME).searchScope(SearchScope.SUBTREE).attributes(CN_SN_ATTRS).filter(FILTER_STRING)) + List list = this.tested.search().query(LdapQueryBuilder.query().base(BASE_NAME) + .searchScope(SearchScope.SUBTREE).attributes(CN_SN_ATTRS).filter(FILTER_STRING)) .toList(this.attributesMapper); assertThat(list).hasSize(1); } @@ -285,8 +290,8 @@ public class DefaultLdapClientSearchResultITests extends AbstractLdapTemplateInt public void testSearch_ContextMapper() { this.contextMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.contextMapper.setExpectedValues(ALL_VALUES); - List list = this.tested.search().query(query().base(BASE_STRING).filter(FILTER_STRING)) - .toList(this.contextMapper); + List list = this.tested.search() + .query(LdapQueryBuilder.query().base(BASE_STRING).filter(FILTER_STRING)).toList(this.contextMapper); assertThat(list).hasSize(1); } @@ -294,21 +299,21 @@ public class DefaultLdapClientSearchResultITests extends AbstractLdapTemplateInt public void testSearchForObject() { this.contextMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.contextMapper.setExpectedValues(ALL_VALUES); - DirContextAdapter result = this.tested.search().query(query().base(BASE_STRING).filter(FILTER_STRING)) - .toObject(this.contextMapper); + DirContextAdapter result = this.tested.search() + .query(LdapQueryBuilder.query().base(BASE_STRING).filter(FILTER_STRING)).toObject(this.contextMapper); assertThat(result).isNotNull(); } @Test(expected = IncorrectResultSizeDataAccessException.class) public void testSearchForObjectWithMultipleHits() { - this.tested.search().query(query().base(BASE_STRING).filter("(&(objectclass=person)(sn=*))")) + this.tested.search().query(LdapQueryBuilder.query().base(BASE_STRING).filter("(&(objectclass=person)(sn=*))")) .toObject((Object ctx) -> ctx); } @Test // (expected = EmptyResultDataAccessException.class) public void testSearchForObjectNoHits() { - Object result = this.tested.search() - .query(query().base(BASE_STRING).filter("(&(objectclass=person)(sn=Person does not exist))")) + Object result = this.tested.search().query( + LdapQueryBuilder.query().base(BASE_STRING).filter("(&(objectclass=person)(sn=Person does not exist))")) .toObject((Object ctx) -> ctx); assertThat(result).isNull(); } @@ -317,8 +322,8 @@ public class DefaultLdapClientSearchResultITests extends AbstractLdapTemplateInt public void testSearch_SearchScope_ContextMapper() { this.contextMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.contextMapper.setExpectedValues(ALL_VALUES); - List list = this.tested.search() - .query(query().base(BASE_STRING).searchScope(SearchScope.SUBTREE).filter(FILTER_STRING)) + List list = this.tested.search().query( + LdapQueryBuilder.query().base(BASE_STRING).searchScope(SearchScope.SUBTREE).filter(FILTER_STRING)) .toList(this.contextMapper); assertThat(list).hasSize(1); } @@ -328,8 +333,9 @@ public class DefaultLdapClientSearchResultITests extends AbstractLdapTemplateInt this.contextMapper.setExpectedAttributes(CN_SN_ATTRS); this.contextMapper.setExpectedValues(CN_SN_VALUES); this.contextMapper.setAbsentAttributes(ABSENT_ATTRIBUTES); - List list = this.tested.search().query(query().base(BASE_STRING).searchScope(SearchScope.SUBTREE) - .attributes(CN_SN_ATTRS).filter(FILTER_STRING)).toList(this.contextMapper); + List list = this.tested.search().query(LdapQueryBuilder.query().base(BASE_STRING) + .searchScope(SearchScope.SUBTREE).attributes(CN_SN_ATTRS).filter(FILTER_STRING)) + .toList(this.contextMapper); assertThat(list).hasSize(1); } @@ -337,8 +343,8 @@ public class DefaultLdapClientSearchResultITests extends AbstractLdapTemplateInt public void testSearch_ContextMapper_Name() { this.contextMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.contextMapper.setExpectedValues(ALL_VALUES); - List list = this.tested.search().query(query().base(BASE_NAME).filter(FILTER_STRING)) - .toList(this.contextMapper); + List list = this.tested.search() + .query(LdapQueryBuilder.query().base(BASE_NAME).filter(FILTER_STRING)).toList(this.contextMapper); assertThat(list).hasSize(1); } @@ -346,8 +352,8 @@ public class DefaultLdapClientSearchResultITests extends AbstractLdapTemplateInt public void testSearch_ContextMapper_LdapQuery() { this.contextMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.contextMapper.setExpectedValues(ALL_VALUES); - List list = this.tested.search() - .query(query().base(BASE_NAME).where("objectclass").is("person").and("sn").is("Person2")) + List list = this.tested.search().query( + LdapQueryBuilder.query().base(BASE_NAME).where("objectclass").is("person").and("sn").is("Person2")) .toList(this.contextMapper); assertThat(list).hasSize(1); } @@ -356,8 +362,8 @@ public class DefaultLdapClientSearchResultITests extends AbstractLdapTemplateInt public void testSearchForStream_ContextMapper_LdapQuery() { this.contextMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.contextMapper.setExpectedValues(ALL_VALUES); - List list = this.tested.search() - .query(query().base(BASE_NAME).where("objectclass").is("person").and("sn").is("Person2")) + List list = this.tested.search().query( + LdapQueryBuilder.query().base(BASE_NAME).where("objectclass").is("person").and("sn").is("Person2")) .toStream(this.contextMapper).collect(Collectors.toList()); assertThat(list).hasSize(1); } @@ -367,7 +373,8 @@ public class DefaultLdapClientSearchResultITests extends AbstractLdapTemplateInt this.contextMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.contextMapper.setExpectedValues(ALL_VALUES); List list = this.tested.search() - .query(query().where("objectclass").is("person").and("sn").is("Person2")).toList(this.contextMapper); + .query(LdapQueryBuilder.query().where("objectclass").is("person").and("sn").is("Person2")) + .toList(this.contextMapper); assertThat(list).hasSize(1); } @@ -376,8 +383,8 @@ public class DefaultLdapClientSearchResultITests extends AbstractLdapTemplateInt this.contextMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.contextMapper.setExpectedValues(ALL_VALUES); List list = this.tested.search() - .query(query().where("objectclass").is("person").and("sn").is("Person2")).toStream(this.contextMapper) - .collect(Collectors.toList()); + .query(LdapQueryBuilder.query().where("objectclass").is("person").and("sn").is("Person2")) + .toStream(this.contextMapper).collect(Collectors.toList()); assertThat(list).hasSize(1); } @@ -385,8 +392,9 @@ public class DefaultLdapClientSearchResultITests extends AbstractLdapTemplateInt public void testSearch_ContextMapper_LdapQuery_SearchScope() { this.contextMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.contextMapper.setExpectedValues(ALL_VALUES); - List list = this.tested.search().query(query().base(BASE_NAME).searchScope(SearchScope.ONELEVEL) - .where("objectclass").is("person").and("sn").is("Person2")).toList(this.contextMapper); + List list = this.tested.search().query(LdapQueryBuilder.query().base(BASE_NAME) + .searchScope(SearchScope.ONELEVEL).where("objectclass").is("person").and("sn").is("Person2")) + .toList(this.contextMapper); assertThat(list).isEmpty(); } @@ -394,9 +402,10 @@ public class DefaultLdapClientSearchResultITests extends AbstractLdapTemplateInt public void testSearchForStream_ContextMapper_LdapQuery_SearchScope() { this.contextMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.contextMapper.setExpectedValues(ALL_VALUES); - List list = this.tested.search().query(query().base(BASE_NAME).searchScope(SearchScope.ONELEVEL) - .where("objectclass").is("person").and("sn").is("Person2")).toStream(this.contextMapper) - .collect(Collectors.toList()); + List list = this.tested.search() + .query(LdapQueryBuilder.query().base(BASE_NAME).searchScope(SearchScope.ONELEVEL).where("objectclass") + .is("person").and("sn").is("Person2")) + .toStream(this.contextMapper).collect(Collectors.toList()); assertThat(list).isEmpty(); } @@ -404,7 +413,7 @@ public class DefaultLdapClientSearchResultITests extends AbstractLdapTemplateInt public void testSearch_ContextMapper_LdapQuery_SearchScope_CorrectBase() { this.contextMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.contextMapper.setExpectedValues(ALL_VALUES); - List list = this.tested.search().query(query().base("ou=company1,ou=Sweden") + List list = this.tested.search().query(LdapQueryBuilder.query().base("ou=company1,ou=Sweden") .searchScope(SearchScope.ONELEVEL).where("objectclass").is("person").and("sn").is("Person2")) .toList(this.contextMapper); assertThat(list).hasSize(1); @@ -414,8 +423,8 @@ public class DefaultLdapClientSearchResultITests extends AbstractLdapTemplateInt public void testSearchForStream_ContextMapper_LdapQuery_SearchScope_CorrectBase() { this.contextMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.contextMapper.setExpectedValues(ALL_VALUES); - List list = this.tested - .search().query(query().base("ou=company1,ou=Sweden").searchScope(SearchScope.ONELEVEL) + List list = this.tested.search() + .query(LdapQueryBuilder.query().base("ou=company1,ou=Sweden").searchScope(SearchScope.ONELEVEL) .where("objectclass").is("person").and("sn").is("Person2")) .toStream(this.contextMapper).collect(Collectors.toList()); assertThat(list).hasSize(1); @@ -425,24 +434,25 @@ public class DefaultLdapClientSearchResultITests extends AbstractLdapTemplateInt public void testSearchForContext_LdapQuery() { ContextMapper mapper = (result) -> (DirContextOperations) result; DirContextOperations result = this.tested.search() - .query(query().where("objectclass").is("person").and("sn").is("Person2")).toObject(mapper); + .query(LdapQueryBuilder.query().where("objectclass").is("person").and("sn").is("Person2")) + .toObject(mapper); assertThat(result).isNotNull(); assertThat(result.getStringAttribute("sn")).isEqualTo("Person2"); } @Test // (expected = EmptyResultDataAccessException.class) public void testSearchForContext_LdapQuery_SearchScopeNotFound() { - Object result = this.tested.search().query( - query().searchScope(SearchScope.ONELEVEL).where("objectclass").is("person").and("sn").is("Person2")) - .toObject(this.attributesMapper); + Object result = this.tested.search().query(LdapQueryBuilder.query().searchScope(SearchScope.ONELEVEL) + .where("objectclass").is("person").and("sn").is("Person2")).toObject(this.attributesMapper); assertThat(result).isNull(); } @Test public void testSearchForContext_LdapQuery_SearchScope_CorrectBase() { ContextMapper mapper = (result) -> (DirContextOperations) result; - DirContextOperations result = this.tested.search().query(query().searchScope(SearchScope.ONELEVEL) - .base("ou=company1,ou=Sweden").where("objectclass").is("person").and("sn").is("Person2")) + DirContextOperations result = this.tested.search() + .query(LdapQueryBuilder.query().searchScope(SearchScope.ONELEVEL).base("ou=company1,ou=Sweden") + .where("objectclass").is("person").and("sn").is("Person2")) .toObject(mapper); assertThat(result).isNotNull(); @@ -454,7 +464,7 @@ public class DefaultLdapClientSearchResultITests extends AbstractLdapTemplateInt this.contextMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.contextMapper.setExpectedValues(ALL_VALUES); List list = this.tested.search() - .query(query().base(BASE_NAME).searchScope(SearchScope.SUBTREE).filter(FILTER_STRING)) + .query(LdapQueryBuilder.query().base(BASE_NAME).searchScope(SearchScope.SUBTREE).filter(FILTER_STRING)) .toList(this.contextMapper); assertThat(list).hasSize(1); } @@ -464,8 +474,8 @@ public class DefaultLdapClientSearchResultITests extends AbstractLdapTemplateInt this.contextMapper.setExpectedAttributes(CN_SN_ATTRS); this.contextMapper.setExpectedValues(CN_SN_VALUES); this.contextMapper.setAbsentAttributes(ABSENT_ATTRIBUTES); - List list = this.tested.search().query( - query().base(BASE_NAME).searchScope(SearchScope.SUBTREE).attributes(CN_SN_ATTRS).filter(FILTER_STRING)) + List list = this.tested.search().query(LdapQueryBuilder.query().base(BASE_NAME) + .searchScope(SearchScope.SUBTREE).attributes(CN_SN_ATTRS).filter(FILTER_STRING)) .toList(this.contextMapper); assertThat(list).hasSize(1); } @@ -473,8 +483,10 @@ public class DefaultLdapClientSearchResultITests extends AbstractLdapTemplateInt @Test public void testSearchWithInvalidSearchBaseShouldByDefaultThrowException() { try { - this.tested.search().query(query().base(BASE_NAME + "ou=unknown").searchScope(SearchScope.SUBTREE) - .attributes(CN_SN_ATTRS).filter(FILTER_STRING)).toObject(this.contextMapper); + this.tested + .search().query(LdapQueryBuilder.query().base(BASE_NAME + "ou=unknown") + .searchScope(SearchScope.SUBTREE).attributes(CN_SN_ATTRS).filter(FILTER_STRING)) + .toObject(this.contextMapper); fail("NameNotFoundException expected"); } catch (NameNotFoundException expected) { @@ -488,14 +500,17 @@ public class DefaultLdapClientSearchResultITests extends AbstractLdapTemplateInt this.contextMapper.setExpectedAttributes(CN_SN_ATTRS); this.contextMapper.setExpectedValues(CN_SN_VALUES); this.contextMapper.setAbsentAttributes(ABSENT_ATTRIBUTES); - List list = this.tested.search().query(query().base(BASE_NAME + "ou=unknown") - .searchScope(SearchScope.SUBTREE).attributes(CN_SN_ATTRS).filter(FILTER_STRING)).toList(this.contextMapper); + List list = this.tested.search() + .query(LdapQueryBuilder.query().base(BASE_NAME + "ou=unknown").searchScope(SearchScope.SUBTREE) + .attributes(CN_SN_ATTRS).filter(FILTER_STRING)) + .toList(this.contextMapper); assertThat(list).isEmpty(); } @Test public void verifyThatSearchWithCountLimitReturnsTheEntriesFoundSoFar() { - List result = this.tested.search().query(query().countLimit(3).where("objectclass").is("person")) + List result = this.tested.search() + .query(LdapQueryBuilder.query().countLimit(3).where("objectclass").is("person")) .toList((Object ctx) -> new Object()); assertThat(result).hasSize(3); @@ -504,7 +519,8 @@ public class DefaultLdapClientSearchResultITests extends AbstractLdapTemplateInt @Test(expected = SizeLimitExceededException.class) public void verifyThatSearchWithCountLimitWithFlagToFalseThrowsException() { ReflectionTestUtils.setField(this.tested, "ignoreSizeLimitExceededException", false); - this.tested.search().query(query().countLimit(3).where("objectclass").is("person")).toList((Object ctx) -> ctx); + this.tested.search().query(LdapQueryBuilder.query().countLimit(3).where("objectclass").is("person")) + .toList((Object ctx) -> ctx); } } diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateAuthenticationITests.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateAuthenticationITests.java index 928d7661..7ea12c3f 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateAuthenticationITests.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateAuthenticationITests.java @@ -34,10 +34,10 @@ import org.springframework.ldap.core.LdapTemplate; import org.springframework.ldap.core.support.LookupAttemptingCallback; import org.springframework.ldap.filter.AndFilter; import org.springframework.ldap.filter.EqualsFilter; +import org.springframework.ldap.query.LdapQueryBuilder; import org.springframework.test.context.ContextConfiguration; import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.ldap.query.LdapQueryBuilder.query; /** * Tests the authenticate methods of LdapTemplate. @@ -64,7 +64,8 @@ public class LdapTemplateAuthenticationITests extends AbstractLdapTemplateIntegr public void testAuthenticateWithLdapQuery() { AndFilter filter = new AndFilter(); filter.and(new EqualsFilter("objectclass", "person")).and(new EqualsFilter("uid", "some.person3")); - this.tested.authenticate(query().where("objectclass").is("person").and("uid").is("some.person3"), "password"); + this.tested.authenticate( + LdapQueryBuilder.query().where("objectclass").is("person").and("uid").is("some.person3"), "password"); } @Test @@ -80,7 +81,9 @@ public class LdapTemplateAuthenticationITests extends AbstractLdapTemplateIntegr public void testAuthenticateWithLdapQueryAndInvalidPassword() { AndFilter filter = new AndFilter(); filter.and(new EqualsFilter("objectclass", "person")).and(new EqualsFilter("uid", "some.person3")); - this.tested.authenticate(query().where("objectclass").is("person").and("uid").is("some.person3"), "invalidpassword"); + this.tested.authenticate( + LdapQueryBuilder.query().where("objectclass").is("person").and("uid").is("some.person3"), + "invalidpassword"); } @Test @@ -94,8 +97,8 @@ public class LdapTemplateAuthenticationITests extends AbstractLdapTemplateIntegr DirContextAdapter adapter = (DirContextAdapter) ctx.lookup(ldapEntryIdentification.getRelativeDn()); assertThat(adapter.getStringAttribute("cn")).isEqualTo("Some Person3"); } - catch (NamingException e) { - throw new RuntimeException("Failed to lookup " + ldapEntryIdentification.getRelativeDn(), e); + catch (NamingException ex) { + throw new RuntimeException("Failed to lookup " + ldapEntryIdentification.getRelativeDn(), ex); } } }; @@ -106,7 +109,7 @@ public class LdapTemplateAuthenticationITests extends AbstractLdapTemplateIntegr @Category(NoAdTests.class) public void testAuthenticateWithLdapQueryAndMapper() { DirContextOperations ctx = this.tested.authenticate( - query().where("objectclass").is("person").and("uid").is("some.person3"), "password", + LdapQueryBuilder.query().where("objectclass").is("person").and("uid").is("some.person3"), "password", new LookupAttemptingCallback()); assertThat(ctx).isNotNull(); @@ -117,8 +120,8 @@ public class LdapTemplateAuthenticationITests extends AbstractLdapTemplateIntegr @Category(NoAdTests.class) public void testAuthenticateWithLdapQueryAndMapperAndInvalidPassword() { DirContextOperations ctx = this.tested.authenticate( - query().where("objectclass").is("person").and("uid").is("some.person3"), "invalidpassword", - new LookupAttemptingCallback()); + LdapQueryBuilder.query().where("objectclass").is("person").and("uid").is("some.person3"), + "invalidpassword", new LookupAttemptingCallback()); } @Test diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateContextExecutorTests.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateContextExecutorTests.java index d2caf5ef..dd8c6410 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateContextExecutorTests.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateContextExecutorTests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ldap.itest; import javax.naming.NamingException; diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateListITests.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateListITests.java index 9096a4dd..523246fb 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateListITests.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateListITests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ldap.itest; import java.util.LinkedList; diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateLookupITests.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateLookupITests.java index 4786f0e3..37aefe22 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateLookupITests.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateLookupITests.java @@ -84,37 +84,14 @@ public class LdapTemplateLookupITests extends AbstractLdapTemplateIntegrationTes @Test public void testLookup_AttributesMapper_LdapName() { AttributesMapper mapper = new PersonAttributesMapper(); - Person person = (Person) this.tested.lookup(LdapUtils.newLdapName("cn=Some Person2, ou=company1,ou=Sweden"), mapper); + Person person = (Person) this.tested.lookup(LdapUtils.newLdapName("cn=Some Person2, ou=company1,ou=Sweden"), + mapper); assertThat(person.getFullname()).isEqualTo("Some Person2"); assertThat(person.getLastname()).isEqualTo("Person2"); assertThat(person.getDescription()).isEqualTo("Sweden, Company1, Some Person2"); } - /** - * An {@link AttributesMapper} that only maps a subset of the full attributes list. - * Used in tests where the return attributes list has been limited. - * - * @author Ulrik Sandberg - */ - private final class SubsetPersonAttributesMapper implements AttributesMapper { - - /** - * Maps the cn attribute into a {@link Person} object. Also verifies - * that the other attributes haven't been set. - * - * @see org.springframework.ldap.core.AttributesMapper#mapFromAttributes(javax.naming.directory.Attributes) - */ - public Object mapFromAttributes(Attributes attributes) throws NamingException { - Person person = new Person(); - person.setFullname((String) attributes.get("cn").get()); - assertThat(attributes.get("sn")).as("sn should be null").isNull(); - assertThat(attributes.get("description")).as("description should be null").isNull(); - return person; - } - - } - /** * Verifies that only the subset is used when specifying a subset of the available * attributes as return attributes. @@ -123,7 +100,8 @@ public class LdapTemplateLookupITests extends AbstractLdapTemplateIntegrationTes public void testLookup_ReturnAttributes_AttributesMapper() { AttributesMapper mapper = new SubsetPersonAttributesMapper(); - Person person = (Person) this.tested.lookup("cn=Some Person2, ou=company1,ou=Sweden", new String[] { "cn" }, mapper); + Person person = (Person) this.tested.lookup("cn=Some Person2, ou=company1,ou=Sweden", new String[] { "cn" }, + mapper); assertThat(person.getFullname()).isEqualTo("Some Person2"); assertThat(person.getLastname()).as("lastName should not be set").isNull(); @@ -168,7 +146,8 @@ public class LdapTemplateLookupITests extends AbstractLdapTemplateIntegrationTes public void testLookup_ReturnAttributes_ContextMapper() { ContextMapper mapper = new PersonContextMapper(); - Person person = (Person) this.tested.lookup("cn=Some Person2, ou=company1,ou=Sweden", new String[] { "cn" }, mapper); + Person person = (Person) this.tested.lookup("cn=Some Person2, ou=company1,ou=Sweden", new String[] { "cn" }, + mapper); assertThat(person.getFullname()).isEqualTo("Some Person2"); assertThat(person.getLastname()).as("lastName should not be set").isNull(); @@ -185,4 +164,28 @@ public class LdapTemplateLookupITests extends AbstractLdapTemplateIntegrationTes assertThat(result.getNameInNamespace()).isEqualTo("cn=Some Person2,ou=company1,ou=Sweden," + base); } + /** + * An {@link AttributesMapper} that only maps a subset of the full attributes list. + * Used in tests where the return attributes list has been limited. + * + * @author Ulrik Sandberg + */ + private final class SubsetPersonAttributesMapper implements AttributesMapper { + + /** + * Maps the cn attribute into a {@link Person} object. Also verifies + * that the other attributes haven't been set. + * + * @see org.springframework.ldap.core.AttributesMapper#mapFromAttributes(javax.naming.directory.Attributes) + */ + public Object mapFromAttributes(Attributes attributes) throws NamingException { + Person person = new Person(); + person.setFullname((String) attributes.get("cn").get()); + assertThat(attributes.get("sn")).as("sn should be null").isNull(); + assertThat(attributes.get("description")).as("description should be null").isNull(); + return person; + } + + } + } diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateLookupMultiRdnITests.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateLookupMultiRdnITests.java index 4d60b39f..42c9554f 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateLookupMultiRdnITests.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateLookupMultiRdnITests.java @@ -68,7 +68,8 @@ public class LdapTemplateLookupMultiRdnITests extends AbstractLdapTemplateIntegr @Test @Category(NoAdTests.class) public void testLookup_MultiValuedRdn_DirContextAdapter() { - DirContextAdapter result = (DirContextAdapter) this.tested.lookup("cn=Some Person+sn=Person, ou=company1,ou=Norway"); + DirContextAdapter result = (DirContextAdapter) this.tested + .lookup("cn=Some Person+sn=Person, ou=company1,ou=Norway"); assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person"); assertThat(result.getStringAttribute("sn")).isEqualTo("Person"); @@ -78,7 +79,8 @@ public class LdapTemplateLookupMultiRdnITests extends AbstractLdapTemplateIntegr @Test @Category(NoAdTests.class) public void testLookup_GetNameInNamespace_MultiRdn() { - DirContextAdapter result = (DirContextAdapter) this.tested.lookup("cn=Some Person+sn=Person,ou=company1,ou=Norway"); + DirContextAdapter result = (DirContextAdapter) this.tested + .lookup("cn=Some Person+sn=Person,ou=company1,ou=Norway"); assertThat(result.getDn().toString()).isEqualTo("cn=Some Person+sn=Person,ou=company1,ou=Norway"); assertThat(result.getNameInNamespace()).isEqualTo("cn=Some Person+sn=Person,ou=company1,ou=Norway," + base); diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateNoBaseSuffixITests.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateNoBaseSuffixITests.java index beddd3f7..51eb20a9 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateNoBaseSuffixITests.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateNoBaseSuffixITests.java @@ -86,7 +86,8 @@ public class LdapTemplateNoBaseSuffixITests extends AbstractLdapTemplateIntegrat adapter.setAttributeValue("sn", "Person4"); this.tested.bind("cn=Some Person4, ou=company1, ou=Sweden," + base, adapter, null); - DirContextAdapter result = (DirContextAdapter) this.tested.lookup("cn=Some Person4, ou=company1, ou=Sweden," + base); + DirContextAdapter result = (DirContextAdapter) this.tested + .lookup("cn=Some Person4, ou=company1, ou=Sweden," + base); assertThat(result.getStringAttribute("cn")).isEqualTo("Some Person4"); assertThat(result.getStringAttribute("sn")).isEqualTo("Person4"); diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateRecursiveDeleteITests.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateRecursiveDeleteITests.java index 04f607ff..e79f2f75 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateRecursiveDeleteITests.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateRecursiveDeleteITests.java @@ -31,7 +31,7 @@ import org.springframework.ldap.core.LdapTemplate; import org.springframework.ldap.support.LdapUtils; import org.springframework.test.context.ContextConfiguration; -import static junit.framework.Assert.fail; +import static org.assertj.core.api.Assertions.fail; /** * Tests the recursive modification methods (unbind and the protected delete methods) of diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateSearchResultITests.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateSearchResultITests.java index 1801f540..7f7dcd55 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateSearchResultITests.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateSearchResultITests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ldap.itest; import java.util.List; @@ -36,6 +37,7 @@ import org.springframework.ldap.core.DirContextAdapter; import org.springframework.ldap.core.DirContextOperations; import org.springframework.ldap.core.LdapTemplate; import org.springframework.ldap.core.support.AbstractContextMapper; +import org.springframework.ldap.query.LdapQueryBuilder; import org.springframework.ldap.query.SearchScope; import org.springframework.ldap.support.LdapUtils; import org.springframework.ldap.test.AttributeCheckAttributesMapper; @@ -46,7 +48,6 @@ import org.springframework.test.context.ContextConfiguration; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; -import static org.springframework.ldap.query.LdapQueryBuilder.query; /** * Tests for LdapTemplate's search methods. This test class tests all the different @@ -108,7 +109,8 @@ public class LdapTemplateSearchResultITests extends AbstractLdapTemplateIntegrat this.attributesMapper.setExpectedValues(ALL_VALUES); List list = this.tested.search( - query().base(BASE_STRING).where("objectclass").is("person").and("sn").is("Person2"), this.attributesMapper); + LdapQueryBuilder.query().base(BASE_STRING).where("objectclass").is("person").and("sn").is("Person2"), + this.attributesMapper); assertThat(list).hasSize(1); } @@ -117,10 +119,9 @@ public class LdapTemplateSearchResultITests extends AbstractLdapTemplateIntegrat this.attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.attributesMapper.setExpectedValues(ALL_VALUES); - List list = this.tested - .searchForStream(query().base(BASE_STRING).where("objectclass").is("person").and("sn").is("Person2"), - this.attributesMapper) - .collect(Collectors.toList()); + List list = this.tested.searchForStream( + LdapQueryBuilder.query().base(BASE_STRING).where("objectclass").is("person").and("sn").is("Person2"), + this.attributesMapper).collect(Collectors.toList()); assertThat(list).hasSize(1); } @@ -129,9 +130,8 @@ public class LdapTemplateSearchResultITests extends AbstractLdapTemplateIntegrat this.attributesMapper.setExpectedAttributes(new String[] { "cn" }); this.attributesMapper.setExpectedValues(new String[] { "Some Person2" }); - List list = this.tested.search( - query().base(BASE_STRING).attributes("cn").where("objectclass").is("person").and("sn").is("Person2"), - this.attributesMapper); + List list = this.tested.search(LdapQueryBuilder.query().base(BASE_STRING).attributes("cn") + .where("objectclass").is("person").and("sn").is("Person2"), this.attributesMapper); assertThat(list).hasSize(1); } @@ -140,9 +140,9 @@ public class LdapTemplateSearchResultITests extends AbstractLdapTemplateIntegrat this.attributesMapper.setExpectedAttributes(new String[] { "cn" }); this.attributesMapper.setExpectedValues(new String[] { "Some Person2" }); - List list = this.tested.searchForStream( - query().base(BASE_STRING).attributes("cn").where("objectclass").is("person").and("sn").is("Person2"), - this.attributesMapper).collect(Collectors.toList()); + List list = this.tested.searchForStream(LdapQueryBuilder.query().base(BASE_STRING).attributes("cn") + .where("objectclass").is("person").and("sn").is("Person2"), this.attributesMapper) + .collect(Collectors.toList()); assertThat(list).hasSize(1); } @@ -151,8 +151,9 @@ public class LdapTemplateSearchResultITests extends AbstractLdapTemplateIntegrat this.attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.attributesMapper.setExpectedValues(ALL_VALUES); - List list = this.tested.search(query().base(BASE_STRING).searchScope(SearchScope.ONELEVEL) - .where("objectclass").is("person").and("sn").is("Person2"), this.attributesMapper); + List list = this.tested.search(LdapQueryBuilder.query().base(BASE_STRING) + .searchScope(SearchScope.ONELEVEL).where("objectclass").is("person").and("sn").is("Person2"), + this.attributesMapper); assertThat(list).isEmpty(); } @@ -161,8 +162,9 @@ public class LdapTemplateSearchResultITests extends AbstractLdapTemplateIntegrat this.attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.attributesMapper.setExpectedValues(ALL_VALUES); - List list = this.tested.searchForStream(query().base(BASE_STRING).searchScope(SearchScope.ONELEVEL) - .where("objectclass").is("person").and("sn").is("Person2"), this.attributesMapper) + List list = this.tested + .searchForStream(LdapQueryBuilder.query().base(BASE_STRING).searchScope(SearchScope.ONELEVEL) + .where("objectclass").is("person").and("sn").is("Person2"), this.attributesMapper) .collect(Collectors.toList()); assertThat(list).isEmpty(); } @@ -172,8 +174,9 @@ public class LdapTemplateSearchResultITests extends AbstractLdapTemplateIntegrat this.attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.attributesMapper.setExpectedValues(ALL_VALUES); - List list = this.tested.search(query().base("ou=company1,ou=Sweden").searchScope(SearchScope.ONELEVEL) - .where("objectclass").is("person").and("sn").is("Person2"), this.attributesMapper); + List list = this.tested.search(LdapQueryBuilder.query().base("ou=company1,ou=Sweden") + .searchScope(SearchScope.ONELEVEL).where("objectclass").is("person").and("sn").is("Person2"), + this.attributesMapper); assertThat(list).hasSize(1); } @@ -182,10 +185,9 @@ public class LdapTemplateSearchResultITests extends AbstractLdapTemplateIntegrat this.attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.attributesMapper.setExpectedValues(ALL_VALUES); - List list = this.tested - .searchForStream(query().base("ou=company1,ou=Sweden").searchScope(SearchScope.ONELEVEL) - .where("objectclass").is("person").and("sn").is("Person2"), this.attributesMapper) - .collect(Collectors.toList()); + List list = this.tested.searchForStream(LdapQueryBuilder.query().base("ou=company1,ou=Sweden") + .searchScope(SearchScope.ONELEVEL).where("objectclass").is("person").and("sn").is("Person2"), + this.attributesMapper).collect(Collectors.toList()); assertThat(list).hasSize(1); } @@ -194,7 +196,8 @@ public class LdapTemplateSearchResultITests extends AbstractLdapTemplateIntegrat this.attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.attributesMapper.setExpectedValues(ALL_VALUES); - List list = this.tested.search(query().where("objectclass").is("person").and("sn").is("Person2"), + List list = this.tested.search( + LdapQueryBuilder.query().where("objectclass").is("person").and("sn").is("Person2"), this.attributesMapper); assertThat(list).hasSize(1); } @@ -205,7 +208,8 @@ public class LdapTemplateSearchResultITests extends AbstractLdapTemplateIntegrat this.attributesMapper.setExpectedValues(ALL_VALUES); List list = this.tested - .searchForStream(query().where("objectclass").is("person").and("sn").is("Person2"), this.attributesMapper) + .searchForStream(LdapQueryBuilder.query().where("objectclass").is("person").and("sn").is("Person2"), + this.attributesMapper) .collect(Collectors.toList()); assertThat(list).hasSize(1); } @@ -216,7 +220,8 @@ public class LdapTemplateSearchResultITests extends AbstractLdapTemplateIntegrat this.attributesMapper.setExpectedValues(ALL_VALUES); List list = this.tested.search( - query().base("ou=Norway").where("objectclass").is("person").and("sn").is("Person2"), this.attributesMapper); + LdapQueryBuilder.query().base("ou=Norway").where("objectclass").is("person").and("sn").is("Person2"), + this.attributesMapper); assertThat(list).isEmpty(); } @@ -225,10 +230,9 @@ public class LdapTemplateSearchResultITests extends AbstractLdapTemplateIntegrat this.attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.attributesMapper.setExpectedValues(ALL_VALUES); - List list = this.tested - .searchForStream(query().base("ou=Norway").where("objectclass").is("person").and("sn").is("Person2"), - this.attributesMapper) - .collect(Collectors.toList()); + List list = this.tested.searchForStream( + LdapQueryBuilder.query().base("ou=Norway").where("objectclass").is("person").and("sn").is("Person2"), + this.attributesMapper).collect(Collectors.toList()); assertThat(list).isEmpty(); } @@ -327,7 +331,8 @@ public class LdapTemplateSearchResultITests extends AbstractLdapTemplateIntegrat this.contextMapper.setExpectedAttributes(CN_SN_ATTRS); this.contextMapper.setExpectedValues(CN_SN_VALUES); this.contextMapper.setAbsentAttributes(ABSENT_ATTRIBUTES); - List list = this.tested.search(BASE_STRING, FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS, this.contextMapper); + List list = this.tested.search(BASE_STRING, FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS, + this.contextMapper); assertThat(list).hasSize(1); } @@ -344,7 +349,8 @@ public class LdapTemplateSearchResultITests extends AbstractLdapTemplateIntegrat this.contextMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.contextMapper.setExpectedValues(ALL_VALUES); List list = this.tested.search( - query().base(BASE_NAME).where("objectclass").is("person").and("sn").is("Person2"), this.contextMapper); + LdapQueryBuilder.query().base(BASE_NAME).where("objectclass").is("person").and("sn").is("Person2"), + this.contextMapper); assertThat(list).hasSize(1); } @@ -352,10 +358,9 @@ public class LdapTemplateSearchResultITests extends AbstractLdapTemplateIntegrat public void testSearchForStream_ContextMapper_LdapQuery() { this.contextMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.contextMapper.setExpectedValues(ALL_VALUES); - List list = this.tested - .searchForStream(query().base(BASE_NAME).where("objectclass").is("person").and("sn").is("Person2"), - this.contextMapper) - .collect(Collectors.toList()); + List list = this.tested.searchForStream( + LdapQueryBuilder.query().base(BASE_NAME).where("objectclass").is("person").and("sn").is("Person2"), + this.contextMapper).collect(Collectors.toList()); assertThat(list).hasSize(1); } @@ -363,8 +368,8 @@ public class LdapTemplateSearchResultITests extends AbstractLdapTemplateIntegrat public void testSearch_ContextMapper_LdapQuery_NoBase() { this.contextMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.contextMapper.setExpectedValues(ALL_VALUES); - List list = this.tested.search(query().where("objectclass").is("person").and("sn").is("Person2"), - this.contextMapper); + List list = this.tested.search( + LdapQueryBuilder.query().where("objectclass").is("person").and("sn").is("Person2"), this.contextMapper); assertThat(list).hasSize(1); } @@ -373,7 +378,8 @@ public class LdapTemplateSearchResultITests extends AbstractLdapTemplateIntegrat this.contextMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.contextMapper.setExpectedValues(ALL_VALUES); List list = this.tested - .searchForStream(query().where("objectclass").is("person").and("sn").is("Person2"), this.contextMapper) + .searchForStream(LdapQueryBuilder.query().where("objectclass").is("person").and("sn").is("Person2"), + this.contextMapper) .collect(Collectors.toList()); assertThat(list).hasSize(1); } @@ -382,8 +388,9 @@ public class LdapTemplateSearchResultITests extends AbstractLdapTemplateIntegrat public void testSearch_ContextMapper_LdapQuery_SearchScope() { this.contextMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.contextMapper.setExpectedValues(ALL_VALUES); - List list = this.tested.search(query().base(BASE_NAME).searchScope(SearchScope.ONELEVEL) - .where("objectclass").is("person").and("sn").is("Person2"), this.contextMapper); + List list = this.tested.search(LdapQueryBuilder.query().base(BASE_NAME) + .searchScope(SearchScope.ONELEVEL).where("objectclass").is("person").and("sn").is("Person2"), + this.contextMapper); assertThat(list).isEmpty(); } @@ -391,8 +398,10 @@ public class LdapTemplateSearchResultITests extends AbstractLdapTemplateIntegrat public void testSearchForStream_ContextMapper_LdapQuery_SearchScope() { this.contextMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.contextMapper.setExpectedValues(ALL_VALUES); - List list = this.tested.searchForStream(query().base(BASE_NAME).searchScope(SearchScope.ONELEVEL) - .where("objectclass").is("person").and("sn").is("Person2"), this.contextMapper).collect(Collectors.toList()); + List list = this.tested + .searchForStream(LdapQueryBuilder.query().base(BASE_NAME).searchScope(SearchScope.ONELEVEL) + .where("objectclass").is("person").and("sn").is("Person2"), this.contextMapper) + .collect(Collectors.toList()); assertThat(list).isEmpty(); } @@ -400,7 +409,7 @@ public class LdapTemplateSearchResultITests extends AbstractLdapTemplateIntegrat public void testSearch_ContextMapper_LdapQuery_SearchScope_CorrectBase() { this.contextMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.contextMapper.setExpectedValues(ALL_VALUES); - List list = this.tested.search(query().base("ou=company1,ou=Sweden") + List list = this.tested.search(LdapQueryBuilder.query().base("ou=company1,ou=Sweden") .searchScope(SearchScope.ONELEVEL).where("objectclass").is("person").and("sn").is("Person2"), this.contextMapper); assertThat(list).hasSize(1); @@ -411,8 +420,9 @@ public class LdapTemplateSearchResultITests extends AbstractLdapTemplateIntegrat this.contextMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.contextMapper.setExpectedValues(ALL_VALUES); List list = this.tested - .searchForStream(query().base("ou=company1,ou=Sweden").searchScope(SearchScope.ONELEVEL) - .where("objectclass").is("person").and("sn").is("Person2"), this.contextMapper) + .searchForStream(LdapQueryBuilder.query().base("ou=company1,ou=Sweden") + .searchScope(SearchScope.ONELEVEL).where("objectclass").is("person").and("sn").is("Person2"), + this.contextMapper) .collect(Collectors.toList()); assertThat(list).hasSize(1); } @@ -420,7 +430,7 @@ public class LdapTemplateSearchResultITests extends AbstractLdapTemplateIntegrat @Test public void testSearchForContext_LdapQuery() { DirContextOperations result = this.tested - .searchForContext(query().where("objectclass").is("person").and("sn").is("Person2")); + .searchForContext(LdapQueryBuilder.query().where("objectclass").is("person").and("sn").is("Person2")); assertThat(result).isNotNull(); assertThat(result.getStringAttribute("sn")).isEqualTo("Person2"); @@ -428,14 +438,15 @@ public class LdapTemplateSearchResultITests extends AbstractLdapTemplateIntegrat @Test(expected = EmptyResultDataAccessException.class) public void testSearchForContext_LdapQuery_SearchScopeNotFound() { - this.tested.searchForContext( - query().searchScope(SearchScope.ONELEVEL).where("objectclass").is("person").and("sn").is("Person2")); + this.tested.searchForContext(LdapQueryBuilder.query().searchScope(SearchScope.ONELEVEL).where("objectclass") + .is("person").and("sn").is("Person2")); } @Test public void testSearchForContext_LdapQuery_SearchScope_CorrectBase() { - DirContextOperations result = this.tested.searchForContext(query().searchScope(SearchScope.ONELEVEL) - .base("ou=company1,ou=Sweden").where("objectclass").is("person").and("sn").is("Person2")); + DirContextOperations result = this.tested + .searchForContext(LdapQueryBuilder.query().searchScope(SearchScope.ONELEVEL) + .base("ou=company1,ou=Sweden").where("objectclass").is("person").and("sn").is("Person2")); assertThat(result).isNotNull(); assertThat(result.getStringAttribute("sn")).isEqualTo("Person2"); @@ -454,7 +465,8 @@ public class LdapTemplateSearchResultITests extends AbstractLdapTemplateIntegrat this.contextMapper.setExpectedAttributes(CN_SN_ATTRS); this.contextMapper.setExpectedValues(CN_SN_VALUES); this.contextMapper.setAbsentAttributes(ABSENT_ATTRIBUTES); - List list = this.tested.search(BASE_NAME, FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS, this.contextMapper); + List list = this.tested.search(BASE_NAME, FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS, + this.contextMapper); assertThat(list).hasSize(1); } @@ -476,15 +488,15 @@ public class LdapTemplateSearchResultITests extends AbstractLdapTemplateIntegrat this.contextMapper.setExpectedAttributes(CN_SN_ATTRS); this.contextMapper.setExpectedValues(CN_SN_VALUES); this.contextMapper.setAbsentAttributes(ABSENT_ATTRIBUTES); - List list = this.tested.search(BASE_NAME + "ou=unknown", FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS, - this.contextMapper); + List list = this.tested.search(BASE_NAME + "ou=unknown", FILTER_STRING, SearchControls.SUBTREE_SCOPE, + CN_SN_ATTRS, this.contextMapper); assertThat(list).isEmpty(); } @Test public void verifyThatSearchWithCountLimitReturnsTheEntriesFoundSoFar() { - List result = this.tested.search(query().countLimit(3).where("objectclass").is("person"), - new ContextMapper() { + List result = this.tested.search( + LdapQueryBuilder.query().countLimit(3).where("objectclass").is("person"), new ContextMapper() { @Override public Object mapFromContext(Object ctx) throws NamingException { return new Object(); @@ -497,12 +509,13 @@ public class LdapTemplateSearchResultITests extends AbstractLdapTemplateIntegrat @Test(expected = SizeLimitExceededException.class) public void verifyThatSearchWithCountLimitWithFlagToFalseThrowsException() { this.tested.setIgnoreSizeLimitExceededException(false); - this.tested.search(query().countLimit(3).where("objectclass").is("person"), new ContextMapper() { - @Override - public Object mapFromContext(Object ctx) throws NamingException { - return new Object(); - } - }); + this.tested.search(LdapQueryBuilder.query().countLimit(3).where("objectclass").is("person"), + new ContextMapper() { + @Override + public Object mapFromContext(Object ctx) throws NamingException { + return new Object(); + } + }); } } diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateSearchResultNamespaceConfigITests.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateSearchResultNamespaceConfigITests.java index 633917c2..aef2a5ce 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateSearchResultNamespaceConfigITests.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/LdapTemplateSearchResultNamespaceConfigITests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ldap.itest; import java.util.List; @@ -33,6 +34,7 @@ import org.springframework.ldap.core.DirContextAdapter; import org.springframework.ldap.core.DirContextOperations; import org.springframework.ldap.core.LdapTemplate; import org.springframework.ldap.core.support.AbstractContextMapper; +import org.springframework.ldap.query.LdapQueryBuilder; import org.springframework.ldap.query.SearchScope; import org.springframework.ldap.support.LdapUtils; import org.springframework.ldap.test.AttributeCheckAttributesMapper; @@ -43,7 +45,6 @@ import org.springframework.test.context.ContextConfiguration; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; -import static org.springframework.ldap.query.LdapQueryBuilder.query; /** * Tests for LdapTemplate's search methods. This test class tests all the different @@ -105,7 +106,8 @@ public class LdapTemplateSearchResultNamespaceConfigITests extends AbstractLdapT this.attributesMapper.setExpectedValues(ALL_VALUES); List list = this.tested.search( - query().base(BASE_STRING).where("objectclass").is("person").and("sn").is("Person2"), this.attributesMapper); + LdapQueryBuilder.query().base(BASE_STRING).where("objectclass").is("person").and("sn").is("Person2"), + this.attributesMapper); assertThat(list).hasSize(1); } @@ -114,10 +116,9 @@ public class LdapTemplateSearchResultNamespaceConfigITests extends AbstractLdapT this.attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.attributesMapper.setExpectedValues(ALL_VALUES); - List list = this.tested - .searchForStream(query().base(BASE_STRING).where("objectclass").is("person").and("sn").is("Person2"), - this.attributesMapper) - .collect(Collectors.toList()); + List list = this.tested.searchForStream( + LdapQueryBuilder.query().base(BASE_STRING).where("objectclass").is("person").and("sn").is("Person2"), + this.attributesMapper).collect(Collectors.toList()); assertThat(list).hasSize(1); } @@ -126,9 +127,8 @@ public class LdapTemplateSearchResultNamespaceConfigITests extends AbstractLdapT this.attributesMapper.setExpectedAttributes(new String[] { "cn" }); this.attributesMapper.setExpectedValues(new String[] { "Some Person2" }); - List list = this.tested.search( - query().base(BASE_STRING).attributes("cn").where("objectclass").is("person").and("sn").is("Person2"), - this.attributesMapper); + List list = this.tested.search(LdapQueryBuilder.query().base(BASE_STRING).attributes("cn") + .where("objectclass").is("person").and("sn").is("Person2"), this.attributesMapper); assertThat(list).hasSize(1); } @@ -137,9 +137,9 @@ public class LdapTemplateSearchResultNamespaceConfigITests extends AbstractLdapT this.attributesMapper.setExpectedAttributes(new String[] { "cn" }); this.attributesMapper.setExpectedValues(new String[] { "Some Person2" }); - List list = this.tested.searchForStream( - query().base(BASE_STRING).attributes("cn").where("objectclass").is("person").and("sn").is("Person2"), - this.attributesMapper).collect(Collectors.toList()); + List list = this.tested.searchForStream(LdapQueryBuilder.query().base(BASE_STRING).attributes("cn") + .where("objectclass").is("person").and("sn").is("Person2"), this.attributesMapper) + .collect(Collectors.toList()); assertThat(list).hasSize(1); } @@ -148,8 +148,9 @@ public class LdapTemplateSearchResultNamespaceConfigITests extends AbstractLdapT this.attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.attributesMapper.setExpectedValues(ALL_VALUES); - List list = this.tested.search(query().base(BASE_STRING).searchScope(SearchScope.ONELEVEL) - .where("objectclass").is("person").and("sn").is("Person2"), this.attributesMapper); + List list = this.tested.search(LdapQueryBuilder.query().base(BASE_STRING) + .searchScope(SearchScope.ONELEVEL).where("objectclass").is("person").and("sn").is("Person2"), + this.attributesMapper); assertThat(list).isEmpty(); } @@ -158,8 +159,9 @@ public class LdapTemplateSearchResultNamespaceConfigITests extends AbstractLdapT this.attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.attributesMapper.setExpectedValues(ALL_VALUES); - List list = this.tested.searchForStream(query().base(BASE_STRING).searchScope(SearchScope.ONELEVEL) - .where("objectclass").is("person").and("sn").is("Person2"), this.attributesMapper) + List list = this.tested + .searchForStream(LdapQueryBuilder.query().base(BASE_STRING).searchScope(SearchScope.ONELEVEL) + .where("objectclass").is("person").and("sn").is("Person2"), this.attributesMapper) .collect(Collectors.toList()); assertThat(list).isEmpty(); } @@ -169,8 +171,9 @@ public class LdapTemplateSearchResultNamespaceConfigITests extends AbstractLdapT this.attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.attributesMapper.setExpectedValues(ALL_VALUES); - List list = this.tested.search(query().base("ou=company1,ou=Sweden").searchScope(SearchScope.ONELEVEL) - .where("objectclass").is("person").and("sn").is("Person2"), this.attributesMapper); + List list = this.tested.search(LdapQueryBuilder.query().base("ou=company1,ou=Sweden") + .searchScope(SearchScope.ONELEVEL).where("objectclass").is("person").and("sn").is("Person2"), + this.attributesMapper); assertThat(list).hasSize(1); } @@ -179,10 +182,9 @@ public class LdapTemplateSearchResultNamespaceConfigITests extends AbstractLdapT this.attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.attributesMapper.setExpectedValues(ALL_VALUES); - List list = this.tested - .searchForStream(query().base("ou=company1,ou=Sweden").searchScope(SearchScope.ONELEVEL) - .where("objectclass").is("person").and("sn").is("Person2"), this.attributesMapper) - .collect(Collectors.toList()); + List list = this.tested.searchForStream(LdapQueryBuilder.query().base("ou=company1,ou=Sweden") + .searchScope(SearchScope.ONELEVEL).where("objectclass").is("person").and("sn").is("Person2"), + this.attributesMapper).collect(Collectors.toList()); assertThat(list).hasSize(1); } @@ -191,7 +193,8 @@ public class LdapTemplateSearchResultNamespaceConfigITests extends AbstractLdapT this.attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.attributesMapper.setExpectedValues(ALL_VALUES); - List list = this.tested.search(query().where("objectclass").is("person").and("sn").is("Person2"), + List list = this.tested.search( + LdapQueryBuilder.query().where("objectclass").is("person").and("sn").is("Person2"), this.attributesMapper); assertThat(list).hasSize(1); } @@ -202,7 +205,8 @@ public class LdapTemplateSearchResultNamespaceConfigITests extends AbstractLdapT this.attributesMapper.setExpectedValues(ALL_VALUES); List list = this.tested - .searchForStream(query().where("objectclass").is("person").and("sn").is("Person2"), this.attributesMapper) + .searchForStream(LdapQueryBuilder.query().where("objectclass").is("person").and("sn").is("Person2"), + this.attributesMapper) .collect(Collectors.toList()); assertThat(list).hasSize(1); } @@ -213,7 +217,8 @@ public class LdapTemplateSearchResultNamespaceConfigITests extends AbstractLdapT this.attributesMapper.setExpectedValues(ALL_VALUES); List list = this.tested.search( - query().base("ou=Norway").where("objectclass").is("person").and("sn").is("Person2"), this.attributesMapper); + LdapQueryBuilder.query().base("ou=Norway").where("objectclass").is("person").and("sn").is("Person2"), + this.attributesMapper); assertThat(list).isEmpty(); } @@ -222,10 +227,9 @@ public class LdapTemplateSearchResultNamespaceConfigITests extends AbstractLdapT this.attributesMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.attributesMapper.setExpectedValues(ALL_VALUES); - List list = this.tested - .searchForStream(query().base("ou=Norway").where("objectclass").is("person").and("sn").is("Person2"), - this.attributesMapper) - .collect(Collectors.toList()); + List list = this.tested.searchForStream( + LdapQueryBuilder.query().base("ou=Norway").where("objectclass").is("person").and("sn").is("Person2"), + this.attributesMapper).collect(Collectors.toList()); assertThat(list).isEmpty(); } @@ -324,7 +328,8 @@ public class LdapTemplateSearchResultNamespaceConfigITests extends AbstractLdapT this.contextMapper.setExpectedAttributes(CN_SN_ATTRS); this.contextMapper.setExpectedValues(CN_SN_VALUES); this.contextMapper.setAbsentAttributes(ABSENT_ATTRIBUTES); - List list = this.tested.search(BASE_STRING, FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS, this.contextMapper); + List list = this.tested.search(BASE_STRING, FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS, + this.contextMapper); assertThat(list).hasSize(1); } @@ -341,7 +346,8 @@ public class LdapTemplateSearchResultNamespaceConfigITests extends AbstractLdapT this.contextMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.contextMapper.setExpectedValues(ALL_VALUES); List list = this.tested.search( - query().base(BASE_NAME).where("objectclass").is("person").and("sn").is("Person2"), this.contextMapper); + LdapQueryBuilder.query().base(BASE_NAME).where("objectclass").is("person").and("sn").is("Person2"), + this.contextMapper); assertThat(list).hasSize(1); } @@ -349,10 +355,9 @@ public class LdapTemplateSearchResultNamespaceConfigITests extends AbstractLdapT public void testSearchForStream_ContextMapper_LdapQuery() { this.contextMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.contextMapper.setExpectedValues(ALL_VALUES); - List list = this.tested - .searchForStream(query().base(BASE_NAME).where("objectclass").is("person").and("sn").is("Person2"), - this.contextMapper) - .collect(Collectors.toList()); + List list = this.tested.searchForStream( + LdapQueryBuilder.query().base(BASE_NAME).where("objectclass").is("person").and("sn").is("Person2"), + this.contextMapper).collect(Collectors.toList()); assertThat(list).hasSize(1); } @@ -360,8 +365,8 @@ public class LdapTemplateSearchResultNamespaceConfigITests extends AbstractLdapT public void testSearch_ContextMapper_LdapQuery_NoBase() { this.contextMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.contextMapper.setExpectedValues(ALL_VALUES); - List list = this.tested.search(query().where("objectclass").is("person").and("sn").is("Person2"), - this.contextMapper); + List list = this.tested.search( + LdapQueryBuilder.query().where("objectclass").is("person").and("sn").is("Person2"), this.contextMapper); assertThat(list).hasSize(1); } @@ -370,7 +375,8 @@ public class LdapTemplateSearchResultNamespaceConfigITests extends AbstractLdapT this.contextMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.contextMapper.setExpectedValues(ALL_VALUES); List list = this.tested - .searchForStream(query().where("objectclass").is("person").and("sn").is("Person2"), this.contextMapper) + .searchForStream(LdapQueryBuilder.query().where("objectclass").is("person").and("sn").is("Person2"), + this.contextMapper) .collect(Collectors.toList()); assertThat(list).hasSize(1); } @@ -379,8 +385,9 @@ public class LdapTemplateSearchResultNamespaceConfigITests extends AbstractLdapT public void testSearch_ContextMapper_LdapQuery_SearchScope() { this.contextMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.contextMapper.setExpectedValues(ALL_VALUES); - List list = this.tested.search(query().base(BASE_NAME).searchScope(SearchScope.ONELEVEL) - .where("objectclass").is("person").and("sn").is("Person2"), this.contextMapper); + List list = this.tested.search(LdapQueryBuilder.query().base(BASE_NAME) + .searchScope(SearchScope.ONELEVEL).where("objectclass").is("person").and("sn").is("Person2"), + this.contextMapper); assertThat(list).isEmpty(); } @@ -388,8 +395,10 @@ public class LdapTemplateSearchResultNamespaceConfigITests extends AbstractLdapT public void testSearchForStream_ContextMapper_LdapQuery_SearchScope() { this.contextMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.contextMapper.setExpectedValues(ALL_VALUES); - List list = this.tested.searchForStream(query().base(BASE_NAME).searchScope(SearchScope.ONELEVEL) - .where("objectclass").is("person").and("sn").is("Person2"), this.contextMapper).collect(Collectors.toList()); + List list = this.tested + .searchForStream(LdapQueryBuilder.query().base(BASE_NAME).searchScope(SearchScope.ONELEVEL) + .where("objectclass").is("person").and("sn").is("Person2"), this.contextMapper) + .collect(Collectors.toList()); assertThat(list).isEmpty(); } @@ -397,7 +406,7 @@ public class LdapTemplateSearchResultNamespaceConfigITests extends AbstractLdapT public void testSearch_ContextMapper_LdapQuery_SearchScope_CorrectBase() { this.contextMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.contextMapper.setExpectedValues(ALL_VALUES); - List list = this.tested.search(query().base("ou=company1,ou=Sweden") + List list = this.tested.search(LdapQueryBuilder.query().base("ou=company1,ou=Sweden") .searchScope(SearchScope.ONELEVEL).where("objectclass").is("person").and("sn").is("Person2"), this.contextMapper); assertThat(list).hasSize(1); @@ -408,8 +417,9 @@ public class LdapTemplateSearchResultNamespaceConfigITests extends AbstractLdapT this.contextMapper.setExpectedAttributes(ALL_ATTRIBUTES); this.contextMapper.setExpectedValues(ALL_VALUES); List list = this.tested - .searchForStream(query().base("ou=company1,ou=Sweden").searchScope(SearchScope.ONELEVEL) - .where("objectclass").is("person").and("sn").is("Person2"), this.contextMapper) + .searchForStream(LdapQueryBuilder.query().base("ou=company1,ou=Sweden") + .searchScope(SearchScope.ONELEVEL).where("objectclass").is("person").and("sn").is("Person2"), + this.contextMapper) .collect(Collectors.toList()); assertThat(list).hasSize(1); } @@ -417,7 +427,7 @@ public class LdapTemplateSearchResultNamespaceConfigITests extends AbstractLdapT @Test public void testSearchForContext_LdapQuery() { DirContextOperations result = this.tested - .searchForContext(query().where("objectclass").is("person").and("sn").is("Person2")); + .searchForContext(LdapQueryBuilder.query().where("objectclass").is("person").and("sn").is("Person2")); assertThat(result).isNotNull(); assertThat(result.getStringAttribute("sn")).isEqualTo("Person2"); @@ -425,14 +435,15 @@ public class LdapTemplateSearchResultNamespaceConfigITests extends AbstractLdapT @Test(expected = EmptyResultDataAccessException.class) public void testSearchForContext_LdapQuery_SearchScopeNotFound() { - this.tested.searchForContext( - query().searchScope(SearchScope.ONELEVEL).where("objectclass").is("person").and("sn").is("Person2")); + this.tested.searchForContext(LdapQueryBuilder.query().searchScope(SearchScope.ONELEVEL).where("objectclass") + .is("person").and("sn").is("Person2")); } @Test public void testSearchForContext_LdapQuery_SearchScope_CorrectBase() { - DirContextOperations result = this.tested.searchForContext(query().searchScope(SearchScope.ONELEVEL) - .base("ou=company1,ou=Sweden").where("objectclass").is("person").and("sn").is("Person2")); + DirContextOperations result = this.tested + .searchForContext(LdapQueryBuilder.query().searchScope(SearchScope.ONELEVEL) + .base("ou=company1,ou=Sweden").where("objectclass").is("person").and("sn").is("Person2")); assertThat(result).isNotNull(); assertThat(result.getStringAttribute("sn")).isEqualTo("Person2"); @@ -451,7 +462,8 @@ public class LdapTemplateSearchResultNamespaceConfigITests extends AbstractLdapT this.contextMapper.setExpectedAttributes(CN_SN_ATTRS); this.contextMapper.setExpectedValues(CN_SN_VALUES); this.contextMapper.setAbsentAttributes(ABSENT_ATTRIBUTES); - List list = this.tested.search(BASE_NAME, FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS, this.contextMapper); + List list = this.tested.search(BASE_NAME, FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS, + this.contextMapper); assertThat(list).hasSize(1); } @@ -473,8 +485,8 @@ public class LdapTemplateSearchResultNamespaceConfigITests extends AbstractLdapT this.contextMapper.setExpectedAttributes(CN_SN_ATTRS); this.contextMapper.setExpectedValues(CN_SN_VALUES); this.contextMapper.setAbsentAttributes(ABSENT_ATTRIBUTES); - List list = this.tested.search(BASE_NAME + "ou=unknown", FILTER_STRING, SearchControls.SUBTREE_SCOPE, CN_SN_ATTRS, - this.contextMapper); + List list = this.tested.search(BASE_NAME + "ou=unknown", FILTER_STRING, SearchControls.SUBTREE_SCOPE, + CN_SN_ATTRS, this.contextMapper); assertThat(list).isEmpty(); } diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/core/DistinguishedNameEditorITests.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/core/DistinguishedNameEditorITests.java index 862927bf..6182bd77 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/core/DistinguishedNameEditorITests.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/core/DistinguishedNameEditorITests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ldap.itest.core; import org.junit.Test; diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/core/simple/SimpleLdapTemplateITests.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/core/simple/SimpleLdapTemplateITests.java index 9657308d..3f410944 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/core/simple/SimpleLdapTemplateITests.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/core/simple/SimpleLdapTemplateITests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ldap.itest.core.simple; import java.util.List; diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/core/support/LdapContextSourceIntegrationTests.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/core/support/LdapContextSourceIntegrationTests.java index c416f828..1804624f 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/core/support/LdapContextSourceIntegrationTests.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/core/support/LdapContextSourceIntegrationTests.java @@ -76,7 +76,7 @@ public class LdapContextSourceIntegrationTests extends AbstractLdapTemplateInteg try { ctx.close(); } - catch (Exception e) { + catch (Exception ex) { // Never mind this } } @@ -102,7 +102,7 @@ public class LdapContextSourceIntegrationTests extends AbstractLdapTemplateInteg try { ctx.close(); } - catch (Exception e) { + catch (Exception ex) { // Never mind this } } @@ -131,7 +131,7 @@ public class LdapContextSourceIntegrationTests extends AbstractLdapTemplateInteg try { ctx.close(); } - catch (Exception e) { + catch (Exception ex) { // Never mind this } } @@ -153,7 +153,7 @@ public class LdapContextSourceIntegrationTests extends AbstractLdapTemplateInteg ctx = this.tested.getContext(results.get(0), "password"); assertThat(true).isTrue(); } - catch (Exception e) { + catch (Exception ex) { fail("Authentication failed"); } finally { diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/core/support/LdapContextSourceMultiServerIntegrationTests.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/core/support/LdapContextSourceMultiServerIntegrationTests.java index 80edb1bb..72cd4d17 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/core/support/LdapContextSourceMultiServerIntegrationTests.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/core/support/LdapContextSourceMultiServerIntegrationTests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ldap.itest.core.support; import javax.naming.NamingException; diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/filter/HardcodedFilterIntegrationTests.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/filter/HardcodedFilterIntegrationTests.java index d1397a09..39aba8a3 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/filter/HardcodedFilterIntegrationTests.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/filter/HardcodedFilterIntegrationTests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ldap.itest.filter; import org.junit.Test; diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/ldap321/Ldap321Tests.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/ldap321/Ldap321Tests.java index 52d66f7d..1fda14de 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/ldap321/Ldap321Tests.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/ldap321/Ldap321Tests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ldap.itest.ldap321; import java.util.Map; diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/ldap321/RoleRepo.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/ldap321/RoleRepo.java index 258ebd25..89cdb12a 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/ldap321/RoleRepo.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/ldap321/RoleRepo.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ldap.itest.ldap321; import java.util.HashMap; diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/ContextSourceAndDataSourceTransactionManagerIntegrationTests.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/ContextSourceAndDataSourceTransactionManagerIntegrationTests.java index 27d14246..62303847 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/ContextSourceAndDataSourceTransactionManagerIntegrationTests.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/ContextSourceAndDataSourceTransactionManagerIntegrationTests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ldap.itest.manager; import java.sql.ResultSet; @@ -87,7 +88,8 @@ public class ContextSourceAndDataSourceTransactionManagerIntegrationTests extend @Test public void testCreateWithException() { try { - this.dummyDao.createWithException("Sweden", "company1", "some testperson", "testperson", "some description"); + this.dummyDao.createWithException("Sweden", "company1", "some testperson", "testperson", + "some description"); fail("DummyException expected"); } catch (DummyException expected) { diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/ContextSourceAndDataSourceTransactionManagerNamespaceITests.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/ContextSourceAndDataSourceTransactionManagerNamespaceITests.java index 5004acd9..58ff8270 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/ContextSourceAndDataSourceTransactionManagerNamespaceITests.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/ContextSourceAndDataSourceTransactionManagerNamespaceITests.java @@ -89,7 +89,8 @@ public class ContextSourceAndDataSourceTransactionManagerNamespaceITests extends @Test public void testCreateWithException() { try { - this.dummyDao.createWithException("Sweden", "company1", "some testperson", "testperson", "some description"); + this.dummyDao.createWithException("Sweden", "company1", "some testperson", "testperson", + "some description"); fail("DummyException expected"); } catch (DummyException expected) { diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/ContextSourceTransactionManagerIntegrationTests.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/ContextSourceTransactionManagerIntegrationTests.java index 4faed9b0..5c63ea9f 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/ContextSourceTransactionManagerIntegrationTests.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/ContextSourceTransactionManagerIntegrationTests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ldap.itest.manager; import javax.naming.NamingException; @@ -65,7 +66,8 @@ public class ContextSourceTransactionManagerIntegrationTests extends AbstractLda @Test public void testCreateWithException() { try { - this.dummyDao.createWithException("Sweden", "company1", "some testperson", "testperson", "some description"); + this.dummyDao.createWithException("Sweden", "company1", "some testperson", "testperson", + "some description"); fail("DummyException expected"); } catch (DummyException expected) { diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/ContextSourceTransactionManagerNamespaceIntegrationTests.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/ContextSourceTransactionManagerNamespaceIntegrationTests.java index cae7fcec..7433993d 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/ContextSourceTransactionManagerNamespaceIntegrationTests.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/ContextSourceTransactionManagerNamespaceIntegrationTests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ldap.itest.manager; import javax.naming.NamingException; @@ -66,7 +67,8 @@ public class ContextSourceTransactionManagerNamespaceIntegrationTests extends Ab @Test public void testCreateWithException() { try { - this.dummyDao.createWithException("Sweden", "company1", "some testperson", "testperson", "some description"); + this.dummyDao.createWithException("Sweden", "company1", "some testperson", "testperson", + "some description"); fail("DummyException expected"); } catch (DummyException expected) { diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/hibernate/ContextSourceAndHibernateTransactionManagerIntegrationTests.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/hibernate/ContextSourceAndHibernateTransactionManagerIntegrationTests.java index 10d45c9d..2301c9b6 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/hibernate/ContextSourceAndHibernateTransactionManagerIntegrationTests.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/hibernate/ContextSourceAndHibernateTransactionManagerIntegrationTests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ldap.itest.manager.hibernate; import java.util.List; diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/hibernate/ContextSourceAndHibernateTransactionManagerNamespaceITests.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/hibernate/ContextSourceAndHibernateTransactionManagerNamespaceITests.java index 64e63e30..72df87ac 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/hibernate/ContextSourceAndHibernateTransactionManagerNamespaceITests.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/hibernate/ContextSourceAndHibernateTransactionManagerNamespaceITests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ldap.itest.manager.hibernate; import java.util.List; diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/odm/LdapTemplateOdmGroupManipulationITests.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/odm/LdapTemplateOdmGroupManipulationITests.java index 2d308598..90ae257c 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/odm/LdapTemplateOdmGroupManipulationITests.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/odm/LdapTemplateOdmGroupManipulationITests.java @@ -26,11 +26,11 @@ import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.ldap.core.LdapTemplate; import org.springframework.ldap.itest.AbstractLdapTemplateIntegrationTests; +import org.springframework.ldap.query.LdapQueryBuilder; import org.springframework.ldap.support.LdapUtils; import org.springframework.test.context.ContextConfiguration; import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.ldap.query.LdapQueryBuilder.query; /** * @author Mattias Hellborg Arthursson @@ -43,7 +43,7 @@ public class LdapTemplateOdmGroupManipulationITests extends AbstractLdapTemplate @Test public void testFindOne() { - Group group = this.tested.findOne(query().where("cn").is("ROLE_USER"), Group.class); + Group group = this.tested.findOne(LdapQueryBuilder.query().where("cn").is("ROLE_USER"), Group.class); assertThat(group).isNotNull(); assertThat(group.getName()).isEqualTo("ROLE_USER"); @@ -58,12 +58,12 @@ public class LdapTemplateOdmGroupManipulationITests extends AbstractLdapTemplate @Test public void testRemoveMember() { - Group group = this.tested.findOne(query().where("cn").is("ROLE_USER"), Group.class); + Group group = this.tested.findOne(LdapQueryBuilder.query().where("cn").is("ROLE_USER"), Group.class); group.removeMember(LdapUtils.newLdapName("cn=Some Person,ou=company1,ou=Sweden," + base)); this.tested.update(group); - Group verification = this.tested.findOne(query().where("cn").is("ROLE_USER"), Group.class); + Group verification = this.tested.findOne(LdapQueryBuilder.query().where("cn").is("ROLE_USER"), Group.class); Set members = verification.getMembers(); assertThat(members).hasSize(3); @@ -72,12 +72,12 @@ public class LdapTemplateOdmGroupManipulationITests extends AbstractLdapTemplate @Test public void testRemoveMemberSyntacticallyEqual() { - Group group = this.tested.findOne(query().where("cn").is("ROLE_USER"), Group.class); + Group group = this.tested.findOne(LdapQueryBuilder.query().where("cn").is("ROLE_USER"), Group.class); group.removeMember(LdapUtils.newLdapName("cn=Some Person,OU=company1, ou=Sweden," + base)); this.tested.update(group); - Group verification = this.tested.findOne(query().where("cn").is("ROLE_USER"), Group.class); + Group verification = this.tested.findOne(LdapQueryBuilder.query().where("cn").is("ROLE_USER"), Group.class); Set members = verification.getMembers(); assertThat(members).hasSize(3); @@ -86,12 +86,12 @@ public class LdapTemplateOdmGroupManipulationITests extends AbstractLdapTemplate @Test public void testAddMember() { - Group group = this.tested.findOne(query().where("cn").is("ROLE_USER"), Group.class); + Group group = this.tested.findOne(LdapQueryBuilder.query().where("cn").is("ROLE_USER"), Group.class); group.addMember(LdapUtils.newLdapName("cn=Some Person,ou=company1,ou=Norway," + base)); this.tested.update(group); - Group verification = this.tested.findOne(query().where("cn").is("ROLE_USER"), Group.class); + Group verification = this.tested.findOne(LdapQueryBuilder.query().where("cn").is("ROLE_USER"), Group.class); Set members = verification.getMembers(); assertThat(members).hasSize(5); @@ -100,12 +100,12 @@ public class LdapTemplateOdmGroupManipulationITests extends AbstractLdapTemplate @Test public void testAddMemberDuplicate() { - Group group = this.tested.findOne(query().where("cn").is("ROLE_USER"), Group.class); + Group group = this.tested.findOne(LdapQueryBuilder.query().where("cn").is("ROLE_USER"), Group.class); group.addMember(LdapUtils.newLdapName("cn=Some Person,ou=company1,ou=Sweden," + base)); this.tested.update(group); - Group verification = this.tested.findOne(query().where("cn").is("ROLE_USER"), Group.class); + Group verification = this.tested.findOne(LdapQueryBuilder.query().where("cn").is("ROLE_USER"), Group.class); Set members = verification.getMembers(); assertThat(members).hasSize(4); @@ -114,12 +114,12 @@ public class LdapTemplateOdmGroupManipulationITests extends AbstractLdapTemplate @Test public void testAddMemberSyntacticallyEqualDuplicate() { - Group group = this.tested.findOne(query().where("cn").is("ROLE_USER"), Group.class); + Group group = this.tested.findOne(LdapQueryBuilder.query().where("cn").is("ROLE_USER"), Group.class); group.addMember(LdapUtils.newLdapName("cn=Some Person,OU=company1 ,ou=Sweden," + base)); this.tested.update(group); - Group verification = this.tested.findOne(query().where("cn").is("ROLE_USER"), Group.class); + Group verification = this.tested.findOne(LdapQueryBuilder.query().where("cn").is("ROLE_USER"), Group.class); Set members = verification.getMembers(); assertThat(members).hasSize(4); @@ -128,7 +128,7 @@ public class LdapTemplateOdmGroupManipulationITests extends AbstractLdapTemplate @Test public void testSetMembersSyntacticallyEqual() { - Group group = this.tested.findOne(query().where("cn").is("ROLE_USER"), Group.class); + Group group = this.tested.findOne(LdapQueryBuilder.query().where("cn").is("ROLE_USER"), Group.class); group.setMembers(new HashSet() { { @@ -138,7 +138,7 @@ public class LdapTemplateOdmGroupManipulationITests extends AbstractLdapTemplate }); this.tested.update(group); - Group verification = this.tested.findOne(query().where("cn").is("ROLE_USER"), Group.class); + Group verification = this.tested.findOne(LdapQueryBuilder.query().where("cn").is("ROLE_USER"), Group.class); Set members = verification.getMembers(); diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/odm/LdapTemplateOdmWithDnAnnotationsITests.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/odm/LdapTemplateOdmWithDnAnnotationsITests.java index ed729b46..70524bb5 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/odm/LdapTemplateOdmWithDnAnnotationsITests.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/odm/LdapTemplateOdmWithDnAnnotationsITests.java @@ -25,12 +25,12 @@ import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.ldap.core.LdapTemplate; import org.springframework.ldap.itest.AbstractLdapTemplateIntegrationTests; +import org.springframework.ldap.query.LdapQueryBuilder; import org.springframework.ldap.support.LdapUtils; import org.springframework.test.context.ContextConfiguration; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; -import static org.springframework.ldap.query.LdapQueryBuilder.query; /** * @author Mattias Hellborg Arthursson @@ -43,7 +43,7 @@ public class LdapTemplateOdmWithDnAnnotationsITests extends AbstractLdapTemplate @Test public void testFindOne() { - PersonWithDnAnnotations person = this.tested.findOne(query().where("cn").is("Some Person3"), + PersonWithDnAnnotations person = this.tested.findOne(LdapQueryBuilder.query().where("cn").is("Some Person3"), PersonWithDnAnnotations.class); assertThat(person).isNotNull(); @@ -60,8 +60,8 @@ public class LdapTemplateOdmWithDnAnnotationsITests extends AbstractLdapTemplate @Test public void testFindByDn() { - PersonWithDnAnnotations person = this.tested.findByDn(LdapUtils.newLdapName("cn=Some Person3,ou=company1,ou=Sweden"), - PersonWithDnAnnotations.class); + PersonWithDnAnnotations person = this.tested.findByDn( + LdapUtils.newLdapName("cn=Some Person3,ou=company1,ou=Sweden"), PersonWithDnAnnotations.class); assertThat(person).isNotNull(); assertThat(person.getCommonName()).isEqualTo("Some Person3"); @@ -77,8 +77,8 @@ public class LdapTemplateOdmWithDnAnnotationsITests extends AbstractLdapTemplate @Test public void testFindInCountry() { - List persons = this.tested.find(query().base("ou=Sweden").where("cn").isPresent(), - PersonWithDnAnnotations.class); + List persons = this.tested.find( + LdapQueryBuilder.query().base("ou=Sweden").where("cn").isPresent(), PersonWithDnAnnotations.class); assertThat(persons).hasSize(4); @@ -93,7 +93,8 @@ public class LdapTemplateOdmWithDnAnnotationsITests extends AbstractLdapTemplate @Test public void testFindForStreamInCountry() { List persons = this.tested - .findForStream(query().base("ou=Sweden").where("cn").isPresent(), PersonWithDnAnnotations.class) + .findForStream(LdapQueryBuilder.query().base("ou=Sweden").where("cn").isPresent(), + PersonWithDnAnnotations.class) .collect(Collectors.toList()); assertThat(persons).hasSize(4); @@ -150,7 +151,7 @@ public class LdapTemplateOdmWithDnAnnotationsITests extends AbstractLdapTemplate @Test public void testUpdate() { - PersonWithDnAnnotations person = this.tested.findOne(query().where("cn").is("Some Person3"), + PersonWithDnAnnotations person = this.tested.findOne(LdapQueryBuilder.query().where("cn").is("Some Person3"), PersonWithDnAnnotations.class); person.setDesc(Arrays.asList("New Description")); @@ -170,7 +171,7 @@ public class LdapTemplateOdmWithDnAnnotationsITests extends AbstractLdapTemplate @Test public void testUpdateWithChangedDn() { - PersonWithDnAnnotations person = this.tested.findOne(query().where("cn").is("Some Person3"), + PersonWithDnAnnotations person = this.tested.findOne(LdapQueryBuilder.query().where("cn").is("Some Person3"), PersonWithDnAnnotations.class); // This should make the entry move diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/odm/LdapTemplateOdmWithNoDnAnnotationsITests.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/odm/LdapTemplateOdmWithNoDnAnnotationsITests.java index 56a5fd31..6a603dbf 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/odm/LdapTemplateOdmWithNoDnAnnotationsITests.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/odm/LdapTemplateOdmWithNoDnAnnotationsITests.java @@ -27,13 +27,13 @@ import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.ldap.core.LdapTemplate; import org.springframework.ldap.itest.AbstractLdapTemplateIntegrationTests; import org.springframework.ldap.odm.core.OdmException; +import org.springframework.ldap.query.LdapQueryBuilder; import org.springframework.ldap.support.LdapNameBuilder; import org.springframework.ldap.support.LdapUtils; import org.springframework.test.context.ContextConfiguration; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; -import static org.springframework.ldap.query.LdapQueryBuilder.query; /** * @author Mattias Hellborg Arthursson @@ -46,7 +46,7 @@ public class LdapTemplateOdmWithNoDnAnnotationsITests extends AbstractLdapTempla @Test public void testFindOne() { - Person person = this.tested.findOne(query().where("cn").is("Some Person3"), Person.class); + Person person = this.tested.findOne(LdapQueryBuilder.query().where("cn").is("Some Person3"), Person.class); assertThat(person).isNotNull(); assertThat(person.getCommonName()).isEqualTo("Some Person3"); @@ -58,7 +58,8 @@ public class LdapTemplateOdmWithNoDnAnnotationsITests extends AbstractLdapTempla @Test public void testFindByDn() { - Person person = this.tested.findByDn(LdapUtils.newLdapName("cn=Some Person3,ou=company1,ou=Sweden"), Person.class); + Person person = this.tested.findByDn(LdapUtils.newLdapName("cn=Some Person3,ou=company1,ou=Sweden"), + Person.class); assertThat(person).isNotNull(); assertThat(person.getCommonName()).isEqualTo("Some Person3"); @@ -75,12 +76,12 @@ public class LdapTemplateOdmWithNoDnAnnotationsITests extends AbstractLdapTempla @Test(expected = EmptyResultDataAccessException.class) public void testFindOneThrowsEmptyResultIfNotFound() { - this.tested.findOne(query().where("cn").is("This cn does not exist"), Person.class); + this.tested.findOne(LdapQueryBuilder.query().where("cn").is("This cn does not exist"), Person.class); } @Test public void testFind() { - List persons = this.tested.find(query().where("cn").is("Some Person3"), Person.class); + List persons = this.tested.find(LdapQueryBuilder.query().where("cn").is("Some Person3"), Person.class); assertThat(persons).hasSize(1); Person person = persons.get(0); @@ -95,7 +96,8 @@ public class LdapTemplateOdmWithNoDnAnnotationsITests extends AbstractLdapTempla @Test public void testFindForStream() { - List persons = this.tested.findForStream(query().where("cn").is("Some Person3"), Person.class) + List persons = this.tested + .findForStream(LdapQueryBuilder.query().where("cn").is("Some Person3"), Person.class) .collect(Collectors.toList()); assertThat(persons).hasSize(1); @@ -111,7 +113,8 @@ public class LdapTemplateOdmWithNoDnAnnotationsITests extends AbstractLdapTempla @Test public void testFindInCountry() { - List persons = this.tested.find(query().base("ou=Sweden").where("cn").isPresent(), Person.class); + List persons = this.tested.find(LdapQueryBuilder.query().base("ou=Sweden").where("cn").isPresent(), + Person.class); assertThat(persons).hasSize(4); Person person = persons.get(0); @@ -121,7 +124,8 @@ public class LdapTemplateOdmWithNoDnAnnotationsITests extends AbstractLdapTempla @Test public void testFindForStreamInCountry() { - List persons = this.tested.findForStream(query().base("ou=Sweden").where("cn").isPresent(), Person.class) + List persons = this.tested + .findForStream(LdapQueryBuilder.query().base("ou=Sweden").where("cn").isPresent(), Person.class) .collect(Collectors.toList()); assertThat(persons).hasSize(4); @@ -149,7 +153,7 @@ public class LdapTemplateOdmWithNoDnAnnotationsITests extends AbstractLdapTempla assertThat(this.tested.findAll(Person.class)).hasSize(6); - person = this.tested.findOne(query().where("cn").is("New Person"), Person.class); + person = this.tested.findOne(LdapQueryBuilder.query().where("cn").is("New Person"), Person.class); assertThat(person.getCommonName()).isEqualTo("New Person"); assertThat(person.getSurname()).isEqualTo("Person"); @@ -160,14 +164,14 @@ public class LdapTemplateOdmWithNoDnAnnotationsITests extends AbstractLdapTempla @Test public void testUpdate() { - Person person = this.tested.findOne(query().where("cn").is("Some Person3"), Person.class); + Person person = this.tested.findOne(LdapQueryBuilder.query().where("cn").is("Some Person3"), Person.class); person.setDesc(Arrays.asList("New Description")); String entryUuid = person.getEntryUuid(); assertThat(entryUuid).describedAs("The operational attribute 'entryUUID' was not set").isNotEmpty(); this.tested.update(person); - person = this.tested.findOne(query().where("cn").is("Some Person3"), Person.class); + person = this.tested.findOne(LdapQueryBuilder.query().where("cn").is("Some Person3"), Person.class); assertThat(person.getCommonName()).isEqualTo("Some Person3"); assertThat(person.getSurname()).isEqualTo("Person3"); @@ -178,15 +182,15 @@ public class LdapTemplateOdmWithNoDnAnnotationsITests extends AbstractLdapTempla @Test public void testDelete() { - Person person = this.tested.findOne(query().where("cn").is("Some Person3"), Person.class); + Person person = this.tested.findOne(LdapQueryBuilder.query().where("cn").is("Some Person3"), Person.class); this.tested.delete(person); try { - this.tested.findOne(query().where("cn").is("Some Person3"), Person.class); + this.tested.findOne(LdapQueryBuilder.query().where("cn").is("Some Person3"), Person.class); fail("EmptyResultDataAccessException e"); } - catch (EmptyResultDataAccessException e) { + catch (EmptyResultDataAccessException ex) { assertThat(true).isTrue(); } } @@ -196,13 +200,13 @@ public class LdapTemplateOdmWithNoDnAnnotationsITests extends AbstractLdapTempla */ @Test public void testLdap271() { - Person person = this.tested.findOne(query().where("cn").is("Some Person3"), Person.class); + Person person = this.tested.findOne(LdapQueryBuilder.query().where("cn").is("Some Person3"), Person.class); // Perform test person.setTelephoneNumber(null); this.tested.update(person); - person = this.tested.findOne(query().where("cn").is("Some Person3"), Person.class); + person = this.tested.findOne(LdapQueryBuilder.query().where("cn").is("Some Person3"), Person.class); assertThat(person.getTelephoneNumber()).as("TelephoneNumber should be null").isNull(); }