Skip to content

Commit

Permalink
Merge branch 'main' into FMWK-259-add-converters
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/test/java/org/springframework/data/aerospike/core/AerospikeTemplateSaveTests.java
  • Loading branch information
agrgr committed Oct 31, 2023
2 parents 1e83d36 + b507fb8 commit 1755f06
Show file tree
Hide file tree
Showing 6 changed files with 308 additions and 158 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,7 @@ public static class DocumentWithBigIntegerAndNestedArray {
private ObjectWithArray objectWithArray;
}

@Data
public static class ObjectWithArray {

@Version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ public void afterAll() {
// test for RecordExistsAction.REPLACE_ONLY policy
@Test
public void shouldReplaceAllBinsPresentInAerospikeWhenSavingDocument() {
Key key = new Key(getNameSpace(), "versioned-set", id);
VersionedClass first = new VersionedClass(id, "foo");
template.save(first);
Key key = new Key(getNameSpace(), template.getSetName(VersionedClass.class), id);
additionalAerospikeTestOperations.addNewFieldToSavedDataInAerospike(key);

template.save(new VersionedClass(id, "foo2", 2L));
Expand All @@ -74,26 +74,30 @@ public void shouldReplaceAllBinsPresentInAerospikeWhenSavingDocument() {

@Test
public void shouldSaveDocumentWithArray() {
SampleClasses.DocumentWithIntArray doc = new SampleClasses.DocumentWithIntArray(id, new int[]{0, 1, 2, 3, 4,
5});
int[] array = new int[]{0, 1, 2, 3, 4, 5};
SampleClasses.DocumentWithIntArray doc = new SampleClasses.DocumentWithIntArray(id, array);
template.save(doc);

Key key = new Key(getNameSpace(), template.getSetName(SampleClasses.DocumentWithIntArray.class), id);
Record aeroRecord = client.get(new Policy(), key);
assertThat(aeroRecord.bins.get("array")).isNotNull();
SampleClasses.DocumentWithIntArray result = template.findById(id, SampleClasses.DocumentWithIntArray.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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Person> allPersons = List.of(dave, donny, oliver, alicia, carter, boyd, stefan,
leroi, leroi2, matias, douglas);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<Person> 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<Person> persons;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class Person {
private LocalDate regDate;
private List<String> strings;
private List<Integer> ints;
private int[] intArray;
private List<List<Integer>> listOfIntLists;
private List<Map<String, Integer>> listOfIntMaps;
private Set<Integer> intSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,27 @@ List<P> findByStringMapContaining(String key1, String value1, String key2, Strin
*/
List<P> findByIntsContaining(int integer1, int integer2, int integer3);

/**
* Find all entities that satisfy the condition "have the array which contains the given integer"
* <p>
* Array name in this case is IntArray
* </p>
*
* @param integer number to check
*/
List<P> findByIntArrayContaining(int integer);

/**
* Find all entities that satisfy the condition "have the array which contains the given integers"
* <p>
* Array name in this case is IntArray
* </p>
*
* @param integer1 number to check
* @param integer2 number to check
*/
List<P> findByIntArrayContaining(int integer1, int integer2);

/**
* Find all entities that satisfy the condition "have the list which contains the given boolean"
*
Expand Down Expand Up @@ -886,6 +907,28 @@ List<P> findByStringMapContaining(String key1, String value1, String key2, Strin
*/
List<P> findByListOfIntListsGreaterThan(List<List<Integer>> list);

/**
* Find all entities that satisfy the condition "have at least one array value which is greater than the given
* integer"
* <p>
* Array name in this case is IntArray
* </p>
*
* @param integer lower limit, exclusive, [Long.MIN_VALUE..Long.MAX_VALUE-1]
*/
List<P> findByIntArrayGreaterThan(int integer);

/**
* Find all entities that satisfy the condition "have at least one array value which is greater than the given
* integer"
* <p>
* Array name in this case is IntArray
* </p>
*
* @param value lower limit, exclusive
*/
List<P> 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)"
Expand Down

0 comments on commit 1755f06

Please sign in to comment.