mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-01 09:42:11 +00:00
parent
c9b8b1af19
commit
43ab49b5fa
1
.gitignore
vendored
1
.gitignore
vendored
@ -24,4 +24,5 @@ target
|
||||
|
||||
|
||||
/zap.env
|
||||
/localdocker.env
|
||||
.localdocker-env
|
||||
|
@ -15,10 +15,16 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.repository.support.querybyexample;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.data.elasticsearch.utils.IdGenerator.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.assertj.core.api.AbstractThrowableAssert;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.IncorrectResultSizeDataAccessException;
|
||||
@ -39,14 +45,6 @@ import org.springframework.data.elasticsearch.utils.IndexNameProvider;
|
||||
import org.springframework.data.repository.query.QueryByExampleExecutor;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.springframework.data.elasticsearch.utils.IdGenerator.nextIdAsString;
|
||||
|
||||
/**
|
||||
* @author Ezequiel Antúnez Camacho
|
||||
* @since 5.1
|
||||
@ -65,410 +63,398 @@ abstract class QueryByExampleElasticsearchExecutorIntegrationTests {
|
||||
}
|
||||
|
||||
@Test // #2418
|
||||
@org.junit.jupiter.api.Order(Integer.MAX_VALUE)
|
||||
@Order(Integer.MAX_VALUE)
|
||||
void cleanup() {
|
||||
operations.indexOps(IndexCoordinates.of(indexNameProvider.getPrefix() + "*")).delete();
|
||||
}
|
||||
|
||||
@Nested
|
||||
@DisplayName("All QueryByExampleExecutor operations should work")
|
||||
class QueryByExampleExecutorOperations {
|
||||
@Test // #2418
|
||||
void shouldFindOne() {
|
||||
// given
|
||||
String documentId = nextIdAsString();
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(documentId);
|
||||
sampleEntity.setMessage("some message");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
@Test // #2418
|
||||
void shouldFindOne() {
|
||||
// given
|
||||
String documentId = nextIdAsString();
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(documentId);
|
||||
sampleEntity.setMessage("some message");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
|
||||
String documentId2 = nextIdAsString();
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(documentId2);
|
||||
sampleEntity2.setMessage("some message");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
String documentId2 = nextIdAsString();
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(documentId2);
|
||||
sampleEntity2.setMessage("some message");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2));
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2));
|
||||
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
probe.setDocumentId(documentId2);
|
||||
Optional<SampleEntity> entityFromElasticSearch = repository.findOne(Example.of(probe));
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
probe.setDocumentId(documentId2);
|
||||
Optional<SampleEntity> entityFromElasticSearch = repository.findOne(Example.of(probe));
|
||||
|
||||
// then
|
||||
assertThat(entityFromElasticSearch).contains(sampleEntity2);
|
||||
|
||||
}
|
||||
|
||||
@Test // #2418
|
||||
void shouldThrowExceptionIfMoreThanOneResultInFindOne() {
|
||||
// given
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(nextIdAsString());
|
||||
sampleEntity.setMessage("some message");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(nextIdAsString());
|
||||
sampleEntity2.setMessage("some message");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2));
|
||||
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
probe.setMessage("some message");
|
||||
final Example<SampleEntity> example = Example.of(probe);
|
||||
AbstractThrowableAssert<?, ? extends Throwable> assertThatThrownBy = assertThatThrownBy(
|
||||
() -> repository.findOne(example));
|
||||
|
||||
// then
|
||||
assertThatThrownBy.isInstanceOf(IncorrectResultSizeDataAccessException.class);
|
||||
|
||||
}
|
||||
|
||||
@Test // #2418
|
||||
void shouldFindOneWithNestedField() {
|
||||
// given
|
||||
SampleEntity.SampleNestedEntity sampleNestedEntity = new SampleEntity.SampleNestedEntity();
|
||||
sampleNestedEntity.setNestedData("sampleNestedData");
|
||||
sampleNestedEntity.setAnotherNestedData("sampleAnotherNestedData");
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(nextIdAsString());
|
||||
sampleEntity.setMessage("some message");
|
||||
sampleEntity.setSampleNestedEntity(sampleNestedEntity);
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity.SampleNestedEntity sampleNestedEntity2 = new SampleEntity.SampleNestedEntity();
|
||||
sampleNestedEntity2.setNestedData("sampleNestedData2");
|
||||
sampleNestedEntity2.setAnotherNestedData("sampleAnotherNestedData2");
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(nextIdAsString());
|
||||
sampleEntity2.setMessage("some message");
|
||||
sampleEntity2.setSampleNestedEntity(sampleNestedEntity2);
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2));
|
||||
|
||||
// when
|
||||
SampleEntity.SampleNestedEntity sampleNestedEntityProbe = new SampleEntity.SampleNestedEntity();
|
||||
sampleNestedEntityProbe.setNestedData("sampleNestedData");
|
||||
SampleEntity probe = new SampleEntity();
|
||||
probe.setSampleNestedEntity(sampleNestedEntityProbe);
|
||||
|
||||
Optional<SampleEntity> entityFromElasticSearch = repository.findOne(Example.of(probe));
|
||||
|
||||
// then
|
||||
assertThat(entityFromElasticSearch).contains(sampleEntity);
|
||||
|
||||
}
|
||||
|
||||
@Test // #2418
|
||||
void shouldFindAll() {
|
||||
// given
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(nextIdAsString());
|
||||
sampleEntity.setMessage("hello world");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(nextIdAsString());
|
||||
sampleEntity2.setMessage("hello world");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntity3 = new SampleEntity();
|
||||
sampleEntity3.setDocumentId(nextIdAsString());
|
||||
sampleEntity3.setMessage("bye world");
|
||||
sampleEntity3.setVersion(System.currentTimeMillis());
|
||||
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2, sampleEntity3));
|
||||
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
probe.setMessage("hello world");
|
||||
Iterable<SampleEntity> sampleEntities = repository.findAll(Example.of(probe));
|
||||
|
||||
// then
|
||||
assertThat(sampleEntities).isNotNull().hasSize(2);
|
||||
}
|
||||
|
||||
@Test // #2418
|
||||
void shouldFindAllWithSort() {
|
||||
// given
|
||||
SampleEntity sampleEntityWithRate11 = new SampleEntity();
|
||||
sampleEntityWithRate11.setDocumentId(nextIdAsString());
|
||||
sampleEntityWithRate11.setMessage("hello world");
|
||||
sampleEntityWithRate11.setRate(11);
|
||||
sampleEntityWithRate11.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntityWithRate13 = new SampleEntity();
|
||||
sampleEntityWithRate13.setDocumentId(nextIdAsString());
|
||||
sampleEntityWithRate13.setMessage("hello world");
|
||||
sampleEntityWithRate13.setRate(13);
|
||||
sampleEntityWithRate13.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntityWithRate22 = new SampleEntity();
|
||||
sampleEntityWithRate22.setDocumentId(nextIdAsString());
|
||||
sampleEntityWithRate22.setMessage("hello world");
|
||||
sampleEntityWithRate22.setRate(22);
|
||||
sampleEntityWithRate22.setVersion(System.currentTimeMillis());
|
||||
|
||||
repository.saveAll(List.of(sampleEntityWithRate11, sampleEntityWithRate13, sampleEntityWithRate22));
|
||||
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
final Iterable<SampleEntity> all = repository.findAll();
|
||||
Iterable<SampleEntity> sampleEntities = repository.findAll(Example.of(probe),
|
||||
Sort.by(Sort.Direction.DESC, "rate"));
|
||||
|
||||
// then
|
||||
assertThat(sampleEntities).isNotNull().hasSize(3).containsExactly(sampleEntityWithRate22, sampleEntityWithRate13,
|
||||
sampleEntityWithRate11);
|
||||
}
|
||||
|
||||
@Test // #2418
|
||||
void shouldFindAllWithPageable() {
|
||||
// given
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(nextIdAsString());
|
||||
sampleEntity.setMessage("hello world");
|
||||
sampleEntity.setRate(1);
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(nextIdAsString());
|
||||
sampleEntity2.setMessage("hello world");
|
||||
sampleEntity2.setRate(3);
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntity3 = new SampleEntity();
|
||||
sampleEntity3.setDocumentId(nextIdAsString());
|
||||
sampleEntity3.setMessage("hello world");
|
||||
sampleEntity3.setRate(2);
|
||||
sampleEntity3.setVersion(System.currentTimeMillis());
|
||||
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2, sampleEntity3));
|
||||
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
Iterable<SampleEntity> page1 = repository.findAll(Example.of(probe),
|
||||
PageRequest.of(0, 2, Sort.Direction.DESC, "rate"));
|
||||
Iterable<SampleEntity> page2 = repository.findAll(Example.of(probe),
|
||||
PageRequest.of(1, 2, Sort.Direction.DESC, "rate"));
|
||||
|
||||
// then
|
||||
assertThat(page1).isNotNull().hasSize(2).containsExactly(sampleEntity2, sampleEntity3);
|
||||
assertThat(page2).isNotNull().hasSize(1).containsExactly(sampleEntity);
|
||||
}
|
||||
|
||||
@Test // #2418
|
||||
void shouldCount() {
|
||||
// given
|
||||
String documentId = nextIdAsString();
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(documentId);
|
||||
sampleEntity.setMessage("some message");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
|
||||
String documentId2 = nextIdAsString();
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(documentId2);
|
||||
sampleEntity2.setMessage("some message");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2));
|
||||
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
probe.setDocumentId(documentId2);
|
||||
final long count = repository.count(Example.of(probe));
|
||||
|
||||
// then
|
||||
assertThat(count).isPositive();
|
||||
}
|
||||
|
||||
@Test // #2418
|
||||
void shouldExists() {
|
||||
// given
|
||||
String documentId = nextIdAsString();
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(documentId);
|
||||
sampleEntity.setMessage("some message");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
|
||||
String documentId2 = nextIdAsString();
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(documentId2);
|
||||
sampleEntity2.setMessage("some message");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2));
|
||||
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
probe.setDocumentId(documentId2);
|
||||
boolean exists = repository.exists(Example.of(probe));
|
||||
|
||||
// then
|
||||
assertThat(exists).isTrue();
|
||||
}
|
||||
// then
|
||||
assertThat(entityFromElasticSearch).contains(sampleEntity2);
|
||||
|
||||
}
|
||||
|
||||
@Nested
|
||||
@DisplayName("All ExampleMatchers should work")
|
||||
class AllExampleMatchersShouldWork {
|
||||
@Test // #2418
|
||||
void shouldThrowExceptionIfMoreThanOneResultInFindOne() {
|
||||
// given
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(nextIdAsString());
|
||||
sampleEntity.setMessage("some message");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
|
||||
@Test // #2418
|
||||
void defaultStringMatcherShouldWork() {
|
||||
// given
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(nextIdAsString());
|
||||
sampleEntity.setMessage("hello world");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(nextIdAsString());
|
||||
sampleEntity2.setMessage("some message");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(nextIdAsString());
|
||||
sampleEntity2.setMessage("bye world");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2));
|
||||
|
||||
SampleEntity sampleEntity3 = new SampleEntity();
|
||||
sampleEntity3.setDocumentId(nextIdAsString());
|
||||
sampleEntity3.setMessage("hola mundo");
|
||||
sampleEntity3.setVersion(System.currentTimeMillis());
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
probe.setMessage("some message");
|
||||
final Example<SampleEntity> example = Example.of(probe);
|
||||
AbstractThrowableAssert<?, ? extends Throwable> assertThatThrownBy = assertThatThrownBy(
|
||||
() -> repository.findOne(example));
|
||||
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2, sampleEntity3));
|
||||
// then
|
||||
assertThatThrownBy.isInstanceOf(IncorrectResultSizeDataAccessException.class);
|
||||
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
probe.setMessage("hello world");
|
||||
Iterable<SampleEntity> sampleEntities = repository.findAll(Example.of(probe, ExampleMatcher.matching()
|
||||
.withMatcher("message", ExampleMatcher.GenericPropertyMatcher.of(ExampleMatcher.StringMatcher.DEFAULT))));
|
||||
}
|
||||
|
||||
// then
|
||||
assertThat(sampleEntities).isNotNull().hasSize(1);
|
||||
}
|
||||
@Test // #2418
|
||||
void shouldFindOneWithNestedField() {
|
||||
// given
|
||||
SampleEntity.SampleNestedEntity sampleNestedEntity = new SampleEntity.SampleNestedEntity();
|
||||
sampleNestedEntity.setNestedData("sampleNestedData");
|
||||
sampleNestedEntity.setAnotherNestedData("sampleAnotherNestedData");
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(nextIdAsString());
|
||||
sampleEntity.setMessage("some message");
|
||||
sampleEntity.setSampleNestedEntity(sampleNestedEntity);
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
|
||||
@Test // #2418
|
||||
void exactStringMatcherShouldWork() {
|
||||
// given
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(nextIdAsString());
|
||||
sampleEntity.setMessage("hello world");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
SampleEntity.SampleNestedEntity sampleNestedEntity2 = new SampleEntity.SampleNestedEntity();
|
||||
sampleNestedEntity2.setNestedData("sampleNestedData2");
|
||||
sampleNestedEntity2.setAnotherNestedData("sampleAnotherNestedData2");
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(nextIdAsString());
|
||||
sampleEntity2.setMessage("some message");
|
||||
sampleEntity2.setSampleNestedEntity(sampleNestedEntity2);
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(nextIdAsString());
|
||||
sampleEntity2.setMessage("bye world");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2));
|
||||
|
||||
SampleEntity sampleEntity3 = new SampleEntity();
|
||||
sampleEntity3.setDocumentId(nextIdAsString());
|
||||
sampleEntity3.setMessage("hola mundo");
|
||||
sampleEntity3.setVersion(System.currentTimeMillis());
|
||||
// when
|
||||
SampleEntity.SampleNestedEntity sampleNestedEntityProbe = new SampleEntity.SampleNestedEntity();
|
||||
sampleNestedEntityProbe.setNestedData("sampleNestedData");
|
||||
SampleEntity probe = new SampleEntity();
|
||||
probe.setSampleNestedEntity(sampleNestedEntityProbe);
|
||||
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2, sampleEntity3));
|
||||
Optional<SampleEntity> entityFromElasticSearch = repository.findOne(Example.of(probe));
|
||||
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
probe.setMessage("bye world");
|
||||
Iterable<SampleEntity> sampleEntities = repository.findAll(Example.of(probe, ExampleMatcher.matching()
|
||||
.withMatcher("message", ExampleMatcher.GenericPropertyMatcher.of(ExampleMatcher.StringMatcher.EXACT))));
|
||||
// then
|
||||
assertThat(entityFromElasticSearch).contains(sampleEntity);
|
||||
|
||||
// then
|
||||
assertThat(sampleEntities).isNotNull().hasSize(1);
|
||||
}
|
||||
}
|
||||
|
||||
@Test // #2418
|
||||
void startingStringMatcherShouldWork() {
|
||||
// given
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(nextIdAsString());
|
||||
sampleEntity.setMessage("hello world");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
@Test // #2418
|
||||
void shouldFindAll() {
|
||||
// given
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(nextIdAsString());
|
||||
sampleEntity.setMessage("hello world");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(nextIdAsString());
|
||||
sampleEntity2.setMessage("bye world");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(nextIdAsString());
|
||||
sampleEntity2.setMessage("hello world");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntity3 = new SampleEntity();
|
||||
sampleEntity3.setDocumentId(nextIdAsString());
|
||||
sampleEntity3.setMessage("hola mundo");
|
||||
sampleEntity3.setVersion(System.currentTimeMillis());
|
||||
SampleEntity sampleEntity3 = new SampleEntity();
|
||||
sampleEntity3.setDocumentId(nextIdAsString());
|
||||
sampleEntity3.setMessage("bye world");
|
||||
sampleEntity3.setVersion(System.currentTimeMillis());
|
||||
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2, sampleEntity3));
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2, sampleEntity3));
|
||||
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
probe.setMessage("h");
|
||||
Iterable<SampleEntity> sampleEntities = repository.findAll(Example.of(probe, ExampleMatcher.matching()
|
||||
.withMatcher("message", ExampleMatcher.GenericPropertyMatcher.of(ExampleMatcher.StringMatcher.STARTING))));
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
probe.setMessage("hello world");
|
||||
Iterable<SampleEntity> sampleEntities = repository.findAll(Example.of(probe));
|
||||
|
||||
// then
|
||||
assertThat(sampleEntities).isNotNull().hasSize(2);
|
||||
}
|
||||
// then
|
||||
assertThat(sampleEntities).isNotNull().hasSize(2);
|
||||
}
|
||||
|
||||
@Test // #2418
|
||||
void endingStringMatcherShouldWork() {
|
||||
// given
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(nextIdAsString());
|
||||
sampleEntity.setMessage("hello world");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
@Test // #2418
|
||||
void shouldFindAllWithSort() {
|
||||
// given
|
||||
SampleEntity sampleEntityWithRate11 = new SampleEntity();
|
||||
sampleEntityWithRate11.setDocumentId(nextIdAsString());
|
||||
sampleEntityWithRate11.setMessage("hello world");
|
||||
sampleEntityWithRate11.setRate(11);
|
||||
sampleEntityWithRate11.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(nextIdAsString());
|
||||
sampleEntity2.setMessage("bye world");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
SampleEntity sampleEntityWithRate13 = new SampleEntity();
|
||||
sampleEntityWithRate13.setDocumentId(nextIdAsString());
|
||||
sampleEntityWithRate13.setMessage("hello world");
|
||||
sampleEntityWithRate13.setRate(13);
|
||||
sampleEntityWithRate13.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntity3 = new SampleEntity();
|
||||
sampleEntity3.setDocumentId(nextIdAsString());
|
||||
sampleEntity3.setMessage("hola mundo");
|
||||
sampleEntity3.setVersion(System.currentTimeMillis());
|
||||
SampleEntity sampleEntityWithRate22 = new SampleEntity();
|
||||
sampleEntityWithRate22.setDocumentId(nextIdAsString());
|
||||
sampleEntityWithRate22.setMessage("hello world");
|
||||
sampleEntityWithRate22.setRate(22);
|
||||
sampleEntityWithRate22.setVersion(System.currentTimeMillis());
|
||||
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2, sampleEntity3));
|
||||
repository.saveAll(List.of(sampleEntityWithRate11, sampleEntityWithRate13, sampleEntityWithRate22));
|
||||
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
probe.setMessage("world");
|
||||
Iterable<SampleEntity> sampleEntities = repository.findAll(Example.of(probe, ExampleMatcher.matching()
|
||||
.withMatcher("message", ExampleMatcher.GenericPropertyMatcher.of(ExampleMatcher.StringMatcher.ENDING))));
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
final Iterable<SampleEntity> all = repository.findAll();
|
||||
Iterable<SampleEntity> sampleEntities = repository.findAll(Example.of(probe), Sort.by(Sort.Direction.DESC, "rate"));
|
||||
|
||||
// then
|
||||
assertThat(sampleEntities).isNotNull().hasSize(2);
|
||||
}
|
||||
// then
|
||||
assertThat(sampleEntities).isNotNull().hasSize(3).containsExactly(sampleEntityWithRate22, sampleEntityWithRate13,
|
||||
sampleEntityWithRate11);
|
||||
}
|
||||
|
||||
@Test // #2418
|
||||
void regexStringMatcherShouldWork() {
|
||||
// given
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(nextIdAsString());
|
||||
sampleEntity.setMessage("hello world");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
@Test // #2418
|
||||
void shouldFindAllWithPageable() {
|
||||
// given
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(nextIdAsString());
|
||||
sampleEntity.setMessage("hello world");
|
||||
sampleEntity.setRate(1);
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(nextIdAsString());
|
||||
sampleEntity2.setMessage("bye world");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(nextIdAsString());
|
||||
sampleEntity2.setMessage("hello world");
|
||||
sampleEntity2.setRate(3);
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntity3 = new SampleEntity();
|
||||
sampleEntity3.setDocumentId(nextIdAsString());
|
||||
sampleEntity3.setMessage("hola mundo");
|
||||
sampleEntity3.setVersion(System.currentTimeMillis());
|
||||
SampleEntity sampleEntity3 = new SampleEntity();
|
||||
sampleEntity3.setDocumentId(nextIdAsString());
|
||||
sampleEntity3.setMessage("hello world");
|
||||
sampleEntity3.setRate(2);
|
||||
sampleEntity3.setVersion(System.currentTimeMillis());
|
||||
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2, sampleEntity3));
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2, sampleEntity3));
|
||||
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
probe.setMessage("[(hello)(hola)].*");
|
||||
Iterable<SampleEntity> sampleEntities = repository.findAll(Example.of(probe, ExampleMatcher.matching()
|
||||
.withMatcher("message", ExampleMatcher.GenericPropertyMatcher.of(ExampleMatcher.StringMatcher.REGEX))));
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
Iterable<SampleEntity> page1 = repository.findAll(Example.of(probe),
|
||||
PageRequest.of(0, 2, Sort.Direction.DESC, "rate"));
|
||||
Iterable<SampleEntity> page2 = repository.findAll(Example.of(probe),
|
||||
PageRequest.of(1, 2, Sort.Direction.DESC, "rate"));
|
||||
|
||||
// then
|
||||
assertThat(sampleEntities).isNotNull().hasSize(2);
|
||||
}
|
||||
// then
|
||||
assertThat(page1).isNotNull().hasSize(2).containsExactly(sampleEntity2, sampleEntity3);
|
||||
assertThat(page2).isNotNull().hasSize(1).containsExactly(sampleEntity);
|
||||
}
|
||||
|
||||
@Test // #2418
|
||||
void shouldCount() {
|
||||
// given
|
||||
String documentId = nextIdAsString();
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(documentId);
|
||||
sampleEntity.setMessage("some message");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
|
||||
String documentId2 = nextIdAsString();
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(documentId2);
|
||||
sampleEntity2.setMessage("some message");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2));
|
||||
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
probe.setDocumentId(documentId2);
|
||||
final long count = repository.count(Example.of(probe));
|
||||
|
||||
// then
|
||||
assertThat(count).isPositive();
|
||||
}
|
||||
|
||||
@Test // #2418
|
||||
void shouldExists() {
|
||||
// given
|
||||
String documentId = nextIdAsString();
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(documentId);
|
||||
sampleEntity.setMessage("some message");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
|
||||
String documentId2 = nextIdAsString();
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(documentId2);
|
||||
sampleEntity2.setMessage("some message");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2));
|
||||
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
probe.setDocumentId(documentId2);
|
||||
boolean exists = repository.exists(Example.of(probe));
|
||||
|
||||
// then
|
||||
assertThat(exists).isTrue();
|
||||
}
|
||||
|
||||
@Test // #2418
|
||||
void defaultStringMatcherShouldWork() {
|
||||
// given
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(nextIdAsString());
|
||||
sampleEntity.setMessage("hello world");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(nextIdAsString());
|
||||
sampleEntity2.setMessage("bye world");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntity3 = new SampleEntity();
|
||||
sampleEntity3.setDocumentId(nextIdAsString());
|
||||
sampleEntity3.setMessage("hola mundo");
|
||||
sampleEntity3.setVersion(System.currentTimeMillis());
|
||||
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2, sampleEntity3));
|
||||
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
probe.setMessage("hello world");
|
||||
Iterable<SampleEntity> sampleEntities = repository.findAll(Example.of(probe, ExampleMatcher.matching()
|
||||
.withMatcher("message", ExampleMatcher.GenericPropertyMatcher.of(ExampleMatcher.StringMatcher.DEFAULT))));
|
||||
|
||||
// then
|
||||
assertThat(sampleEntities).isNotNull().hasSize(1);
|
||||
}
|
||||
|
||||
@Test // #2418
|
||||
void exactStringMatcherShouldWork() {
|
||||
// given
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(nextIdAsString());
|
||||
sampleEntity.setMessage("hello world");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(nextIdAsString());
|
||||
sampleEntity2.setMessage("bye world");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntity3 = new SampleEntity();
|
||||
sampleEntity3.setDocumentId(nextIdAsString());
|
||||
sampleEntity3.setMessage("hola mundo");
|
||||
sampleEntity3.setVersion(System.currentTimeMillis());
|
||||
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2, sampleEntity3));
|
||||
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
probe.setMessage("bye world");
|
||||
Iterable<SampleEntity> sampleEntities = repository.findAll(Example.of(probe, ExampleMatcher.matching()
|
||||
.withMatcher("message", ExampleMatcher.GenericPropertyMatcher.of(ExampleMatcher.StringMatcher.EXACT))));
|
||||
|
||||
// then
|
||||
assertThat(sampleEntities).isNotNull().hasSize(1);
|
||||
}
|
||||
|
||||
@Test // #2418
|
||||
void startingStringMatcherShouldWork() {
|
||||
// given
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(nextIdAsString());
|
||||
sampleEntity.setMessage("hello world");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(nextIdAsString());
|
||||
sampleEntity2.setMessage("bye world");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntity3 = new SampleEntity();
|
||||
sampleEntity3.setDocumentId(nextIdAsString());
|
||||
sampleEntity3.setMessage("hola mundo");
|
||||
sampleEntity3.setVersion(System.currentTimeMillis());
|
||||
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2, sampleEntity3));
|
||||
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
probe.setMessage("h");
|
||||
Iterable<SampleEntity> sampleEntities = repository.findAll(Example.of(probe, ExampleMatcher.matching()
|
||||
.withMatcher("message", ExampleMatcher.GenericPropertyMatcher.of(ExampleMatcher.StringMatcher.STARTING))));
|
||||
|
||||
// then
|
||||
assertThat(sampleEntities).isNotNull().hasSize(2);
|
||||
}
|
||||
|
||||
@Test // #2418
|
||||
void endingStringMatcherShouldWork() {
|
||||
// given
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(nextIdAsString());
|
||||
sampleEntity.setMessage("hello world");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(nextIdAsString());
|
||||
sampleEntity2.setMessage("bye world");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntity3 = new SampleEntity();
|
||||
sampleEntity3.setDocumentId(nextIdAsString());
|
||||
sampleEntity3.setMessage("hola mundo");
|
||||
sampleEntity3.setVersion(System.currentTimeMillis());
|
||||
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2, sampleEntity3));
|
||||
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
probe.setMessage("world");
|
||||
Iterable<SampleEntity> sampleEntities = repository.findAll(Example.of(probe, ExampleMatcher.matching()
|
||||
.withMatcher("message", ExampleMatcher.GenericPropertyMatcher.of(ExampleMatcher.StringMatcher.ENDING))));
|
||||
|
||||
// then
|
||||
assertThat(sampleEntities).isNotNull().hasSize(2);
|
||||
}
|
||||
|
||||
@Test // #2418
|
||||
void regexStringMatcherShouldWork() {
|
||||
// given
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(nextIdAsString());
|
||||
sampleEntity.setMessage("hello world");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(nextIdAsString());
|
||||
sampleEntity2.setMessage("bye world");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntity3 = new SampleEntity();
|
||||
sampleEntity3.setDocumentId(nextIdAsString());
|
||||
sampleEntity3.setMessage("hola mundo");
|
||||
sampleEntity3.setVersion(System.currentTimeMillis());
|
||||
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2, sampleEntity3));
|
||||
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
probe.setMessage("[(hello)(hola)].*");
|
||||
Iterable<SampleEntity> sampleEntities = repository.findAll(Example.of(probe, ExampleMatcher.matching()
|
||||
.withMatcher("message", ExampleMatcher.GenericPropertyMatcher.of(ExampleMatcher.StringMatcher.REGEX))));
|
||||
|
||||
// then
|
||||
assertThat(sampleEntities).isNotNull().hasSize(2);
|
||||
}
|
||||
|
||||
@Document(indexName = "#{@indexNameProvider.indexName()}")
|
||||
|
@ -15,9 +15,16 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.repository.support.querybyexample;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.data.elasticsearch.utils.IdGenerator.*;
|
||||
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.IncorrectResultSizeDataAccessException;
|
||||
@ -36,13 +43,6 @@ import org.springframework.data.elasticsearch.repository.ReactiveElasticsearchRe
|
||||
import org.springframework.data.elasticsearch.utils.IndexNameProvider;
|
||||
import org.springframework.data.repository.query.ReactiveQueryByExampleExecutor;
|
||||
import org.springframework.lang.Nullable;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.data.elasticsearch.utils.IdGenerator.nextIdAsString;
|
||||
|
||||
/**
|
||||
* @author Ezequiel Antúnez Camacho
|
||||
@ -58,430 +58,418 @@ abstract class ReactiveQueryByExampleElasticsearchExecutorIntegrationTests {
|
||||
@BeforeEach
|
||||
void before() {
|
||||
indexNameProvider.increment();
|
||||
operations.indexOps(SampleEntity.class).createWithMapping()
|
||||
operations.indexOps(SampleEntity.class).createWithMapping().as(StepVerifier::create) //
|
||||
.expectNext(true) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test // #2418
|
||||
@Order(Integer.MAX_VALUE)
|
||||
void cleanup() {
|
||||
operations.indexOps(IndexCoordinates.of(indexNameProvider.getPrefix() + "*")).delete().block();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldFindOne() {
|
||||
// given
|
||||
String documentId = nextIdAsString();
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(documentId);
|
||||
sampleEntity.setMessage("some message");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
|
||||
String documentId2 = nextIdAsString();
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(documentId2);
|
||||
sampleEntity2.setMessage("some message");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2)) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNextCount(2L) //
|
||||
.verifyComplete();
|
||||
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
probe.setDocumentId(documentId2);
|
||||
repository.findOne(Example.of(probe))
|
||||
// then
|
||||
.as(StepVerifier::create) //
|
||||
.consumeNextWith(entityFromElasticSearch -> assertThat(entityFromElasticSearch).isEqualTo(sampleEntity2)) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldThrowExceptionIfMoreThanOneResultInFindOne() {
|
||||
// given
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(nextIdAsString());
|
||||
sampleEntity.setMessage("some message");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(nextIdAsString());
|
||||
sampleEntity2.setMessage("some message");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2)) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNextCount(2L) //
|
||||
.verifyComplete();
|
||||
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
repository.findOne(Example.of(probe))
|
||||
// then
|
||||
.as(StepVerifier::create) //
|
||||
.expectError(IncorrectResultSizeDataAccessException.class) //
|
||||
.verify();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldFindOneWithNestedField() {
|
||||
// given
|
||||
SampleEntity.SampleNestedEntity sampleNestedEntity = new SampleEntity.SampleNestedEntity();
|
||||
sampleNestedEntity.setNestedData("sampleNestedData");
|
||||
sampleNestedEntity.setAnotherNestedData("sampleAnotherNestedData");
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(nextIdAsString());
|
||||
sampleEntity.setMessage("some message");
|
||||
sampleEntity.setSampleNestedEntity(sampleNestedEntity);
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity.SampleNestedEntity sampleNestedEntity2 = new SampleEntity.SampleNestedEntity();
|
||||
sampleNestedEntity2.setNestedData("sampleNestedData2");
|
||||
sampleNestedEntity2.setAnotherNestedData("sampleAnotherNestedData2");
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(nextIdAsString());
|
||||
sampleEntity2.setMessage("some message");
|
||||
sampleEntity2.setSampleNestedEntity(sampleNestedEntity2);
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2)) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNextCount(2L) //
|
||||
.verifyComplete();
|
||||
|
||||
// when
|
||||
SampleEntity.SampleNestedEntity sampleNestedEntityProbe = new SampleEntity.SampleNestedEntity();
|
||||
sampleNestedEntityProbe.setNestedData("sampleNestedData");
|
||||
SampleEntity probe = new SampleEntity();
|
||||
probe.setSampleNestedEntity(sampleNestedEntityProbe);
|
||||
repository.findOne(Example.of(probe))
|
||||
// then
|
||||
.as(StepVerifier::create) //
|
||||
.expectNext(sampleEntity) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldFindAll() {
|
||||
// given
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(nextIdAsString());
|
||||
sampleEntity.setMessage("hello world");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(nextIdAsString());
|
||||
sampleEntity2.setMessage("hello world");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntity3 = new SampleEntity();
|
||||
sampleEntity3.setDocumentId(nextIdAsString());
|
||||
sampleEntity3.setMessage("bye world");
|
||||
sampleEntity3.setVersion(System.currentTimeMillis());
|
||||
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2, sampleEntity3)) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNextCount(3L) //
|
||||
.verifyComplete();
|
||||
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
probe.setMessage("hello world");
|
||||
repository.findAll(Example.of(probe))
|
||||
// then
|
||||
.as(StepVerifier::create) //
|
||||
.expectNextSequence(List.of(sampleEntity, sampleEntity2)) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldFindAllWithSort() {
|
||||
// given
|
||||
SampleEntity sampleEntityWithRate11 = new SampleEntity();
|
||||
sampleEntityWithRate11.setDocumentId(nextIdAsString());
|
||||
sampleEntityWithRate11.setMessage("hello world");
|
||||
sampleEntityWithRate11.setRate(11);
|
||||
sampleEntityWithRate11.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntityWithRate13 = new SampleEntity();
|
||||
sampleEntityWithRate13.setDocumentId(nextIdAsString());
|
||||
sampleEntityWithRate13.setMessage("hello world");
|
||||
sampleEntityWithRate13.setRate(13);
|
||||
sampleEntityWithRate13.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntityWithRate22 = new SampleEntity();
|
||||
sampleEntityWithRate22.setDocumentId(nextIdAsString());
|
||||
sampleEntityWithRate22.setMessage("hello world");
|
||||
sampleEntityWithRate22.setRate(22);
|
||||
sampleEntityWithRate22.setVersion(System.currentTimeMillis());
|
||||
|
||||
repository.saveAll(List.of(sampleEntityWithRate11, sampleEntityWithRate13, sampleEntityWithRate22)) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNextCount(3L) //
|
||||
.verifyComplete();
|
||||
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
repository.findAll(Example.of(probe), Sort.by(Sort.Direction.DESC, "rate"))
|
||||
// then
|
||||
.as(StepVerifier::create) //
|
||||
.expectNextSequence(List.of(sampleEntityWithRate22, sampleEntityWithRate13, sampleEntityWithRate11)) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldCount() {
|
||||
// given
|
||||
String documentId = nextIdAsString();
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(documentId);
|
||||
sampleEntity.setMessage("some message");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
|
||||
String documentId2 = nextIdAsString();
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(documentId2);
|
||||
sampleEntity2.setMessage("some message");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2)) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNextCount(2L) //
|
||||
.verifyComplete();
|
||||
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
probe.setDocumentId(documentId2);
|
||||
repository.count(Example.of(probe))
|
||||
// then
|
||||
.as(StepVerifier::create) //
|
||||
.expectNext(1L) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldExists() {
|
||||
// given
|
||||
String documentId = nextIdAsString();
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(documentId);
|
||||
sampleEntity.setMessage("some message");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
|
||||
String documentId2 = nextIdAsString();
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(documentId2);
|
||||
sampleEntity2.setMessage("some message");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2)) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNextCount(2L) //
|
||||
.verifyComplete();
|
||||
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
probe.setDocumentId(documentId2);
|
||||
repository.exists(Example.of(probe))
|
||||
// then
|
||||
.as(StepVerifier::create) //
|
||||
.expectNext(true) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test // #2418
|
||||
@org.junit.jupiter.api.Order(Integer.MAX_VALUE)
|
||||
void cleanup() {
|
||||
operations.indexOps(IndexCoordinates.of(indexNameProvider.getPrefix() + "*")).delete();
|
||||
void defaultStringMatcherShouldWork() {
|
||||
// given
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(nextIdAsString());
|
||||
sampleEntity.setMessage("hello world");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(nextIdAsString());
|
||||
sampleEntity2.setMessage("bye world");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntity3 = new SampleEntity();
|
||||
sampleEntity3.setDocumentId(nextIdAsString());
|
||||
sampleEntity3.setMessage("hola mundo");
|
||||
sampleEntity3.setVersion(System.currentTimeMillis());
|
||||
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2, sampleEntity3)) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNextCount(3L) //
|
||||
.verifyComplete();
|
||||
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
probe.setMessage("hello world");
|
||||
repository
|
||||
.findAll(Example.of(probe,
|
||||
ExampleMatcher.matching().withMatcher("message",
|
||||
ExampleMatcher.GenericPropertyMatcher.of(ExampleMatcher.StringMatcher.DEFAULT))))
|
||||
// then
|
||||
.as(StepVerifier::create) //
|
||||
.expectNext(sampleEntity) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Nested
|
||||
@DisplayName("All QueryByExampleExecutor operations should work")
|
||||
class ReactiveQueryByExampleExecutorOperations {
|
||||
@Test
|
||||
void shouldFindOne() {
|
||||
// given
|
||||
String documentId = nextIdAsString();
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(documentId);
|
||||
sampleEntity.setMessage("some message");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
@Test // #2418
|
||||
void exactStringMatcherShouldWork() {
|
||||
// given
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(nextIdAsString());
|
||||
sampleEntity.setMessage("hello world");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
|
||||
String documentId2 = nextIdAsString();
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(documentId2);
|
||||
sampleEntity2.setMessage("some message");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(nextIdAsString());
|
||||
sampleEntity2.setMessage("bye world");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2)) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNextCount(2L) //
|
||||
.verifyComplete();
|
||||
SampleEntity sampleEntity3 = new SampleEntity();
|
||||
sampleEntity3.setDocumentId(nextIdAsString());
|
||||
sampleEntity3.setMessage("hola mundo");
|
||||
sampleEntity3.setVersion(System.currentTimeMillis());
|
||||
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
probe.setDocumentId(documentId2);
|
||||
repository.findOne(Example.of(probe))
|
||||
// then
|
||||
.as(StepVerifier::create) //
|
||||
.consumeNextWith(entityFromElasticSearch -> assertThat(entityFromElasticSearch).isEqualTo(sampleEntity2)) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldThrowExceptionIfMoreThanOneResultInFindOne() {
|
||||
// given
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(nextIdAsString());
|
||||
sampleEntity.setMessage("some message");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(nextIdAsString());
|
||||
sampleEntity2.setMessage("some message");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2)) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNextCount(2L) //
|
||||
.verifyComplete();
|
||||
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
repository.findOne(Example.of(probe))
|
||||
// then
|
||||
.as(StepVerifier::create) //
|
||||
.expectError(IncorrectResultSizeDataAccessException.class) //
|
||||
.verify();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldFindOneWithNestedField() {
|
||||
// given
|
||||
SampleEntity.SampleNestedEntity sampleNestedEntity = new SampleEntity.SampleNestedEntity();
|
||||
sampleNestedEntity.setNestedData("sampleNestedData");
|
||||
sampleNestedEntity.setAnotherNestedData("sampleAnotherNestedData");
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(nextIdAsString());
|
||||
sampleEntity.setMessage("some message");
|
||||
sampleEntity.setSampleNestedEntity(sampleNestedEntity);
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity.SampleNestedEntity sampleNestedEntity2 = new SampleEntity.SampleNestedEntity();
|
||||
sampleNestedEntity2.setNestedData("sampleNestedData2");
|
||||
sampleNestedEntity2.setAnotherNestedData("sampleAnotherNestedData2");
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(nextIdAsString());
|
||||
sampleEntity2.setMessage("some message");
|
||||
sampleEntity2.setSampleNestedEntity(sampleNestedEntity2);
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2)) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNextCount(2L) //
|
||||
.verifyComplete();
|
||||
|
||||
// when
|
||||
SampleEntity.SampleNestedEntity sampleNestedEntityProbe = new SampleEntity.SampleNestedEntity();
|
||||
sampleNestedEntityProbe.setNestedData("sampleNestedData");
|
||||
SampleEntity probe = new SampleEntity();
|
||||
probe.setSampleNestedEntity(sampleNestedEntityProbe);
|
||||
repository.findOne(Example.of(probe))
|
||||
// then
|
||||
.as(StepVerifier::create) //
|
||||
.expectNext(sampleEntity) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldFindAll() {
|
||||
// given
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(nextIdAsString());
|
||||
sampleEntity.setMessage("hello world");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(nextIdAsString());
|
||||
sampleEntity2.setMessage("hello world");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntity3 = new SampleEntity();
|
||||
sampleEntity3.setDocumentId(nextIdAsString());
|
||||
sampleEntity3.setMessage("bye world");
|
||||
sampleEntity3.setVersion(System.currentTimeMillis());
|
||||
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2, sampleEntity3)) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNextCount(3L) //
|
||||
.verifyComplete();
|
||||
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
probe.setMessage("hello world");
|
||||
repository.findAll(Example.of(probe))
|
||||
// then
|
||||
.as(StepVerifier::create) //
|
||||
.expectNextSequence(List.of(sampleEntity, sampleEntity2)) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldFindAllWithSort() {
|
||||
// given
|
||||
SampleEntity sampleEntityWithRate11 = new SampleEntity();
|
||||
sampleEntityWithRate11.setDocumentId(nextIdAsString());
|
||||
sampleEntityWithRate11.setMessage("hello world");
|
||||
sampleEntityWithRate11.setRate(11);
|
||||
sampleEntityWithRate11.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntityWithRate13 = new SampleEntity();
|
||||
sampleEntityWithRate13.setDocumentId(nextIdAsString());
|
||||
sampleEntityWithRate13.setMessage("hello world");
|
||||
sampleEntityWithRate13.setRate(13);
|
||||
sampleEntityWithRate13.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntityWithRate22 = new SampleEntity();
|
||||
sampleEntityWithRate22.setDocumentId(nextIdAsString());
|
||||
sampleEntityWithRate22.setMessage("hello world");
|
||||
sampleEntityWithRate22.setRate(22);
|
||||
sampleEntityWithRate22.setVersion(System.currentTimeMillis());
|
||||
|
||||
repository.saveAll(List.of(sampleEntityWithRate11, sampleEntityWithRate13, sampleEntityWithRate22)) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNextCount(3L) //
|
||||
.verifyComplete();
|
||||
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
repository.findAll(Example.of(probe), Sort.by(Sort.Direction.DESC, "rate"))
|
||||
// then
|
||||
.as(StepVerifier::create) //
|
||||
.expectNextSequence(List.of(sampleEntityWithRate22, sampleEntityWithRate13, sampleEntityWithRate11)) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldCount() {
|
||||
// given
|
||||
String documentId = nextIdAsString();
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(documentId);
|
||||
sampleEntity.setMessage("some message");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
|
||||
String documentId2 = nextIdAsString();
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(documentId2);
|
||||
sampleEntity2.setMessage("some message");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2)) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNextCount(2L) //
|
||||
.verifyComplete();
|
||||
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
probe.setDocumentId(documentId2);
|
||||
repository.count(Example.of(probe))
|
||||
// then
|
||||
.as(StepVerifier::create) //
|
||||
.expectNext(1L) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldExists() {
|
||||
// given
|
||||
String documentId = nextIdAsString();
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(documentId);
|
||||
sampleEntity.setMessage("some message");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
|
||||
String documentId2 = nextIdAsString();
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(documentId2);
|
||||
sampleEntity2.setMessage("some message");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2)) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNextCount(2L) //
|
||||
.verifyComplete();
|
||||
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
probe.setDocumentId(documentId2);
|
||||
repository.exists(Example.of(probe))
|
||||
// then
|
||||
.as(StepVerifier::create) //
|
||||
.expectNext(true) //
|
||||
.verifyComplete();
|
||||
}
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2, sampleEntity3)) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNextCount(3L) //
|
||||
.verifyComplete();
|
||||
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
probe.setMessage("bye world");
|
||||
repository
|
||||
.findAll(Example.of(probe,
|
||||
ExampleMatcher.matching().withMatcher("message",
|
||||
ExampleMatcher.GenericPropertyMatcher.of(ExampleMatcher.StringMatcher.EXACT))))
|
||||
// then
|
||||
.as(StepVerifier::create) //
|
||||
.expectNext(sampleEntity2) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Nested
|
||||
@DisplayName("All ExampleMatchers should work")
|
||||
class AllExampleMatchersShouldWork {
|
||||
@Test // #2418
|
||||
void startingStringMatcherShouldWork() {
|
||||
// given
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(nextIdAsString());
|
||||
sampleEntity.setMessage("hello world");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
|
||||
@Test // #2418
|
||||
void defaultStringMatcherShouldWork() {
|
||||
// given
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(nextIdAsString());
|
||||
sampleEntity.setMessage("hello world");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(nextIdAsString());
|
||||
sampleEntity2.setMessage("bye world");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(nextIdAsString());
|
||||
sampleEntity2.setMessage("bye world");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
SampleEntity sampleEntity3 = new SampleEntity();
|
||||
sampleEntity3.setDocumentId(nextIdAsString());
|
||||
sampleEntity3.setMessage("hola mundo");
|
||||
sampleEntity3.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntity3 = new SampleEntity();
|
||||
sampleEntity3.setDocumentId(nextIdAsString());
|
||||
sampleEntity3.setMessage("hola mundo");
|
||||
sampleEntity3.setVersion(System.currentTimeMillis());
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2, sampleEntity3)) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNextCount(3L) //
|
||||
.verifyComplete();
|
||||
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2, sampleEntity3)) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNextCount(3L) //
|
||||
.verifyComplete();
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
probe.setMessage("h");
|
||||
repository
|
||||
.findAll(Example.of(probe,
|
||||
ExampleMatcher.matching().withMatcher("message",
|
||||
ExampleMatcher.GenericPropertyMatcher.of(ExampleMatcher.StringMatcher.STARTING))))
|
||||
// then
|
||||
.as(StepVerifier::create) //
|
||||
.expectNextSequence(List.of(sampleEntity, sampleEntity3)) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
probe.setMessage("hello world");
|
||||
repository
|
||||
.findAll(Example.of(probe,
|
||||
ExampleMatcher.matching().withMatcher("message",
|
||||
ExampleMatcher.GenericPropertyMatcher.of(ExampleMatcher.StringMatcher.DEFAULT))))
|
||||
// then
|
||||
.as(StepVerifier::create) //
|
||||
.expectNext(sampleEntity) //
|
||||
.verifyComplete();
|
||||
}
|
||||
@Test // #2418
|
||||
void endingStringMatcherShouldWork() {
|
||||
// given
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(nextIdAsString());
|
||||
sampleEntity.setMessage("hello world");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
|
||||
@Test // #2418
|
||||
void exactStringMatcherShouldWork() {
|
||||
// given
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(nextIdAsString());
|
||||
sampleEntity.setMessage("hello world");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(nextIdAsString());
|
||||
sampleEntity2.setMessage("bye world");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(nextIdAsString());
|
||||
sampleEntity2.setMessage("bye world");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
SampleEntity sampleEntity3 = new SampleEntity();
|
||||
sampleEntity3.setDocumentId(nextIdAsString());
|
||||
sampleEntity3.setMessage("hola mundo");
|
||||
sampleEntity3.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntity3 = new SampleEntity();
|
||||
sampleEntity3.setDocumentId(nextIdAsString());
|
||||
sampleEntity3.setMessage("hola mundo");
|
||||
sampleEntity3.setVersion(System.currentTimeMillis());
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2, sampleEntity3)) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNextCount(3L) //
|
||||
.verifyComplete();
|
||||
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2, sampleEntity3)) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNextCount(3L) //
|
||||
.verifyComplete();
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
probe.setMessage("world");
|
||||
repository
|
||||
.findAll(Example.of(probe,
|
||||
ExampleMatcher.matching().withMatcher("message",
|
||||
ExampleMatcher.GenericPropertyMatcher.of(ExampleMatcher.StringMatcher.ENDING))))
|
||||
// then
|
||||
.as(StepVerifier::create) //
|
||||
.expectNextSequence(List.of(sampleEntity, sampleEntity2)) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
probe.setMessage("bye world");
|
||||
repository
|
||||
.findAll(Example.of(probe,
|
||||
ExampleMatcher.matching().withMatcher("message",
|
||||
ExampleMatcher.GenericPropertyMatcher.of(ExampleMatcher.StringMatcher.EXACT))))
|
||||
// then
|
||||
.as(StepVerifier::create) //
|
||||
.expectNext(sampleEntity2) //
|
||||
.verifyComplete();
|
||||
}
|
||||
@Test // #2418
|
||||
void regexStringMatcherShouldWork() {
|
||||
// given
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(nextIdAsString());
|
||||
sampleEntity.setMessage("hello world");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
|
||||
@Test // #2418
|
||||
void startingStringMatcherShouldWork() {
|
||||
// given
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(nextIdAsString());
|
||||
sampleEntity.setMessage("hello world");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(nextIdAsString());
|
||||
sampleEntity2.setMessage("bye world");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(nextIdAsString());
|
||||
sampleEntity2.setMessage("bye world");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
SampleEntity sampleEntity3 = new SampleEntity();
|
||||
sampleEntity3.setDocumentId(nextIdAsString());
|
||||
sampleEntity3.setMessage("hola mundo");
|
||||
sampleEntity3.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntity3 = new SampleEntity();
|
||||
sampleEntity3.setDocumentId(nextIdAsString());
|
||||
sampleEntity3.setMessage("hola mundo");
|
||||
sampleEntity3.setVersion(System.currentTimeMillis());
|
||||
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2, sampleEntity3)) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNextCount(3L) //
|
||||
.verifyComplete();
|
||||
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
probe.setMessage("h");
|
||||
repository
|
||||
.findAll(Example.of(probe,
|
||||
ExampleMatcher.matching().withMatcher("message",
|
||||
ExampleMatcher.GenericPropertyMatcher.of(ExampleMatcher.StringMatcher.STARTING))))
|
||||
// then
|
||||
.as(StepVerifier::create) //
|
||||
.expectNextSequence(List.of(sampleEntity, sampleEntity3)) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test // #2418
|
||||
void endingStringMatcherShouldWork() {
|
||||
// given
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(nextIdAsString());
|
||||
sampleEntity.setMessage("hello world");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(nextIdAsString());
|
||||
sampleEntity2.setMessage("bye world");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntity3 = new SampleEntity();
|
||||
sampleEntity3.setDocumentId(nextIdAsString());
|
||||
sampleEntity3.setMessage("hola mundo");
|
||||
sampleEntity3.setVersion(System.currentTimeMillis());
|
||||
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2, sampleEntity3)) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNextCount(3L) //
|
||||
.verifyComplete();
|
||||
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
probe.setMessage("world");
|
||||
repository
|
||||
.findAll(Example.of(probe,
|
||||
ExampleMatcher.matching().withMatcher("message",
|
||||
ExampleMatcher.GenericPropertyMatcher.of(ExampleMatcher.StringMatcher.ENDING))))
|
||||
// then
|
||||
.as(StepVerifier::create) //
|
||||
.expectNextSequence(List.of(sampleEntity, sampleEntity2)) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test // #2418
|
||||
void regexStringMatcherShouldWork() {
|
||||
// given
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setDocumentId(nextIdAsString());
|
||||
sampleEntity.setMessage("hello world");
|
||||
sampleEntity.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setDocumentId(nextIdAsString());
|
||||
sampleEntity2.setMessage("bye world");
|
||||
sampleEntity2.setVersion(System.currentTimeMillis());
|
||||
|
||||
SampleEntity sampleEntity3 = new SampleEntity();
|
||||
sampleEntity3.setDocumentId(nextIdAsString());
|
||||
sampleEntity3.setMessage("hola mundo");
|
||||
sampleEntity3.setVersion(System.currentTimeMillis());
|
||||
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2, sampleEntity3)) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNextCount(3L) //
|
||||
.verifyComplete();
|
||||
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
probe.setMessage("[(hello)(hola)].*");
|
||||
repository
|
||||
.findAll(Example.of(probe,
|
||||
ExampleMatcher.matching().withMatcher("message",
|
||||
ExampleMatcher.GenericPropertyMatcher.of(ExampleMatcher.StringMatcher.REGEX))))
|
||||
// then
|
||||
.as(StepVerifier::create) //
|
||||
.expectNextSequence(List.of(sampleEntity, sampleEntity3)) //
|
||||
.verifyComplete();
|
||||
}
|
||||
repository.saveAll(List.of(sampleEntity, sampleEntity2, sampleEntity3)) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNextCount(3L) //
|
||||
.verifyComplete();
|
||||
|
||||
// when
|
||||
SampleEntity probe = new SampleEntity();
|
||||
probe.setMessage("[(hello)(hola)].*");
|
||||
repository
|
||||
.findAll(Example.of(probe,
|
||||
ExampleMatcher.matching().withMatcher("message",
|
||||
ExampleMatcher.GenericPropertyMatcher.of(ExampleMatcher.StringMatcher.REGEX))))
|
||||
// then
|
||||
.as(StepVerifier::create) //
|
||||
.expectNextSequence(List.of(sampleEntity, sampleEntity3)) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Document(indexName = "#{@indexNameProvider.indexName()}")
|
||||
|
Loading…
x
Reference in New Issue
Block a user