diff --git a/src/main/asciidoc/reference/query-methods-collection.adoc b/src/main/asciidoc/reference/query-methods-collection.adoc index 107d628e9..73797e1d7 100644 --- a/src/main/asciidoc/reference/query-methods-collection.adoc +++ b/src/main/asciidoc/reference/query-methods-collection.adoc @@ -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 diff --git a/src/main/asciidoc/reference/query-methods-id.adoc b/src/main/asciidoc/reference/query-methods-id.adoc index aeb1b9344..c2f4ef508 100644 --- a/src/main/asciidoc/reference/query-methods-id.adoc +++ b/src/main/asciidoc/reference/query-methods-id.adoc @@ -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 diff --git a/src/main/asciidoc/reference/query-methods-map.adoc b/src/main/asciidoc/reference/query-methods-map.adoc index 613b90db0..4107fb90c 100644 --- a/src/main/asciidoc/reference/query-methods-map.adoc +++ b/src/main/asciidoc/reference/query-methods-map.adoc @@ -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 diff --git a/src/main/asciidoc/reference/query-methods-pojo.adoc b/src/main/asciidoc/reference/query-methods-pojo.adoc index 46448775d..0c5cf855f 100644 --- a/src/main/asciidoc/reference/query-methods-pojo.adoc +++ b/src/main/asciidoc/reference/query-methods-pojo.adoc @@ -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 diff --git a/src/main/asciidoc/reference/query-methods-preface.adoc b/src/main/asciidoc/reference/query-methods-preface.adoc index f311a2ac5..a40203d91 100644 --- a/src/main/asciidoc/reference/query-methods-preface.adoc +++ b/src/main/asciidoc/reference/query-methods-preface.adoc @@ -22,6 +22,9 @@ Here are the references to the examples of repository queries: <> +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: diff --git a/src/main/asciidoc/reference/query-methods-simple-property.adoc b/src/main/asciidoc/reference/query-methods-simple-property.adoc index 934986677..b3e29f83a 100644 --- a/src/main/asciidoc/reference/query-methods-simple-property.adoc +++ b/src/main/asciidoc/reference/query-methods-simple-property.adoc @@ -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 diff --git a/src/test/java/org/springframework/data/aerospike/BaseReactiveIntegrationTests.java b/src/test/java/org/springframework/data/aerospike/BaseReactiveIntegrationTests.java index 2b8007f09..38d7bdc64 100644 --- a/src/test/java/org/springframework/data/aerospike/BaseReactiveIntegrationTests.java +++ b/src/test/java/org/springframework/data/aerospike/BaseReactiveIntegrationTests.java @@ -62,6 +62,8 @@ public abstract class BaseReactiveIntegrationTests extends BaseIntegrationTests protected IndexesCache indexesCache; @Autowired protected MappingContext, AerospikePersistentProperty> mappingContext; + @Autowired + protected ReactiveBlockingAerospikeTestOperations reactiveBlockingAerospikeTestOperations; protected T findById(Serializable id, Class type) { return reactiveTemplate.findById(id, type).block(); diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/PersonRepositoryQueryTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/PersonRepositoryQueryTests.java similarity index 99% rename from src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/PersonRepositoryQueryTests.java rename to src/test/java/org/springframework/data/aerospike/repository/query/blocking/PersonRepositoryQueryTests.java index c8c8be689..3c855cc7f 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/PersonRepositoryQueryTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/PersonRepositoryQueryTests.java @@ -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; diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/countBy/AfterTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/count/AfterTests.java similarity index 93% rename from src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/countBy/AfterTests.java rename to src/test/java/org/springframework/data/aerospike/repository/query/blocking/count/AfterTests.java index b716c6918..ef20b8f75 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/countBy/AfterTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/count/AfterTests.java @@ -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; diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/countBy/BetweenTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/count/BetweenTests.java similarity index 98% rename from src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/countBy/BetweenTests.java rename to src/test/java/org/springframework/data/aerospike/repository/query/blocking/count/BetweenTests.java index 7616bc37e..1b07a4325 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/countBy/BetweenTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/count/BetweenTests.java @@ -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; diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/countBy/EqualsTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/count/EqualsTests.java similarity index 93% rename from src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/countBy/EqualsTests.java rename to src/test/java/org/springframework/data/aerospike/repository/query/blocking/count/EqualsTests.java index 3ab8b4985..92e82f3cc 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/countBy/EqualsTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/count/EqualsTests.java @@ -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; @@ -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); diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/deleteBy/AfterTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/delete/AfterTests.java similarity index 94% rename from src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/deleteBy/AfterTests.java rename to src/test/java/org/springframework/data/aerospike/repository/query/blocking/delete/AfterTests.java index 6721b5d9b..f367da23a 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/deleteBy/AfterTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/delete/AfterTests.java @@ -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; diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/deleteBy/BetweenTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/delete/BetweenTests.java similarity index 98% rename from src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/deleteBy/BetweenTests.java rename to src/test/java/org/springframework/data/aerospike/repository/query/blocking/delete/BetweenTests.java index e10b29346..6424b9232 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/deleteBy/BetweenTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/delete/BetweenTests.java @@ -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; diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/delete/EqualsTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/delete/EqualsTests.java new file mode 100644 index 000000000..907855dfd --- /dev/null +++ b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/delete/EqualsTests.java @@ -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); + } +} diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/deleteBy/GreaterThanTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/delete/GreaterThanTests.java similarity index 95% rename from src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/deleteBy/GreaterThanTests.java rename to src/test/java/org/springframework/data/aerospike/repository/query/blocking/delete/GreaterThanTests.java index 4a2c0c54f..e0938e333 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/deleteBy/GreaterThanTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/delete/GreaterThanTests.java @@ -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; diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/existsBy/AfterTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/exists/AfterTests.java similarity index 93% rename from src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/existsBy/AfterTests.java rename to src/test/java/org/springframework/data/aerospike/repository/query/blocking/exists/AfterTests.java index 9f108bfff..c88938c2a 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/existsBy/AfterTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/exists/AfterTests.java @@ -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; diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/existsBy/BetweenTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/exists/BetweenTests.java similarity index 98% rename from src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/existsBy/BetweenTests.java rename to src/test/java/org/springframework/data/aerospike/repository/query/blocking/exists/BetweenTests.java index 24f0682ad..82d7e5d01 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/existsBy/BetweenTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/exists/BetweenTests.java @@ -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; diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/existsBy/EqualsTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/exists/EqualsTests.java similarity index 82% rename from src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/existsBy/EqualsTests.java rename to src/test/java/org/springframework/data/aerospike/repository/query/blocking/exists/EqualsTests.java index 722459794..7c97d7656 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/existsBy/EqualsTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/exists/EqualsTests.java @@ -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; @@ -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); diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/AfterTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/AfterTests.java similarity index 92% rename from src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/AfterTests.java rename to src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/AfterTests.java index c88563385..0b2d51ad8 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/AfterTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/AfterTests.java @@ -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; diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/BeforeTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/BeforeTests.java similarity index 93% rename from src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/BeforeTests.java rename to src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/BeforeTests.java index f501efa40..465e682ff 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/BeforeTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/BeforeTests.java @@ -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; diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/BetweenTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/BetweenTests.java similarity index 99% rename from src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/BetweenTests.java rename to src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/BetweenTests.java index 4b6511336..e853cfb74 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/BetweenTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/BetweenTests.java @@ -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; diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/ContainingTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/ContainingTests.java similarity index 99% rename from src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/ContainingTests.java rename to src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/ContainingTests.java index 73743bd0d..71dbfa513 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/ContainingTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/ContainingTests.java @@ -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; diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/CrudRepositoryQueryTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/CrudRepositoryQueryTests.java similarity index 74% rename from src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/CrudRepositoryQueryTests.java rename to src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/CrudRepositoryQueryTests.java index 2797c0376..3e3bec54f 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/CrudRepositoryQueryTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/CrudRepositoryQueryTests.java @@ -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; @@ -19,7 +19,7 @@ public class CrudRepositoryQueryTests extends PersonRepositoryQueryTests { @Test - void findPersonById() { + void findById() { Optional person = repository.findById(dave.getId()); assertThat(person).hasValueSatisfying(actual -> { @@ -28,6 +28,12 @@ void findPersonById() { }); } + @Test + void findAllByIds() { + Iterable result = repository.findAllById(List.of(dave.getId(), carter.getId())); + assertThat(result).containsExactlyInAnyOrder(dave, carter); + } + @Test void findAll() { List result = (List) repository.findAll(); @@ -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 - } } diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/CustomQueriesTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/CustomQueriesTests.java similarity index 99% rename from src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/CustomQueriesTests.java rename to src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/CustomQueriesTests.java index cfba09714..1eb9d1361 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/CustomQueriesTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/CustomQueriesTests.java @@ -1,10 +1,10 @@ -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.query.FilterOperation; import org.springframework.data.aerospike.query.qualifier.Qualifier; import org.springframework.data.aerospike.repository.query.Query; -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.Sort; diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/EqualsTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/EqualsTests.java similarity index 98% rename from src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/EqualsTests.java rename to src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/EqualsTests.java index 6acecfe6a..f58503698 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/EqualsTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/EqualsTests.java @@ -1,4 +1,4 @@ -package org.springframework.data.aerospike.repository.query.blocking.noindex.findBy; +package org.springframework.data.aerospike.repository.query.blocking.find; import com.aerospike.client.Value; import org.assertj.core.api.Assertions; @@ -8,7 +8,7 @@ import org.springframework.data.aerospike.query.QueryParam; import org.springframework.data.aerospike.query.qualifier.Qualifier; import org.springframework.data.aerospike.repository.query.Query; -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.sample.PersonSomeFields; @@ -16,6 +16,7 @@ import java.util.List; import java.util.Map; +import java.util.Optional; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -41,6 +42,12 @@ void findBySimplePropertyEquals_String() { assertThat(result3).hasSize(0); } + @Test + void findBySimpleProperty_String_projection() { + List result = repository.findPersonSomeFieldsByLastName("Beauford"); + assertThat(result).containsOnly(carter.toPersonSomeFields()); + } + @Test void findBySimplePropertyEquals_String_NegativeTest() { assertThatThrownBy(() -> negativeTestsRepository.findByFirstName(100)) @@ -124,7 +131,14 @@ void findBySimplePropertyEquals_Boolean_NegativeTest() { } @Test - void findPersonById_AND_simpleProperty() { + void findById() { + Optional result = repository.findById(dave.getId()); + assertThat(result).isPresent(); + assertThat(result.get()).isEqualTo(dave); + } + + @Test + void findById_AND_simpleProperty() { QueryParam ids = of(dave.getId()); QueryParam name = of(carter.getFirstName()); List persons = repository.findByIdAndFirstName(ids, name); @@ -164,36 +178,11 @@ void findPersonById_AND_simpleProperty() { } @Test - void findAllByIds() { - Iterable result = repository.findAllById(List.of(dave.getId(), carter.getId())); - assertThat(result).containsExactlyInAnyOrder(dave, carter); - } - - @Test - void findAllPersonByIds_AND_simpleProperty() { - QueryParam ids1 = of(List.of(dave.getId(), boyd.getId())); - QueryParam name1 = of(dave.getFirstName()); - List persons1 = repository.findAllByIdAndFirstName(ids1, name1); - assertThat(persons1).contains(dave); - - QueryParam ids2 = of(List.of(dave.getId(), boyd.getId())); - QueryParam name2 = of(carter.getFirstName()); - List persons2 = repository.findAllByIdAndFirstName(ids2, name2); - assertThat(persons2).isEmpty(); - } - - @Test - void findByIds_dynamicProjection() { + void findById_dynamicProjection() { List result = repository.findById(dave.getId(), PersonSomeFields.class); assertThat(result).containsOnly(dave.toPersonSomeFields()); } - @Test - void findBySimpleProperty_String_projection() { - List result = repository.findPersonSomeFieldsByLastName("Beauford"); - assertThat(result).containsOnly(carter.toPersonSomeFields()); - } - @Test void findById_AND_simpleProperty_dynamicProjection() { QueryParam ids = of(List.of(boyd.getId(), dave.getId(), carter.getId())); @@ -227,6 +216,25 @@ void findBySimpleProperty_AND_simpleProperty_DynamicProjection() { assertThat(result).containsOnly(carter.toPersonSomeFields()); } + @Test + void findAllByIds() { + Iterable result = repository.findAllById(List.of(dave.getId(), carter.getId())); + assertThat(result).containsExactlyInAnyOrder(dave, carter); + } + + @Test + void findAllByIds_AND_simpleProperty() { + QueryParam ids1 = of(List.of(dave.getId(), boyd.getId())); + QueryParam name1 = of(dave.getFirstName()); + List persons1 = repository.findAllByIdAndFirstName(ids1, name1); + assertThat(persons1).contains(dave); + + QueryParam ids2 = of(List.of(dave.getId(), boyd.getId())); + QueryParam name2 = of(carter.getFirstName()); + List persons2 = repository.findAllByIdAndFirstName(ids2, name2); + assertThat(persons2).isEmpty(); + } + @Test void findByNestedSimplePropertyEquals() { String zipCode = "C0124"; diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/ExistsTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/ExistsTests.java similarity index 98% rename from src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/ExistsTests.java rename to src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/ExistsTests.java index 7f09b3ec7..08fa06f0f 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/ExistsTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/ExistsTests.java @@ -1,8 +1,8 @@ -package org.springframework.data.aerospike.repository.query.blocking.noindex.findBy; +package org.springframework.data.aerospike.repository.query.blocking.find; import org.assertj.core.api.Assertions; 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; diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/FalseTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/FalseTests.java similarity index 96% rename from src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/FalseTests.java rename to src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/FalseTests.java index 850a81506..7958657f4 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/FalseTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/FalseTests.java @@ -1,9 +1,9 @@ -package org.springframework.data.aerospike.repository.query.blocking.noindex.findBy; +package org.springframework.data.aerospike.repository.query.blocking.find; import com.aerospike.client.Value; import org.assertj.core.api.Assertions; 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; /** diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/GreaterThanOrEqualTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/GreaterThanOrEqualTests.java similarity index 98% rename from src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/GreaterThanOrEqualTests.java rename to src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/GreaterThanOrEqualTests.java index 6579a0612..50c7eb580 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/GreaterThanOrEqualTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/GreaterThanOrEqualTests.java @@ -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; diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/GreaterThanTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/GreaterThanTests.java similarity index 99% rename from src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/GreaterThanTests.java rename to src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/GreaterThanTests.java index 82b469707..6fe6689ff 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/GreaterThanTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/GreaterThanTests.java @@ -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.sample.PersonSomeFields; diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/InTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/InTests.java similarity index 98% rename from src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/InTests.java rename to src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/InTests.java index 8e5e426eb..3701cf34e 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/InTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/InTests.java @@ -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; diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/LessThanOrEqualTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/LessThanOrEqualTests.java similarity index 99% rename from src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/LessThanOrEqualTests.java rename to src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/LessThanOrEqualTests.java index b43a54d22..0c96ed1f0 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/LessThanOrEqualTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/LessThanOrEqualTests.java @@ -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; diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/LessThanTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/LessThanTests.java similarity index 99% rename from src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/LessThanTests.java rename to src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/LessThanTests.java index 0debfcf35..228538ab6 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/LessThanTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/LessThanTests.java @@ -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; diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/LikeTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/LikeTests.java similarity index 95% rename from src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/LikeTests.java rename to src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/LikeTests.java index 90e82202c..5f8237569 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/LikeTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/LikeTests.java @@ -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.aerospike.util.TestUtils; diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/MatchesRegexTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/MatchesRegexTests.java similarity index 96% rename from src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/MatchesRegexTests.java rename to src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/MatchesRegexTests.java index fb577bdec..ba688afd6 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/MatchesRegexTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/MatchesRegexTests.java @@ -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.aerospike.util.TestUtils; diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/NotContainingTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/NotContainingTests.java similarity index 99% rename from src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/NotContainingTests.java rename to src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/NotContainingTests.java index 32731c487..807227bd1 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/NotContainingTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/NotContainingTests.java @@ -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; diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/NotEqualTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/NotEqualTests.java similarity index 99% rename from src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/NotEqualTests.java rename to src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/NotEqualTests.java index 024d1e854..ee8cb9995 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/NotEqualTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/NotEqualTests.java @@ -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; diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/NotInTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/NotInTests.java similarity index 98% rename from src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/NotInTests.java rename to src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/NotInTests.java index b887227db..a3c58be1b 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/NotInTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/NotInTests.java @@ -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; diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/NotNullTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/NotNullTests.java similarity index 98% rename from src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/NotNullTests.java rename to src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/NotNullTests.java index 76b5542f9..1abea1196 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/NotNullTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/NotNullTests.java @@ -1,8 +1,8 @@ -package org.springframework.data.aerospike.repository.query.blocking.noindex.findBy; +package org.springframework.data.aerospike.repository.query.blocking.find; import org.assertj.core.api.Assertions; 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; diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/NullTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/NullTests.java similarity index 98% rename from src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/NullTests.java rename to src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/NullTests.java index 58acfae24..3b73203d4 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/NullTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/NullTests.java @@ -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; diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/StartsWithTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/StartsWithTests.java similarity index 98% rename from src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/StartsWithTests.java rename to src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/StartsWithTests.java index 45554516d..249ca35be 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/StartsWithTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/StartsWithTests.java @@ -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.aerospike.util.TestUtils; import org.springframework.data.domain.Page; diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/TrueTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/TrueTests.java similarity index 97% rename from src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/TrueTests.java rename to src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/TrueTests.java index 7d433aa06..2f54969a1 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/TrueTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/TrueTests.java @@ -1,8 +1,8 @@ -package org.springframework.data.aerospike.repository.query.blocking.noindex.findBy; +package org.springframework.data.aerospike.repository.query.blocking.find; import com.aerospike.client.Value; 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.List; diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/findByKeywordSynonymsTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/findByKeywordSynonymsTests.java similarity index 95% rename from src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/findByKeywordSynonymsTests.java rename to src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/findByKeywordSynonymsTests.java index 498552591..05c28a7e4 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/findBy/findByKeywordSynonymsTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/find/findByKeywordSynonymsTests.java @@ -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.List; diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/deleteBy/EqualsTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/deleteBy/EqualsTests.java deleted file mode 100644 index ddea013d4..000000000 --- a/src/test/java/org/springframework/data/aerospike/repository/query/blocking/noindex/deleteBy/EqualsTests.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.springframework.data.aerospike.repository.query.blocking.noindex.deleteBy; - -import org.junit.jupiter.api.Test; -import org.springframework.data.aerospike.repository.query.blocking.noindex.PersonRepositoryQueryTests; - -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * 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(); - } - - @Test - void deletePersonById_AND_simpleProperty() { -// QueryParam ids = of(dave.getId()); -// QueryParam name = of(carter.getFirstName()); -// repository.deleteByIdAndFirstName(ids, name); -// assertThat(repository.findByIdAndFirstName(ids, name)).isEmpty(); -// -// ids = of(dave.getId()); -// name = of(dave.getFirstName()); -// assertThat(repository.findByIdAndFirstName(ids, name)).isNotEmpty(); -// repository.deleteByIdAndFirstName(ids, name); -// assertThat(repository.findByIdAndFirstName(ids, name)).isEmpty(); - - repository.deleteAllById(List.of(dave.getId(), carter.getId())); - } -} diff --git a/src/test/java/org/springframework/data/aerospike/repository/reactive/ReactiveAerospikeRepositorySaveRelatedTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/reactive/ReactiveAerospikeRepositorySaveRelatedTests.java similarity index 50% rename from src/test/java/org/springframework/data/aerospike/repository/reactive/ReactiveAerospikeRepositorySaveRelatedTests.java rename to src/test/java/org/springframework/data/aerospike/repository/query/reactive/ReactiveAerospikeRepositorySaveRelatedTests.java index 74271d460..2dc374329 100644 --- a/src/test/java/org/springframework/data/aerospike/repository/reactive/ReactiveAerospikeRepositorySaveRelatedTests.java +++ b/src/test/java/org/springframework/data/aerospike/repository/query/reactive/ReactiveAerospikeRepositorySaveRelatedTests.java @@ -1,13 +1,10 @@ -package org.springframework.data.aerospike.repository.reactive; +package org.springframework.data.aerospike.repository.query.reactive; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.aerospike.BaseReactiveIntegrationTests; import org.springframework.data.aerospike.sample.CompositeObject; import org.springframework.data.aerospike.sample.Customer; import org.springframework.data.aerospike.sample.ReactiveCompositeObjectRepository; -import org.springframework.data.aerospike.sample.ReactiveCustomerRepository; import org.springframework.data.aerospike.sample.SimpleObject; import reactor.core.publisher.Flux; import reactor.core.scheduler.Schedulers; @@ -21,101 +18,90 @@ /** * @author Igor Ermolenko */ -public class ReactiveAerospikeRepositorySaveRelatedTests extends BaseReactiveIntegrationTests { - - @Autowired - ReactiveCustomerRepository customerRepo; +public class ReactiveAerospikeRepositorySaveRelatedTests extends ReactiveCustomerRepositoryQueryTests { + @Autowired ReactiveCompositeObjectRepository compositeRepo; - private Customer customer1, customer2, customer3; - - @BeforeEach - public void setUp() { - customer1 = Customer.builder().id(nextId()).firstName("Homer").lastName("Simpson").age(42).build(); - customer2 = Customer.builder().id(nextId()).firstName("Marge").lastName("Simpson").age(39).build(); - customer3 = Customer.builder().id(nextId()).firstName("Bart").lastName("Simpson").age(15).build(); - } - @Test public void saveEntityShouldInsertNewEntity() { - StepVerifier.create(customerRepo.save(customer1).subscribeOn(Schedulers.parallel())).expectNext(customer1) + StepVerifier.create(reactiveRepository.save(matt).subscribeOn(Schedulers.parallel())).expectNext(matt) .verifyComplete(); - assertCustomerExistsInRepo(customer1); + assertCustomerExistsInRepo(matt); } @Test public void saveEntityShouldUpdateExistingEntity() { - StepVerifier.create(customerRepo.save(customer1).subscribeOn(Schedulers.parallel())).expectNext(customer1) + StepVerifier.create(reactiveRepository.save(matt).subscribeOn(Schedulers.parallel())).expectNext(matt) .verifyComplete(); - customer1.setFirstName("Matt"); - customer1.setLastName("Groening"); + matt.setFirstName("Matt"); + matt.setLastName("Groening"); - StepVerifier.create(customerRepo.save(customer1).subscribeOn(Schedulers.parallel())).expectNext(customer1) + StepVerifier.create(reactiveRepository.save(matt).subscribeOn(Schedulers.parallel())).expectNext(matt) .verifyComplete(); - assertCustomerExistsInRepo(customer1); + assertCustomerExistsInRepo(matt); } @Test public void saveIterableOfNewEntitiesShouldInsertEntity() { - StepVerifier.create(customerRepo.saveAll(Arrays.asList(customer1, customer2, customer3)) + StepVerifier.create(reactiveRepository.saveAll(Arrays.asList(matt, marge, maggie)) .subscribeOn(Schedulers.parallel())) .recordWith(ArrayList::new) .thenConsumeWhile(customer -> true) .consumeRecordedWith(actual -> - assertThat(actual).containsOnly(customer1, customer2, customer3) + assertThat(actual).containsOnly(matt, marge, maggie) ).verifyComplete(); - assertCustomerExistsInRepo(customer1); - assertCustomerExistsInRepo(customer2); - assertCustomerExistsInRepo(customer3); + assertCustomerExistsInRepo(matt); + assertCustomerExistsInRepo(marge); + assertCustomerExistsInRepo(maggie); } @Test public void saveIterableOfMixedEntitiesShouldInsertNewAndUpdateOld() { - StepVerifier.create(customerRepo.save(customer1).subscribeOn(Schedulers.parallel())) - .expectNext(customer1).verifyComplete(); + StepVerifier.create(reactiveRepository.save(matt).subscribeOn(Schedulers.parallel())) + .expectNext(matt).verifyComplete(); - customer1.setFirstName("Matt"); - customer1.setLastName("Groening"); + matt.setFirstName("Matt"); + matt.setLastName("Groening"); - StepVerifier.create(customerRepo.saveAll(Arrays.asList(customer1, customer2, customer3)) + StepVerifier.create(reactiveRepository.saveAll(Arrays.asList(matt, marge, maggie)) .subscribeOn(Schedulers.parallel())) .expectNextCount(3).verifyComplete(); - assertCustomerExistsInRepo(customer1); - assertCustomerExistsInRepo(customer2); - assertCustomerExistsInRepo(customer3); + assertCustomerExistsInRepo(matt); + assertCustomerExistsInRepo(marge); + assertCustomerExistsInRepo(maggie); } @Test public void savePublisherOfEntitiesShouldInsertEntity() { - StepVerifier.create(customerRepo.saveAll(Flux.just(customer1, customer2, customer3)) + StepVerifier.create(reactiveRepository.saveAll(Flux.just(matt, marge, maggie)) .subscribeOn(Schedulers.parallel())) .expectNextCount(3).verifyComplete(); - assertCustomerExistsInRepo(customer1); - assertCustomerExistsInRepo(customer2); - assertCustomerExistsInRepo(customer3); + assertCustomerExistsInRepo(matt); + assertCustomerExistsInRepo(marge); + assertCustomerExistsInRepo(maggie); } @Test public void savePublisherOfMixedEntitiesShouldInsertNewAndUpdateOld() { - StepVerifier.create(customerRepo.save(customer1).subscribeOn(Schedulers.parallel())) - .expectNext(customer1).verifyComplete(); + StepVerifier.create(reactiveRepository.save(matt).subscribeOn(Schedulers.parallel())) + .expectNext(matt).verifyComplete(); - customer1.setFirstName("Matt"); - customer1.setLastName("Groening"); + matt.setFirstName("Matt"); + matt.setLastName("Groening"); - StepVerifier.create(customerRepo.saveAll(Flux.just(customer1, customer2, customer3))).expectNextCount(3) + StepVerifier.create(reactiveRepository.saveAll(Flux.just(matt, marge, maggie))).expectNextCount(3) .verifyComplete(); - assertCustomerExistsInRepo(customer1); - assertCustomerExistsInRepo(customer2); - assertCustomerExistsInRepo(customer3); + assertCustomerExistsInRepo(matt); + assertCustomerExistsInRepo(marge); + assertCustomerExistsInRepo(maggie); } @Test @@ -137,7 +123,7 @@ public void shouldSaveObjectWithPersistenceConstructorThatHasAllFields() { } private void assertCustomerExistsInRepo(Customer customer) { - StepVerifier.create(customerRepo.findById(customer.getId())).consumeNextWith(actual -> { + StepVerifier.create(reactiveRepository.findById(customer.getId())).consumeNextWith(actual -> { assertThat(actual.getFirstName()).isEqualTo(customer.getFirstName()); assertThat(actual.getLastName()).isEqualTo(customer.getLastName()); }).verifyComplete(); diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/reactive/ReactiveCustomerRepositoryQueryTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/reactive/ReactiveCustomerRepositoryQueryTests.java new file mode 100644 index 000000000..70904072f --- /dev/null +++ b/src/test/java/org/springframework/data/aerospike/repository/query/reactive/ReactiveCustomerRepositoryQueryTests.java @@ -0,0 +1,48 @@ +package org.springframework.data.aerospike.repository.query.reactive; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.TestInstance; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.aerospike.BaseReactiveIntegrationTests; +import org.springframework.data.aerospike.sample.Customer; +import org.springframework.data.aerospike.sample.ReactiveCustomerRepository; + +import java.util.List; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public class ReactiveCustomerRepositoryQueryTests extends BaseReactiveIntegrationTests { + + protected static final Customer homer = Customer.builder() + .id(nextId()).firstName("Homer").lastName("Simpson").age(42).group('a').build(); + protected static final Customer marge = Customer.builder() + .id(nextId()).firstName("Marge").lastName("Simpson").age(39).group('b').build(); + protected static final Customer bart = Customer.builder() + .id(nextId()).firstName("Bart").lastName("Simpson").age(10).group('b').build(); + protected static final Customer lisa = Customer.builder() + .id(nextId()).firstName("Lisa").lastName("Simpson").age(8).build(); + protected static final Customer maggie = Customer.builder() + .id(nextId()).firstName("Maggie").lastName("Simpson").age(1).build(); + protected static final Customer matt = Customer.builder() + .id(nextId()).firstName("Matt").lastName("Groening").age(65).group('c').build(); + protected static final Customer fry = Customer.builder() + .id(nextId()).firstName("Philip J.").lastName("Fry").age(1029).build(); + protected static final Customer leela = Customer.builder(). + id(nextId()).firstName("Leela").lastName("Turanga").age(29).build(); + + protected static final List allCustomers = List.of(homer, marge, bart, lisa, maggie, matt, fry, leela); + + @Autowired + protected ReactiveCustomerRepository reactiveRepository; + + @BeforeAll + void beforeAll() { + reactiveBlockingAerospikeTestOperations.deleteAllAndVerify(Customer.class); + reactiveBlockingAerospikeTestOperations.saveAll(reactiveRepository, allCustomers); + } + + @AfterAll + void afterAll() { + reactiveBlockingAerospikeTestOperations.deleteAll(reactiveRepository, allCustomers); + } +} diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/reactive/count/BetweenTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/reactive/count/BetweenTests.java new file mode 100644 index 000000000..669e14ddc --- /dev/null +++ b/src/test/java/org/springframework/data/aerospike/repository/query/reactive/count/BetweenTests.java @@ -0,0 +1,18 @@ +package org.springframework.data.aerospike.repository.query.reactive.count; + +import org.junit.jupiter.api.Test; +import org.springframework.data.aerospike.repository.query.reactive.ReactiveCustomerRepositoryQueryTests; +import reactor.test.StepVerifier; + +/** + * Tests for the "Is between" reactive repository query. Keywords: Between, IsBetween. + */ +public class BetweenTests extends ReactiveCustomerRepositoryQueryTests { + + @Test + public void countBySimplePropertyBetween_Integer() { + StepVerifier.create(reactiveRepository.countByAgeBetween(20, 1100)) + .expectNextMatches(result -> result >= 2) + .verifyComplete(); + } +} diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/reactive/count/EqualsTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/reactive/count/EqualsTests.java new file mode 100644 index 000000000..61476e086 --- /dev/null +++ b/src/test/java/org/springframework/data/aerospike/repository/query/reactive/count/EqualsTests.java @@ -0,0 +1,26 @@ +package org.springframework.data.aerospike.repository.query.reactive.count; + +import org.junit.jupiter.api.Test; +import org.springframework.data.aerospike.query.QueryParam; +import org.springframework.data.aerospike.repository.query.reactive.ReactiveCustomerRepositoryQueryTests; +import reactor.test.StepVerifier; + +/** + * Tests for the "Equals" reactive repository query. Keywords: Is, Equals (or no keyword). + */ +public class EqualsTests extends ReactiveCustomerRepositoryQueryTests { + + @Test + public void countById_AND_SimpleProperty() { + QueryParam id = QueryParam.of(marge.getId()); + QueryParam firstName = QueryParam.of(marge.getFirstName()); + StepVerifier.create(reactiveRepository.countByIdAndFirstName(id, firstName)) + .expectNext(1L) + .verifyComplete(); + + firstName = QueryParam.of(marge.getFirstName() + "_"); + StepVerifier.create(reactiveRepository.countByIdAndFirstName(id, firstName)) + .expectNext(0L) + .verifyComplete(); + } +} diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/reactive/count/InTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/reactive/count/InTests.java new file mode 100644 index 000000000..36d8ebb0b --- /dev/null +++ b/src/test/java/org/springframework/data/aerospike/repository/query/reactive/count/InTests.java @@ -0,0 +1,28 @@ +package org.springframework.data.aerospike.repository.query.reactive.count; + +import org.junit.jupiter.api.Test; +import org.springframework.data.aerospike.query.QueryParam; +import org.springframework.data.aerospike.repository.query.reactive.ReactiveCustomerRepositoryQueryTests; +import reactor.test.StepVerifier; + +import java.util.List; + +/** + * Tests for the "Is in" reactive repository query. Keywords: In, IsIn. + */ +public class InTests extends ReactiveCustomerRepositoryQueryTests { + + @Test + public void countById_AND_SimplePropertyIn() { + QueryParam ids = QueryParam.of(List.of(marge.getId(), homer.getId())); + QueryParam firstNames = QueryParam.of(List.of(homer.getFirstName(), marge.getFirstName(), "FirstName")); + StepVerifier.create(reactiveRepository.countByIdAndFirstNameIn(ids, firstNames)) + .expectNext(2L) + .verifyComplete(); + + firstNames = QueryParam.of(List.of("FirstName")); + StepVerifier.create(reactiveRepository.countByIdAndFirstNameIn(ids, firstNames)) + .expectNext(0L) + .verifyComplete(); + } +} diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/reactive/delete/EqualsTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/reactive/delete/EqualsTests.java new file mode 100644 index 000000000..d32633702 --- /dev/null +++ b/src/test/java/org/springframework/data/aerospike/repository/query/reactive/delete/EqualsTests.java @@ -0,0 +1,237 @@ +package org.springframework.data.aerospike.repository.query.reactive.delete; + +import com.aerospike.client.AerospikeException; +import org.junit.jupiter.api.Test; +import org.reactivestreams.Publisher; +import org.springframework.data.aerospike.query.QueryParam; +import org.springframework.data.aerospike.repository.query.reactive.ReactiveCustomerRepositoryQueryTests; +import org.springframework.data.aerospike.sample.Customer; +import reactor.core.publisher.Flux; +import reactor.core.scheduler.Schedulers; +import reactor.test.StepVerifier; + +import java.util.List; + +import static java.util.Arrays.asList; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; + +/** + * Tests for the "Equals" reactive repository query. Keywords: Is, Equals (or no keyword). + */ +public class EqualsTests extends ReactiveCustomerRepositoryQueryTests { + + @Test + public void deleteById_ShouldDeleteExistent() { + StepVerifier.create(reactiveRepository.deleteById(marge.getId()).subscribeOn(Schedulers.parallel())) + .verifyComplete(); + + StepVerifier.create(reactiveRepository.findById(marge.getId())).expectNextCount(0).verifyComplete(); + + // cleanup + StepVerifier.create(reactiveRepository.save(marge)) + .expectNextCount(1) + .verifyComplete(); + } + + @Test + public void deleteById_ShouldSkipNonexistent() { + StepVerifier.create(reactiveRepository.deleteById("non-existent-id").subscribeOn(Schedulers.parallel())) + .verifyComplete(); + } + + @Test + @SuppressWarnings("ConstantConditions") + public void deleteById_ShouldRejectNullObject() { + assertThatThrownBy(() -> reactiveRepository.deleteById((String) null).block()) + .isInstanceOf(IllegalArgumentException.class); + } + + @Test + public void deleteByIdPublisher_ShouldDeleteOnlyFirstElement() { + StepVerifier.create( + reactiveRepository + .deleteById(Flux.just(homer.getId(), marge.getId())) + .subscribeOn(Schedulers.parallel())) + .verifyComplete(); + + StepVerifier.create(reactiveRepository.findById(homer.getId())).expectNextCount(0).verifyComplete(); + StepVerifier.create(reactiveRepository.findById(marge.getId())).expectNext(marge).verifyComplete(); + + + // cleanup + StepVerifier.create(reactiveRepository.save(homer)) + .expectNextCount(1) + .verifyComplete(); + } + + @Test + public void deleteByIdPublisher_ShouldSkipNonexistent() { + StepVerifier.create(reactiveRepository.deleteById(Flux.just("non-existent-id")) + .subscribeOn(Schedulers.parallel())) + .verifyComplete(); + } + + @Test + @SuppressWarnings("ConstantConditions") + public void deleteByIdPublisher_ShouldRejectNullObject() { + //noinspection unchecked,rawtypes + assertThatThrownBy(() -> reactiveRepository.deleteById((Publisher) null).block()) + .isInstanceOf(IllegalArgumentException.class); + } + + @Test + public void delete_ShouldDeleteExistent() { + StepVerifier.create(reactiveRepository.delete(marge).subscribeOn(Schedulers.parallel())).verifyComplete(); + + StepVerifier.create(reactiveRepository.findById(marge.getId())).expectNextCount(0).verifyComplete(); + + // cleanup + StepVerifier.create(reactiveRepository.save(marge)) + .expectNextCount(1) + .verifyComplete(); + } + + @Test + public void delete_ShouldSkipNonexistent() { + Customer nonExistentCustomer = Customer.builder().id(nextId()).firstName("Bart").lastName("Simpson").age(15) + .build(); + + StepVerifier.create(reactiveRepository.delete(nonExistentCustomer).subscribeOn(Schedulers.parallel())) + .verifyComplete(); + } + + @Test + @SuppressWarnings("ConstantConditions") + public void delete_ShouldRejectNullObject() { + assertThatThrownBy(() -> reactiveRepository.delete(null).block()) + .isInstanceOf(IllegalArgumentException.class); + + } + + @Test + public void deleteAllIterable_ShouldDeleteExistent() { + reactiveRepository.deleteAll(asList(homer, marge)).subscribeOn(Schedulers.parallel()).block(); + + StepVerifier.create(reactiveRepository.findById(homer.getId())).expectNextCount(0).verifyComplete(); + StepVerifier.create(reactiveRepository.findById(marge.getId())).expectNextCount(0).verifyComplete(); + + // cleanup + StepVerifier.create(reactiveRepository.saveAll(Flux.just(marge, homer))) + .expectNextCount(2) + .verifyComplete(); + } + + @Test + public void deleteAllIterable_ShouldSkipNonexistentAndThrowException() { + Customer nonExistentCustomer = Customer.builder().id(nextId()).firstName("Bart").lastName("Simpson").age(15) + .build(); + + assertThatThrownBy(() -> reactiveRepository.deleteAll(asList(homer, nonExistentCustomer, marge)).block()) + .isInstanceOf(AerospikeException.BatchRecordArray.class); + StepVerifier.create(reactiveRepository.findById(homer.getId())).expectNextCount(0).verifyComplete(); + StepVerifier.create(reactiveRepository.findById(marge.getId())).expectNextCount(0).verifyComplete(); + + // cleanup + StepVerifier.create(reactiveRepository.saveAll(Flux.just(marge, homer))) + .expectNextCount(2) + .verifyComplete(); + } + + @Test + public void deleteAllIterable_ShouldRejectNullObject() { + List entities = asList(homer, null, marge); + + assertThatThrownBy(() -> reactiveRepository.deleteAll(entities).subscribeOn(Schedulers.parallel()).block()) + .isInstanceOf(IllegalArgumentException.class); + } + + @Test + public void deleteAllPublisher_ShouldDeleteExistent() { + reactiveRepository.deleteAll(Flux.just(homer, marge)).subscribeOn(Schedulers.parallel()).block(); + + StepVerifier.create(reactiveRepository.findById(homer.getId())).expectNextCount(0).verifyComplete(); + StepVerifier.create(reactiveRepository.findById(marge.getId())).expectNextCount(0).verifyComplete(); + + // cleanup + StepVerifier.create(reactiveRepository.saveAll(Flux.just(marge, homer))) + .expectNextCount(2) + .verifyComplete(); + } + + @Test + public void deleteAllPublisher_ShouldNotSkipNonexistent() { + Customer nonExistentCustomer = Customer.builder().id(nextId()).firstName("Bart").lastName("Simpson").age(15) + .build(); + + reactiveRepository.deleteAll(Flux.just(homer, nonExistentCustomer, marge)).subscribeOn(Schedulers.parallel()) + .block(); + + StepVerifier.create(reactiveRepository.findById(homer.getId())).expectNextCount(0).verifyComplete(); + StepVerifier.create(reactiveRepository.findById(marge.getId())).expectNextCount(0).verifyComplete(); + + // cleanup + StepVerifier.create(reactiveRepository.saveAll(Flux.just(marge, homer))) + .expectNextCount(2) + .verifyComplete(); + } + + @Test + public void deleteAllById_ShouldDelete() { + reactiveRepository.deleteAllById(asList(homer.getId(), marge.getId())).subscribeOn(Schedulers.parallel()) + .block(); + + StepVerifier.create(reactiveRepository.findById(homer.getId())).expectNextCount(0).verifyComplete(); + StepVerifier.create(reactiveRepository.findById(marge.getId())).expectNextCount(0).verifyComplete(); + + // cleanup + StepVerifier.create(reactiveRepository.saveAll(Flux.just(marge, homer))) + .expectNextCount(2) + .verifyComplete(); + } + + @Test + public void deleteAll_ShouldDelete() { + reactiveRepository.deleteAll().block(); + + StepVerifier.create(reactiveRepository.findById(homer.getId())).expectNextCount(0).verifyComplete(); + StepVerifier.create(reactiveRepository.findById(marge.getId())).expectNextCount(0).verifyComplete(); + + // cleanup + reactiveBlockingAerospikeTestOperations.saveAll(reactiveRepository, allCustomers); + } + + @Test + public void deleteById_AND_SimpleProperty() { + StepVerifier.create(reactiveRepository.findAllById(List.of(bart.getId())).collectList()) + .expectNextMatches(list -> list.size() == 1 && list.contains(bart)) + .verifyComplete(); + + QueryParam id = QueryParam.of(bart.getId()); + QueryParam firstName = QueryParam.of("FirstName"); + // no records satisfying the condition + StepVerifier.create(reactiveRepository.deleteByIdAndFirstName(id, firstName)) + .expectComplete() + .verify(); + + // no records get deleted + StepVerifier.create(reactiveRepository.findAllById(List.of(bart.getId())).collectList()) + .expectNextMatches(list -> list.size() == 1 && list.contains(bart)) + .verifyComplete(); + + // 1 record satisfying the condition + firstName = QueryParam.of(bart.getFirstName()); + StepVerifier.create(reactiveRepository.deleteByIdAndFirstName(id, firstName)) + .expectComplete() + .verify(); + + // 1 record gets deleted + StepVerifier.create(reactiveRepository.findAllById(List.of(bart.getId())).collectList()) + .expectNextMatches(List::isEmpty) + .verifyComplete(); + + // cleanup + StepVerifier.create(reactiveRepository.save(bart)) + .expectNextCount(1) + .verifyComplete(); + } +} diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/reactive/delete/InTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/reactive/delete/InTests.java new file mode 100644 index 000000000..d00ff580f --- /dev/null +++ b/src/test/java/org/springframework/data/aerospike/repository/query/reactive/delete/InTests.java @@ -0,0 +1,50 @@ +package org.springframework.data.aerospike.repository.query.reactive.delete; + +import org.junit.jupiter.api.Test; +import org.springframework.data.aerospike.query.QueryParam; +import org.springframework.data.aerospike.repository.query.reactive.ReactiveCustomerRepositoryQueryTests; +import reactor.core.publisher.Flux; +import reactor.test.StepVerifier; + +import java.util.List; + +/** + * Tests for the "Is in" reactive repository query. Keywords: In, IsIn. + */ +public class InTests extends ReactiveCustomerRepositoryQueryTests { + + @Test + public void deleteById_AND_SimplePropertyIn() { + StepVerifier.create(reactiveRepository.findAllById(List.of(bart.getId(), lisa.getId())).collectList()) + .expectNextMatches(list -> list.size() == 2 && list.contains(bart) && list.contains(lisa)) + .verifyComplete(); + + QueryParam ids = QueryParam.of(List.of(bart.getId(), lisa.getId())); + QueryParam firstNames = QueryParam.of(List.of("FirstName")); + // no records satisfying the condition + StepVerifier.create(reactiveRepository.deleteByIdAndFirstNameIn(ids, firstNames)) + .expectComplete() + .verify(); + + // no records get deleted + StepVerifier.create(reactiveRepository.findAllById(List.of(bart.getId(), lisa.getId())).collectList()) + .expectNextMatches(list -> list.size() == 2 && list.contains(bart) && list.contains(lisa)) + .verifyComplete(); + + // 2 records satisfying the condition + firstNames = QueryParam.of(List.of(bart.getFirstName(), lisa.getFirstName(), "FirstName")); + StepVerifier.create(reactiveRepository.deleteByIdAndFirstNameIn(ids, firstNames)) + .expectComplete() + .verify(); + + // 2 records get deleted + StepVerifier.create(reactiveRepository.findAllById(List.of(bart.getId(), lisa.getId())).collectList()) + .expectNextMatches(List::isEmpty) + .verifyComplete(); + + // cleanup + StepVerifier.create(reactiveRepository.saveAll(Flux.just(bart, lisa))) + .expectNextCount(2) + .verifyComplete(); + } +} diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/reactive/exists/EqualsTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/reactive/exists/EqualsTests.java new file mode 100644 index 000000000..c6e774ea2 --- /dev/null +++ b/src/test/java/org/springframework/data/aerospike/repository/query/reactive/exists/EqualsTests.java @@ -0,0 +1,59 @@ +package org.springframework.data.aerospike.repository.query.reactive.exists; + +import org.junit.jupiter.api.Test; +import org.springframework.data.aerospike.query.QueryParam; +import org.springframework.data.aerospike.repository.query.reactive.ReactiveCustomerRepositoryQueryTests; +import reactor.core.publisher.Flux; +import reactor.core.scheduler.Schedulers; +import reactor.test.StepVerifier; + +/** + * Tests for the "Equals" reactive repository query. Keywords: Is, Equals (or no keyword). + */ +public class EqualsTests extends ReactiveCustomerRepositoryQueryTests { + + @Test + public void existsById_ShouldReturnTrueWhenExists() { + StepVerifier.create(reactiveRepository.existsById(leela.getId()).subscribeOn(Schedulers.parallel())) + .expectNext(true).verifyComplete(); + } + + @Test + public void existsById_ShouldReturnFalseWhenNotExists() { + StepVerifier.create(reactiveRepository.existsById("non-existent-id").subscribeOn(Schedulers.parallel())) + .expectNext(false).verifyComplete(); + } + + @Test + public void existsByIdPublisher_ShouldReturnTrueWhenExists() { + StepVerifier.create(reactiveRepository.existsById(Flux.just(fry.getId())).subscribeOn(Schedulers.parallel())) + .expectNext(true).verifyComplete(); + } + + @Test + public void existsByIdPublisher_ShouldReturnFalseWhenNotExists() { + StepVerifier.create(reactiveRepository.existsById(Flux.just("non-existent-id")).subscribeOn(Schedulers.parallel())) + .expectNext(false).verifyComplete(); + } + + @Test + public void existsByIdPublisher_ShouldCheckOnlyFirstElement() { + StepVerifier.create(reactiveRepository.existsById(Flux.just(fry.getId(), "non-existent-id")) + .subscribeOn(Schedulers.parallel())) + .expectNext(true).verifyComplete(); + } + + @Test + public void existsById_AND_SimpleProperty() { + QueryParam id = QueryParam.of(leela.getId()); + QueryParam firstname = QueryParam.of(leela.getFirstName()); + StepVerifier.create(reactiveRepository.existsByIdAndFirstName(id, firstname)) + .expectNext(true) + .verifyComplete(); + + firstname = QueryParam.of("FirstName"); + StepVerifier.create(reactiveRepository.existsByIdAndFirstName(id, firstname)) + .expectNext(false) + .verifyComplete(); + } +} diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/reactive/exists/InTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/reactive/exists/InTests.java new file mode 100644 index 000000000..e84b0ef81 --- /dev/null +++ b/src/test/java/org/springframework/data/aerospike/repository/query/reactive/exists/InTests.java @@ -0,0 +1,28 @@ +package org.springframework.data.aerospike.repository.query.reactive.exists; + +import org.junit.jupiter.api.Test; +import org.springframework.data.aerospike.query.QueryParam; +import org.springframework.data.aerospike.repository.query.reactive.ReactiveCustomerRepositoryQueryTests; +import reactor.test.StepVerifier; + +import java.util.List; + +/** + * Tests for the "Is in" reactive repository query. Keywords: In, IsIn. + */ +public class InTests extends ReactiveCustomerRepositoryQueryTests { + + @Test + public void existsById_AND_SImplePropertyIn() { + QueryParam ids = QueryParam.of(List.of(fry.getId(), leela.getId())); + QueryParam firstNames = QueryParam.of(List.of(fry.getFirstName(), leela.getFirstName(), "FirstName")); + StepVerifier.create(reactiveRepository.existsByIdAndFirstNameIn(ids, firstNames)) + .expectNext(true) + .verifyComplete(); + + firstNames = QueryParam.of(List.of("FirstName")); + StepVerifier.create(reactiveRepository.existsByIdAndFirstNameIn(ids, firstNames)) + .expectNext(false) + .verifyComplete(); + } +} diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/reactive/find/BetweenTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/reactive/find/BetweenTests.java new file mode 100644 index 000000000..89434c78c --- /dev/null +++ b/src/test/java/org/springframework/data/aerospike/repository/query/reactive/find/BetweenTests.java @@ -0,0 +1,44 @@ +package org.springframework.data.aerospike.repository.query.reactive.find; + +import org.junit.jupiter.api.Test; +import org.springframework.data.aerospike.query.QueryParam; +import org.springframework.data.aerospike.repository.query.reactive.ReactiveCustomerRepositoryQueryTests; +import org.springframework.data.aerospike.sample.Customer; +import reactor.core.scheduler.Schedulers; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.data.aerospike.query.QueryParam.of; + +/** + * Tests for the "Is between" reactive repository query. Keywords: Between, IsBetween. + */ +public class BetweenTests extends ReactiveCustomerRepositoryQueryTests { + + @Test + public void findBySimplePropertyBetween() { + List results = reactiveRepository.findByAgeBetween(10, 40) + .subscribeOn(Schedulers.parallel()).collectList().block(); + + assertThat(results).containsOnly(marge, bart, leela); + } + + @Test + public void findBySimplePropertyBetween_AND_SimpleProperty() { + QueryParam ageBetween = of(30, 70); + QueryParam lastName = of("Simpson"); + List results = reactiveRepository.findByAgeBetweenAndLastName(ageBetween, lastName) + .subscribeOn(Schedulers.parallel()).collectList().block(); + + assertThat(results).containsOnly(homer, marge); + } + + @Test + public void findBySimplePropertyBetween_OrderByFirstnameDesc() { + List results = reactiveRepository.findByAgeBetweenOrderByFirstNameDesc(30, 70) + .subscribeOn(Schedulers.parallel()).collectList().block(); + + assertThat(results).containsExactly(matt, marge, homer); + } +} diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/reactive/find/ContainingTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/reactive/find/ContainingTests.java new file mode 100644 index 000000000..219af693f --- /dev/null +++ b/src/test/java/org/springframework/data/aerospike/repository/query/reactive/find/ContainingTests.java @@ -0,0 +1,32 @@ +package org.springframework.data.aerospike.repository.query.reactive.find; + +import org.junit.jupiter.api.Test; +import org.springframework.data.aerospike.repository.query.reactive.ReactiveCustomerRepositoryQueryTests; +import org.springframework.data.aerospike.sample.Customer; +import reactor.core.scheduler.Schedulers; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for the "Contains" reactive repository query. Keywords: Containing, IsContaining, Contains. + */ +public class ContainingTests extends ReactiveCustomerRepositoryQueryTests { + + @Test + public void findBySimplePropertyContaining() { + List results = reactiveRepository.findByFirstNameContains("ar") + .subscribeOn(Schedulers.parallel()).collectList().block(); + + assertThat(results).containsOnly(marge, bart); + } + + @Test + public void findBySimplePropertyContaining_IgnoreCase() { + List results = reactiveRepository.findByFirstNameContainingIgnoreCase("m") + .subscribeOn(Schedulers.parallel()).collectList().block(); + + assertThat(results).containsOnly(homer, marge, matt, maggie); + } +} diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/reactive/find/EqualsTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/reactive/find/EqualsTests.java new file mode 100644 index 000000000..1aeb773ae --- /dev/null +++ b/src/test/java/org/springframework/data/aerospike/repository/query/reactive/find/EqualsTests.java @@ -0,0 +1,159 @@ +package org.springframework.data.aerospike.repository.query.reactive.find; + +import org.junit.jupiter.api.Test; +import org.reactivestreams.Publisher; +import org.springframework.data.aerospike.query.QueryParam; +import org.springframework.data.aerospike.repository.query.reactive.ReactiveCustomerRepositoryQueryTests; +import org.springframework.data.aerospike.sample.Customer; +import org.springframework.data.aerospike.sample.CustomerSomeFields; +import reactor.core.publisher.Flux; +import reactor.core.scheduler.Schedulers; + +import java.util.List; + +import static java.util.Arrays.asList; +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.data.aerospike.query.QueryParam.of; + +/** + * Tests for the "Equals" reactive repository query. Keywords: Is, Equals (or no keyword). + */ +public class EqualsTests extends ReactiveCustomerRepositoryQueryTests { + + @Test + public void findById_ShouldReturnExistent() { + Customer result = reactiveRepository.findById(marge.getId()) + .subscribeOn(Schedulers.parallel()).block(); + + assertThat(result).isEqualTo(marge); + } + + @Test + public void findById_ShouldNotReturnNonExistent() { + Customer result = reactiveRepository.findById("non-existent-id") + .subscribeOn(Schedulers.parallel()).block(); + + assertThat(result).isNull(); + } + + @Test + public void findByIdPublisher_ShouldReturnFirst() { + Publisher ids = Flux.just(marge.getId(), matt.getId()); + + Customer result = reactiveRepository.findById(ids).subscribeOn(Schedulers.parallel()).block(); + assertThat(result).isEqualTo(marge); + } + + @Test + public void findByIdPublisher_ShouldNotReturnFirstNonExistent() { + Publisher ids = Flux.just("non-existent-id", marge.getId(), matt.getId()); + + Customer result = reactiveRepository.findById(ids).subscribeOn(Schedulers.parallel()).block(); + assertThat(result).isNull(); + } + + @Test + public void findAll_ShouldReturnAll() { + List results = reactiveRepository.findAll().subscribeOn(Schedulers.parallel()).collectList().block(); + assertThat(results).contains(homer, marge, bart, matt); + } + + @Test + public void findAllByIdsIterable_ShouldReturnAllExistent() { + Iterable ids = asList(marge.getId(), "non-existent-id", matt.getId()); + + List results = reactiveRepository.findAllById(ids) + .subscribeOn(Schedulers.parallel()).collectList().block(); + + assertThat(results).containsOnly(marge, matt); + } + + @Test + public void findAllByIDsPublisher_ShouldReturnAllExistent() { + Publisher ids = Flux.just(homer.getId(), marge.getId(), matt.getId(), "non-existent-id"); + + List results = reactiveRepository.findAllById(ids) + .subscribeOn(Schedulers.parallel()).collectList().block(); + + assertThat(results).containsOnly(homer, marge, matt); + } + + @Test + public void findBySimpleProperty() { + List results = reactiveRepository.findByLastName("Simpson") + .subscribeOn(Schedulers.parallel()).collectList().block(); + + assertThat(results).containsOnly(homer, marge, bart, lisa, maggie); + } + + @Test + public void findBySimpleProperty_Projection() { + List results = reactiveRepository.findCustomerSomeFieldsByLastName("Simpson") + .subscribeOn(Schedulers.parallel()).collectList().block(); + + assertThat(results).contains(homer.toCustomerSomeFields(), marge.toCustomerSomeFields(), + bart.toCustomerSomeFields(), lisa.toCustomerSomeFields(), maggie.toCustomerSomeFields()); + } + + @Test + public void findDynamicTypeBySimpleProperty_DynamicProjection() { + List results = reactiveRepository + .findByLastName("Simpson", CustomerSomeFields.class) + .subscribeOn(Schedulers.parallel()).collectList().block(); + + assertThat(results).containsOnly(homer.toCustomerSomeFields(), marge.toCustomerSomeFields(), + bart.toCustomerSomeFields(), lisa.toCustomerSomeFields(), maggie.toCustomerSomeFields()); + } + + @Test + public void findOneBySimpleProperty() { + Customer result = reactiveRepository.findOneByLastName("Groening") + .subscribeOn(Schedulers.parallel()).block(); + + assertThat(result).isEqualTo(matt); + } + + @Test + public void findBySimpleProperty_OrderByAsc() { + List results = reactiveRepository.findByLastNameOrderByFirstNameAsc("Simpson") + .subscribeOn(Schedulers.parallel()).collectList().block(); + + assertThat(results).contains(bart, homer, marge); + } + + @Test + public void findBySimpleProperty_OrderByDesc() { + List results = reactiveRepository.findByLastNameOrderByFirstNameDesc("Simpson") + .subscribeOn(Schedulers.parallel()).collectList().block(); + + assertThat(results).contains(marge, homer, bart); + } + + @Test + public void findBySimpleProperty_AND_SimpleProperty_String() { + QueryParam firstName = of("Bart"); + QueryParam lastName = of("Simpson"); + Customer result = reactiveRepository.findByFirstNameAndLastName(firstName, lastName) + .subscribeOn(Schedulers.parallel()).blockLast(); + + assertThat(result).isEqualTo(bart); + } + + @Test + public void findBySimpleProperty_AND_SimpleProperty_Integer() { + QueryParam lastName = of("Simpson"); + QueryParam age = of(10); + Customer result = reactiveRepository.findByLastNameAndAge(lastName, age) + .subscribeOn(Schedulers.parallel()).blockLast(); + + assertThat(result).isEqualTo(bart); + } + + @Test + public void findBySimpleProperty_Char() { + List results = reactiveRepository.findByGroup('b') + .subscribeOn(Schedulers.parallel()).collectList().block(); + + assertThat(results).containsOnly(marge, bart); + } +} diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/reactive/find/InTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/reactive/find/InTests.java new file mode 100644 index 000000000..88a5b7be6 --- /dev/null +++ b/src/test/java/org/springframework/data/aerospike/repository/query/reactive/find/InTests.java @@ -0,0 +1,70 @@ +package org.springframework.data.aerospike.repository.query.reactive.find; + +import org.junit.jupiter.api.Test; +import org.springframework.data.aerospike.query.QueryParam; +import org.springframework.data.aerospike.repository.query.reactive.ReactiveCustomerRepositoryQueryTests; +import org.springframework.data.aerospike.sample.Customer; +import reactor.core.scheduler.Schedulers; +import reactor.test.StepVerifier; + +import java.util.List; + +import static java.util.Arrays.asList; +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for the "Is in" reactive repository query. Keywords: In, IsIn. + */ +public class InTests extends ReactiveCustomerRepositoryQueryTests { + + @Test + public void findByFirstnameIn_ShouldWorkProperly() { + List results = reactiveRepository.findByFirstNameIn(asList("Matt", "Homer")) + .subscribeOn(Schedulers.parallel()).collectList().block(); + + assertThat(results).containsOnly(homer, matt); + } + + @Test + public void findByIdAndFirstNameIn() { + QueryParam ids = QueryParam.of(List.of(homer.getId(), marge.getId())); + QueryParam firstNames = QueryParam.of(List.of(homer.getFirstName(), marge.getFirstName(), "FirstName")); + StepVerifier.create(reactiveRepository.findByIdAndFirstNameIn(ids, firstNames).collectList()) + .expectNextMatches(list -> list.size() == 2 && list.contains(homer) && list.contains(marge)) + .verifyComplete(); + + firstNames = QueryParam.of(List.of("FirstName")); + StepVerifier.create(reactiveRepository.findByIdAndFirstNameIn(ids, firstNames)) + .expectComplete() + .verify(); + } + + @Test + public void findByIdAndFirstNameIn_Synonyms() { + QueryParam ids = QueryParam.of(List.of(homer.getId(), marge.getId())); + QueryParam firstNames = QueryParam.of(List.of(homer.getFirstName(), marge.getFirstName(), "FirstName")); + StepVerifier.create(reactiveRepository.readByIdAndFirstNameIn(ids, firstNames).collectList()) + .expectNextMatches(list -> list.size() == 2 && list.contains(homer) && list.contains(marge)) + .verifyComplete(); + + StepVerifier.create(reactiveRepository.readByIdAndFirstNameIn(ids, firstNames).collectList()) + .expectNextMatches(list -> list.size() == 2 && list.contains(homer) && list.contains(marge)) + .verifyComplete(); + + StepVerifier.create(reactiveRepository.getByIdAndFirstNameIn(ids, firstNames).collectList()) + .expectNextMatches(list -> list.size() == 2 && list.contains(homer) && list.contains(marge)) + .verifyComplete(); + + StepVerifier.create(reactiveRepository.queryByIdAndFirstNameIn(ids, firstNames).collectList()) + .expectNextMatches(list -> list.size() == 2 && list.contains(homer) && list.contains(marge)) + .verifyComplete(); + + StepVerifier.create(reactiveRepository.searchByIdAndFirstNameIn(ids, firstNames).collectList()) + .expectNextMatches(list -> list.size() == 2 && list.contains(homer) && list.contains(marge)) + .verifyComplete(); + + StepVerifier.create(reactiveRepository.streamByIdAndFirstNameIn(ids, firstNames).collectList()) + .expectNextMatches(list -> list.size() == 2 && list.contains(homer) && list.contains(marge)) + .verifyComplete(); + } +} diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/reactive/find/LessThanTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/reactive/find/LessThanTests.java new file mode 100644 index 000000000..dccfe6b1e --- /dev/null +++ b/src/test/java/org/springframework/data/aerospike/repository/query/reactive/find/LessThanTests.java @@ -0,0 +1,26 @@ +package org.springframework.data.aerospike.repository.query.reactive.find; + +import org.junit.jupiter.api.Test; +import org.springframework.data.aerospike.repository.query.reactive.ReactiveCustomerRepositoryQueryTests; +import org.springframework.data.aerospike.sample.Customer; +import org.springframework.data.domain.Sort; +import reactor.core.scheduler.Schedulers; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.data.domain.Sort.Order.asc; + +/** + * Tests for the "Is less than" reactive repository query. Keywords: LessThan, IsLessThan. + */ +public class LessThanTests extends ReactiveCustomerRepositoryQueryTests { + + @Test + public void findByAgeLessThan_ShouldWorkProperly() { + List results = reactiveRepository.findByAgeLessThan(40, Sort.by(asc("firstName"))) + .subscribeOn(Schedulers.parallel()).collectList().block(); + + assertThat(results).containsExactly(bart, leela, lisa, maggie, marge); + } +} diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/reactive/find/NotEqualTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/reactive/find/NotEqualTests.java new file mode 100644 index 000000000..988e51763 --- /dev/null +++ b/src/test/java/org/springframework/data/aerospike/repository/query/reactive/find/NotEqualTests.java @@ -0,0 +1,24 @@ +package org.springframework.data.aerospike.repository.query.reactive.find; + +import org.junit.jupiter.api.Test; +import org.springframework.data.aerospike.repository.query.reactive.ReactiveCustomerRepositoryQueryTests; +import org.springframework.data.aerospike.sample.Customer; +import reactor.core.scheduler.Schedulers; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for the "Is not equal" reactive repository query. Keywords: Not, IsNot. + */ +public class NotEqualTests extends ReactiveCustomerRepositoryQueryTests { + + @Test + public void findBySimplePropertyNot() { + List results = reactiveRepository.findByLastNameNot("Simpson") + .subscribeOn(Schedulers.parallel()).collectList().block(); + + assertThat(results).contains(matt); + } +} diff --git a/src/test/java/org/springframework/data/aerospike/repository/query/reactive/find/StartsWithTests.java b/src/test/java/org/springframework/data/aerospike/repository/query/reactive/find/StartsWithTests.java new file mode 100644 index 000000000..72c80f479 --- /dev/null +++ b/src/test/java/org/springframework/data/aerospike/repository/query/reactive/find/StartsWithTests.java @@ -0,0 +1,35 @@ +package org.springframework.data.aerospike.repository.query.reactive.find; + +import org.junit.jupiter.api.Test; +import org.springframework.data.aerospike.repository.query.reactive.ReactiveCustomerRepositoryQueryTests; +import org.springframework.data.aerospike.sample.Customer; +import org.springframework.data.aerospike.sample.CustomerSomeFields; +import reactor.core.scheduler.Schedulers; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for the "Starts with" reactive repository query. Keywords: StartingWith, IsStartingWith, StartsWith. + */ +public class StartsWithTests extends ReactiveCustomerRepositoryQueryTests { + + @Test + public void findByFirstnameStartsWithOrderByAgeAsc_ShouldWorkProperly() { + List results = reactiveRepository.findByFirstNameStartsWithOrderByAgeAsc("Ma") + .subscribeOn(Schedulers.parallel()).collectList().block(); + + assertThat(results).containsExactly(maggie, marge, matt); + } + + @Test + public void findCustomerSomeFieldsByFirstnameStartsWithOrderByAgeAsc_ShouldWorkProperly() { + List results = + reactiveRepository.findCustomerSomeFieldsByFirstNameStartsWithOrderByFirstNameAsc("Ma") + .subscribeOn(Schedulers.parallel()).collectList().block(); + + assertThat(results).containsExactly( maggie.toCustomerSomeFields(), marge.toCustomerSomeFields(), + matt.toCustomerSomeFields()); + } +} diff --git a/src/test/java/org/springframework/data/aerospike/repository/reactive/ReactiveAerospikeRepositoryCountRelatedTests.java b/src/test/java/org/springframework/data/aerospike/repository/reactive/ReactiveAerospikeRepositoryCountRelatedTests.java deleted file mode 100644 index 47cf87507..000000000 --- a/src/test/java/org/springframework/data/aerospike/repository/reactive/ReactiveAerospikeRepositoryCountRelatedTests.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.springframework.data.aerospike.repository.reactive; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.aerospike.BaseReactiveIntegrationTests; -import org.springframework.data.aerospike.query.QueryParam; -import org.springframework.data.aerospike.sample.Customer; -import org.springframework.data.aerospike.sample.ReactiveCustomerRepository; -import reactor.core.publisher.Flux; -import reactor.test.StepVerifier; - -import java.util.List; - -public class ReactiveAerospikeRepositoryCountRelatedTests extends BaseReactiveIntegrationTests { - - @Autowired - ReactiveCustomerRepository customerRepo; - - private Customer customer1, customer2; - - @BeforeEach - public void setUp() { - customer1 = Customer.builder().id(nextId()).firstName("Philip J.").lastName("Fry").age(1029).build(); - customer2 = Customer.builder().id(nextId()).firstName("Leela").lastName("Turanga").age(29).build(); - StepVerifier.create(customerRepo.saveAll(Flux.just(customer1, customer2))).expectNextCount(2).verifyComplete(); - } - - @Test - public void countByAgeBetween() { - StepVerifier.create(customerRepo.countByAgeBetween(20, 1100)) - .expectNextMatches(result -> result >= 2) - .verifyComplete(); - } - - @Test - public void countByIdAndFirstNameIn() { - QueryParam ids = QueryParam.of(List.of(customer1.getId(), customer2.getId())); - QueryParam firstNames = QueryParam.of(List.of(customer1.getFirstName(), customer2.getFirstName(), "FirstName")); - StepVerifier.create(customerRepo.countByIdAndFirstNameIn(ids, firstNames)) - .expectNext(2L) - .verifyComplete(); - - firstNames = QueryParam.of(List.of("FirstName")); - StepVerifier.create(customerRepo.countByIdAndFirstNameIn(ids, firstNames)) - .expectNext(0L) - .verifyComplete(); - } -} diff --git a/src/test/java/org/springframework/data/aerospike/repository/reactive/ReactiveAerospikeRepositoryDeleteRelatedTests.java b/src/test/java/org/springframework/data/aerospike/repository/reactive/ReactiveAerospikeRepositoryDeleteRelatedTests.java deleted file mode 100644 index 41647bbdf..000000000 --- a/src/test/java/org/springframework/data/aerospike/repository/reactive/ReactiveAerospikeRepositoryDeleteRelatedTests.java +++ /dev/null @@ -1,208 +0,0 @@ -package org.springframework.data.aerospike.repository.reactive; - -import com.aerospike.client.AerospikeException; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.reactivestreams.Publisher; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.aerospike.BaseReactiveIntegrationTests; -import org.springframework.data.aerospike.query.QueryParam; -import org.springframework.data.aerospike.sample.Customer; -import org.springframework.data.aerospike.sample.ReactiveCustomerRepository; -import reactor.core.publisher.Flux; -import reactor.core.scheduler.Schedulers; -import reactor.test.StepVerifier; - -import java.util.List; - -import static java.util.Arrays.asList; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - -/** - * @author Igor Ermolenko - */ -public class ReactiveAerospikeRepositoryDeleteRelatedTests extends BaseReactiveIntegrationTests { - - @Autowired - ReactiveCustomerRepository customerRepo; - - private Customer customer1, customer2; - - @BeforeEach - public void setUp() { - customer1 = Customer.builder().id(nextId()).firstName("Homer").lastName("Simpson").age(42).build(); - customer2 = Customer.builder().id(nextId()).firstName("Marge").lastName("Simpson").age(39).build(); - StepVerifier.create(customerRepo.saveAll(Flux.just(customer1, customer2))).expectNextCount(2).verifyComplete(); - - StepVerifier.create(customerRepo.findById(customer1.getId())).expectNext(customer1).verifyComplete(); - StepVerifier.create(customerRepo.findById(customer2.getId())).expectNext(customer2).verifyComplete(); - } - - @Test - public void deleteById_ShouldDeleteExistent() { - StepVerifier.create(customerRepo.deleteById(customer2.getId()).subscribeOn(Schedulers.parallel())) - .verifyComplete(); - - StepVerifier.create(customerRepo.findById(customer2.getId())).expectNextCount(0).verifyComplete(); - } - - @Test - public void deleteById_ShouldSkipNonexistent() { - StepVerifier.create(customerRepo.deleteById("non-existent-id").subscribeOn(Schedulers.parallel())) - .verifyComplete(); - } - - @Test - @SuppressWarnings("ConstantConditions") - public void deleteById_ShouldRejectNullObject() { - assertThatThrownBy(() -> customerRepo.deleteById((String) null).block()) - .isInstanceOf(IllegalArgumentException.class); - } - - @Test - public void deleteByIdPublisher_ShouldDeleteOnlyFirstElement() { - StepVerifier.create(customerRepo.deleteById(Flux.just(customer1.getId(), customer2.getId())) - .subscribeOn(Schedulers.parallel())) - .verifyComplete(); - - StepVerifier.create(customerRepo.findById(customer1.getId())).expectNextCount(0).verifyComplete(); - StepVerifier.create(customerRepo.findById(customer2.getId())).expectNext(customer2).verifyComplete(); - } - - @Test - public void deleteByIdPublisher_ShouldSkipNonexistent() { - StepVerifier.create(customerRepo.deleteById(Flux.just("non-existent-id")) - .subscribeOn(Schedulers.parallel())) - .verifyComplete(); - } - - @Test - @SuppressWarnings("ConstantConditions") - public void deleteByIdPublisher_ShouldRejectNullObject() { - //noinspection unchecked,rawtypes - assertThatThrownBy(() -> customerRepo.deleteById((Publisher) null).block()) - .isInstanceOf(IllegalArgumentException.class); - } - - @Test - public void delete_ShouldDeleteExistent() { - StepVerifier.create(customerRepo.delete(customer2).subscribeOn(Schedulers.parallel())).verifyComplete(); - - StepVerifier.create(customerRepo.findById(customer2.getId())).expectNextCount(0).verifyComplete(); - } - - @Test - public void delete_ShouldSkipNonexistent() { - Customer nonExistentCustomer = Customer.builder().id(nextId()).firstName("Bart").lastName("Simpson").age(15) - .build(); - - StepVerifier.create(customerRepo.delete(nonExistentCustomer).subscribeOn(Schedulers.parallel())) - .verifyComplete(); - } - - @Test - @SuppressWarnings("ConstantConditions") - public void delete_ShouldRejectNullObject() { - assertThatThrownBy(() -> customerRepo.delete(null).block()) - .isInstanceOf(IllegalArgumentException.class); - - } - - @Test - public void deleteAllIterable_ShouldDeleteExistent() { - customerRepo.deleteAll(asList(customer1, customer2)).subscribeOn(Schedulers.parallel()).block(); - - StepVerifier.create(customerRepo.findById(customer1.getId())).expectNextCount(0).verifyComplete(); - StepVerifier.create(customerRepo.findById(customer2.getId())).expectNextCount(0).verifyComplete(); - } - - @Test - public void deleteAllIterable_ShouldSkipNonexistentAndThrowException() { - Customer nonExistentCustomer = Customer.builder().id(nextId()).firstName("Bart").lastName("Simpson").age(15) - .build(); - - assertThatThrownBy(() -> customerRepo.deleteAll(asList(customer1, nonExistentCustomer, customer2)).block()) - .isInstanceOf(AerospikeException.BatchRecordArray.class); - StepVerifier.create(customerRepo.findById(customer1.getId())).expectNextCount(0).verifyComplete(); - StepVerifier.create(customerRepo.findById(customer2.getId())).expectNextCount(0).verifyComplete(); - } - - @Test - public void deleteAllIterable_ShouldRejectNullObject() { - List entities = asList(customer1, null, customer2); - - assertThatThrownBy(() -> customerRepo.deleteAll(entities).subscribeOn(Schedulers.parallel()).block()) - .isInstanceOf(IllegalArgumentException.class); - } - - @Test - public void deleteAllPublisher_ShouldDeleteExistent() { - customerRepo.deleteAll(Flux.just(customer1, customer2)).subscribeOn(Schedulers.parallel()).block(); - - StepVerifier.create(customerRepo.findById(customer1.getId())).expectNextCount(0).verifyComplete(); - StepVerifier.create(customerRepo.findById(customer2.getId())).expectNextCount(0).verifyComplete(); - } - - @Test - public void deleteAllPublisher_ShouldNotSkipNonexistent() { - Customer nonExistentCustomer = Customer.builder().id(nextId()).firstName("Bart").lastName("Simpson").age(15) - .build(); - - customerRepo.deleteAll(Flux.just(customer1, nonExistentCustomer, customer2)).subscribeOn(Schedulers.parallel()) - .block(); - - StepVerifier.create(customerRepo.findById(customer1.getId())).expectNextCount(0).verifyComplete(); - StepVerifier.create(customerRepo.findById(customer2.getId())).expectNextCount(0).verifyComplete(); - } - - @Test - public void deleteAllById_ShouldDelete() { - customerRepo.deleteAllById(asList(customer1.getId(), customer2.getId())).subscribeOn(Schedulers.parallel()) - .block(); - - StepVerifier.create(customerRepo.findById(customer1.getId())).expectNextCount(0).verifyComplete(); - StepVerifier.create(customerRepo.findById(customer2.getId())).expectNextCount(0).verifyComplete(); - } - - @Test - public void deleteAll_ShouldDelete() { - customerRepo.deleteAll().block(); - - StepVerifier.create(customerRepo.findById(customer1.getId())).expectNextCount(0).verifyComplete(); - StepVerifier.create(customerRepo.findById(customer2.getId())).expectNextCount(0).verifyComplete(); - } - - @Test - public void deleteByIdAndFirstNameIn() { - StepVerifier.create(customerRepo.saveAll(Flux.just(customer1, customer2))) - .expectNextCount(2) - .verifyComplete(); - - StepVerifier.create(customerRepo.findAllById(List.of(customer1.getId(), customer2.getId())).collectList()) - .expectNextMatches(list -> list.size() == 2 && list.contains(customer1) && list.contains(customer2)) - .verifyComplete(); - - QueryParam ids = QueryParam.of(List.of(customer1.getId(), customer2.getId())); - QueryParam firstNames = QueryParam.of(List.of("FirstName")); - // no records satisfying the condition - StepVerifier.create(customerRepo.deleteByIdAndFirstNameIn(ids, firstNames)) - .expectComplete() - .verify(); - - // no records get deleted - StepVerifier.create(customerRepo.findAllById(List.of(customer1.getId(), customer2.getId())).collectList()) - .expectNextMatches(list -> list.size() == 2 && list.contains(customer1) && list.contains(customer2)) - .verifyComplete(); - - // 2 records satisfying the condition - firstNames = QueryParam.of(List.of(customer1.getFirstName(), customer2.getFirstName(), "FirstName")); - StepVerifier.create(customerRepo.deleteByIdAndFirstNameIn(ids, firstNames)) - .expectComplete() - .verify(); - - // 2 records get deleted - StepVerifier.create(customerRepo.findAllById(List.of(customer1.getId(), customer2.getId())).collectList()) - .expectNextMatches(List::isEmpty) - .verifyComplete(); - } -} diff --git a/src/test/java/org/springframework/data/aerospike/repository/reactive/ReactiveAerospikeRepositoryExistRelatedTests.java b/src/test/java/org/springframework/data/aerospike/repository/reactive/ReactiveAerospikeRepositoryExistRelatedTests.java deleted file mode 100644 index 6c9a3df54..000000000 --- a/src/test/java/org/springframework/data/aerospike/repository/reactive/ReactiveAerospikeRepositoryExistRelatedTests.java +++ /dev/null @@ -1,77 +0,0 @@ -package org.springframework.data.aerospike.repository.reactive; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.aerospike.BaseReactiveIntegrationTests; -import org.springframework.data.aerospike.query.QueryParam; -import org.springframework.data.aerospike.sample.Customer; -import org.springframework.data.aerospike.sample.ReactiveCustomerRepository; -import reactor.core.publisher.Flux; -import reactor.core.scheduler.Schedulers; -import reactor.test.StepVerifier; - -import java.util.List; - -/** - * @author Igor Ermolenko - */ -public class ReactiveAerospikeRepositoryExistRelatedTests extends BaseReactiveIntegrationTests { - - @Autowired - ReactiveCustomerRepository customerRepo; - - private Customer customer1, customer2; - - @BeforeEach - public void setUp() { - customer1 = Customer.builder().id(nextId()).firstName("Homer").lastName("Simpson").age(42).build(); - customer2 = Customer.builder().id(nextId()).firstName("Marge").lastName("Simpson").age(39).build(); - StepVerifier.create(customerRepo.saveAll(Flux.just(customer1, customer2))).expectNextCount(2).verifyComplete(); - } - - @Test - public void existsById_ShouldReturnTrueWhenExists() { - StepVerifier.create(customerRepo.existsById(customer2.getId()).subscribeOn(Schedulers.parallel())) - .expectNext(true).verifyComplete(); - } - - @Test - public void existsById_ShouldReturnFalseWhenNotExists() { - StepVerifier.create(customerRepo.existsById("non-existent-id").subscribeOn(Schedulers.parallel())) - .expectNext(false).verifyComplete(); - } - - @Test - public void existsByIdPublisher_ShouldReturnTrueWhenExists() { - StepVerifier.create(customerRepo.existsById(Flux.just(customer1.getId())).subscribeOn(Schedulers.parallel())) - .expectNext(true).verifyComplete(); - } - - @Test - public void existsByIdPublisher_ShouldReturnFalseWhenNotExists() { - StepVerifier.create(customerRepo.existsById(Flux.just("non-existent-id")).subscribeOn(Schedulers.parallel())) - .expectNext(false).verifyComplete(); - } - - @Test - public void existsByIdPublisher_ShouldCheckOnlyFirstElement() { - StepVerifier.create(customerRepo.existsById(Flux.just(customer1.getId(), "non-existent-id")) - .subscribeOn(Schedulers.parallel())) - .expectNext(true).verifyComplete(); - } - - @Test - public void existsByIdAndFirstNameIn() { - QueryParam ids = QueryParam.of(List.of(customer1.getId(), customer2.getId())); - QueryParam firstNames = QueryParam.of(List.of(customer1.getFirstName(), customer2.getFirstName(), "FirstName")); - StepVerifier.create(customerRepo.existsByIdAndFirstNameIn(ids, firstNames)) - .expectNext(true) - .verifyComplete(); - - firstNames = QueryParam.of(List.of("FirstName")); - StepVerifier.create(customerRepo.existsByIdAndFirstNameIn(ids, firstNames)) - .expectNext(false) - .verifyComplete(); - } -} diff --git a/src/test/java/org/springframework/data/aerospike/repository/reactive/ReactiveAerospikeRepositoryFindRelatedTests.java b/src/test/java/org/springframework/data/aerospike/repository/reactive/ReactiveAerospikeRepositoryFindRelatedTests.java deleted file mode 100644 index aef3bc012..000000000 --- a/src/test/java/org/springframework/data/aerospike/repository/reactive/ReactiveAerospikeRepositoryFindRelatedTests.java +++ /dev/null @@ -1,346 +0,0 @@ -package org.springframework.data.aerospike.repository.reactive; - -import com.aerospike.client.query.IndexType; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestInstance; -import org.reactivestreams.Publisher; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.aerospike.BaseReactiveIntegrationTests; -import org.springframework.data.aerospike.query.QueryParam; -import org.springframework.data.aerospike.sample.Customer; -import org.springframework.data.aerospike.sample.CustomerSomeFields; -import org.springframework.data.aerospike.sample.ReactiveCustomerRepository; -import org.springframework.data.domain.Sort; -import reactor.core.publisher.Flux; -import reactor.core.scheduler.Schedulers; -import reactor.test.StepVerifier; - -import java.util.List; - -import static java.util.Arrays.asList; -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.data.aerospike.query.QueryParam.of; -import static org.springframework.data.domain.Sort.Order.asc; - -/** - * @author Igor Ermolenko - */ -@TestInstance(TestInstance.Lifecycle.PER_CLASS) -public class ReactiveAerospikeRepositoryFindRelatedTests extends BaseReactiveIntegrationTests { - - @Autowired - ReactiveCustomerRepository customerRepo; - - private Customer customer1, customer2, customer3, customer4; - - @BeforeAll - public void setUpBeforeAll() { - customerRepo.deleteAll().block(); - - customer1 = Customer.builder().id(nextId()).firstName("Homer").lastName("Simpson").age(42).group('a').build(); - customer2 = Customer.builder().id(nextId()).firstName("Marge").lastName("Simpson").age(39).group('b').build(); - customer3 = Customer.builder().id(nextId()).firstName("Bart").lastName("Simpson").age(15).group('b').build(); - customer4 = Customer.builder().id(nextId()).firstName("Matt").lastName("Groening").age(65).group('c').build(); - - additionalAerospikeTestOperations.createIndex(Customer.class, "customer_first_name_index", - "firstname", IndexType.STRING); - additionalAerospikeTestOperations.createIndex(Customer.class, "customer_last_name_index", - "lastname", IndexType.STRING); - additionalAerospikeTestOperations.createIndex(Customer.class, "customer_age_index", "age", - IndexType.NUMERIC); - - customerRepo.saveAll(Flux.just(customer1, customer2, customer3, customer4)) - .subscribeOn(Schedulers.parallel()).collectList().block(); - } - - @AfterAll - public void afterAll() { - customerRepo.deleteAll().block(); - additionalAerospikeTestOperations.dropIndex(Customer.class, "customer_first_name_index"); - additionalAerospikeTestOperations.dropIndex(Customer.class, "customer_last_name_index"); - additionalAerospikeTestOperations.dropIndex(Customer.class, "customer_age_index"); - } - - @Test - public void findById_ShouldReturnExistent() { - Customer result = customerRepo.findById(customer2.getId()) - .subscribeOn(Schedulers.parallel()).block(); - - assertThat(result).isEqualTo(customer2); - } - - @Test - public void findById_ShouldNotReturnNotExistent() { - Customer result = customerRepo.findById("non-existent-id") - .subscribeOn(Schedulers.parallel()).block(); - - assertThat(result).isNull(); - } - - @Test - public void findByIdPublisher_ShouldReturnFirst() { - Publisher ids = Flux.just(customer2.getId(), customer4.getId()); - - Customer result = customerRepo.findById(ids).subscribeOn(Schedulers.parallel()).block(); - assertThat(result).isEqualTo(customer2); - } - - @Test - public void findByIdPublisher_NotReturnFirstNotExistent() { - Publisher ids = Flux.just("non-existent-id", customer2.getId(), customer4.getId()); - - Customer result = customerRepo.findById(ids).subscribeOn(Schedulers.parallel()).block(); - assertThat(result).isNull(); - } - - @Test - public void findAll_ShouldReturnAll() { - List results = customerRepo.findAll().subscribeOn(Schedulers.parallel()).collectList().block(); - assertThat(results) - .containsOnly(customer1, customer2, customer3, customer4); - } - - @Test - public void findAllByIDsIterable_ShouldReturnAllExistent() { - Iterable ids = asList(customer2.getId(), "non-existent-id", customer4.getId()); - - List results = customerRepo.findAllById(ids) - .subscribeOn(Schedulers.parallel()).collectList().block(); - - assertThat(results).containsOnly(customer2, customer4); - } - - @Test - public void findAllByIDsPublisher_ShouldReturnAllExistent() { - Publisher ids = Flux.just(customer1.getId(), customer2.getId(), customer4.getId(), "non-existent-id"); - - List results = customerRepo.findAllById(ids) - .subscribeOn(Schedulers.parallel()).collectList().block(); - - assertThat(results).containsOnly(customer1, customer2, customer4); - } - - @Test - public void findByLastname_ShouldWorkProperly() { - List results = customerRepo.findByLastName("Simpson") - .subscribeOn(Schedulers.parallel()).collectList().block(); - - assertThat(results).containsOnly(customer1, customer2, customer3); - } - - @Test - public void findCustomerSomeFieldsByLastname_ShouldWorkProperlyProjection() { - List results = customerRepo.findCustomerSomeFieldsByLastName("Simpson") - .subscribeOn(Schedulers.parallel()).collectList().block(); - - assertThat(results).containsOnly(customer1.toCustomerSomeFields(), customer2.toCustomerSomeFields(), - customer3.toCustomerSomeFields()); - } - - @Test - public void findDynamicTypeByLastname_ShouldWorkProperlyDynamicProjection() { - List results = customerRepo.findByLastName("Simpson", CustomerSomeFields.class) - .subscribeOn(Schedulers.parallel()).collectList().block(); - - assertThat(results).containsOnly(customer1.toCustomerSomeFields(), customer2.toCustomerSomeFields(), - customer3.toCustomerSomeFields()); - } - - @Test - public void findByLastnameName_ShouldWorkProperly() { - List results = customerRepo.findByLastNameNot("Simpson") - .subscribeOn(Schedulers.parallel()).collectList().block(); - - assertThat(results).containsOnly(customer4); - } - - @Test - public void findOneByLastname_ShouldWorkProperly() { - Customer result = customerRepo.findOneByLastName("Groening") - .subscribeOn(Schedulers.parallel()).block(); - - assertThat(result).isEqualTo(customer4); - } - - @Test - public void findByLastnameOrderByFirstnameAsc_ShouldWorkProperly() { - List results = customerRepo.findByLastNameOrderByFirstNameAsc("Simpson") - .subscribeOn(Schedulers.parallel()).collectList().block(); - - assertThat(results).containsExactly(customer3, customer1, customer2); - } - - @Test - public void findByLastnameOrderByFirstnameDesc_ShouldWorkProperly() { - List results = customerRepo.findByLastNameOrderByFirstNameDesc("Simpson") - .subscribeOn(Schedulers.parallel()).collectList().block(); - - assertThat(results).containsExactly(customer2, customer1, customer3); - } - - @Test - public void findByFirstnameEndsWith_ShouldWorkProperly() { - List results = customerRepo.findByFirstNameEndsWith("t") - .subscribeOn(Schedulers.parallel()).collectList().block(); - - assertThat(results).containsOnly(customer3, customer4); - } - - @Test - public void findByFirstnameStartsWithOrderByAgeAsc_ShouldWorkProperly() { - List results = customerRepo.findByFirstNameStartsWithOrderByAgeAsc("Ma") - .subscribeOn(Schedulers.parallel()).collectList().block(); - - assertThat(results).containsExactly(customer2, customer4); - } - - @Test - public void findCustomerSomeFieldsByFirstnameStartsWithOrderByAgeAsc_ShouldWorkProperly() { - List results = - customerRepo.findCustomerSomeFieldsByFirstNameStartsWithOrderByFirstNameAsc("Ma") - .subscribeOn(Schedulers.parallel()).collectList().block(); - - assertThat(results).containsExactly(customer2.toCustomerSomeFields(), customer4.toCustomerSomeFields()); - } - - @Test - public void findByAgeLessThan_ShouldWorkProperly() { - List results = customerRepo.findByAgeLessThan(40, Sort.by(asc("firstName"))) - .subscribeOn(Schedulers.parallel()).collectList().block(); - - assertThat(results).containsExactly(customer3, customer2); - } - - @Test - public void findByFirstnameIn_ShouldWorkProperly() { - List results = customerRepo.findByFirstNameIn(asList("Matt", "Homer")) - .subscribeOn(Schedulers.parallel()).collectList().block(); - - assertThat(results).containsOnly(customer1, customer4); - } - - @Test - public void findByFirstnameAndLastname_ShouldWorkProperly() { - QueryParam firstName = of("Bart"); - QueryParam lastName = of("Simpson"); - List results = customerRepo.findByFirstNameAndLastName(firstName, lastName) - .subscribeOn(Schedulers.parallel()).collectList().block(); - - assertThat(results).containsOnly(customer3); - } - - @Test - public void findOneByFirstnameAndLastname_ShouldWorkProperly() { - QueryParam firstName = of("Bart"); - QueryParam lastName = of("Simpson"); - Customer result = customerRepo.findByFirstNameAndLastName(firstName, lastName) - .subscribeOn(Schedulers.parallel()).blockLast(); - - assertThat(result).isEqualTo(customer3); - } - - @Test - public void findByLastnameAndAge_ShouldWorkProperly() { - QueryParam lastName = of("Simpson"); - QueryParam age = of(15); - Customer result = customerRepo.findByLastNameAndAge(lastName, age) - .subscribeOn(Schedulers.parallel()).blockLast(); - - assertThat(result).isEqualTo(customer3); - } - - @Test - public void findByAgeBetween_ShouldWorkProperly() { - List results = customerRepo.findByAgeBetween(10, 40) - .subscribeOn(Schedulers.parallel()).collectList().block(); - - assertThat(results).containsOnly(customer2, customer3); - } - - @Test - public void findByFirstnameContains_ShouldWorkProperly() { - List results = customerRepo.findByFirstNameContains("ar") - .subscribeOn(Schedulers.parallel()).collectList().block(); - - assertThat(results).containsOnly(customer2, customer3); - } - - @Test - public void findByFirstnameContainingIgnoreCase_ShouldWorkProperly() { - List results = customerRepo.findByFirstNameContainingIgnoreCase("m") - .subscribeOn(Schedulers.parallel()).collectList().block(); - - assertThat(results).containsOnly(customer1, customer2, customer4); - } - - @Test - public void findByAgeBetweenAndLastname_ShouldWorkProperly() { - QueryParam ageBetween = of(30, 70); - QueryParam lastName = of("Simpson"); - List results = customerRepo.findByAgeBetweenAndLastName(ageBetween, lastName) - .subscribeOn(Schedulers.parallel()).collectList().block(); - - assertThat(results).containsOnly(customer1, customer2); - } - - @Test - public void findByAgeBetweenOrderByFirstnameDesc_ShouldWorkProperly() { - List results = customerRepo.findByAgeBetweenOrderByFirstNameDesc(30, 70) - .subscribeOn(Schedulers.parallel()).collectList().block(); - - assertThat(results).containsExactly(customer4, customer2, customer1); - } - - @Test - public void findByGroup() { - List results = customerRepo.findByGroup('b') - .subscribeOn(Schedulers.parallel()).collectList().block(); - - assertThat(results).containsOnly(customer2, customer3); - } - - @Test - public void findByIdAndFirstNameIn() { - QueryParam ids = QueryParam.of(List.of(customer1.getId(), customer2.getId())); - QueryParam firstNames = QueryParam.of(List.of(customer1.getFirstName(), customer2.getFirstName(), "FirstName")); - StepVerifier.create(customerRepo.findByIdAndFirstNameIn(ids, firstNames).collectList()) - .expectNextMatches(list -> list.size() == 2 && list.contains(customer1) && list.contains(customer2)) - .verifyComplete(); - - firstNames = QueryParam.of(List.of("FirstName")); - StepVerifier.create(customerRepo.findByIdAndFirstNameIn(ids, firstNames)) - .expectComplete() - .verify(); - } - - @Test - public void findByIdAndFirstNameIn_Synonyms() { - QueryParam ids = QueryParam.of(List.of(customer1.getId(), customer2.getId())); - QueryParam firstNames = QueryParam.of(List.of(customer1.getFirstName(), customer2.getFirstName(), "FirstName")); - StepVerifier.create(customerRepo.readByIdAndFirstNameIn(ids, firstNames).collectList()) - .expectNextMatches(list -> list.size() == 2 && list.contains(customer1) && list.contains(customer2)) - .verifyComplete(); - - StepVerifier.create(customerRepo.readByIdAndFirstNameIn(ids, firstNames).collectList()) - .expectNextMatches(list -> list.size() == 2 && list.contains(customer1) && list.contains(customer2)) - .verifyComplete(); - - StepVerifier.create(customerRepo.getByIdAndFirstNameIn(ids, firstNames).collectList()) - .expectNextMatches(list -> list.size() == 2 && list.contains(customer1) && list.contains(customer2)) - .verifyComplete(); - - StepVerifier.create(customerRepo.queryByIdAndFirstNameIn(ids, firstNames).collectList()) - .expectNextMatches(list -> list.size() == 2 && list.contains(customer1) && list.contains(customer2)) - .verifyComplete(); - - StepVerifier.create(customerRepo.searchByIdAndFirstNameIn(ids, firstNames).collectList()) - .expectNextMatches(list -> list.size() == 2 && list.contains(customer1) && list.contains(customer2)) - .verifyComplete(); - - StepVerifier.create(customerRepo.streamByIdAndFirstNameIn(ids, firstNames).collectList()) - .expectNextMatches(list -> list.size() == 2 && list.contains(customer1) && list.contains(customer2)) - .verifyComplete(); - } -} diff --git a/src/test/java/org/springframework/data/aerospike/sample/ReactiveCustomerRepository.java b/src/test/java/org/springframework/data/aerospike/sample/ReactiveCustomerRepository.java index 52bd89334..25a3b1de7 100644 --- a/src/test/java/org/springframework/data/aerospike/sample/ReactiveCustomerRepository.java +++ b/src/test/java/org/springframework/data/aerospike/sample/ReactiveCustomerRepository.java @@ -62,6 +62,12 @@ public interface ReactiveCustomerRepository extends ReactiveAerospikeRepository< Flux findByLastNameAndAge(QueryParam lastName, QueryParam age); + Mono countByIdAndFirstName(QueryParam ids, QueryParam firstNames); + + Mono deleteByIdAndFirstName(QueryParam ids, QueryParam firstNames); + + Mono existsByIdAndFirstName(QueryParam ids, QueryParam firstNames); + Flux findByAgeBetween(long from, long to); Mono countByAgeBetween(long from, long to);