Skip to content

Commit

Permalink
FMWK-546 Refactor repository query tests (#783)
Browse files Browse the repository at this point in the history
* refactor repository query tests, align reactive tests structure with the blocking
* update documentation
  • Loading branch information
agrgr authored Oct 7, 2024
1 parent 92d0cdc commit c6d8aad
Show file tree
Hide file tree
Showing 64 changed files with 1,160 additions and 891 deletions.
2 changes: 2 additions & 0 deletions src/main/asciidoc/reference/query-methods-collection.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[[aerospike.query_methods.collection]]
= Collection Repository Queries

NOTE: *Repository read queries without id* utilize `query()` operation of the underlying Java client.

[width="100%",cols="<7%,<30%,<25%,<20%",options="header",]
|===
|Keyword |Repository query sample |Snippet |Notes
Expand Down
2 changes: 2 additions & 0 deletions src/main/asciidoc/reference/query-methods-id.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[[aerospike.query_methods.id]]
= Id Repository Queries

*Id repository reading queries* (like `findById()`, `findByIds()`, `findByFirstNameAndId()`, `findAllById()`, `countById()`, `existsById()` etc.) utilize `get` operation of the underlying Java client (`client.get()`).

[width="100%",cols="<7%,<30%,<25%,<20%",options="header",]
|===
|Keyword |Repository query sample |Snippet |Notes
Expand Down
2 changes: 2 additions & 0 deletions src/main/asciidoc/reference/query-methods-map.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[[aerospike.query_methods.map]]
= Map Repository Queries

NOTE: *Repository read queries without id* utilize `query()` operation of the underlying Java client.

[width="100%",cols="<7%,<30%,<25%,<20%",options="header",]
|===
|Keyword |Repository query sample |Snippet |Notes
Expand Down
2 changes: 2 additions & 0 deletions src/main/asciidoc/reference/query-methods-pojo.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[[aerospike.query_methods.pojo]]
= POJO Repository Queries

NOTE: *Repository read queries without id* utilize `query()` operation of the underlying Java client.

[width="100%",cols="<7%,<30%,<25%,<20%",options="header",]
|===
|Keyword |Repository query sample |Snippet |Notes
Expand Down
3 changes: 3 additions & 0 deletions src/main/asciidoc/reference/query-methods-preface.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ Here are the references to the examples of repository queries:

<<aerospike.query_methods.id, Id>>

NOTE: *Id repository read queries* (like `findById()`, `findByIds()`, `findByFirstNameAndId()`, `findAllById()`, `countById()`, `existsById()` etc.) utilize `get()` operation of the underlying Java client. *Repository read queries without id* (like `findByFirstName()`, `findByFirstNameAndLastName()`, `findAll()` etc.) utilize `query()` operation of the underlying Java client.


== Repository Interface Example

Below is an example of an interface with several query methods:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[[aerospike.query_methods.simple_property]]
= Simple Property Repository Queries

NOTE: *Repository read queries without id* utilize `query()` operation of the underlying Java client.

[width="100%",cols="<7%,<30%,<25%,<20%",options="header",]
|===
|Keyword |Repository query sample |Snippet |Notes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public abstract class BaseReactiveIntegrationTests extends BaseIntegrationTests
protected IndexesCache indexesCache;
@Autowired
protected MappingContext<BasicAerospikePersistentEntity<?>, AerospikePersistentProperty> mappingContext;
@Autowired
protected ReactiveBlockingAerospikeTestOperations reactiveBlockingAerospikeTestOperations;

protected <T> T findById(Serializable id, Class<T> type) {
return reactiveTemplate.findById(id, type).block();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.springframework.data.aerospike.repository.query.blocking.noindex;
package org.springframework.data.aerospike.repository.query.blocking;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.springframework.data.aerospike.repository.query.blocking.noindex.countBy;
package org.springframework.data.aerospike.repository.query.blocking.count;

import org.junit.jupiter.api.Test;
import org.springframework.data.aerospike.repository.query.blocking.noindex.PersonRepositoryQueryTests;
import org.springframework.data.aerospike.repository.query.blocking.PersonRepositoryQueryTests;

import java.util.Date;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.springframework.data.aerospike.repository.query.blocking.noindex.countBy;
package org.springframework.data.aerospike.repository.query.blocking.count;

import org.junit.jupiter.api.Test;
import org.springframework.data.aerospike.repository.query.blocking.noindex.PersonRepositoryQueryTests;
import org.springframework.data.aerospike.repository.query.blocking.PersonRepositoryQueryTests;
import org.springframework.data.aerospike.util.TestUtils;

import java.util.Comparator;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.springframework.data.aerospike.repository.query.blocking.noindex.countBy;
package org.springframework.data.aerospike.repository.query.blocking.count;

import org.junit.jupiter.api.Test;
import org.springframework.data.aerospike.query.QueryParam;
import org.springframework.data.aerospike.repository.query.blocking.noindex.PersonRepositoryQueryTests;
import org.springframework.data.aerospike.repository.query.blocking.PersonRepositoryQueryTests;

import java.util.List;

Expand All @@ -27,7 +27,7 @@ void countBySimplePropertyEquals_String() {
}

@Test
void countPersonById_AND_simpleProperty() {
void countById_AND_simpleProperty() {
QueryParam ids = of(dave.getId());
QueryParam name = of(carter.getFirstName());
long persons = repository.countByIdAndFirstName(ids, name);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.springframework.data.aerospike.repository.query.blocking.noindex.deleteBy;
package org.springframework.data.aerospike.repository.query.blocking.delete;

import org.junit.jupiter.api.Test;
import org.springframework.data.aerospike.repository.query.blocking.noindex.PersonRepositoryQueryTests;
import org.springframework.data.aerospike.repository.query.blocking.PersonRepositoryQueryTests;

import java.util.Date;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.springframework.data.aerospike.repository.query.blocking.noindex.deleteBy;
package org.springframework.data.aerospike.repository.query.blocking.delete;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.data.aerospike.repository.query.blocking.noindex.PersonRepositoryQueryTests;
import org.springframework.data.aerospike.repository.query.blocking.PersonRepositoryQueryTests;
import org.springframework.data.aerospike.sample.Person;
import org.springframework.data.aerospike.util.TestUtils;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package org.springframework.data.aerospike.repository.query.blocking.delete;

import org.junit.jupiter.api.Test;
import org.springframework.data.aerospike.query.QueryParam;
import org.springframework.data.aerospike.repository.query.blocking.PersonRepositoryQueryTests;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.data.aerospike.query.QueryParam.of;

/**
* Tests for the "Equals" repository query. Keywords: Is, Equals (or no keyword).
*/
public class EqualsTests extends PersonRepositoryQueryTests {

@Test
void deleteBySimplePropertyEquals_String() {
assertThat(repository.findByFirstName("Leroi")).isNotEmpty();
repository.deleteByFirstName("Leroi");
assertThat(repository.findByFirstName("Leroi")).isEmpty();

repository.save(leroi);
assertThat(repository.findByFirstNameIgnoreCase("lEroi")).isNotEmpty();
repository.deleteByFirstNameIgnoreCase("lEroi");
assertThat(repository.findByFirstNameIgnoreCase("lEroi")).isEmpty();
// cleanup
repository.save(leroi);
}

@Test
void deleteById() {
assertThat(repository.existsById(dave.getId())).isTrue();
repository.deleteById(dave.getId());
assertThat(repository.existsById(dave.getId())).isFalse();
// cleanup
repository.save(dave);
}

@Test
void deleteById_AND_simpleProperty() {
assertThat(repository.existsById(leroi.getId())).isTrue();
assertThat(repository.existsById(dave.getId())).isTrue();
assertThat(repository.existsById(carter.getId())).isTrue();

QueryParam id = of(leroi.getId());
QueryParam name = of(leroi.getFirstName());
assertThat(repository.existsByIdAndFirstName(id, name)).isTrue();
repository.deleteByIdAndFirstName(id, name);
assertThat(repository.existsByIdAndFirstName(id, name)).isFalse();

QueryParam id2 = of(dave.getId());
QueryParam name2 = of(carter.getFirstName());
// there is no record with Dave's id and Carter's first name
assertThat(repository.existsByIdAndFirstName(id2, name2)).isFalse();
// delete using id and first name of different records must not change anything
repository.deleteByIdAndFirstName(id2, name2);
assertThat(repository.existsById(dave.getId())).isTrue();
assertThat(repository.existsById(carter.getId())).isTrue();

repository.deleteAllById(List.of(dave.getId(), carter.getId()));
assertThat(repository.existsById(dave.getId())).isFalse();
assertThat(repository.existsById(carter.getId())).isFalse();

// cleanup
repository.save(leroi);
repository.save(dave);
repository.save(carter);
}

@Test
void deleteAllByIds() {
assertThat(repository.existsById(dave.getId())).isTrue();
assertThat(repository.existsById(carter.getId())).isTrue();

repository.deleteAllById(List.of(dave.getId(), carter.getId()));

assertThat(repository.existsById(dave.getId())).isFalse();
assertThat(repository.existsById(carter.getId())).isFalse();

// cleanup
repository.save(dave);
repository.save(carter);
}

@Test
void deleteAll() {
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();
// cleanup
repository.save(dave);
repository.save(carter);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.springframework.data.aerospike.repository.query.blocking.noindex.deleteBy;
package org.springframework.data.aerospike.repository.query.blocking.delete;

import org.junit.jupiter.api.Test;
import org.springframework.data.aerospike.repository.query.blocking.noindex.PersonRepositoryQueryTests;
import org.springframework.data.aerospike.repository.query.blocking.PersonRepositoryQueryTests;
import org.springframework.data.aerospike.sample.Person;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.springframework.data.aerospike.repository.query.blocking.noindex.existsBy;
package org.springframework.data.aerospike.repository.query.blocking.exists;

import org.junit.jupiter.api.Test;
import org.springframework.data.aerospike.repository.query.blocking.noindex.PersonRepositoryQueryTests;
import org.springframework.data.aerospike.repository.query.blocking.PersonRepositoryQueryTests;

import java.util.Date;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.springframework.data.aerospike.repository.query.blocking.noindex.existsBy;
package org.springframework.data.aerospike.repository.query.blocking.exists;

import org.junit.jupiter.api.Test;
import org.springframework.data.aerospike.repository.query.blocking.noindex.PersonRepositoryQueryTests;
import org.springframework.data.aerospike.repository.query.blocking.PersonRepositoryQueryTests;
import org.springframework.data.aerospike.util.TestUtils;

import java.util.Comparator;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.springframework.data.aerospike.repository.query.blocking.noindex.existsBy;
package org.springframework.data.aerospike.repository.query.blocking.exists;

import org.junit.jupiter.api.Test;
import org.springframework.data.aerospike.query.QueryParam;
import org.springframework.data.aerospike.repository.query.blocking.noindex.PersonRepositoryQueryTests;
import org.springframework.data.aerospike.repository.query.blocking.PersonRepositoryQueryTests;

import java.util.List;

Expand All @@ -27,7 +27,16 @@ void existsBySimplePropertyEquals_String() {
}

@Test
void existsPersonById_AND_simpleProperty() {
void existsById() {
boolean result = repository.existsById(dave.getId());
assertThat(result).isTrue();

boolean result2 = repository.existsById(dave.getId() + "test1234__**");
assertThat(result2).isFalse();
}

@Test
void existsById_AND_simpleProperty() {
QueryParam ids = of(dave.getId());
QueryParam name = of(carter.getFirstName());
boolean result = repository.existsByIdAndFirstName(ids, name);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.springframework.data.aerospike.repository.query.blocking.noindex.findBy;
package org.springframework.data.aerospike.repository.query.blocking.find;

import org.junit.jupiter.api.Test;
import org.springframework.data.aerospike.repository.query.blocking.noindex.PersonRepositoryQueryTests;
import org.springframework.data.aerospike.repository.query.blocking.PersonRepositoryQueryTests;
import org.springframework.data.aerospike.sample.Person;

import java.util.Date;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.springframework.data.aerospike.repository.query.blocking.noindex.findBy;
package org.springframework.data.aerospike.repository.query.blocking.find;

import org.junit.jupiter.api.Test;
import org.springframework.data.aerospike.repository.query.blocking.noindex.PersonRepositoryQueryTests;
import org.springframework.data.aerospike.repository.query.blocking.PersonRepositoryQueryTests;
import org.springframework.data.aerospike.sample.Person;

import java.time.LocalDate;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.springframework.data.aerospike.repository.query.blocking.noindex.findBy;
package org.springframework.data.aerospike.repository.query.blocking.find;

import org.junit.jupiter.api.Test;
import org.springframework.data.aerospike.repository.query.blocking.noindex.PersonRepositoryQueryTests;
import org.springframework.data.aerospike.repository.query.blocking.PersonRepositoryQueryTests;
import org.springframework.data.aerospike.sample.Address;
import org.springframework.data.aerospike.sample.Person;
import org.springframework.data.aerospike.util.TestUtils;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.springframework.data.aerospike.repository.query.blocking.noindex.findBy;
package org.springframework.data.aerospike.repository.query.blocking.find;

import org.junit.jupiter.api.Test;
import org.springframework.data.aerospike.repository.query.blocking.noindex.PersonRepositoryQueryTests;
import org.springframework.data.aerospike.repository.query.blocking.PersonRepositoryQueryTests;
import org.springframework.data.aerospike.sample.Address;
import org.springframework.data.aerospike.sample.Person;
import org.springframework.data.aerospike.util.TestUtils;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.springframework.data.aerospike.repository.query.blocking.noindex.findBy;
package org.springframework.data.aerospike.repository.query.blocking.find;

import org.junit.jupiter.api.Test;
import org.springframework.data.aerospike.repository.query.blocking.noindex.PersonRepositoryQueryTests;
import org.springframework.data.aerospike.repository.query.blocking.PersonRepositoryQueryTests;
import org.springframework.data.aerospike.sample.Person;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
Expand All @@ -19,7 +19,7 @@
public class CrudRepositoryQueryTests extends PersonRepositoryQueryTests {

@Test
void findPersonById() {
void findById() {
Optional<Person> person = repository.findById(dave.getId());

assertThat(person).hasValueSatisfying(actual -> {
Expand All @@ -28,6 +28,12 @@ void findPersonById() {
});
}

@Test
void findAllByIds() {
Iterable<Person> result = repository.findAllById(List.of(dave.getId(), carter.getId()));
assertThat(result).containsExactlyInAnyOrder(dave, carter);
}

@Test
void findAll() {
List<Person> result = (List<Person>) repository.findAll();
Expand Down Expand Up @@ -68,26 +74,4 @@ void findAll_doesNotFindPersonDeletedById() {
repository.save(dave);
}
}

@Test
void deletePersonById() {
repository.deleteById(dave.getId());

assertThat(repository.findById(dave.getId())).isEmpty();

repository.save(dave); // cleanup
}

@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
}
}
Loading

0 comments on commit c6d8aad

Please sign in to comment.