diff --git a/core/src/main/java/org/springframework/ldap/repository/LdapRepository.java b/core/src/main/java/org/springframework/ldap/repository/LdapRepository.java new file mode 100644 index 00000000..d01c5b5f --- /dev/null +++ b/core/src/main/java/org/springframework/ldap/repository/LdapRepository.java @@ -0,0 +1,47 @@ +/* + * Copyright 2005-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.ldap.repository; + +import org.springframework.data.repository.CrudRepository; +import org.springframework.ldap.query.LdapQuery; + +import javax.naming.Name; + +/** + * Ldap specific extensions to CrudRepository. + * + * @author Mattias Hellborg Arthursson + * @since 2.0 + */ +public interface LdapRepository extends CrudRepository { + /** + * Find one entry matching the specified query. + * + * @param ldapQuery the query specification. + * @return the found entry or null if no matching entry was found. + * @throws org.springframework.dao.IncorrectResultSizeDataAccessException if more than one entry matches the query. + */ + T findOne(LdapQuery ldapQuery); + + /** + * Find all entries matching the specified query. + * + * @param ldapQuery the query specification. + * @return the entries matching the query. + */ + Iterable findAll(LdapQuery ldapQuery); +} diff --git a/core/src/main/java/org/springframework/ldap/repository/LdapRepositoryFactory.java b/core/src/main/java/org/springframework/ldap/repository/LdapRepositoryFactory.java index cc540f6a..57d73622 100644 --- a/core/src/main/java/org/springframework/ldap/repository/LdapRepositoryFactory.java +++ b/core/src/main/java/org/springframework/ldap/repository/LdapRepositoryFactory.java @@ -24,6 +24,7 @@ import org.springframework.ldap.core.LdapOperations; import java.io.Serializable; /** + * Factory to create {@link LdapRepository} instances. * @author Mattias Hellborg Arthursson * @since 2.0 */ diff --git a/core/src/main/java/org/springframework/ldap/repository/LdapRepositoryFactoryBean.java b/core/src/main/java/org/springframework/ldap/repository/LdapRepositoryFactoryBean.java index 8600f4a2..08462225 100644 --- a/core/src/main/java/org/springframework/ldap/repository/LdapRepositoryFactoryBean.java +++ b/core/src/main/java/org/springframework/ldap/repository/LdapRepositoryFactoryBean.java @@ -1,3 +1,19 @@ +/* + * Copyright 2005-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.springframework.ldap.repository; import org.springframework.data.repository.Repository; @@ -9,6 +25,8 @@ import org.springframework.util.Assert; import javax.naming.Name; /** + * {@link org.springframework.beans.factory.FactoryBean} to create {@link LdapRepository} instances. + * * @author Mattias Hellborg Arthursson * @since 2.0 */ diff --git a/core/src/main/java/org/springframework/ldap/repository/SimpleLdapRepository.java b/core/src/main/java/org/springframework/ldap/repository/SimpleLdapRepository.java index d8e5e844..6ca8f1c6 100644 --- a/core/src/main/java/org/springframework/ldap/repository/SimpleLdapRepository.java +++ b/core/src/main/java/org/springframework/ldap/repository/SimpleLdapRepository.java @@ -16,8 +16,8 @@ package org.springframework.ldap.repository; +import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.data.domain.Persistable; -import org.springframework.data.repository.CrudRepository; import org.springframework.ldap.NameNotFoundException; import org.springframework.ldap.core.LdapOperations; import org.springframework.ldap.core.support.CountNameClassPairCallbackHandler; @@ -28,6 +28,7 @@ import org.springframework.util.Assert; import javax.naming.Name; import java.util.Iterator; +import java.util.LinkedList; import static org.springframework.ldap.query.LdapQueryBuilder.query; @@ -37,7 +38,7 @@ import static org.springframework.ldap.query.LdapQueryBuilder.query; * @author Mattias Hellborg Arthursson * @since 2.0 */ -public class SimpleLdapRepository implements CrudRepository { +public class SimpleLdapRepository implements LdapRepository { private static final String OBJECTCLASS_ATTRIBUTE = "objectclass"; private final LdapOperations ldapOperations; private final ObjectDirectoryMapper odm; @@ -64,7 +65,7 @@ public class SimpleLdapRepository implements CrudRepository { Persistable persistable = (Persistable) entity; return persistable.isNew(); } else { - return id != null; + return id == null; } } @@ -74,15 +75,21 @@ public class SimpleLdapRepository implements CrudRepository { Name declaredId = odm.getId(entity); Name calculatedId = odm.getCalculatedId(entity); - if(isNew(entity, declaredId)) { - if(declaredId == null) { - odm.setId(entity, calculatedId); + if (isNew(entity, declaredId)) { + if (declaredId == null) { + if (calculatedId != null) { + odm.setId(entity, calculatedId); + } else { + throw new IllegalStateException(String.format("Unable to calculate id of entry of class %s - " + + "ID not set and unable to calculate new ID. Missing @DnAttribute annotations with index?", + entity.getClass())); + } } ldapOperations.create(entity); } else { ldapOperations.update(entity); - if(declaredId != calculatedId) { + if (declaredId != calculatedId) { odm.setId(entity, calculatedId); } } @@ -92,7 +99,7 @@ public class SimpleLdapRepository implements CrudRepository { @Override public Iterable save(Iterable entities) { - return new DelegatingIterable(entities, new Function() { + return new TransformingIterable(entities, new Function() { @Override public S transform(S entry) { return save(entry); @@ -110,8 +117,25 @@ public class SimpleLdapRepository implements CrudRepository { } } + @Override + public Iterable findAll(LdapQuery ldapQuery) { + Assert.notNull(ldapQuery, "LdapQuery must not be null"); + return ldapOperations.find(ldapQuery, clazz); + } + + @Override + public T findOne(LdapQuery ldapQuery) { + Assert.notNull(ldapQuery, "LdapQuery must not be null"); + try { + return ldapOperations.findOne(ldapQuery, clazz); + } catch (EmptyResultDataAccessException e) { + return null; + } + } + @Override public boolean exists(Name name) { + Assert.notNull(name, "Id must not be null"); return findOne(name) != null; } @@ -122,12 +146,21 @@ public class SimpleLdapRepository implements CrudRepository { @Override public Iterable findAll(final Iterable names) { - return new DelegatingIterable(names, new Function() { + Iterable found = new TransformingIterable(names, new Function() { @Override public T transform(Name name) { return findOne(name); } }); + + LinkedList list = new LinkedList(); + for (T entry : found) { + if (entry != null) { + list.add(entry); + } + } + + return list; } @Override @@ -154,11 +187,11 @@ public class SimpleLdapRepository implements CrudRepository { delete(findAll()); } - private static class DelegatingIterable implements Iterable { + private final static class TransformingIterable implements Iterable { private final Iterable target; private final Function function; - private DelegatingIterable(Iterable target, Function function) { + private TransformingIterable(Iterable target, Function function) { this.target = target; this.function = function; } 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 c138de9d..d8eebaba 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 @@ -33,13 +33,17 @@ public class Person implements Persistable { private String telephoneNumber; @Transient - private boolean isNew; + private boolean isNew = false; @Override public Name getId() { return getDn(); } + public void setNew() { + isNew = true; + } + @Override public boolean isNew() { return isNew; diff --git a/test/integration-tests/src/main/java/org/springframework/ldap/itest/repositories/PersonRepository.java b/test/integration-tests/src/main/java/org/springframework/ldap/itest/repositories/PersonRepository.java index ba2ce807..79f8a972 100644 --- a/test/integration-tests/src/main/java/org/springframework/ldap/itest/repositories/PersonRepository.java +++ b/test/integration-tests/src/main/java/org/springframework/ldap/itest/repositories/PersonRepository.java @@ -16,13 +16,11 @@ package org.springframework.ldap.itest.repositories; -import org.springframework.data.repository.CrudRepository; import org.springframework.ldap.itest.odm.Person; - -import javax.naming.Name; +import org.springframework.ldap.repository.LdapRepository; /** * @author Mattias Hellborg Arthursson */ -public interface PersonRepository extends CrudRepository { +public interface PersonRepository extends LdapRepository { } diff --git a/test/integration-tests/src/main/java/org/springframework/ldap/itest/repositories/PersonWithDnAnnotationsRepository.java b/test/integration-tests/src/main/java/org/springframework/ldap/itest/repositories/PersonWithDnAnnotationsRepository.java new file mode 100644 index 00000000..8fe5fb7c --- /dev/null +++ b/test/integration-tests/src/main/java/org/springframework/ldap/itest/repositories/PersonWithDnAnnotationsRepository.java @@ -0,0 +1,10 @@ +package org.springframework.ldap.itest.repositories; + +import org.springframework.ldap.itest.odm.PersonWithDnAnnotations; +import org.springframework.ldap.repository.LdapRepository; + +/** + * @author Mattias Hellborg Arthursson + */ +public interface PersonWithDnAnnotationsRepository extends LdapRepository { +} diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/repository/RepositoryScanITest.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/repository/RepositoryScanITest.java index 5ea103ce..6058ca6b 100644 --- a/test/integration-tests/src/test/java/org/springframework/ldap/itest/repository/RepositoryScanITest.java +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/repository/RepositoryScanITest.java @@ -13,160 +13,227 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ldap.itest.repository; -import org.junit.Assert; +import org.apache.commons.lang.StringUtils; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.ldap.core.LdapTemplate; import org.springframework.ldap.itest.AbstractLdapTemplateIntegrationTest; import org.springframework.ldap.itest.odm.Person; import org.springframework.ldap.itest.repositories.PersonRepository; -import org.springframework.ldap.odm.core.OdmException; import org.springframework.ldap.support.LdapNameBuilder; import org.springframework.ldap.support.LdapUtils; import org.springframework.test.context.ContextConfiguration; +import javax.naming.Name; +import javax.naming.ldap.LdapName; import java.util.Arrays; -import java.util.List; +import java.util.Iterator; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.springframework.ldap.query.LdapQueryBuilder.query; /** * Tests for Spring LDAP automatic repository scan functionality. * - * @author Ulrik Sandberg + * @author Mattias Hellborg Arthursson */ @ContextConfiguration(locations = {"/conf/repositoryScanTestContext.xml"}) public class RepositoryScanITest extends AbstractLdapTemplateIntegrationTest { - @Autowired - private LdapTemplate ldapTemplate; + private static final Name PERSON1_DN = LdapUtils.newLdapName("cn=Some Person, ou=Company1, c=Sweden"); + private static final Name PERSON3_DN = LdapUtils.newLdapName("cn=Some Person3, ou=Company1, c=Sweden"); @Autowired private PersonRepository tested; - @Test - public void testFindOne() { -// Person person = tested.findOne(LdapUtils.newLdapName("cn=Some Person3, ou=Company1, c=Sweden")); -// -// assertNotNull(person); -// Assert.assertEquals("Some Person3", person.getCommonName()); -// Assert.assertEquals("Person3", person.getSurname()); -// Assert.assertEquals("Sweden, Company1, Some Person3", person.getDesc().get(0)); -// Assert.assertEquals("+46 555-123654", person.getTelephoneNumber()); + public void testExists() { + assertTrue(tested.exists(PERSON3_DN)); } -// @Test -// public void testFindByDn() { -// Person person = tested.findByDn(LdapUtils.newLdapName("cn=Some Person3,ou=company1,c=Sweden"), Person.class); -// -// assertNotNull(person); -// Assert.assertEquals("Some Person3", person.getCommonName()); -// Assert.assertEquals("Person3", person.getSurname()); -// Assert.assertEquals("Sweden, Company1, Some Person3", person.getDesc().get(0)); -// Assert.assertEquals("+46 555-123654", person.getTelephoneNumber()); -// } -// -// @Test(expected = OdmException.class) -// public void testFindByDnThrowsExceptionOnInvalidEntry() { -// tested.findByDn(LdapUtils.newLdapName("ou=company1,c=Sweden"), Person.class); -// } -// -// @Test(expected = EmptyResultDataAccessException.class) -// public void testFindOneThrowsEmptyResultIfNotFound() { -// tested.findOne(query() -// .where("cn").is("This cn does not exist"), Person.class); -// } -// -// @Test -// public void testFind() { -// List persons = tested.find(query() -// .where("cn").is("Some Person3"), Person.class); -// -// Assert.assertEquals(1, persons.size()); -// Person person = persons.get(0); -// -// assertNotNull(person); -// Assert.assertEquals("Some Person3", person.getCommonName()); -// Assert.assertEquals("Person3", person.getSurname()); -// Assert.assertEquals("Sweden, Company1, Some Person3", person.getDesc().get(0)); -// Assert.assertEquals("+46 555-123654", person.getTelephoneNumber()); -// } -// -// @Test -// public void testFindInCountry() { -// List persons = tested.find(query() -// .base("c=Sweden") -// .where("cn").isPresent(), Person.class); -// -// Assert.assertEquals(4, persons.size()); -// Person person = persons.get(0); -// -// assertNotNull(person); -// } -// -// @Test -// public void testFindAll() { -// List result = tested.findAll(Person.class); -// Assert.assertEquals(5, result.size()); -// } -// -// @Test -// public void testCreate() { -// Person person = new Person(); -// person.setDn(LdapNameBuilder.newLdapName("ou=company1,c=Sweden") -// .add("cn", "New Person").build()); -// person.setCommonName("New Person"); -// person.setSurname("Person"); -// person.setDesc(Arrays.asList("This is the description")); -// person.setTelephoneNumber("0123456"); -// -// tested.create(person); -// -// Assert.assertEquals(6, tested.findAll(Person.class).size()); -// -// person = tested.findOne(query() -// .where("cn").is("New Person"), Person.class); -// -// Assert.assertEquals("New Person", person.getCommonName()); -// Assert.assertEquals("Person", person.getSurname()); -// Assert.assertEquals("This is the description", person.getDesc().get(0)); -// Assert.assertEquals("0123456", person.getTelephoneNumber()); -// } -// -// @Test -// public void testUpdate() { -// Person person = tested.findOne(query() -// .where("cn").is("Some Person3"), Person.class); -// -// person.setDesc(Arrays.asList("New Description")); -// tested.update(person); -// -// person = tested.findOne(query() -// .where("cn").is("Some Person3"), Person.class); -// -// Assert.assertEquals("Some Person3", person.getCommonName()); -// Assert.assertEquals("Person3", person.getSurname()); -// Assert.assertEquals("New Description", person.getDesc().get(0)); -// Assert.assertEquals("+46 555-123654", person.getTelephoneNumber()); -// } -// -// @Test -// public void testDelete() { -// Person person = tested.findOne(query() -// .where("cn").is("Some Person3"), Person.class); -// -// tested.delete(person); -// -// try { -// tested.findOne(query().where("cn").is("Some Person3"), Person.class); -// fail("EmptyResultDataAccessException e"); -// } catch (EmptyResultDataAccessException e) { -// Assert.assertTrue(true); -// } -// } + @Test + public void testFindOneWithDn() { + Person person = tested.findOne(PERSON3_DN); + + assertNotNull(person); + assertEquals("Some Person3", person.getCommonName()); + assertEquals("Person3", person.getSurname()); + assertEquals("Sweden, Company1, Some Person3", person.getDesc().get(0)); + assertEquals("+46 555-123654", person.getTelephoneNumber()); + } + + @Test + public void verifyThatFindOneWithNonexistingDnReturnsNull() { + Person person = tested.findOne(LdapUtils.newLdapName("dn=unknown")); + assertNull(person); + } + + @Test + public void testFindOneWithQuery() { + Person person = tested.findOne(query().where("cn").is("Some Person3")); + + assertNotNull(person); + assertEquals("Some Person3", person.getCommonName()); + assertEquals("Person3", person.getSurname()); + assertEquals("Sweden, Company1, Some Person3", person.getDesc().get(0)); + assertEquals("+46 555-123654", person.getTelephoneNumber()); + } + + @Test + public void testFindAll() { + Iterable result = tested.findAll(); + assertEquals(5, countIterable(result)); + + for (Person person : result) { + if(StringUtils.equals(person.getCommonName(), "Some Person3")) { + assertEquals("Some Person3", person.getCommonName()); + assertEquals("Person3", person.getSurname()); + assertEquals("Sweden, Company1, Some Person3", person.getDesc().get(0)); + assertEquals("+46 555-123654", person.getTelephoneNumber()); + + // Done + return; + } + } + + fail("Entry not found"); + } + + @Test + public void testFindAllWithQuery() { + Iterable persons = tested.findAll(query().where("cn").is("Some Person3")); + + assertNotNull(persons); + Iterator iterator = persons.iterator(); + Person person = iterator.next(); + + assertEquals("Some Person3", person.getCommonName()); + assertEquals("Person3", person.getSurname()); + assertEquals("Sweden, Company1, Some Person3", person.getDesc().get(0)); + assertEquals("+46 555-123654", person.getTelephoneNumber()); + + assertFalse(iterator.hasNext()); + } + + @Test + public void testFindAllWithIterable() { + Iterable persons = tested.findAll(Arrays.asList(PERSON1_DN, PERSON3_DN)); + Iterator iterator = persons.iterator(); + Person person = iterator.next(); + + assertEquals("Some Person", person.getCommonName()); + assertEquals("Person", person.getSurname()); + assertEquals("Sweden, Company1, Some Person", person.getDesc().get(0)); + assertEquals("+46 555-123456", person.getTelephoneNumber()); + + person = iterator.next(); + + assertEquals("Some Person3", person.getCommonName()); + assertEquals("Person3", person.getSurname()); + assertEquals("Sweden, Company1, Some Person3", person.getDesc().get(0)); + assertEquals("+46 555-123654", person.getTelephoneNumber()); + + assertFalse(iterator.hasNext()); + } + + @Test + public void verifyThatFindAllWithIterableFiltersNotFoundEntries() { + Iterable persons = tested.findAll(Arrays.asList(LdapUtils.newLdapName("cn=unknown"), PERSON3_DN)); + Iterator iterator = persons.iterator(); + Person person = iterator.next(); + + assertEquals("Some Person3", person.getCommonName()); + assertEquals("Person3", person.getSurname()); + assertEquals("Sweden, Company1, Some Person3", person.getDesc().get(0)); + assertEquals("+46 555-123654", person.getTelephoneNumber()); + + assertFalse(iterator.hasNext()); + } + + @Test + public void testCount() { + assertEquals(5, tested.count()); + } + + private int countIterable(Iterable iterable) { + int count = 0; + + for (Object o : iterable) { + count++; + } + return count; + } + + @Test + public void testCreate() { + Person person = new Person(); + LdapName dn = LdapNameBuilder.newLdapName("ou=company1,c=Sweden") + .add("cn", "New Person").build(); + person.setDn(dn); + person.setCommonName("New Person"); + person.setSurname("Person"); + person.setDesc(Arrays.asList("This is the description")); + person.setTelephoneNumber("0123456"); + person.setNew(); + tested.save(person); + + assertEquals(6, tested.count()); + + person = tested.findOne(dn); + + assertEquals("New Person", person.getCommonName()); + assertEquals("Person", person.getSurname()); + assertEquals("This is the description", person.getDesc().get(0)); + assertEquals("0123456", person.getTelephoneNumber()); + } + + @Test(expected = IllegalStateException.class) + public void verifyThatCreateWithNoIdSetAndNotAbleToCalculateThrowsIllegalState() { + Person person = new Person(); + person.setCommonName("New Person"); + person.setSurname("Person"); + person.setDesc(Arrays.asList("This is the description")); + person.setTelephoneNumber("0123456"); + person.setNew(); + tested.save(person); + } + + @Test + public void testUpdate() { + Person person = tested.findOne(query().where("cn").is("Some Person3")); + + person.setDesc(Arrays.asList("New Description")); + tested.save(person); + + person = tested.findOne(query().where("cn").is("Some Person3")); + + assertEquals("Some Person3", person.getCommonName()); + assertEquals("Person3", person.getSurname()); + assertEquals("New Description", person.getDesc().get(0)); + assertEquals("+46 555-123654", person.getTelephoneNumber()); + } + + @Test + public void testDelete() { + Person person = tested.findOne(query().where("cn").is("Some Person3")); + tested.delete(person); + + Person found = tested.findOne(query().where("cn").is("Some Person3")); + assertNull(found); + } + + @Test + public void testDeleteWithIterable() { + Iterable found = tested.findAll(Arrays.asList(PERSON1_DN, PERSON3_DN)); + tested.delete(found); + + assertEquals(3, tested.count()); + } } diff --git a/test/integration-tests/src/test/java/org/springframework/ldap/itest/repository/RepositoryScanWithDnAnnotationsITest.java b/test/integration-tests/src/test/java/org/springframework/ldap/itest/repository/RepositoryScanWithDnAnnotationsITest.java new file mode 100644 index 00000000..77f748b1 --- /dev/null +++ b/test/integration-tests/src/test/java/org/springframework/ldap/itest/repository/RepositoryScanWithDnAnnotationsITest.java @@ -0,0 +1,62 @@ +/* + * Copyright 2005-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.ldap.itest.repository; + +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.ldap.itest.AbstractLdapTemplateIntegrationTest; +import org.springframework.ldap.itest.odm.PersonWithDnAnnotations; +import org.springframework.ldap.itest.repositories.PersonWithDnAnnotationsRepository; +import org.springframework.ldap.query.LdapQueryBuilder; +import org.springframework.test.context.ContextConfiguration; + +import java.util.Arrays; + +import static org.junit.Assert.assertEquals; + +/** + * Tests for Spring LDAP automatic repository scan functionality. + * + * @author Mattias Hellborg Arthursson + */ +@ContextConfiguration(locations = {"/conf/repositoryScanTestContext.xml"}) +public class RepositoryScanWithDnAnnotationsITest extends AbstractLdapTemplateIntegrationTest { + @Autowired + private PersonWithDnAnnotationsRepository tested; + + @Test + public void verifyThatCreateWithNoIdSetWillAutomaticallyCalculateDn() { + PersonWithDnAnnotations person = new PersonWithDnAnnotations(); + person.setCommonName("New Person"); + person.setSurname("Person"); + person.setDesc(Arrays.asList("This is the description")); + person.setTelephoneNumber("0123456"); + person.setCountry("Sweden"); + person.setCompany("company1"); + + tested.save(person); + + assertEquals(6, tested.count()); + + person = tested.findOne(LdapQueryBuilder.query().where("cn").is("New Person")); + + assertEquals("New Person", person.getCommonName()); + assertEquals("Person", person.getSurname()); + assertEquals("This is the description", person.getDesc().get(0)); + assertEquals("0123456", person.getTelephoneNumber()); + } +}