Remove Spring Data
Fixes gh-436
This commit is contained in:
@@ -1,12 +0,0 @@
|
||||
package org.springframework.ldap.itest.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.ldap.repository.config.EnableLdapRepositories;
|
||||
|
||||
/**
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@Configuration
|
||||
@EnableLdapRepositories(basePackages = "org.springframework.ldap.itest.repositories")
|
||||
public class SpringLdapConfiguration {
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package org.springframework.ldap.itest.repositories;
|
||||
|
||||
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
|
||||
import org.springframework.ldap.itest.odm.Person;
|
||||
import org.springframework.ldap.repository.LdapRepository;
|
||||
|
||||
/**
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public interface PersonQueryDslRepository extends LdapRepository<Person>, QueryDslPredicateExecutor<Person> {
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* 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.repositories;
|
||||
|
||||
import org.springframework.ldap.itest.odm.Person;
|
||||
import org.springframework.ldap.repository.Query;
|
||||
import org.springframework.ldap.repository.LdapRepository;
|
||||
|
||||
/**
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
public interface PersonRepository extends LdapRepository<Person> {
|
||||
@Query("(sn={0})")
|
||||
Iterable<Person> findByLastName(String lastName);
|
||||
|
||||
@Query("(uid={0})")
|
||||
Person findByUid(String uid);
|
||||
|
||||
Person findByTelephoneNumber(String phoneNumber);
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
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<PersonWithDnAnnotations> {
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005-2016 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.odm;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
import org.springframework.ldap.itest.AbstractLdapTemplateIntegrationTest;
|
||||
import org.springframework.ldap.repository.support.QueryDslLdapQuery;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/ldapTemplateTestContext.xml"})
|
||||
public class LdapTemplateQueryDslLdapQueryITest extends AbstractLdapTemplateIntegrationTest {
|
||||
@Autowired
|
||||
private LdapTemplate tested;
|
||||
private QPerson qperson;
|
||||
private QueryDslLdapQuery<Person> query;
|
||||
|
||||
@Before
|
||||
public void prepareTestedInstance() {
|
||||
qperson = QPerson.person;
|
||||
query = new QueryDslLdapQuery<Person>(tested, qperson);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUniqueResult() {
|
||||
Person person = query.where(qperson.commonName.eq("Some Person3")).uniqueResult();
|
||||
|
||||
assertThat(person).isNotNull();
|
||||
assertThat(person.getCommonName()).isEqualTo("Some Person3");
|
||||
assertThat(person.getSurname()).isEqualTo("Person3");
|
||||
assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3");
|
||||
assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testList() {
|
||||
List<Person> persons = query.where(qperson.commonName.eq("Some Person3")).list();
|
||||
|
||||
Person person = persons.get(0);
|
||||
assertThat(person.getCommonName()).isEqualTo("Some Person3");
|
||||
assertThat(person.getSurname()).isEqualTo("Person3");
|
||||
assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3");
|
||||
assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654");
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005-2016 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.Person;
|
||||
import org.springframework.ldap.itest.repositories.PersonRepository;
|
||||
import org.springframework.ldap.support.LdapUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
import javax.naming.Name;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for Spring LDAP automatic repository scan functionality enabled with
|
||||
* {@link org.springframework.ldap.repository.config.EnableLdapRepositories}.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/repositoryScanAnnotationTestContext.xml"})
|
||||
public class RepositoryScanAnnotationConfiguredITest extends AbstractLdapTemplateIntegrationTest {
|
||||
private static final Name PERSON3_DN = LdapUtils.newLdapName("cn=Some Person3, ou=Company1, ou=Sweden");
|
||||
|
||||
@Autowired
|
||||
private PersonRepository tested;
|
||||
|
||||
@Test
|
||||
public void testExists() {
|
||||
assertThat(tested.exists(PERSON3_DN)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindOneWithDn() {
|
||||
Person person = tested.findOne(PERSON3_DN);
|
||||
|
||||
assertThat(person).isNotNull();
|
||||
assertThat(person.getCommonName()).isEqualTo("Some Person3");
|
||||
assertThat(person.getSurname()).isEqualTo("Person3");
|
||||
assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3");
|
||||
assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654");
|
||||
}
|
||||
}
|
||||
@@ -1,261 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005-2016 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.apache.commons.lang.StringUtils;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ldap.itest.AbstractLdapTemplateIntegrationTest;
|
||||
import org.springframework.ldap.itest.odm.Person;
|
||||
import org.springframework.ldap.itest.repositories.PersonRepository;
|
||||
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.Iterator;
|
||||
|
||||
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 Spring LDAP automatic repository scan functionality.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/repositoryScanTestContext.xml"})
|
||||
public class RepositoryScanITest extends AbstractLdapTemplateIntegrationTest {
|
||||
private static final Name PERSON1_DN = LdapUtils.newLdapName("cn=Some Person, ou=Company1, ou=Sweden");
|
||||
private static final Name PERSON3_DN = LdapUtils.newLdapName("cn=Some Person3, ou=Company1, ou=Sweden");
|
||||
|
||||
@Autowired
|
||||
private PersonRepository tested;
|
||||
|
||||
@Test
|
||||
public void testExists() {
|
||||
assertThat(tested.exists(PERSON3_DN)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindOneWithDn() {
|
||||
Person person = tested.findOne(PERSON3_DN);
|
||||
|
||||
assertThat(person).isNotNull();
|
||||
assertThat(person.getCommonName()).isEqualTo("Some Person3");
|
||||
assertThat(person.getSurname()).isEqualTo("Person3");
|
||||
assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3");
|
||||
assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyThatFindOneWithNonexistingDnReturnsNull() {
|
||||
Person person = tested.findOne(LdapUtils.newLdapName("cn=unknown"));
|
||||
assertThat(person).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindOneWithQuery() {
|
||||
Person person = tested.findOne(query().where("cn").is("Some Person3"));
|
||||
|
||||
assertThat(person).isNotNull();
|
||||
assertThat(person.getCommonName()).isEqualTo("Some Person3");
|
||||
assertThat(person.getSurname()).isEqualTo("Person3");
|
||||
assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3");
|
||||
assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindAll() {
|
||||
Iterable<Person> result = tested.findAll();
|
||||
assertThat(countIterable(result)).isEqualTo(5);
|
||||
|
||||
for (Person person : result) {
|
||||
if(StringUtils.equals(person.getCommonName(), "Some Person3")) {
|
||||
assertThat(person.getCommonName()).isEqualTo("Some Person3");
|
||||
assertThat(person.getSurname()).isEqualTo("Person3");
|
||||
assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3");
|
||||
assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654");
|
||||
|
||||
// Done
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
fail("Entry not found");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindAllWithQuery() {
|
||||
Iterable<Person> persons = tested.findAll(query().where("cn").is("Some Person3"));
|
||||
|
||||
assertThat(persons).isNotNull();
|
||||
Iterator<Person> iterator = persons.iterator();
|
||||
Person person = iterator.next();
|
||||
|
||||
assertThat(person.getCommonName()).isEqualTo("Some Person3");
|
||||
assertThat(person.getSurname()).isEqualTo("Person3");
|
||||
assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3");
|
||||
assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654");
|
||||
|
||||
assertThat(iterator.hasNext()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindAllWithIterable() {
|
||||
Iterable<Person> persons = tested.findAll(Arrays.asList(PERSON1_DN, PERSON3_DN));
|
||||
Iterator<Person> iterator = persons.iterator();
|
||||
Person person = iterator.next();
|
||||
|
||||
assertThat(person.getCommonName()).isEqualTo("Some Person");
|
||||
assertThat(person.getSurname()).isEqualTo("Person");
|
||||
assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person");
|
||||
assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123456");
|
||||
|
||||
person = iterator.next();
|
||||
|
||||
assertThat(person.getCommonName()).isEqualTo("Some Person3");
|
||||
assertThat(person.getSurname()).isEqualTo("Person3");
|
||||
assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3");
|
||||
assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654");
|
||||
|
||||
assertThat(iterator.hasNext()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyThatFindAllWithIterableFiltersNotFoundEntries() {
|
||||
Iterable<Person> persons = tested.findAll(Arrays.asList(LdapUtils.newLdapName("cn=unknown"), PERSON3_DN));
|
||||
Iterator<Person> iterator = persons.iterator();
|
||||
Person person = iterator.next();
|
||||
|
||||
assertThat(person.getCommonName()).isEqualTo("Some Person3");
|
||||
assertThat(person.getSurname()).isEqualTo("Person3");
|
||||
assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3");
|
||||
assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654");
|
||||
|
||||
assertThat(iterator.hasNext()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCount() {
|
||||
assertThat(tested.count()).isEqualTo(5);
|
||||
}
|
||||
|
||||
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.newInstance("ou=company1,ou=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);
|
||||
|
||||
assertThat(tested.count()).isEqualTo(6);
|
||||
|
||||
person = tested.findOne(dn);
|
||||
|
||||
assertThat(person.getCommonName()).isEqualTo("New Person");
|
||||
assertThat(person.getSurname()).isEqualTo("Person");
|
||||
assertThat(person.getDesc().get(0)).isEqualTo("This is the description");
|
||||
assertThat(person.getTelephoneNumber()).isEqualTo("0123456");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void verifyThatCreateWithNoIdSetAndNotAbleToCalculateThrowsIllegalArgument() {
|
||||
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"));
|
||||
|
||||
assertThat(person.getCommonName()).isEqualTo("Some Person3");
|
||||
assertThat(person.getSurname()).isEqualTo("Person3");
|
||||
assertThat(person.getDesc().get(0)).isEqualTo("New Description");
|
||||
assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654");
|
||||
}
|
||||
|
||||
@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"));
|
||||
assertThat(found).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteWithIterable() {
|
||||
Iterable<Person> found = tested.findAll(Arrays.asList(PERSON1_DN, PERSON3_DN));
|
||||
tested.delete(found);
|
||||
|
||||
assertThat(tested.count()).isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindByLastName() {
|
||||
Iterable<Person> found = tested.findByLastName("Person3");
|
||||
assertThat(countIterable(found)).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindByUid() {
|
||||
Person person = tested.findByUid("some.person3");
|
||||
|
||||
assertThat(person.getCommonName()).isEqualTo("Some Person3");
|
||||
assertThat(person.getSurname()).isEqualTo("Person3");
|
||||
assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3");
|
||||
assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindByPhoneNumber() {
|
||||
Person person = tested.findByTelephoneNumber("+46 555-123654");
|
||||
|
||||
assertThat(person.getCommonName()).isEqualTo("Some Person3");
|
||||
assertThat(person.getSurname()).isEqualTo("Person3");
|
||||
assertThat(person.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3");
|
||||
assertThat(person.getTelephoneNumber()).isEqualTo("+46 555-123654");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005-2016 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.Person;
|
||||
import org.springframework.ldap.itest.odm.QPerson;
|
||||
import org.springframework.ldap.itest.repositories.PersonQueryDslRepository;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for Spring LDAP automatic repository scan functionality.
|
||||
*
|
||||
* @author Mattias Hellborg Arthursson
|
||||
*/
|
||||
@ContextConfiguration(locations = {"/conf/repositoryScanTestContext.xml"})
|
||||
public class RepositoryScanQueryDslITest extends AbstractLdapTemplateIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private PersonQueryDslRepository tested;
|
||||
|
||||
@Test
|
||||
public void testFindOneWithPredicate() {
|
||||
QPerson person = QPerson.person;
|
||||
|
||||
Person found = tested.findOne(person.commonName.eq("Some Person3"));
|
||||
|
||||
assertThat(found).isNotNull();
|
||||
assertThat(found.getCommonName()).isEqualTo("Some Person3");
|
||||
assertThat(found.getSurname()).isEqualTo("Person3");
|
||||
assertThat(found.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3");
|
||||
assertThat(found.getTelephoneNumber()).isEqualTo("+46 555-123654");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindAllWithPredicate() {
|
||||
QPerson person = QPerson.person;
|
||||
|
||||
Iterable<Person> foundPersons = tested.findAll(person.commonName.eq("Some Person3"));
|
||||
|
||||
Person found = foundPersons.iterator().next();
|
||||
assertThat(found.getCommonName()).isEqualTo("Some Person3");
|
||||
assertThat(found.getSurname()).isEqualTo("Person3");
|
||||
assertThat(found.getDesc().get(0)).isEqualTo("Sweden, Company1, Some Person3");
|
||||
assertThat(found.getTelephoneNumber()).isEqualTo("+46 555-123654");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCountWithPredicate() {
|
||||
QPerson person = QPerson.person;
|
||||
|
||||
long count = tested.count(person.commonName.eq("Some Person3"));
|
||||
assertThat(count).isEqualTo(1);
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
* Copyright 2005-2016 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.support.LdapUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.ldap.query.LdapQueryBuilder.query;
|
||||
|
||||
/**
|
||||
* 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");
|
||||
|
||||
assertThat(person.getDn()).isNull();
|
||||
|
||||
tested.save(person);
|
||||
|
||||
assertThat(person.getDn()).isNotNull();
|
||||
|
||||
assertThat(tested.count()).isEqualTo(6);
|
||||
|
||||
person = tested.findOne(query().where("cn").is("New Person"));
|
||||
|
||||
assertThat(person.getCommonName()).isEqualTo("New Person");
|
||||
assertThat(person.getSurname()).isEqualTo("Person");
|
||||
assertThat(person.getDesc().get(0)).isEqualTo("This is the description");
|
||||
assertThat(person.getTelephoneNumber()).isEqualTo("0123456");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyThatMovedEntryGetsUpdatedId() {
|
||||
PersonWithDnAnnotations found = tested.findOne(query().where("cn").is("Some Person3"));
|
||||
assertThat(found).isNotNull();
|
||||
|
||||
assertThat(found.getDn()).isEqualTo(LdapUtils.newLdapName("cn=Some Person3,ou=company1,ou=Sweden"));
|
||||
|
||||
found.setCompany("company2");
|
||||
|
||||
tested.save(found);
|
||||
|
||||
assertThat(found.getDn()).isEqualTo(LdapUtils.newLdapName("cn=Some Person3,ou=company2,ou=Sweden"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user