refactor tests

Original Pull Request #2480
Closes #2479
This commit is contained in:
Peter-Josef Meisch 2023-02-25 13:38:50 +01:00 committed by GitHub
parent c9b8b1af19
commit 43ab49b5fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 752 additions and 777 deletions

1
.gitignore vendored
View File

@ -24,4 +24,5 @@ target
/zap.env /zap.env
/localdocker.env
.localdocker-env .localdocker-env

View File

@ -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,14 +63,11 @@ 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
@DisplayName("All QueryByExampleExecutor operations should work")
class QueryByExampleExecutorOperations {
@Test // #2418 @Test // #2418
void shouldFindOne() { void shouldFindOne() {
// given // given
@ -218,8 +213,7 @@ abstract class QueryByExampleElasticsearchExecutorIntegrationTests {
// when // when
SampleEntity probe = new SampleEntity(); SampleEntity probe = new SampleEntity();
final Iterable<SampleEntity> all = repository.findAll(); final Iterable<SampleEntity> all = repository.findAll();
Iterable<SampleEntity> sampleEntities = repository.findAll(Example.of(probe), Iterable<SampleEntity> sampleEntities = repository.findAll(Example.of(probe), Sort.by(Sort.Direction.DESC, "rate"));
Sort.by(Sort.Direction.DESC, "rate"));
// then // then
assertThat(sampleEntities).isNotNull().hasSize(3).containsExactly(sampleEntityWithRate22, sampleEntityWithRate13, assertThat(sampleEntities).isNotNull().hasSize(3).containsExactly(sampleEntityWithRate22, sampleEntityWithRate13,
@ -313,12 +307,6 @@ abstract class QueryByExampleElasticsearchExecutorIntegrationTests {
assertThat(exists).isTrue(); assertThat(exists).isTrue();
} }
}
@Nested
@DisplayName("All ExampleMatchers should work")
class AllExampleMatchersShouldWork {
@Test // #2418 @Test // #2418
void defaultStringMatcherShouldWork() { void defaultStringMatcherShouldWork() {
// given // given
@ -469,8 +457,6 @@ abstract class QueryByExampleElasticsearchExecutorIntegrationTests {
assertThat(sampleEntities).isNotNull().hasSize(2); assertThat(sampleEntities).isNotNull().hasSize(2);
} }
}
@Document(indexName = "#{@indexNameProvider.indexName()}") @Document(indexName = "#{@indexNameProvider.indexName()}")
static class SampleEntity { static class SampleEntity {
@Nullable @Nullable

View File

@ -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,21 +58,17 @@ 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) //
.as(StepVerifier::create) //
.expectNext(true) // .expectNext(true) //
.verifyComplete(); .verifyComplete();
} }
@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().block();
} }
@Nested
@DisplayName("All QueryByExampleExecutor operations should work")
class ReactiveQueryByExampleExecutorOperations {
@Test @Test
void shouldFindOne() { void shouldFindOne() {
// given // given
@ -296,12 +292,6 @@ abstract class ReactiveQueryByExampleElasticsearchExecutorIntegrationTests {
.verifyComplete(); .verifyComplete();
} }
}
@Nested
@DisplayName("All ExampleMatchers should work")
class AllExampleMatchersShouldWork {
@Test // #2418 @Test // #2418
void defaultStringMatcherShouldWork() { void defaultStringMatcherShouldWork() {
// given // given
@ -482,8 +472,6 @@ abstract class ReactiveQueryByExampleElasticsearchExecutorIntegrationTests {
.verifyComplete(); .verifyComplete();
} }
}
@Document(indexName = "#{@indexNameProvider.indexName()}") @Document(indexName = "#{@indexNameProvider.indexName()}")
static class SampleEntity { static class SampleEntity {
@Nullable @Nullable