added ITs

This commit is contained in:
Konrad Windszus
2016-10-26 10:28:09 +02:00
committed by Rob Winch
parent 8dd61f9b6a
commit dd73c9c0a2
7 changed files with 77 additions and 44 deletions

View File

@@ -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);
}

View File

@@ -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<String> managedAttributeNames = new HashSet<String>();
// 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);

View File

@@ -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())) {

View File

@@ -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<Name> {
@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<Name> {
public void setTelephoneNumber(String telephoneNumber) {
this.telephoneNumber = telephoneNumber;
}
public String getEntryUuid() {
return entryUuid;
}
}

View File

@@ -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;
}
}

View File

@@ -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<PersonWithDnAnnotations> 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);
}
}

View File

@@ -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