forked from spring-attic/spring-data-aerospike
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FMWK-337 Convert PersonRepositoryQueryTests to dedicated test classes (…
- Loading branch information
Showing
33 changed files
with
2,637 additions
and
2,757 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2,748 changes: 0 additions & 2,748 deletions
2,748
src/test/java/org/springframework/data/aerospike/repository/PersonRepositoryQueryTests.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ry/IndexedPersonRepositoryQueryTests.java → ...ed/IndexedPersonRepositoryQueryTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
370 changes: 370 additions & 0 deletions
370
...a/org/springframework/data/aerospike/repository/query/findBy/noindex/ContainingTests.java
Large diffs are not rendered by default.
Oops, something went wrong.
72 changes: 72 additions & 0 deletions
72
...ingframework/data/aerospike/repository/query/findBy/noindex/CrudRepositoryQueryTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package org.springframework.data.aerospike.repository.query.findBy.noindex; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.data.aerospike.sample.Person; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.data.domain.Sort; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* Tests for the CrudRepository queries API. | ||
*/ | ||
public class CrudRepositoryQueryTests extends PersonRepositoryQueryTests { | ||
|
||
@Test | ||
void findAll() { | ||
List<Person> result = (List<Person>) repository.findAll(); | ||
assertThat(result).containsExactlyInAnyOrderElementsOf(allPersons); | ||
} | ||
|
||
@Test | ||
void findAll_Paginated() { | ||
Page<Person> result = repository.findAll(PageRequest.of(1, 2, Sort.Direction.ASC, "lastname", "firstname")); | ||
assertThat(result.isFirst()).isFalse(); | ||
assertThat(result.isLast()).isFalse(); | ||
} | ||
|
||
@Test | ||
void findAll_doesNotFindDeletedPersonByEntity() { | ||
try { | ||
repository.delete(dave); | ||
List<Person> result = (List<Person>) repository.findAll(); | ||
assertThat(result) | ||
.doesNotContain(dave) | ||
.containsExactlyInAnyOrderElementsOf( | ||
allPersons.stream().filter(person -> !person.equals(dave)).collect(Collectors.toList()) | ||
); | ||
} finally { | ||
repository.save(dave); | ||
} | ||
} | ||
|
||
@Test | ||
void findAll_doesNotFindPersonDeletedById() { | ||
try { | ||
repository.deleteById(dave.getId()); | ||
List<Person> result = (List<Person>) repository.findAll(); | ||
assertThat(result) | ||
.doesNotContain(dave) | ||
.hasSize(allPersons.size() - 1); | ||
} finally { | ||
repository.save(dave); | ||
} | ||
} | ||
|
||
@Test | ||
void deleteAllPersonsFromList() { | ||
if (serverVersionSupport.isBatchWriteSupported()) { | ||
// batch delete requires server ver. >= 6.0.0 | ||
repository.deleteAll(List.of(dave, carter)); | ||
} else { | ||
List.of(dave, carter).forEach(repository::delete); | ||
} | ||
assertThat(repository.findAllById(List.of(dave.getId(), carter.getId()))).isEmpty(); | ||
repository.save(dave); // cleanup | ||
repository.save(carter); // cleanup | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...ava/org/springframework/data/aerospike/repository/query/findBy/noindex/EndsWithTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.springframework.data.aerospike.repository.query.findBy.noindex; | ||
|
||
/** | ||
* Tests for the "Ends with" repository query. Keywords: EndingWith, IsEndingWith, EndsWith. | ||
*/ | ||
public class EndsWithTests extends PersonRepositoryQueryTests { | ||
|
||
} |
245 changes: 245 additions & 0 deletions
245
.../java/org/springframework/data/aerospike/repository/query/findBy/noindex/EqualsTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,245 @@ | ||
package org.springframework.data.aerospike.repository.query.findBy.noindex; | ||
|
||
import com.aerospike.client.Value; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.data.aerospike.BaseIntegrationTests; | ||
import org.springframework.data.aerospike.sample.Address; | ||
import org.springframework.data.aerospike.sample.Person; | ||
import org.springframework.data.aerospike.utility.TestUtils; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
/** | ||
* Tests for the "Equals" repository query. Keywords: Is, Equals (or no keyword). | ||
*/ | ||
public class EqualsTests extends PersonRepositoryQueryTests { | ||
|
||
@Test | ||
void findByBooleanIntSimplePropertyEquals() { | ||
boolean initialValue = Value.UseBoolBin; | ||
Value.UseBoolBin = false; // save boolean as int | ||
Person intBoolBinPerson = Person.builder().id(BaseIntegrationTests.nextId()).isActive(true).firstName("Test") | ||
.build(); | ||
repository.save(intBoolBinPerson); | ||
|
||
List<Person> persons = repository.findByIsActive(true); | ||
assertThat(persons).contains(intBoolBinPerson); | ||
|
||
Value.UseBoolBin = initialValue; // set back to the default value | ||
repository.delete(intBoolBinPerson); | ||
} | ||
|
||
@Test | ||
void findByBooleanIntSimplePropertyEquals_NegativeTest() { | ||
boolean initialValue = Value.UseBoolBin; | ||
Value.UseBoolBin = false; // save boolean as int | ||
|
||
assertThatThrownBy(() -> negativeTestsRepository.findByIsActive()) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessage("Person.isActive EQ: invalid number of arguments, expecting one"); | ||
|
||
assertThatThrownBy(() -> negativeTestsRepository.findByIsActive(true, false)) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessage("Person.isActive EQ: invalid number of arguments, expecting one"); | ||
|
||
Value.UseBoolBin = initialValue; // set back to the default value | ||
} | ||
|
||
@Test | ||
void findByBooleanSimplePropertyEquals() { | ||
boolean initialValue = Value.UseBoolBin; | ||
Value.UseBoolBin = true; // save boolean as bool, available in Server 5.6+ | ||
Person intBoolBinPerson = Person.builder().id(BaseIntegrationTests.nextId()).isActive(true).firstName("Test") | ||
.build(); | ||
repository.save(intBoolBinPerson); | ||
|
||
List<Person> persons = repository.findByIsActive(true); | ||
assertThat(persons).contains(intBoolBinPerson); | ||
|
||
Value.UseBoolBin = initialValue; // set back to the default value | ||
repository.delete(intBoolBinPerson); | ||
} | ||
|
||
@Test | ||
void findByBooleanSimplePropertyEquals_NegativeTest() { | ||
boolean initialValue = Value.UseBoolBin; | ||
Value.UseBoolBin = true; // save boolean as bool, available in Server 5.6+ | ||
|
||
assertThatThrownBy(() -> negativeTestsRepository.findByIsActive()) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessage("Person.isActive EQ: invalid number of arguments, expecting one"); | ||
|
||
assertThatThrownBy(() -> negativeTestsRepository.findByIsActive(true, false)) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessage("Person.isActive EQ: invalid number of arguments, expecting one"); | ||
|
||
Value.UseBoolBin = initialValue; // set back to the default value | ||
} | ||
|
||
@Test | ||
void findBySimplePropertyEquals_String() { | ||
List<Person> result = repository.findByFirstName("Leroi"); | ||
assertThat(result).containsOnly(leroi, leroi2); | ||
|
||
List<Person> result1 = repository.findByFirstNameIgnoreCase("lEroi"); | ||
assertThat(result1).containsOnly(leroi, leroi2); | ||
|
||
List<Person> result2 = repository.findByFirstNameIs("lEroi"); // another way to call the query method | ||
assertThat(result2).hasSize(0); | ||
|
||
List<Person> result3 = repository.findByFirstNameEquals("leroi "); // another way to call the query method | ||
assertThat(result3).hasSize(0); | ||
} | ||
|
||
@Test | ||
void findBySimplePropertyEquals_String_NegativeTest() { | ||
assertThatThrownBy(() -> negativeTestsRepository.findByFirstName(100)) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessage("Person.firstName EQ: Type mismatch, expecting String"); | ||
|
||
assertThatThrownBy(() -> negativeTestsRepository.findByLastName("Beauford", "Boford")) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessage("Person.lastName EQ: invalid number of arguments, expecting one"); | ||
} | ||
|
||
@Test | ||
void findByNestedSimplePropertyEquals() { | ||
String zipCode = "C012345"; | ||
Address address = new Address("Foo Street 1", 1, zipCode, "Bar"); | ||
dave.setAddress(address); | ||
repository.save(dave); | ||
|
||
carter.setFriend(dave); | ||
repository.save(carter); | ||
|
||
List<Person> result = repository.findByFriendAddressZipCode(zipCode); | ||
|
||
assertThat(result).containsExactly(carter); | ||
|
||
TestUtils.setFriendsToNull(repository, carter); | ||
} | ||
|
||
@Test | ||
void findByNestedSimplePropertyEqualsNegativeTest() { | ||
assertThatThrownBy(() -> negativeTestsRepository.findByFriendAddressZipCode()) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessage("Address.zipCode EQ: invalid number of arguments, expecting one"); | ||
|
||
assertThatThrownBy(() -> negativeTestsRepository.findByFriendAddressZipCodeEquals()) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessage("Address.zipCode EQ: invalid number of arguments, expecting one"); | ||
} | ||
|
||
@Test | ||
void findByCollectionEquals() { | ||
if (serverVersionSupport.isFindByCDTSupported()) { | ||
List<String> listToCompareWith = List.of("str0", "str1", "str2"); | ||
Assertions.assertThat(dave.getStrings()).isEqualTo(listToCompareWith); | ||
|
||
List<Person> persons = repository.findByStringsEquals(listToCompareWith); | ||
assertThat(persons).contains(dave); | ||
|
||
// another way to call the method | ||
List<Person> persons2 = repository.findByStrings(listToCompareWith); | ||
assertThat(persons2).contains(dave); | ||
} | ||
} | ||
|
||
@Test | ||
void findByCollectionEquals_NegativeTest() { | ||
assertThatThrownBy(() -> negativeTestsRepository.findByStrings()) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessage("Person.strings EQ: invalid number of arguments, expecting one"); | ||
|
||
assertThatThrownBy(() -> negativeTestsRepository.findByStringsEquals("string1", "string2")) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessage("Person.strings EQ: invalid number of arguments, expecting one"); | ||
} | ||
|
||
@Test | ||
void findByMapEquals() { | ||
if (serverVersionSupport.isFindByCDTSupported()) { | ||
Map<String, String> mapToCompareWith = Map.of("key1", "val1", "key2", "val2"); | ||
assertThat(boyd.getStringMap()).isEqualTo(mapToCompareWith); | ||
|
||
List<Person> persons = repository.findByStringMapEquals(mapToCompareWith); | ||
assertThat(persons).contains(boyd); | ||
|
||
// another way to call the method | ||
List<Person> persons2 = repository.findByStringMap(mapToCompareWith); | ||
assertThat(persons2).contains(boyd); | ||
} | ||
} | ||
|
||
@Test | ||
void findByMapEquals_NegativeTest() { | ||
assertThatThrownBy(() -> negativeTestsRepository.findByStringMapEquals("map1")) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessage("Person.stringMap EQ: invalid combination of arguments, expecting either a Map or a key-value" + | ||
" pair"); | ||
|
||
assertThatThrownBy(() -> negativeTestsRepository.findByStringMap(100)) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessage("Person.stringMap EQ: invalid combination of arguments, expecting either a Map or a key-value" + | ||
" pair"); | ||
|
||
assertThatThrownBy(() -> negativeTestsRepository.findByStringMapEquals(Map.of("key", "value"), Map.of("key", | ||
"value"))) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessage("Person.stringMap EQ: invalid combination of arguments, expecting either a Map or a key-value" + | ||
" pair"); | ||
} | ||
|
||
@Test | ||
void findByPOJOEquals() { | ||
if (serverVersionSupport.isFindByCDTSupported()) { | ||
alicia.setAddress(new Address("Foo Street 1", 1, "C0123", "Bar")); | ||
repository.save(alicia); | ||
oliver.setFriend(alicia); | ||
repository.save(oliver); | ||
|
||
List<Person> persons = repository.findByFriend(alicia); | ||
assertThat(persons).containsOnly(oliver); | ||
|
||
alicia.setAddress(null); | ||
repository.save(alicia); | ||
} | ||
} | ||
|
||
@Test | ||
void findByNestedPOJOEquals() { | ||
if (serverVersionSupport.isFindByCDTSupported()) { | ||
Address address = new Address("Foo Street 1", 1, "C0123", "Bar"); | ||
dave.setAddress(address); | ||
repository.save(dave); | ||
|
||
carter.setFriend(dave); | ||
repository.save(carter); | ||
|
||
List<Person> result = repository.findByFriendAddress(address); | ||
|
||
assertThat(result).contains(carter); | ||
TestUtils.setFriendsToNull(repository, carter); | ||
} | ||
} | ||
|
||
@Test | ||
void findByNestedPojoEqualsNegativeTest() { | ||
assertThatThrownBy(() -> negativeTestsRepository.findByFriendAddress()) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessage("Person.address EQ: invalid number of arguments, expecting one POJO"); | ||
|
||
assertThatThrownBy(() -> negativeTestsRepository.findByFriendAddressEquals()) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessage("Person.address EQ: invalid number of arguments, expecting one POJO"); | ||
|
||
assertThatThrownBy(() -> negativeTestsRepository.findByFriendAddress(100)) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessage("Person.address EQ: Type mismatch, expecting Address"); | ||
} | ||
} |
Oops, something went wrong.