@@ -13,4 +13,17 @@
|
|||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<argLine>--add-exports=java.naming/com.sun.jndi.ldap=ALL-UNNAMED
|
||||||
|
</argLine>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -17,9 +17,6 @@ package example.springdata.ldap;
|
|||||||
|
|
||||||
import static org.assertj.core.api.Assertions.*;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import javax.naming.InvalidNameException;
|
import javax.naming.InvalidNameException;
|
||||||
import javax.naming.ldap.LdapName;
|
import javax.naming.ldap.LdapName;
|
||||||
|
|
||||||
@@ -47,7 +44,7 @@ public class PersonRepositoryIntegrationTests {
|
|||||||
@Test
|
@Test
|
||||||
void findOneByName() throws InvalidNameException {
|
void findOneByName() throws InvalidNameException {
|
||||||
|
|
||||||
Optional<Person> person = personRepository.findById(new LdapName("uid=bob,ou=people,dc=springframework,dc=org"));
|
var person = personRepository.findById(new LdapName("uid=bob,ou=people,dc=springframework,dc=org"));
|
||||||
|
|
||||||
assertThat(person).hasValueSatisfying(it -> {
|
assertThat(person).hasValueSatisfying(it -> {
|
||||||
assertThat(it.getFullName()).isEqualTo("Bob Hamilton");
|
assertThat(it.getFullName()).isEqualTo("Bob Hamilton");
|
||||||
@@ -62,7 +59,7 @@ public class PersonRepositoryIntegrationTests {
|
|||||||
@Test
|
@Test
|
||||||
void findAll() {
|
void findAll() {
|
||||||
|
|
||||||
Iterable<Person> people = personRepository.findAll();
|
var people = personRepository.findAll();
|
||||||
|
|
||||||
assertThat(people).hasSize(3).extracting("uid").contains("bob", "joe", "ben");
|
assertThat(people).hasSize(3).extracting("uid").contains("bob", "joe", "ben");
|
||||||
}
|
}
|
||||||
@@ -73,7 +70,7 @@ public class PersonRepositoryIntegrationTests {
|
|||||||
@Test
|
@Test
|
||||||
void findByLastname() {
|
void findByLastname() {
|
||||||
|
|
||||||
List<Person> people = personRepository.findByLastnameStartsWith("Ham");
|
var people = personRepository.findByLastnameStartsWith("Ham");
|
||||||
|
|
||||||
assertThat(people).hasSize(1).extracting("uid").contains("bob");
|
assertThat(people).hasSize(1).extracting("uid").contains("bob");
|
||||||
}
|
}
|
||||||
@@ -86,14 +83,14 @@ public class PersonRepositoryIntegrationTests {
|
|||||||
@Test
|
@Test
|
||||||
void addUser() throws InvalidNameException {
|
void addUser() throws InvalidNameException {
|
||||||
|
|
||||||
Person walter = new Person();
|
var walter = new Person();
|
||||||
walter.setFullName("Walter White");
|
walter.setFullName("Walter White");
|
||||||
walter.setUid("heisenberg");
|
walter.setUid("heisenberg");
|
||||||
walter.setLastname("White");
|
walter.setLastname("White");
|
||||||
|
|
||||||
personRepository.save(walter);
|
personRepository.save(walter);
|
||||||
|
|
||||||
List<Person> people = personRepository.findByUid("heisenberg");
|
var people = personRepository.findByUid("heisenberg");
|
||||||
|
|
||||||
assertThat(people).hasSize(1).extracting("fullName").contains("Walter White");
|
assertThat(people).hasSize(1).extracting("fullName").contains("Walter White");
|
||||||
|
|
||||||
|
|||||||
@@ -17,9 +17,8 @@ package example.springdata.map;
|
|||||||
|
|
||||||
import static org.assertj.core.api.Assertions.*;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
@@ -43,7 +42,7 @@ class PersonRepositoryIntegrationTest {
|
|||||||
@Test
|
@Test
|
||||||
void storesPerson() {
|
void storesPerson() {
|
||||||
|
|
||||||
Person person = repository.save(new Person("Dave", "Matthews", 47));
|
var person = repository.save(new Person("Dave", "Matthews", 47));
|
||||||
|
|
||||||
assertThat(repository.findById(person.getId())).hasValue(person);
|
assertThat(repository.findById(person.getId())).hasValue(person);
|
||||||
}
|
}
|
||||||
@@ -51,12 +50,11 @@ class PersonRepositoryIntegrationTest {
|
|||||||
@Test
|
@Test
|
||||||
void findsPersonByAge() {
|
void findsPersonByAge() {
|
||||||
|
|
||||||
Person dave = repository.save(new Person("Dave", "Matthews", 47));
|
var dave = repository.save(new Person("Dave", "Matthews", 47));
|
||||||
Person oliver = repository.save(new Person("Oliver August", "Matthews", 7));
|
var oliver = repository.save(new Person("Oliver August", "Matthews", 7));
|
||||||
|
|
||||||
List<Person> result = repository.findByAgeGreaterThan(18);
|
var result = repository.findByAgeGreaterThan(18);
|
||||||
|
|
||||||
assertThat(result).contains(dave);
|
assertThat(result).contains(dave).doesNotContain(oliver);
|
||||||
assertThat(result).doesNotContain(oliver);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user