Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FMWK-260 Add tests for reading arrays of primitives #648

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,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 @@ -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
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
Loading