diff --git a/src/test/java/org/springframework/data/aerospike/SampleClasses.java b/src/test/java/org/springframework/data/aerospike/SampleClasses.java index a6e7b9d46..acbd270af 100644 --- a/src/test/java/org/springframework/data/aerospike/SampleClasses.java +++ b/src/test/java/org/springframework/data/aerospike/SampleClasses.java @@ -766,6 +766,7 @@ public static class DocumentWithBigIntegerAndNestedArray { private ObjectWithArray objectWithArray; } + @Data public static class ObjectWithArray { @Version diff --git a/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateSaveTests.java b/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateSaveTests.java index 7a6b519c0..b8015c5eb 100644 --- a/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateSaveTests.java +++ b/src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateSaveTests.java @@ -74,27 +74,30 @@ public void shouldReplaceAllBinsPresentInAerospikeWhenSavingDocument() { @Test public void shouldSaveDocumentWithArray() { - SampleClasses.DocumentWithArray doc = new SampleClasses.DocumentWithArray(id, new int[]{0, 1, 2, 3, 4, 5}); + int[] array = new int[]{0, 1, 2, 3, 4, 5}; + SampleClasses.DocumentWithArray doc = new SampleClasses.DocumentWithArray(id, array); template.save(doc); Key key = new Key(getNameSpace(), "DocumentWithArray", id); Record aeroRecord = client.get(new Policy(), key); assertThat(aeroRecord.bins.get("array")).isNotNull(); + SampleClasses.DocumentWithArray result = template.findById(id, SampleClasses.DocumentWithArray.class); + assertThat(result.getArray()).isEqualTo(array); } @Test - public void shouldSaveDocumentWithoutCustomConverter() { - SampleClasses.ObjectWithArray objectWithArray = new SampleClasses.ObjectWithArray(new Integer[]{0, 1, 2, - 3, 4}); + public void shouldSaveDocumentWithNestedArrayAndBigInteger() { + Integer[] array = new Integer[]{0, 1, 2, 3, 4}; + SampleClasses.ObjectWithArray objectWithArray = new SampleClasses.ObjectWithArray(array); + BigInteger bigInteger = new BigInteger("100"); SampleClasses.DocumentWithBigIntegerAndNestedArray doc = - new SampleClasses.DocumentWithBigIntegerAndNestedArray(id, - new BigInteger("100"), objectWithArray); + new SampleClasses.DocumentWithBigIntegerAndNestedArray(id, bigInteger, objectWithArray); template.save(doc); - Key key = new Key(getNameSpace(), - template.getSetName(SampleClasses.DocumentWithBigIntegerAndNestedArray.class), id); - Record aeroRecord = client.get(new Policy(), key); - assertThat(aeroRecord.bins).isNotEmpty(); + SampleClasses.DocumentWithBigIntegerAndNestedArray result = + template.findById(id, SampleClasses.DocumentWithBigIntegerAndNestedArray.class); + assertThat(result.getBigInteger()).isEqualTo(bigInteger); + assertThat(result.getObjectWithArray().getArray()).isEqualTo(array); } @Test diff --git a/src/test/java/org/springframework/data/aerospike/repository/PersonRepositoryQueryTests.java b/src/test/java/org/springframework/data/aerospike/repository/PersonRepositoryQueryTests.java index 33604bd54..9282b9d01 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/PersonRepositoryQueryTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/PersonRepositoryQueryTests.java @@ -62,9 +62,11 @@ public class PersonRepositoryQueryTests extends BaseBlockingIntegrationTests { .stringMap(of("key1", "val1", "key2", "val2")).address(new Address(null, null, null, null)) .build(); static final Person stefan = Person.builder().id(nextId()).firstName("Stefan").lastName("Lessard").age(34).build(); - static final Person leroi = Person.builder().id(nextId()).firstName("Leroi").lastName("Moore").age(44).build(); + static final Person leroi = Person.builder().id(nextId()).firstName("Leroi").lastName("Moore").age(44) + .intArray(new int[]{5, 6, 7, 8, 9, 10}).build(); static final Person leroi2 = Person.builder().id(nextId()).firstName("Leroi").lastName("Moore").age(25).build(); - static final Person matias = Person.builder().id(nextId()).firstName("Matias").lastName("Craft").age(24).build(); + static final Person matias = Person.builder().id(nextId()).firstName("Matias").lastName("Craft").age(24) + .intArray(new int[]{1, 2, 3, 4, 5}).build(); static final Person douglas = Person.builder().id(nextId()).firstName("Douglas").lastName("Ford").age(25).build(); public static final List allPersons = List.of(dave, donny, oliver, alicia, carter, boyd, stefan, leroi, leroi2, matias, douglas); @@ -185,6 +187,16 @@ void findByListNotContainingAddress() { repository.save(stefan); } + @Test + void findByArrayContainingInteger_forExistingResult() { + assertThat(repository.findByIntArrayContaining(1)).containsOnly(matias); + assertThat(repository.findByIntArrayContaining(5)).containsOnly(matias, leroi); + assertThat(repository.findByIntArrayContaining(10)).containsOnly(leroi); + + assertThat(repository.findByIntArrayContaining(1, 2)).containsOnly(matias); + assertThat(repository.findByIntArrayContaining(6, 7)).containsOnly(leroi); + } + @Test void findByBooleanInt() { boolean initialValue = Value.UseBoolBin; @@ -272,6 +284,23 @@ void findByListValueGreaterThanNumber() { .hasMessage("LIST_VAL_GT FilterExpression unsupported value: expected [Long.MIN_VALUE..Long.MAX_VALUE-1]"); } + @Test + void findByArrayValueGreaterThanNumber() { + List persons; + persons = repository.findByIntArrayGreaterThan(1); + assertThat(persons).containsOnly(matias, leroi); + + persons = repository.findByIntArrayGreaterThan(Long.MIN_VALUE); + assertThat(persons).containsOnly(matias, leroi); + + persons = repository.findByIntArrayGreaterThan(Long.MAX_VALUE - 1); + assertThat(persons).isEmpty(); + + assertThatThrownBy(() -> repository.findByIntArrayGreaterThan(Long.MAX_VALUE)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("LIST_VAL_GT FilterExpression unsupported value: expected [Long.MIN_VALUE..Long.MAX_VALUE-1]"); + } + @Test void findByListValueGreaterThanString() { List persons; diff --git a/src/test/java/org/springframework/data/aerospike/sample/Person.java b/src/test/java/org/springframework/data/aerospike/sample/Person.java index c7a446682..c53865b0a 100644 --- a/src/test/java/org/springframework/data/aerospike/sample/Person.java +++ b/src/test/java/org/springframework/data/aerospike/sample/Person.java @@ -62,6 +62,7 @@ public class Person { private LocalDate regDate; private List strings; private List ints; + private int[] intArray; private List> listOfIntLists; private List> listOfIntMaps; private Set intSet; diff --git a/src/test/java/org/springframework/data/aerospike/sample/PersonRepository.java b/src/test/java/org/springframework/data/aerospike/sample/PersonRepository.java index 017add0f3..d385f3995 100644 --- a/src/test/java/org/springframework/data/aerospike/sample/PersonRepository.java +++ b/src/test/java/org/springframework/data/aerospike/sample/PersonRepository.java @@ -831,6 +831,27 @@ List

findByStringMapContaining(String key1, String value1, String key2, Strin */ List

findByIntsContaining(int integer1, int integer2, int integer3); + /** + * Find all entities that satisfy the condition "have the array which contains the given integer" + *

+ * Array name in this case is IntArray + *

+ * + * @param integer number to check + */ + List

findByIntArrayContaining(int integer); + + /** + * Find all entities that satisfy the condition "have the array which contains the given integers" + *

+ * Array name in this case is IntArray + *

+ * + * @param integer1 number to check + * @param integer2 number to check + */ + List

findByIntArrayContaining(int integer1, int integer2); + /** * Find all entities that satisfy the condition "have the list which contains the given boolean" * @@ -886,6 +907,28 @@ List

findByStringMapContaining(String key1, String value1, String key2, Strin */ List

findByListOfIntListsGreaterThan(List> list); + /** + * Find all entities that satisfy the condition "have at least one array value which is greater than the given + * integer" + *

+ * Array name in this case is IntArray + *

+ * + * @param integer lower limit, exclusive, [Long.MIN_VALUE..Long.MAX_VALUE-1] + */ + List

findByIntArrayGreaterThan(int integer); + + /** + * Find all entities that satisfy the condition "have at least one array value which is greater than the given + * integer" + *

+ * Array name in this case is IntArray + *

+ * + * @param value lower limit, exclusive + */ + List

findByIntArrayGreaterThan(long value); + /** * Find all entities that satisfy the condition "have at least one map value (with the given key) which is greater * than the given parameter (list of integers)"