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