From 8dbbc808871ee1f2bed99321af1e941302c3a72a Mon Sep 17 00:00:00 2001 From: Peter-Josef Meisch Date: Fri, 5 Jun 2020 21:25:01 +0200 Subject: [PATCH] DATAES-853 - Cleanup tests that do not delete test indices. Original PR: #476 --- .../data/elasticsearch/NestedObjectTests.java | 12 +++++++++--- .../EnableElasticsearchRepositoriesTests.java | 8 ++++++++ .../core/ElasticsearchTemplateTests.java | 2 ++ .../core/ReactiveElasticsearchTemplateTests.java | 4 +++- .../core/index/MappingBuilderTests.java | 4 +++- 5 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/springframework/data/elasticsearch/NestedObjectTests.java b/src/test/java/org/springframework/data/elasticsearch/NestedObjectTests.java index 05ac0838..64686a1a 100644 --- a/src/test/java/org/springframework/data/elasticsearch/NestedObjectTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/NestedObjectTests.java @@ -34,6 +34,7 @@ import java.util.Map; import org.apache.lucene.search.join.ScoreMode; import org.elasticsearch.index.query.BoolQueryBuilder; import org.elasticsearch.index.query.QueryBuilder; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -67,11 +68,16 @@ public class NestedObjectTests { @Autowired private ElasticsearchOperations operations; + private final List> entityClasses = Arrays.asList(Book.class, Person.class, PersonMultipleLevelNested.class); + @BeforeEach public void before() { - IndexInitializer.init(operations.indexOps(Book.class)); - IndexInitializer.init(operations.indexOps(Person.class)); - IndexInitializer.init(operations.indexOps(PersonMultipleLevelNested.class)); + entityClasses.stream().map(operations::indexOps).forEach(IndexInitializer::init); + } + + @AfterEach + void tearDown() { + entityClasses.forEach(clazz -> operations.indexOps(clazz).delete()); } @Test diff --git a/src/test/java/org/springframework/data/elasticsearch/config/notnested/EnableElasticsearchRepositoriesTests.java b/src/test/java/org/springframework/data/elasticsearch/config/notnested/EnableElasticsearchRepositoriesTests.java index 33f41c2f..38d656f9 100644 --- a/src/test/java/org/springframework/data/elasticsearch/config/notnested/EnableElasticsearchRepositoriesTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/config/notnested/EnableElasticsearchRepositoriesTests.java @@ -24,6 +24,7 @@ import java.lang.Double; import java.lang.Long; import java.util.UUID; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.BeansException; @@ -42,6 +43,7 @@ import org.springframework.data.elasticsearch.annotations.ScriptedField; import org.springframework.data.elasticsearch.core.ElasticsearchOperations; import org.springframework.data.elasticsearch.core.IndexOperations; import org.springframework.data.elasticsearch.core.geo.GeoPoint; +import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates; import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration; import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest; import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; @@ -90,6 +92,12 @@ public class EnableElasticsearchRepositoriesTests implements ApplicationContextA IndexInitializer.init(indexOperations); } + @AfterEach + void tearDown() { + operations.indexOps(IndexCoordinates.of("test-index-sample-config-not-nested")).delete(); + operations.indexOps(IndexCoordinates.of("test-index-uuid-keyed-config-not-nested")).delete(); + } + @Test public void bootstrapsRepository() { diff --git a/src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchTemplateTests.java b/src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchTemplateTests.java index a21057f8..89d96a02 100755 --- a/src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchTemplateTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchTemplateTests.java @@ -151,6 +151,8 @@ public abstract class ElasticsearchTemplateTests { operations.indexOps(IndexCoordinates.of(INDEX_3_NAME)).delete(); operations.indexOps(SearchHitsEntity.class).delete(); operations.indexOps(HighlightEntity.class).delete(); + operations.indexOps(OptimisticEntity.class).delete(); + operations.indexOps(OptimisticAndVersionedEntity.class).delete(); } @Test // DATAES-106 diff --git a/src/test/java/org/springframework/data/elasticsearch/core/ReactiveElasticsearchTemplateTests.java b/src/test/java/org/springframework/data/elasticsearch/core/ReactiveElasticsearchTemplateTests.java index 4bd1be85..ed640371 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/ReactiveElasticsearchTemplateTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/ReactiveElasticsearchTemplateTests.java @@ -119,7 +119,9 @@ public class ReactiveElasticsearchTemplateTests { } private void deleteIndices() { - TestUtils.deleteIndex(DEFAULT_INDEX, ALTERNATE_INDEX, "rx-template-test-index-this", "rx-template-test-index-that"); + TestUtils.deleteIndex(DEFAULT_INDEX, ALTERNATE_INDEX, "rx-template-test-index-this", "rx-template-test-index-that", + "test-index-reactive-optimistic-entity-template", + "test-index-reactive-optimistic-and-versioned-entity-template"); } @Test // DATAES-504 diff --git a/src/test/java/org/springframework/data/elasticsearch/core/index/MappingBuilderTests.java b/src/test/java/org/springframework/data/elasticsearch/core/index/MappingBuilderTests.java index b0f702c5..a8101bef 100644 --- a/src/test/java/org/springframework/data/elasticsearch/core/index/MappingBuilderTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/core/index/MappingBuilderTests.java @@ -47,6 +47,7 @@ import java.util.Set; import org.assertj.core.data.Percentage; import org.elasticsearch.search.suggest.completion.context.ContextMapping; import org.json.JSONException; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -91,8 +92,9 @@ public class MappingBuilderTests extends MappingContextBaseTests { @Autowired private ElasticsearchOperations operations; private IndexOperations indexOperations; + @AfterEach @BeforeEach - public void before() { + public void deleteIndices() { indexOperations = operations.indexOps(SimpleRecursiveEntity.class); indexOperations.delete(); operations.indexOps(StockPrice.class).delete();