From 9bf6b6a98497a5836047ec29aa285a8f96a435e3 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Wed, 25 Nov 2020 12:10:19 +0100 Subject: [PATCH] DATAES-976 - Polishing. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use deleteAllById(…) from deleteAll(…). Simplify implementation in SimpleReactiveElasticsearchRepository. Original pull request: #554. --- .../core/ElasticsearchRestTemplate.java | 2 +- .../SimpleElasticsearchRepository.java | 70 +++++++--------- ...SimpleReactiveElasticsearchRepository.java | 51 +++++------- ...eReactiveElasticsearchRepositoryTests.java | 82 +++++++++---------- ...asticsearchRepositoryIntegrationTests.java | 62 +++++++------- 5 files changed, 126 insertions(+), 141 deletions(-) diff --git a/src/main/java/org/springframework/data/elasticsearch/core/ElasticsearchRestTemplate.java b/src/main/java/org/springframework/data/elasticsearch/core/ElasticsearchRestTemplate.java index ce0d9f4d5..b679ef14e 100644 --- a/src/main/java/org/springframework/data/elasticsearch/core/ElasticsearchRestTemplate.java +++ b/src/main/java/org/springframework/data/elasticsearch/core/ElasticsearchRestTemplate.java @@ -166,7 +166,7 @@ public class ElasticsearchRestTemplate extends AbstractElasticsearchTemplate { public List multiGet(Query query, Class clazz, IndexCoordinates index) { Assert.notNull(index, "index must not be null"); - Assert.notEmpty(query.getIds(), "No Id define for Query"); + Assert.notEmpty(query.getIds(), "No Id defined for Query"); MultiGetRequest request = requestFactory.multiGetRequest(query, clazz, index); MultiGetResponse result = execute(client -> client.mget(request, RequestOptions.DEFAULT)); diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/support/SimpleElasticsearchRepository.java b/src/main/java/org/springframework/data/elasticsearch/repository/support/SimpleElasticsearchRepository.java index e232f8cd1..69d88a34a 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/support/SimpleElasticsearchRepository.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/support/SimpleElasticsearchRepository.java @@ -27,6 +27,7 @@ import org.elasticsearch.index.query.IdsQueryBuilder; import org.elasticsearch.index.query.QueryBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; @@ -37,7 +38,6 @@ import org.springframework.data.elasticsearch.core.IndexOperations; import org.springframework.data.elasticsearch.core.SearchHit; import org.springframework.data.elasticsearch.core.SearchHitSupport; import org.springframework.data.elasticsearch.core.SearchHits; -import org.springframework.data.elasticsearch.core.SearchPage; import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage; import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity; import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates; @@ -50,6 +50,7 @@ import org.springframework.data.util.StreamUtils; import org.springframework.data.util.Streamable; import org.springframework.lang.Nullable; import org.springframework.util.Assert; +import org.springframework.util.CollectionUtils; /** * Elasticsearch specific repository implementation. Likely to be used as target within @@ -151,14 +152,12 @@ public class SimpleElasticsearchRepository implements ElasticsearchReposi Assert.notNull(ids, "ids can't be null."); List result = new ArrayList<>(); - List stringIds = stringIdsRepresentation(ids); - - if (stringIds.isEmpty()) { + Query idQuery = getIdQuery(ids); + if (CollectionUtils.isEmpty(idQuery.getIds())) { return result; } - NativeSearchQuery query = new NativeSearchQueryBuilder().withIds(stringIds).build(); - List multiGetEntities = execute(operations -> operations.multiGet(query, entityClass, getIndexCoordinates())); + List multiGetEntities = execute(operations -> operations.multiGet(idQuery, entityClass, getIndexCoordinates())); if (multiGetEntities != null) { multiGetEntities.forEach(entity -> { @@ -290,32 +289,6 @@ public class SimpleElasticsearchRepository implements ElasticsearchReposi doDelete(extractIdFromBean(entity), operations.getEntityRouting(entity), getIndexCoordinates()); } - @Override - public void deleteAll(Iterable entities) { - - Assert.notNull(entities, "Cannot delete 'null' list."); - - IndexCoordinates indexCoordinates = getIndexCoordinates(); - IdsQueryBuilder idsQueryBuilder = idsQuery(); - for (T entity : entities) { - ID id = extractIdFromBean(entity); - if (id != null) { - idsQueryBuilder.addIds(stringIdRepresentation(id)); - } - } - - if (idsQueryBuilder.ids().isEmpty()) { - return; - } - - Query query = new NativeSearchQueryBuilder().withQuery(idsQueryBuilder).build(); - - executeAndRefresh((OperationsCallback) operations -> { - operations.delete(query, entityClass, indexCoordinates); - return null; - }); - } - @Override public void deleteAllById(Iterable ids) { @@ -324,23 +297,36 @@ public class SimpleElasticsearchRepository implements ElasticsearchReposi IndexCoordinates indexCoordinates = getIndexCoordinates(); IdsQueryBuilder idsQueryBuilder = idsQuery(); for (ID id : ids) { - if (id != null) { - idsQueryBuilder.addIds(stringIdRepresentation(id)); - } + idsQueryBuilder.addIds(stringIdRepresentation(id)); } if (idsQueryBuilder.ids().isEmpty()) { return; } - Query query = new NativeSearchQueryBuilder().withQuery(idsQueryBuilder).build(); - executeAndRefresh((OperationsCallback) operations -> { - operations.delete(query, entityClass, indexCoordinates); + operations.delete(new NativeSearchQueryBuilder().withQuery(idsQueryBuilder).build(), entityClass, + indexCoordinates); return null; }); } + @Override + public void deleteAll(Iterable entities) { + + Assert.notNull(entities, "Cannot delete 'null' list."); + + List ids = new ArrayList<>(); + for (T entity : entities) { + ID id = extractIdFromBean(entity); + if (id != null) { + ids.add(id); + } + } + + deleteAllById(ids); + } + private void doDelete(@Nullable ID id, @Nullable String routing, IndexCoordinates indexCoordinates) { if (id != null) { @@ -369,7 +355,7 @@ public class SimpleElasticsearchRepository implements ElasticsearchReposi return entityInformation.getId(entity); } - private List stringIdsRepresentation(Iterable ids) { + private List stringIdsRepresentation(Iterable ids) { Assert.notNull(ids, "ids can't be null."); @@ -385,6 +371,12 @@ public class SimpleElasticsearchRepository implements ElasticsearchReposi return operations.getIndexCoordinatesFor(entityClass); } + private Query getIdQuery(Iterable ids) { + List stringIds = stringIdsRepresentation(ids); + + return new NativeSearchQueryBuilder().withIds(stringIds).build(); + } + // region operations callback @FunctionalInterface public interface OperationsCallback { diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/support/SimpleReactiveElasticsearchRepository.java b/src/main/java/org/springframework/data/elasticsearch/repository/support/SimpleReactiveElasticsearchRepository.java index 85ea85268..aa7b4c3b3 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/support/SimpleReactiveElasticsearchRepository.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/support/SimpleReactiveElasticsearchRepository.java @@ -15,14 +15,15 @@ */ package org.springframework.data.elasticsearch.repository.support; +import org.elasticsearch.index.query.IdsQueryBuilder; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import org.elasticsearch.action.support.WriteRequest.RefreshPolicy; -import org.elasticsearch.index.query.QueryBuilders; import org.reactivestreams.Publisher; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.data.elasticsearch.core.ReactiveElasticsearchOperations; @@ -33,9 +34,7 @@ import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersiste import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates; import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder; import org.springframework.data.elasticsearch.core.query.Query; -import org.springframework.data.elasticsearch.core.query.StringQuery; import org.springframework.data.elasticsearch.repository.ReactiveElasticsearchRepository; -import org.springframework.data.util.Streamable; import org.springframework.util.Assert; /** @@ -167,7 +166,7 @@ public class SimpleReactiveElasticsearchRepository implements ReactiveEla Assert.notNull(idStream, "IdStream must not be null!"); return Flux.from(idStream) // - .map(ID::toString) // + .map(this::convertId) // .collectList() // .map(ids -> new NativeSearchQueryBuilder().withIds(ids).build()) // .flatMapMany(query -> { @@ -206,6 +205,20 @@ public class SimpleReactiveElasticsearchRepository implements ReactiveEla .then(doRefresh()); } + @Override + public Mono deleteAllById(Iterable ids) { + + Assert.notNull(ids, "Ids must not be null!"); + + return Flux.fromIterable(ids) // + .map(this::convertId) // + .collectList() // + .map(it -> new NativeSearchQueryBuilder().withQuery(new IdsQueryBuilder().addIds(it.toArray(new String[0]))) + .build()) + .flatMap(it -> operations.delete(it, entityInformation.getJavaType(), entityInformation.getIndexCoordinates())) // + .then(doRefresh()); + } + @Override public Mono deleteAll(Iterable entities) { @@ -213,36 +226,16 @@ public class SimpleReactiveElasticsearchRepository implements ReactiveEla return deleteAll(Flux.fromIterable(entities)); } - @Override - public Mono deleteAllById(Iterable ids) { - - Assert.notNull(ids, "Ids must not be null!"); - - return Mono.just(Streamable.of(ids) // - .map(this::convertId).toList() // - ).map(objects -> new StringQuery(QueryBuilders.idsQuery() // - .addIds(objects.toArray(new String[0])) // - .toString()) // - ).flatMap( - query -> operations.delete(query, entityInformation.getJavaType(), entityInformation.getIndexCoordinates())) // - .then(doRefresh()); - } - @Override public Mono deleteAll(Publisher entityStream) { Assert.notNull(entityStream, "EntityStream must not be null!"); return Flux.from(entityStream) // - .map(entity -> { - - ID id = entityInformation.getId(entity); - if (id == null) { - throw new IllegalStateException("Entity id must not be null!"); - } - return convertId(id); - }).collectList().map(objects -> new StringQuery(QueryBuilders.idsQuery() // - .addIds(objects.toArray(new String[0])) // - .toString())) // + .map(entityInformation::getRequiredId) // + .map(this::convertId) // + .collectList() // + .map(it -> new NativeSearchQueryBuilder().withQuery(new IdsQueryBuilder().addIds(it.toArray(new String[0]))) + .build()) .flatMap( query -> operations.delete(query, entityInformation.getJavaType(), entityInformation.getIndexCoordinates())) // .then(doRefresh()); diff --git a/src/test/java/org/springframework/data/elasticsearch/repository/support/SimpleReactiveElasticsearchRepositoryTests.java b/src/test/java/org/springframework/data/elasticsearch/repository/support/SimpleReactiveElasticsearchRepositoryTests.java index a6a0a432c..1e8194228 100644 --- a/src/test/java/org/springframework/data/elasticsearch/repository/support/SimpleReactiveElasticsearchRepositoryTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/repository/support/SimpleReactiveElasticsearchRepositoryTests.java @@ -15,7 +15,6 @@ */ package org.springframework.data.elasticsearch.repository.support; -import static java.util.Arrays.*; import static org.assertj.core.api.Assertions.*; import static org.springframework.data.elasticsearch.annotations.FieldType.*; import static org.springframework.data.elasticsearch.core.query.Query.*; @@ -31,6 +30,7 @@ import reactor.test.StepVerifier; import java.lang.Boolean; import java.lang.Long; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.stream.IntStream; @@ -69,7 +69,7 @@ import org.springframework.test.context.ContextConfiguration; */ @SpringIntegrationTest @ContextConfiguration(classes = { SimpleReactiveElasticsearchRepositoryTests.Config.class }) -public class SimpleReactiveElasticsearchRepositoryTests { +class SimpleReactiveElasticsearchRepositoryTests { @Configuration @Import({ ReactiveElasticsearchRestTemplateConfiguration.class }) @@ -82,7 +82,7 @@ public class SimpleReactiveElasticsearchRepositoryTests { @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") @Autowired ReactiveSampleEntityRepository repository; @BeforeEach - public void setUp() { + void setUp() { operations.indexOps(IndexCoordinates.of(INDEX)).delete().block(); } @@ -92,7 +92,7 @@ public class SimpleReactiveElasticsearchRepositoryTests { } @Test // DATAES-519 - public void saveShouldSaveSingleEntity() { + void saveShouldSaveSingleEntity() { repository.save(SampleEntity.builder().build()) // .map(SampleEntity::getId) // @@ -106,10 +106,10 @@ public class SimpleReactiveElasticsearchRepositoryTests { } @Test // DATAES-519 - public void saveShouldComputeMultipleEntities() { + void saveShouldComputeMultipleEntities() { repository - .saveAll(asList(SampleEntity.builder().build(), SampleEntity.builder().build(), + .saveAll(Arrays.asList(SampleEntity.builder().build(), SampleEntity.builder().build(), SampleEntity.builder().build())) // .map(SampleEntity::getId) // .flatMap(this::documentWithIdExistsInIndex) // @@ -121,14 +121,14 @@ public class SimpleReactiveElasticsearchRepositoryTests { } @Test // DATAES-519, DATAES-767, DATAES-822 - public void findByIdShouldErrorIfIndexDoesNotExist() { + void findByIdShouldErrorIfIndexDoesNotExist() { repository.findById("id-two") // .as(StepVerifier::create) // .expectError(ElasticsearchStatusException.class); } @Test // DATAES-519 - public void findShouldRetrieveSingleEntityById() { + void findShouldRetrieveSingleEntityById() { bulkIndex(SampleEntity.builder().id("id-one").build(), // SampleEntity.builder().id("id-two").build(), // @@ -141,7 +141,7 @@ public class SimpleReactiveElasticsearchRepositoryTests { } @Test // DATAES-519 - public void findByIdShouldCompleteIfNothingFound() { + void findByIdShouldCompleteIfNothingFound() { bulkIndex(SampleEntity.builder().id("id-one").build(), // SampleEntity.builder().id("id-two").build(), // @@ -153,7 +153,7 @@ public class SimpleReactiveElasticsearchRepositoryTests { } @Test // DATAES-720 - public void findAllShouldReturnAllElements() { + void findAllShouldReturnAllElements() { // make sure to be above the default page size of the Query interface int count = DEFAULT_PAGE_SIZE * 2; bulkIndex(IntStream.range(1, count + 1) // @@ -168,19 +168,19 @@ public class SimpleReactiveElasticsearchRepositoryTests { } @Test // DATAES-519 - public void findAllByIdByIdShouldCompleteIfIndexDoesNotExist() { - repository.findAllById(asList("id-two", "id-two")).as(StepVerifier::create).verifyComplete(); + void findAllByIdByIdShouldCompleteIfIndexDoesNotExist() { + repository.findAllById(Arrays.asList("id-two", "id-two")).as(StepVerifier::create).verifyComplete(); } @Test // DATAES-519 - public void findAllByIdShouldRetrieveMatchingDocuments() { + void findAllByIdShouldRetrieveMatchingDocuments() { bulkIndex(SampleEntity.builder().id("id-one").build(), // SampleEntity.builder().id("id-two").build(), // SampleEntity.builder().id("id-three").build()) // .block(); - repository.findAllById(asList("id-one", "id-two")) // + repository.findAllById(Arrays.asList("id-one", "id-two")) // .as(StepVerifier::create)// .expectNextMatches(entity -> entity.getId().equals("id-one") || entity.getId().equals("id-two")) // .expectNextMatches(entity -> entity.getId().equals("id-one") || entity.getId().equals("id-two")) // @@ -188,14 +188,14 @@ public class SimpleReactiveElasticsearchRepositoryTests { } @Test // DATAES-519 - public void findAllByIdShouldCompleteWhenNothingFound() { + void findAllByIdShouldCompleteWhenNothingFound() { bulkIndex(SampleEntity.builder().id("id-one").build(), // SampleEntity.builder().id("id-two").build(), // SampleEntity.builder().id("id-three").build()) // .block(); - repository.findAllById(asList("can't", "touch", "this")) // + repository.findAllById(Arrays.asList("can't", "touch", "this")) // .as(StepVerifier::create)// .verifyComplete(); } @@ -267,14 +267,14 @@ public class SimpleReactiveElasticsearchRepositoryTests { } @Test // DATAES-519, DATAES-767, DATAES-822 - public void countShouldErrorWhenIndexDoesNotExist() { + void countShouldErrorWhenIndexDoesNotExist() { repository.count() // .as(StepVerifier::create) // .expectError(ElasticsearchStatusException.class); } @Test // DATAES-519 - public void countShouldCountDocuments() { + void countShouldCountDocuments() { bulkIndex(SampleEntity.builder().id("id-one").build(), // SampleEntity.builder().id("id-two").build()) // @@ -284,7 +284,7 @@ public class SimpleReactiveElasticsearchRepositoryTests { } @Test // DATAES-519 - public void existsByIdShouldReturnTrueIfExists() { + void existsByIdShouldReturnTrueIfExists() { bulkIndex(SampleEntity.builder().id("id-one").message("message").build(), // SampleEntity.builder().id("id-two").message("test message").build(), // @@ -298,7 +298,7 @@ public class SimpleReactiveElasticsearchRepositoryTests { } @Test // DATAES-519 - public void existsByIdShouldReturnFalseIfNotExists() { + void existsByIdShouldReturnFalseIfNotExists() { bulkIndex(SampleEntity.builder().id("id-one").message("message").build(), // SampleEntity.builder().id("id-two").message("test message").build(), // @@ -312,7 +312,7 @@ public class SimpleReactiveElasticsearchRepositoryTests { } @Test // DATAES-519 - public void countShouldCountMatchingDocuments() { + void countShouldCountMatchingDocuments() { bulkIndex(SampleEntity.builder().id("id-one").message("message").build(), // SampleEntity.builder().id("id-two").message("test message").build(), // @@ -326,7 +326,7 @@ public class SimpleReactiveElasticsearchRepositoryTests { } @Test // DATAES-519 - public void existsShouldReturnTrueIfExists() { + void existsShouldReturnTrueIfExists() { bulkIndex(SampleEntity.builder().id("id-one").message("message").build(), // SampleEntity.builder().id("id-two").message("test message").build(), // @@ -340,7 +340,7 @@ public class SimpleReactiveElasticsearchRepositoryTests { } @Test // DATAES-519 - public void existsShouldReturnFalseIfNotExists() { + void existsShouldReturnFalseIfNotExists() { bulkIndex(SampleEntity.builder().id("id-one").message("message").build(), // SampleEntity.builder().id("id-two").message("test message").build(), // @@ -354,7 +354,7 @@ public class SimpleReactiveElasticsearchRepositoryTests { } @Test // DATAES-519 - public void deleteByIdShouldCompleteIfNothingDeleted() { + void deleteByIdShouldCompleteIfNothingDeleted() { bulkIndex(SampleEntity.builder().id("id-one").build(), // SampleEntity.builder().id("id-two").build()) // @@ -364,14 +364,14 @@ public class SimpleReactiveElasticsearchRepositoryTests { } @Test // DATAES-519, DATAES-767, DATAES-822, DATAES-678 - public void deleteByIdShouldCompleteWhenIndexDoesNotExist() { + void deleteByIdShouldCompleteWhenIndexDoesNotExist() { repository.deleteById("does-not-exist") // .as(StepVerifier::create) // .verifyComplete(); } @Test // DATAES-519 - public void deleteByIdShouldDeleteEntry() { + void deleteByIdShouldDeleteEntry() { SampleEntity toBeDeleted = SampleEntity.builder().id("id-two").build(); bulkIndex(SampleEntity.builder().id("id-one").build(), toBeDeleted) // @@ -383,19 +383,19 @@ public class SimpleReactiveElasticsearchRepositoryTests { } @Test // DATAES-976 - public void deleteAllByIdShouldDeleteEntry() { + void deleteAllByIdShouldDeleteEntry() { SampleEntity toBeDeleted = SampleEntity.builder().id("id-two").build(); bulkIndex(SampleEntity.builder().id("id-one").build(), toBeDeleted) // .block(); - repository.deleteAllById(asList(toBeDeleted.getId())).as(StepVerifier::create).verifyComplete(); + repository.deleteAllById(Collections.singletonList(toBeDeleted.getId())).as(StepVerifier::create).verifyComplete(); assertThat(documentWithIdExistsInIndex(toBeDeleted.getId()).block()).isFalse(); } @Test // DATAES-519 - public void deleteShouldDeleteEntry() { + void deleteShouldDeleteEntry() { SampleEntity toBeDeleted = SampleEntity.builder().id("id-two").build(); bulkIndex(SampleEntity.builder().id("id-one").build(), toBeDeleted) // @@ -407,7 +407,7 @@ public class SimpleReactiveElasticsearchRepositoryTests { } @Test // DATAES-519 - public void deleteAllShouldDeleteGivenEntries() { + void deleteAllShouldDeleteGivenEntries() { SampleEntity toBeDeleted = SampleEntity.builder().id("id-one").build(); SampleEntity hangInThere = SampleEntity.builder().id("id-two").build(); @@ -416,7 +416,7 @@ public class SimpleReactiveElasticsearchRepositoryTests { bulkIndex(toBeDeleted, hangInThere, toBeDeleted2) // .block(); - repository.deleteAll(asList(toBeDeleted, toBeDeleted2)).as(StepVerifier::create).verifyComplete(); + repository.deleteAll(Arrays.asList(toBeDeleted, toBeDeleted2)).as(StepVerifier::create).verifyComplete(); assertThat(documentWithIdExistsInIndex(toBeDeleted.getId()).block()).isFalse(); assertThat(documentWithIdExistsInIndex(toBeDeleted2.getId()).block()).isFalse(); @@ -424,7 +424,7 @@ public class SimpleReactiveElasticsearchRepositoryTests { } @Test // DATAES-519 - public void deleteAllShouldDeleteAllEntries() { + void deleteAllShouldDeleteAllEntries() { bulkIndex(SampleEntity.builder().id("id-one").build(), // SampleEntity.builder().id("id-two").build(), // @@ -440,7 +440,7 @@ public class SimpleReactiveElasticsearchRepositoryTests { } @Test // DATAES-519 - public void derivedFinderMethodShouldBeExecutedCorrectly() { + void derivedFinderMethodShouldBeExecutedCorrectly() { bulkIndex(SampleEntity.builder().id("id-one").message("message").build(), // SampleEntity.builder().id("id-two").message("test message").build(), // @@ -454,7 +454,7 @@ public class SimpleReactiveElasticsearchRepositoryTests { } @Test // DATAES-519 - public void derivedFinderMethodShouldBeExecutedCorrectlyWhenGivenPublisher() { + void derivedFinderMethodShouldBeExecutedCorrectlyWhenGivenPublisher() { bulkIndex(SampleEntity.builder().id("id-one").message("message").build(), // SampleEntity.builder().id("id-two").message("test message").build(), // @@ -468,7 +468,7 @@ public class SimpleReactiveElasticsearchRepositoryTests { } @Test // DATAES-519 - public void derivedFinderWithDerivedSortMethodShouldBeExecutedCorrectly() { + void derivedFinderWithDerivedSortMethodShouldBeExecutedCorrectly() { bulkIndex(SampleEntity.builder().id("id-one").message("test").rate(3).build(), // SampleEntity.builder().id("id-two").message("test test").rate(1).build(), // @@ -484,7 +484,7 @@ public class SimpleReactiveElasticsearchRepositoryTests { } @Test // DATAES-519 - public void derivedFinderMethodWithSortParameterShouldBeExecutedCorrectly() { + void derivedFinderMethodWithSortParameterShouldBeExecutedCorrectly() { bulkIndex(SampleEntity.builder().id("id-one").message("test").rate(3).build(), // SampleEntity.builder().id("id-two").message("test test").rate(1).build(), // @@ -500,7 +500,7 @@ public class SimpleReactiveElasticsearchRepositoryTests { } @Test // DATAES-519 - public void derivedFinderMethodWithPageableParameterShouldBeExecutedCorrectly() { + void derivedFinderMethodWithPageableParameterShouldBeExecutedCorrectly() { bulkIndex(SampleEntity.builder().id("id-one").message("test").rate(3).build(), // SampleEntity.builder().id("id-two").message("test test").rate(1).build(), // @@ -515,7 +515,7 @@ public class SimpleReactiveElasticsearchRepositoryTests { } @Test // DATAES-519 - public void derivedFinderMethodReturningMonoShouldBeExecutedCorrectly() { + void derivedFinderMethodReturningMonoShouldBeExecutedCorrectly() { bulkIndex(SampleEntity.builder().id("id-one").message("message").build(), // SampleEntity.builder().id("id-two").message("test message").build(), // @@ -529,7 +529,7 @@ public class SimpleReactiveElasticsearchRepositoryTests { } @Test // DATAES-519 - public void annotatedFinderMethodShouldBeExecutedCorrectly() { + void annotatedFinderMethodShouldBeExecutedCorrectly() { bulkIndex(SampleEntity.builder().id("id-one").message("message").build(), // SampleEntity.builder().id("id-two").message("test message").build(), // @@ -543,7 +543,7 @@ public class SimpleReactiveElasticsearchRepositoryTests { } @Test // DATAES-519 - public void derivedDeleteMethodShouldBeExecutedCorrectly() { + void derivedDeleteMethodShouldBeExecutedCorrectly() { bulkIndex(SampleEntity.builder().id("id-one").message("message").build(), // SampleEntity.builder().id("id-two").message("test message").build(), // @@ -561,7 +561,7 @@ public class SimpleReactiveElasticsearchRepositoryTests { } Mono bulkIndex(SampleEntity... entities) { - return operations.saveAll(asList(entities), IndexCoordinates.of(INDEX)).then(); + return operations.saveAll(Arrays.asList(entities), IndexCoordinates.of(INDEX)).then(); } interface ReactiveSampleEntityRepository extends ReactiveCrudRepository { diff --git a/src/test/java/org/springframework/data/elasticsearch/repository/support/simple/SimpleElasticsearchRepositoryIntegrationTests.java b/src/test/java/org/springframework/data/elasticsearch/repository/support/simple/SimpleElasticsearchRepositoryIntegrationTests.java index 75e67274a..06cd88948 100644 --- a/src/test/java/org/springframework/data/elasticsearch/repository/support/simple/SimpleElasticsearchRepositoryIntegrationTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/repository/support/simple/SimpleElasticsearchRepositoryIntegrationTests.java @@ -76,7 +76,7 @@ import org.springframework.test.context.ContextConfiguration; */ @SpringIntegrationTest @ContextConfiguration(classes = { SimpleElasticsearchRepositoryIntegrationTests.Config.class }) -public class SimpleElasticsearchRepositoryIntegrationTests { +class SimpleElasticsearchRepositoryIntegrationTests { @Configuration @Import({ ElasticsearchRestTemplateConfiguration.class }) @@ -91,7 +91,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests { private IndexOperations indexOperations; @BeforeEach - public void before() { + void before() { indexOperations = operations.indexOps(SampleEntity.class); IndexInitializer.init(indexOperations); } @@ -102,7 +102,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests { } @Test - public void shouldDoBulkIndexDocument() { + void shouldDoBulkIndexDocument() { // given String documentId1 = nextIdAsString(); @@ -129,7 +129,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests { } @Test - public void shouldSaveDocument() { + void shouldSaveDocument() { // given String documentId = nextIdAsString(); @@ -147,7 +147,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests { } @Test - public void throwExceptionWhenTryingToInsertWithVersionButWithoutId() { + void throwExceptionWhenTryingToInsertWithVersionButWithoutId() { // given SampleEntity sampleEntity = new SampleEntity(); @@ -159,7 +159,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests { } @Test - public void shouldFindDocumentById() { + void shouldFindDocumentById() { // given String documentId = nextIdAsString(); @@ -178,7 +178,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests { } @Test - public void shouldReturnCountOfDocuments() { + void shouldReturnCountOfDocuments() { // given String documentId = nextIdAsString(); @@ -196,7 +196,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests { } @Test - public void shouldFindAllDocuments() { + void shouldFindAllDocuments() { // when Iterable results = repository.findAll(); @@ -206,7 +206,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests { } @Test - public void shouldDeleteDocument() { + void shouldDeleteDocument() { // given String documentId = nextIdAsString(); @@ -225,7 +225,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests { } @Test - public void shouldSearchDocumentsGivenSearchQuery() { + void shouldSearchDocumentsGivenSearchQuery() { // given String documentId = nextIdAsString(); @@ -246,7 +246,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests { } @Test - public void shouldSearchDocumentsGivenElasticsearchQuery() { + void shouldSearchDocumentsGivenElasticsearchQuery() { // given String documentId = nextIdAsString(); @@ -265,7 +265,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests { } @Test // DATAES-82 - public void shouldFindAllByIdQuery() { + void shouldFindAllByIdQuery() { // given String documentId = nextIdAsString(); @@ -290,7 +290,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests { } @Test - public void shouldSaveIterableEntities() { + void shouldSaveIterableEntities() { // given String documentId = nextIdAsString(); @@ -316,7 +316,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests { } @Test - public void shouldReturnTrueGivenDocumentWithIdExists() { + void shouldReturnTrueGivenDocumentWithIdExists() { // given String documentId = nextIdAsString(); @@ -334,7 +334,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests { } @Test // DATAES-363 - public void shouldReturnFalseGivenDocumentWithIdDoesNotExist() { + void shouldReturnFalseGivenDocumentWithIdDoesNotExist() { // given String documentId = nextIdAsString(); @@ -347,7 +347,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests { } @Test - public void shouldReturnResultsForGivenSearchQuery() { + void shouldReturnResultsForGivenSearchQuery() { // given String documentId = nextIdAsString(); @@ -366,7 +366,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests { } @Test - public void shouldDeleteAll() { + void shouldDeleteAll() { // given String documentId = nextIdAsString(); @@ -386,7 +386,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests { } @Test - public void shouldDeleteById() { + void shouldDeleteById() { // given String documentId = nextIdAsString(); @@ -407,7 +407,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests { } @Test //DATAES-976 - public void shouldDeleteAllById() { + void shouldDeleteAllById() { // given String id1 = nextIdAsString(); @@ -441,7 +441,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests { } @Test - public void shouldDeleteByMessageAndReturnList() { + void shouldDeleteByMessageAndReturnList() { // given String documentId = nextIdAsString(); @@ -477,7 +477,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests { } @Test - public void shouldDeleteByListForMessage() { + void shouldDeleteByListForMessage() { // given String documentId = nextIdAsString(); @@ -510,7 +510,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests { } @Test - public void shouldDeleteByType() { + void shouldDeleteByType() { // given String documentId = nextIdAsString(); @@ -542,7 +542,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests { } @Test - public void shouldDeleteEntity() { + void shouldDeleteEntity() { // given String documentId = nextIdAsString(); @@ -562,7 +562,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests { } @Test - public void shouldReturnIterableEntities() { + void shouldReturnIterableEntities() { // given String documentId1 = nextIdAsString(); @@ -587,7 +587,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests { } @Test - public void shouldDeleteIterableEntities() { + void shouldDeleteIterableEntities() { // given String documentId1 = nextIdAsString(); @@ -614,7 +614,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests { } @Test - public void shouldIndexEntity() { + void shouldIndexEntity() { // given String documentId = nextIdAsString(); @@ -632,7 +632,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests { } @Test - public void shouldIndexWithoutRefreshEntity() { + void shouldIndexWithoutRefreshEntity() { // given String documentId = nextIdAsString(); @@ -655,7 +655,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests { } @Test - public void shouldSortByGivenField() { + void shouldSortByGivenField() { // given String documentId = nextIdAsString(); @@ -678,7 +678,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests { } @Test - public void shouldReturnSimilarEntities() { + void shouldReturnSimilarEntities() { // given String sampleMessage = "So we build a web site or an application and want to add search to it, " @@ -699,7 +699,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests { } @Test // DATAES-142 - public void shouldIndexNotEmptyList() { + void shouldIndexNotEmptyList() { // given List list = new ArrayList<>(); String documentId = nextIdAsString(); @@ -720,7 +720,7 @@ public class SimpleElasticsearchRepositoryIntegrationTests { } @Test // DATAES-142 - public void shouldNotFailOnIndexingEmptyList() { + void shouldNotFailOnIndexingEmptyList() { Iterable savedEntities = repository.saveAll(Collections.emptyList()); assertThat(savedEntities).hasSize(0);