From dd73c9c0a2e132f2c82b2a1fbc531c74c298aa8e Mon Sep 17 00:00:00 2001 From: Konrad Windszus Date: Wed, 26 Oct 2016 10:28:09 +0200 Subject: [PATCH] added ITs --- .../ldap/odm/core/ObjectDirectoryMapper.java | 14 ++++------ .../impl/DefaultObjectDirectoryMapper.java | 28 +++++++++---------- .../DefaultObjectDirectoryMapperTest.java | 4 +-- .../ldap/itest/odm/Person.java | 15 ++++++++-- .../itest/odm/PersonWithDnAnnotations.java | 15 ++++++++-- ...LdapTemplateOdmWithDnAnnotationsITest.java | 24 +++++++++++----- ...apTemplateOdmWithNoDnAnnotationsITest.java | 21 +++++++++----- 7 files changed, 77 insertions(+), 44 deletions(-) diff --git a/core/src/main/java/org/springframework/ldap/odm/core/ObjectDirectoryMapper.java b/core/src/main/java/org/springframework/ldap/odm/core/ObjectDirectoryMapper.java index d64b295d..1674fff1 100644 --- a/core/src/main/java/org/springframework/ldap/odm/core/ObjectDirectoryMapper.java +++ b/core/src/main/java/org/springframework/ldap/odm/core/ObjectDirectoryMapper.java @@ -16,11 +16,11 @@ package org.springframework.ldap.odm.core; +import javax.naming.Name; + import org.springframework.LdapDataEntry; import org.springframework.ldap.filter.Filter; -import javax.naming.Name; - /** * The ObjectDirectoryMapper keeps track of managed class metadata and is used by {@link org.springframework.ldap.core.LdapTemplate} * to map to/from entity objects annotated with the annotations specified in the {@link org.springframework.ldap.odm.annotations} @@ -88,13 +88,11 @@ public interface ObjectDirectoryMapper { */ String attributeFor(Class clazz, String fieldName); - /** - * Check if the specified class is already managed by this instance; if not, check the metadata and add the class to the - * managed classes. + /** Check if the specified class is already managed by this instance; if not, check the metadata and add the class to the managed + * classes. * * @param clazz the class to manage. - * @return all relevant attribute names used in the given class. - * @throws org.springframework.ldap.NamingException on error. - */ + * @return all relevant attribute names used in the given class (either for reading from LDAP or for writing to LDAP or both) + * @throws org.springframework.ldap.NamingException on error. */ String[] manageClass(Class clazz); } diff --git a/core/src/main/java/org/springframework/ldap/odm/core/impl/DefaultObjectDirectoryMapper.java b/core/src/main/java/org/springframework/ldap/odm/core/impl/DefaultObjectDirectoryMapper.java index 0d1ea91e..225b7498 100644 --- a/core/src/main/java/org/springframework/ldap/odm/core/impl/DefaultObjectDirectoryMapper.java +++ b/core/src/main/java/org/springframework/ldap/odm/core/impl/DefaultObjectDirectoryMapper.java @@ -70,7 +70,7 @@ public class DefaultObjectDirectoryMapper implements ObjectDirectoryMapper { public DefaultObjectDirectoryMapper() { - this.converterManager = createDefaultConverterManager(); + converterManager = createDefaultConverterManager(); } private static ConverterManager createDefaultConverterManager() { @@ -117,19 +117,19 @@ public class DefaultObjectDirectoryMapper implements ObjectDirectoryMapper { Set managedAttributeNames = new HashSet(); // extract all relevant attributes for (Field field : entityData.metaData) { - AttributeMetaData attributeMetaData = entityData.metaData.getAttribute(field); - // skip transient field - if (attributeMetaData.isTransient()) { - continue; - } - String[] attributesOfField = attributeMetaData.getAttributes(); - if (attributesOfField != null && attributesOfField.length > 0) { - // attribute names are either given through annotation - managedAttributeNames.addAll(Arrays.asList(attributesOfField)); - } else { - // or implicitly by relying on the field name - managedAttributeNames.add(field.getName()); - } + AttributeMetaData attributeMetaData = entityData.metaData.getAttribute(field); + // skip transient fields + if (attributeMetaData.isTransient()) { + continue; + } + String[] attributesOfField = attributeMetaData.getAttributes(); + if (attributesOfField != null && attributesOfField.length > 0) { + // attribute names are either given through annotation + managedAttributeNames.addAll(Arrays.asList(attributesOfField)); + } else { + // or implicitly by relying on the field name + managedAttributeNames.add(field.getName()); + } } // always add the mandatory attribute objectclass (which is always used for the mapping) managedAttributeNames.add(OBJECT_CLASS_ATTRIBUTE); diff --git a/core/src/test/java/org/springframework/ldap/odm/core/impl/DefaultObjectDirectoryMapperTest.java b/core/src/test/java/org/springframework/ldap/odm/core/impl/DefaultObjectDirectoryMapperTest.java index 6a57c25d..0d760fef 100644 --- a/core/src/test/java/org/springframework/ldap/odm/core/impl/DefaultObjectDirectoryMapperTest.java +++ b/core/src/test/java/org/springframework/ldap/odm/core/impl/DefaultObjectDirectoryMapperTest.java @@ -114,8 +114,8 @@ public class DefaultObjectDirectoryMapperTest { String expectedDnAttributeName, boolean expectedBinary, boolean expectedTransient, - boolean expectedList, - boolean expectedReadOnly) { + boolean expectedList, + boolean expectedReadOnly) { for (Field field : entityData.metaData) { if (fieldName.equals(field.getName())) { diff --git a/test/integration-tests/src/main/java/org/springframework/ldap/itest/odm/Person.java b/test/integration-tests/src/main/java/org/springframework/ldap/itest/odm/Person.java index d8eebaba..0b42077d 100644 --- a/test/integration-tests/src/main/java/org/springframework/ldap/itest/odm/Person.java +++ b/test/integration-tests/src/main/java/org/springframework/ldap/itest/odm/Person.java @@ -1,14 +1,15 @@ package org.springframework.ldap.itest.odm; +import java.util.List; + +import javax.naming.Name; + import org.springframework.data.domain.Persistable; import org.springframework.ldap.odm.annotations.Attribute; import org.springframework.ldap.odm.annotations.Entry; import org.springframework.ldap.odm.annotations.Id; import org.springframework.ldap.odm.annotations.Transient; -import javax.naming.Name; -import java.util.List; - /** * @author Mattias Hellborg Arthursson */ @@ -35,6 +36,10 @@ public class Person implements Persistable { @Transient private boolean isNew = false; + // operational attribute according to https://tools.ietf.org/html/rfc4530 + @Attribute(name = "entryUUID", readonly = true) + private String entryUuid; + @Override public Name getId() { return getDn(); @@ -96,4 +101,8 @@ public class Person implements Persistable { public void setTelephoneNumber(String telephoneNumber) { this.telephoneNumber = telephoneNumber; } + + public String getEntryUuid() { + return entryUuid; + } } diff --git a/test/integration-tests/src/main/java/org/springframework/ldap/itest/odm/PersonWithDnAnnotations.java b/test/integration-tests/src/main/java/org/springframework/ldap/itest/odm/PersonWithDnAnnotations.java index 5d262b9f..d22cca0b 100644 --- a/test/integration-tests/src/main/java/org/springframework/ldap/itest/odm/PersonWithDnAnnotations.java +++ b/test/integration-tests/src/main/java/org/springframework/ldap/itest/odm/PersonWithDnAnnotations.java @@ -1,14 +1,15 @@ package org.springframework.ldap.itest.odm; +import java.util.List; + +import javax.naming.Name; + import org.springframework.ldap.odm.annotations.Attribute; import org.springframework.ldap.odm.annotations.DnAttribute; import org.springframework.ldap.odm.annotations.Entry; import org.springframework.ldap.odm.annotations.Id; import org.springframework.ldap.odm.annotations.Transient; -import javax.naming.Name; -import java.util.List; - /** * @author Mattias Hellborg Arthursson */ @@ -41,6 +42,10 @@ public class PersonWithDnAnnotations { @Transient private String country; + // operational attribute according to https://tools.ietf.org/html/rfc4530 + @Attribute(name = "entryUUID", readonly = true) + private String entryUuid; + public Name getDn() { return dn; } @@ -104,4 +109,8 @@ public class PersonWithDnAnnotations { public void setCountry(String country) { this.country = country; } + + public String getEntryUuid() { + return entryUuid; + } } diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/odm/LdapTemplateOdmWithDnAnnotationsITest.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/odm/LdapTemplateOdmWithDnAnnotationsITest.java index 566c59b2..e945d107 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/odm/LdapTemplateOdmWithDnAnnotationsITest.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/odm/LdapTemplateOdmWithDnAnnotationsITest.java @@ -16,6 +16,13 @@ package org.springframework.ldap.itest.odm; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; +import static org.springframework.ldap.query.LdapQueryBuilder.query; + +import java.util.Arrays; +import java.util.List; + import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.ldap.core.LdapTemplate; @@ -23,13 +30,6 @@ import org.springframework.ldap.itest.AbstractLdapTemplateIntegrationTest; import org.springframework.ldap.support.LdapUtils; import org.springframework.test.context.ContextConfiguration; -import java.util.Arrays; -import java.util.List; - -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 */ @@ -52,6 +52,7 @@ public class LdapTemplateOdmWithDnAnnotationsITest extends AbstractLdapTemplateI // Automatically calculated assertThat(person.getCompany()).isEqualTo("company1"); assertThat(person.getCountry()).isEqualTo("Sweden"); + assertThat(person.getEntryUuid()).describedAs("The operational attribute 'entryUUID' was not set").isNotEmpty(); } @Test @@ -68,6 +69,7 @@ public class LdapTemplateOdmWithDnAnnotationsITest extends AbstractLdapTemplateI // Automatically calculated assertThat(person.getCompany()).isEqualTo("company1"); assertThat(person.getCountry()).isEqualTo("Sweden"); + assertThat(person.getEntryUuid()).describedAs("The operational attribute 'entryUUID' was not set").isNotEmpty(); } @Test @@ -83,6 +85,7 @@ public class LdapTemplateOdmWithDnAnnotationsITest extends AbstractLdapTemplateI // Automatically calculated assertThat(person.getCompany()).isEqualTo("company1"); assertThat(person.getCountry()).isEqualTo("Sweden"); + assertThat(person.getEntryUuid()).describedAs("The operational attribute 'entryUUID' was not set").isNotEmpty(); } private PersonWithDnAnnotations findPerson(List persons, String cn) { @@ -124,6 +127,7 @@ public class LdapTemplateOdmWithDnAnnotationsITest extends AbstractLdapTemplateI // Automatically calculated assertThat(person.getCompany()).isEqualTo("company1"); assertThat(person.getCountry()).isEqualTo("Sweden"); + assertThat(person.getEntryUuid()).describedAs("The operational attribute 'entryUUID' was not set").isNotEmpty(); } @Test @@ -132,6 +136,8 @@ public class LdapTemplateOdmWithDnAnnotationsITest extends AbstractLdapTemplateI .where("cn").is("Some Person3"), PersonWithDnAnnotations.class); person.setDesc(Arrays.asList("New Description")); + String entryUuid = person.getEntryUuid(); + assertThat(entryUuid).describedAs("The operational attribute 'entryUUID' was not set").isNotEmpty(); tested.update(person); person = tested.findByDn( @@ -142,6 +148,7 @@ public class LdapTemplateOdmWithDnAnnotationsITest extends AbstractLdapTemplateI assertThat(person.getSurname()).isEqualTo("Person3"); assertThat(person.getDesc().get(0)).isEqualTo("New Description"); assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654"); + assertThat(person.getEntryUuid()).isEqualTo(entryUuid); } @Test @@ -151,6 +158,8 @@ public class LdapTemplateOdmWithDnAnnotationsITest extends AbstractLdapTemplateI // This should make the entry move person.setCountry("Norway"); + String entryUuid = person.getEntryUuid(); + assertThat(entryUuid).describedAs("The operational attribute 'entryUUID' was not set").isNotEmpty(); tested.update(person); person = tested.findByDn( @@ -162,5 +171,6 @@ public class LdapTemplateOdmWithDnAnnotationsITest extends AbstractLdapTemplateI assertThat(person.getCountry()).isEqualTo("Norway"); assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3"); assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654"); + assertThat(person.getEntryUuid()).isEqualTo(entryUuid); } } diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/odm/LdapTemplateOdmWithNoDnAnnotationsITest.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/odm/LdapTemplateOdmWithNoDnAnnotationsITest.java index a42d1af1..bfdbaf7b 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/odm/LdapTemplateOdmWithNoDnAnnotationsITest.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/odm/LdapTemplateOdmWithNoDnAnnotationsITest.java @@ -16,6 +16,13 @@ package org.springframework.ldap.itest.odm; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; +import static org.springframework.ldap.query.LdapQueryBuilder.query; + +import java.util.Arrays; +import java.util.List; + import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.EmptyResultDataAccessException; @@ -26,13 +33,6 @@ import org.springframework.ldap.support.LdapNameBuilder; import org.springframework.ldap.support.LdapUtils; import org.springframework.test.context.ContextConfiguration; -import java.util.Arrays; -import java.util.List; - -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 */ @@ -51,6 +51,7 @@ public class LdapTemplateOdmWithNoDnAnnotationsITest extends AbstractLdapTemplat assertThat(person.getSurname()).isEqualTo("Person3"); assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3"); assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654"); + assertThat(person.getEntryUuid()).describedAs("The operational attribute 'entryUUID' was not set").isNotEmpty(); } @Test @@ -62,6 +63,7 @@ public class LdapTemplateOdmWithNoDnAnnotationsITest extends AbstractLdapTemplat assertThat(person.getSurname()).isEqualTo("Person3"); assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3"); assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654"); + assertThat(person.getEntryUuid()).describedAs("The operational attribute 'entryUUID' was not set").isNotEmpty(); } @Test(expected = OdmException.class) @@ -88,6 +90,7 @@ public class LdapTemplateOdmWithNoDnAnnotationsITest extends AbstractLdapTemplat assertThat(person.getSurname()).isEqualTo("Person3"); assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3"); assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654"); + assertThat(person.getEntryUuid()).describedAs("The operational attribute 'entryUUID' was not set").isNotEmpty(); } @Test @@ -129,6 +132,7 @@ public class LdapTemplateOdmWithNoDnAnnotationsITest extends AbstractLdapTemplat assertThat(person.getSurname()).isEqualTo("Person"); assertThat(person.getDesc().get(0)).isEqualTo("This is the description"); assertThat(person.getTelephoneNumber()).isEqualTo("0123456"); + assertThat(person.getEntryUuid()).describedAs("The operational attribute 'entryUUID' was not set").isNotEmpty(); } @Test @@ -137,6 +141,8 @@ public class LdapTemplateOdmWithNoDnAnnotationsITest extends AbstractLdapTemplat .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(); tested.update(person); person = tested.findOne(query() @@ -146,6 +152,7 @@ public class LdapTemplateOdmWithNoDnAnnotationsITest extends AbstractLdapTemplat assertThat(person.getSurname()).isEqualTo("Person3"); assertThat(person.getDesc().get(0)).isEqualTo("New Description"); assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654"); + assertThat(person.getEntryUuid()).isEqualTo(entryUuid); } @Test