diff --git a/pom.xml b/pom.xml
index 6333b1cda..4b990ec3e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -289,7 +289,6 @@
test
-
diff --git a/src/main/java/org/springframework/data/elasticsearch/core/AbstractElasticsearchTemplate.java b/src/main/java/org/springframework/data/elasticsearch/core/AbstractElasticsearchTemplate.java
index 806d52842..5f71bb590 100644
--- a/src/main/java/org/springframework/data/elasticsearch/core/AbstractElasticsearchTemplate.java
+++ b/src/main/java/org/springframework/data/elasticsearch/core/AbstractElasticsearchTemplate.java
@@ -13,8 +13,10 @@ import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.search.MultiSearchRequest;
import org.elasticsearch.action.search.MultiSearchResponse;
import org.elasticsearch.action.search.SearchRequest;
+import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.index.query.MoreLikeThisQueryBuilder;
+import org.elasticsearch.search.suggest.SuggestBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
@@ -259,6 +261,8 @@ public abstract class AbstractElasticsearchTemplate implements ElasticsearchOper
abstract protected MultiSearchResponse.Item[] getMultiSearchResult(MultiSearchRequest request);
+ public abstract SearchResponse suggest(SuggestBuilder suggestion, IndexCoordinates index);
+
protected void setPersistentEntityId(Object entity, String id) {
ElasticsearchPersistentEntity> persistentEntity = getPersistentEntityFor(entity.getClass());
diff --git a/src/test/java/org/springframework/data/elasticsearch/NestedObjectTests.java b/src/test/java/org/springframework/data/elasticsearch/NestedObjectTests.java
index 5e9a37e7a..3afdbcc42 100644
--- a/src/test/java/org/springframework/data/elasticsearch/NestedObjectTests.java
+++ b/src/test/java/org/springframework/data/elasticsearch/NestedObjectTests.java
@@ -44,7 +44,7 @@ import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.annotations.InnerField;
import org.springframework.data.elasticsearch.annotations.MultiField;
-import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
+import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.IndexCoordinates;
import org.springframework.data.elasticsearch.core.query.GetQuery;
import org.springframework.data.elasticsearch.core.query.IndexQuery;
@@ -66,7 +66,7 @@ import org.springframework.test.context.ContextConfiguration;
@ContextConfiguration(classes = { ElasticsearchTemplateConfiguration.class })
public class NestedObjectTests {
- @Autowired private ElasticsearchTemplate elasticsearchTemplate;
+ @Autowired private ElasticsearchOperations elasticsearchTemplate;
@BeforeEach
public void before() {
@@ -123,7 +123,7 @@ public class NestedObjectTests {
indexQueries.add(indexQuery1);
indexQueries.add(indexQuery2);
- IndexCoordinates index = IndexCoordinates.of("test-index-person").withTypes( "user");
+ IndexCoordinates index = IndexCoordinates.of("test-index-person").withTypes("user");
elasticsearchTemplate.bulkIndex(indexQueries, index);
elasticsearchTemplate.refresh(Person.class);
@@ -144,14 +144,14 @@ public class NestedObjectTests {
// when
elasticsearchTemplate.bulkIndex(indexQueries,
- IndexCoordinates.of("test-index-person-multiple-level-nested").withTypes( "user"));
+ IndexCoordinates.of("test-index-person-multiple-level-nested").withTypes("user"));
elasticsearchTemplate.refresh(PersonMultipleLevelNested.class);
// then
GetQuery getQuery = new GetQuery();
getQuery.setId("1");
PersonMultipleLevelNested personIndexed = elasticsearchTemplate.get(getQuery, PersonMultipleLevelNested.class,
- IndexCoordinates.of("test-index-person-multiple-level-nested").withTypes( "user"));
+ IndexCoordinates.of("test-index-person-multiple-level-nested").withTypes("user"));
assertThat(personIndexed).isNotNull();
}
@@ -163,7 +163,7 @@ public class NestedObjectTests {
// when
elasticsearchTemplate.bulkIndex(indexQueries,
- IndexCoordinates.of("test-index-person-multiple-level-nested").withTypes( "user"));
+ IndexCoordinates.of("test-index-person-multiple-level-nested").withTypes("user"));
// then
Map mapping = elasticsearchTemplate.getMapping(PersonMultipleLevelNested.class);
@@ -182,9 +182,8 @@ public class NestedObjectTests {
List indexQueries = createPerson();
// when
- IndexCoordinates index = IndexCoordinates.of("test-index-person-multiple-level-nested").withTypes( "user");
- elasticsearchTemplate.bulkIndex(indexQueries,
- index);
+ IndexCoordinates index = IndexCoordinates.of("test-index-person-multiple-level-nested").withTypes("user");
+ elasticsearchTemplate.bulkIndex(indexQueries, index);
elasticsearchTemplate.refresh(PersonMultipleLevelNested.class);
// then
@@ -323,7 +322,7 @@ public class NestedObjectTests {
indexQueries.add(indexQuery1);
indexQueries.add(indexQuery2);
- IndexCoordinates index = IndexCoordinates.of("test-index-person").withTypes( "user");
+ IndexCoordinates index = IndexCoordinates.of("test-index-person").withTypes("user");
elasticsearchTemplate.bulkIndex(indexQueries, index);
elasticsearchTemplate.refresh(Person.class);
@@ -372,7 +371,7 @@ public class NestedObjectTests {
indexQueries.add(indexQuery2);
// when
- IndexCoordinates index = IndexCoordinates.of("test-index-book-nested-objects").withTypes( "book");
+ IndexCoordinates index = IndexCoordinates.of("test-index-book-nested-objects").withTypes("book");
elasticsearchTemplate.bulkIndex(indexQueries, index);
elasticsearchTemplate.refresh(Book.class);
diff --git a/src/test/java/org/springframework/data/elasticsearch/config/namespace/ElasticsearchNamespaceHandlerTests.java b/src/test/java/org/springframework/data/elasticsearch/config/namespace/ElasticsearchNamespaceHandlerTests.java
index 9c7d0aa8f..1618e0732 100644
--- a/src/test/java/org/springframework/data/elasticsearch/config/namespace/ElasticsearchNamespaceHandlerTests.java
+++ b/src/test/java/org/springframework/data/elasticsearch/config/namespace/ElasticsearchNamespaceHandlerTests.java
@@ -17,8 +17,8 @@ package org.springframework.data.elasticsearch.config.namespace;
import static org.assertj.core.api.Assertions.*;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.data.annotation.Id;
@@ -27,7 +27,7 @@ import org.springframework.data.elasticsearch.client.RestClientFactoryBean;
import org.springframework.data.elasticsearch.client.TransportClientFactoryBean;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
/**
* @author Rizwan Idrees
@@ -36,7 +36,7 @@ import org.springframework.test.context.junit4.SpringRunner;
* @author Peter-Josef Meisch
*/
-@RunWith(SpringRunner.class)
+@ExtendWith(SpringExtension.class)
@ContextConfiguration("namespace.xml")
public class ElasticsearchNamespaceHandlerTests {
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 41d45b138..348abe6e5 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
@@ -39,7 +39,7 @@ import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.annotations.Score;
import org.springframework.data.elasticsearch.annotations.ScriptedField;
-import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
+import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
@@ -70,10 +70,10 @@ public class EnableElasticsearchRepositoriesTests implements ApplicationContextA
@Configuration
@Import({ ElasticsearchTemplateConfiguration.class })
- @EnableElasticsearchRepositories(basePackages = { "org.springframework.data.elasticsearch.config.notnested" })
+ @EnableElasticsearchRepositories
static class Config {}
- @Autowired ElasticsearchTemplate elasticsearchTemplate;
+ @Autowired ElasticsearchOperations operations;
@Autowired private SampleElasticsearchRepository repository;
@@ -83,7 +83,7 @@ public class EnableElasticsearchRepositoriesTests implements ApplicationContextA
@BeforeEach
public void before() {
- IndexInitializer.init(elasticsearchTemplate, SampleEntity.class);
+ IndexInitializer.init(operations, SampleEntity.class);
}
@Test
diff --git a/src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchTemplateParentChildTests.java b/src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchTemplateParentChildTests.java
deleted file mode 100644
index d4d186d97..000000000
--- a/src/test/java/org/springframework/data/elasticsearch/core/ElasticsearchTemplateParentChildTests.java
+++ /dev/null
@@ -1,250 +0,0 @@
-/*
- * Copyright 2014-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.data.elasticsearch.core;
-
-import static org.assertj.core.api.Assertions.*;
-import static org.elasticsearch.common.xcontent.XContentFactory.*;
-import static org.elasticsearch.join.query.JoinQueryBuilders.*;
-
-import java.util.List;
-
-import org.apache.lucene.search.join.ScoreMode;
-import org.elasticsearch.action.RoutingMissingException;
-import org.elasticsearch.action.update.UpdateRequest;
-import org.elasticsearch.action.update.UpdateResponse;
-import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.index.query.QueryBuilder;
-import org.elasticsearch.index.query.QueryBuilders;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.core.style.ToStringCreator;
-import org.springframework.data.annotation.Id;
-import org.springframework.data.elasticsearch.annotations.Document;
-import org.springframework.data.elasticsearch.annotations.Field;
-import org.springframework.data.elasticsearch.annotations.FieldType;
-import org.springframework.data.elasticsearch.annotations.Parent;
-import org.springframework.data.elasticsearch.core.ElasticsearchTemplateParentChildTests.ParentEntity.ChildEntity;
-import org.springframework.data.elasticsearch.core.query.IndexQuery;
-import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
-import org.springframework.data.elasticsearch.core.query.UpdateQuery;
-import org.springframework.data.elasticsearch.utils.IndexInitializer;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringRunner;
-
-/**
- * @author Philipp Jardas
- * @author Peter-Josef Meisch
- */
-@RunWith(SpringRunner.class)
-@ContextConfiguration("classpath:elasticsearch-template-test.xml")
-public class ElasticsearchTemplateParentChildTests {
-
- @Autowired private ElasticsearchTemplate elasticsearchTemplate;
-
- @Before
- public void before() {
-
- IndexInitializer.init(elasticsearchTemplate, ParentEntity.class);
- IndexInitializer.init(elasticsearchTemplate, ChildEntity.class);
- }
-
- @Ignore(value = "DATAES-421")
- @Test
- public void shouldIndexParentChildEntity() {
-
- // index two parents
- ParentEntity parent1 = index("parent1", "First Parent");
- ParentEntity parent2 = index("parent2", "Second Parent");
-
- // index a child for each parent
- String child1name = "First";
- index("child1", parent1.getId(), child1name);
- index("child2", parent2.getId(), "Second");
-
- elasticsearchTemplate.refresh(ParentEntity.class);
- elasticsearchTemplate.refresh(ChildEntity.class);
-
- // find all parents that have the first child
- QueryBuilder query = hasChildQuery(ParentEntity.CHILD_TYPE,
- QueryBuilders.termQuery("name", child1name.toLowerCase()), ScoreMode.None);
- List parents = elasticsearchTemplate.queryForList(new NativeSearchQuery(query), ParentEntity.class, IndexCoordinates.of(ParentEntity.INDEX));
-
- // we're expecting only the first parent as result
- assertThat(parents).hasSize(1);
- assertThat(parents.get(0).getId()).isEqualTo(parent1.getId());
- }
-
- @Ignore(value = "DATAES-421")
- @Test
- public void shouldUpdateChild() throws Exception {
-
- // index parent and child
- ParentEntity parent = index("parent", "Parent");
- ChildEntity child = index("child", parent.getId(), "Child");
- String newChildName = "New Child Name";
-
- // update the child, not forgetting to set the parent id as routing parameter
- UpdateRequest updateRequest = new UpdateRequest(ParentEntity.INDEX, ParentEntity.CHILD_TYPE, child.getId());
- updateRequest.routing(parent.getId());
- XContentBuilder builder;
- builder = jsonBuilder().startObject().field("name", newChildName).endObject();
- updateRequest.doc(builder);
- UpdateResponse response = update(updateRequest, IndexCoordinates.of(ParentEntity.INDEX).withTypes( ParentEntity.CHILD_TYPE));
-
- assertThat(response.getShardInfo().getSuccessful()).isEqualTo(1);
- }
-
- @Ignore(value = "DATAES-421")
- @Test(expected = RoutingMissingException.class)
- public void shouldFailWithRoutingMissingExceptionOnUpdateChildIfNotRoutingSetOnUpdateRequest() throws Exception {
-
- // index parent and child
- ParentEntity parent = index("parent", "Parent");
- ChildEntity child = index("child", parent.getId(), "Child");
- String newChildName = "New Child Name";
-
- // update the child, forget routing parameter
- UpdateRequest updateRequest = new UpdateRequest(ParentEntity.INDEX, ParentEntity.CHILD_TYPE, child.getId());
- XContentBuilder builder;
- builder = jsonBuilder().startObject().field("name", newChildName).endObject();
- updateRequest.doc(builder);
- update(updateRequest, IndexCoordinates.of(ParentEntity.INDEX).withTypes( ParentEntity.CHILD_TYPE));
- }
-
- @Ignore(value = "DATAES-421")
- @Test(expected = RoutingMissingException.class)
- public void shouldFailWithRoutingMissingExceptionOnUpdateChildIfRoutingOnlySetOnRequestDoc() throws Exception {
-
- // index parent and child
- ParentEntity parent = index("parent", "Parent");
- ChildEntity child = index("child", parent.getId(), "Child");
- String newChildName = "New Child Name";
-
- // update the child
- UpdateRequest updateRequest = new UpdateRequest(ParentEntity.INDEX, ParentEntity.CHILD_TYPE, child.getId());
- XContentBuilder builder;
- builder = jsonBuilder().startObject().field("name", newChildName).endObject();
- updateRequest.doc(builder);
- updateRequest.doc().routing(parent.getId());
- update(updateRequest, IndexCoordinates.of(ParentEntity.INDEX).withTypes( ParentEntity.CHILD_TYPE));
- }
-
- private ParentEntity index(String parentId, String name) {
-
- ParentEntity parent = new ParentEntity(parentId, name);
- IndexQuery index = new IndexQuery();
- index.setId(parent.getId());
- index.setObject(parent);
- elasticsearchTemplate.index(index, IndexCoordinates.of(ParentEntity.INDEX).withTypes( ParentEntity.PARENT_TYPE));
-
- return parent;
- }
-
- private ChildEntity index(String childId, String parentId, String name) {
-
- ChildEntity child = new ChildEntity(childId, parentId, name);
- IndexQuery index = new IndexQuery();
- index.setId(child.getId());
- index.setObject(child);
- index.setParentId(child.getParentId());
- elasticsearchTemplate.index(index, IndexCoordinates.of(ParentEntity.INDEX).withTypes( ParentEntity.CHILD_TYPE));
-
- return child;
- }
-
- private UpdateResponse update(UpdateRequest updateRequest, IndexCoordinates index) {
-
- UpdateQuery update = new UpdateQuery();
- update.setId(updateRequest.id());
- update.setUpdateRequest(updateRequest);
- return elasticsearchTemplate.update(update, index);
- }
-
- /**
- * @author Philipp Jardas
- * @author Mohsin Husen
- */
- @Document(
- indexName = org.springframework.data.elasticsearch.core.ElasticsearchTemplateParentChildTests.ParentEntity.INDEX,
- type = org.springframework.data.elasticsearch.core.ElasticsearchTemplateParentChildTests.ParentEntity.PARENT_TYPE,
- shards = 1, replicas = 0, refreshInterval = "-1")
- static class ParentEntity {
-
- public static final String INDEX = "parent-child";
- public static final String PARENT_TYPE = "parent-entity";
- public static final String CHILD_TYPE = "child-entity";
-
- @Id private String id;
- @Field(type = FieldType.Text, store = true) private String name;
-
- public ParentEntity() {}
-
- public ParentEntity(String id, String name) {
- this.id = id;
- this.name = name;
- }
-
- public String getId() {
- return id;
- }
-
- public String getName() {
- return name;
- }
-
- @Override
- public String toString() {
- return new ToStringCreator(this).append("id", id).append("name", name).toString();
- }
-
- @Document(indexName = INDEX, type = CHILD_TYPE, shards = 1, replicas = 0, refreshInterval = "-1")
- static class ChildEntity {
-
- @Id private String id;
- @Field(type = FieldType.Text, store = true) @Parent(type = PARENT_TYPE) private String parentId;
- @Field(type = FieldType.Text, store = true) private String name;
-
- public ChildEntity() {}
-
- public ChildEntity(String id, String parentId, String name) {
- this.id = id;
- this.parentId = parentId;
- this.name = name;
- }
-
- public String getId() {
- return id;
- }
-
- public String getParentId() {
- return parentId;
- }
-
- public String getName() {
- return name;
- }
-
- @Override
- public String toString() {
- return new ToStringCreator(this).append("id", id).append("parentId", parentId).append("name", name).toString();
- }
- }
- }
-
-}
diff --git a/src/test/java/org/springframework/data/elasticsearch/core/LogEntityTests.java b/src/test/java/org/springframework/data/elasticsearch/core/LogEntityTests.java
index be4a527f6..46ddeec4d 100644
--- a/src/test/java/org/springframework/data/elasticsearch/core/LogEntityTests.java
+++ b/src/test/java/org/springframework/data/elasticsearch/core/LogEntityTests.java
@@ -27,17 +27,19 @@ import java.util.Arrays;
import java.util.Date;
import java.util.List;
-import org.elasticsearch.action.search.SearchPhaseExecutionException;
+import org.elasticsearch.ElasticsearchException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.core.query.IndexQuery;
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
-import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
+import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
import org.springframework.data.elasticsearch.utils.IndexInitializer;
import org.springframework.test.context.ContextConfiguration;
@@ -50,16 +52,20 @@ import org.springframework.test.context.ContextConfiguration;
* @author Peter-Josef Meisch
*/
@SpringIntegrationTest
-@ContextConfiguration(classes = { ElasticsearchTemplateConfiguration.class })
+@ContextConfiguration(classes = { LogEntityTests.Config.class })
public class LogEntityTests {
- private final IndexCoordinates index = IndexCoordinates.of("test-index-log-core").withTypes( "test-log-type");
- @Autowired private ElasticsearchTemplate template;
+ @Configuration
+ @Import({ ElasticsearchRestTemplateConfiguration.class })
+ static class Config {}
+
+ private final IndexCoordinates index = IndexCoordinates.of("test-index-log-core").withTypes("test-log-type");
+ @Autowired private ElasticsearchOperations operations;
@BeforeEach
public void before() throws ParseException {
- IndexInitializer.init(template, LogEntity.class);
+ IndexInitializer.init(operations, LogEntity.class);
SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
IndexQuery indexQuery1 = new LogEntityBuilder("1").action("update").date(dateFormatter.parse("2013-10-18 18:01"))
@@ -74,8 +80,8 @@ public class LogEntityTests {
IndexQuery indexQuery4 = new LogEntityBuilder("4").action("update").date(dateFormatter.parse("2013-10-19 18:04"))
.code(2).ip("10.10.10.4").buildIndex();
- template.bulkIndex(Arrays.asList(indexQuery1, indexQuery2, indexQuery3, indexQuery4), index);
- template.refresh(LogEntity.class);
+ operations.bulkIndex(Arrays.asList(indexQuery1, indexQuery2, indexQuery3, indexQuery4), index);
+ operations.refresh(LogEntity.class);
}
@Test // DATAES-66
@@ -83,7 +89,7 @@ public class LogEntityTests {
// when
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(termQuery("ip", "10.10.10.1")).build();
- List entities = template.queryForList(searchQuery, LogEntity.class, index);
+ List entities = operations.queryForList(searchQuery, LogEntity.class, index);
// then
assertThat(entities).isNotNull().hasSize(1);
@@ -96,8 +102,8 @@ public class LogEntityTests {
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(termQuery("ip", "10.10.10")).build();
assertThatThrownBy(() -> {
- List entities = template.queryForList(searchQuery, LogEntity.class, index);
- }).isInstanceOf(SearchPhaseExecutionException.class);
+ List entities = operations.queryForList(searchQuery, LogEntity.class, index);
+ }).isInstanceOf(ElasticsearchException.class);
}
@Test // DATAES-66
@@ -106,7 +112,7 @@ public class LogEntityTests {
// when
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder()
.withQuery(rangeQuery("ip").from("10.10.10.1").to("10.10.10.3")).build();
- List entities = template.queryForList(searchQuery, LogEntity.class, index);
+ List entities = operations.queryForList(searchQuery, LogEntity.class, index);
// then
assertThat(entities).isNotNull().hasSize(3);
diff --git a/src/test/java/org/springframework/data/elasticsearch/core/LogEntityTransportTests.java b/src/test/java/org/springframework/data/elasticsearch/core/LogEntityTransportTests.java
new file mode 100644
index 000000000..76e2e4d8c
--- /dev/null
+++ b/src/test/java/org/springframework/data/elasticsearch/core/LogEntityTransportTests.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2019 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.data.elasticsearch.core;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
+import org.springframework.test.context.ContextConfiguration;
+
+/**
+ * @author Peter-Josef Meisch
+ */
+@ContextConfiguration(classes = { LogEntityTransportTests.Config.class })
+public class LogEntityTransportTests extends LogEntityTests {
+ @Configuration
+ @Import({ ElasticsearchTemplateConfiguration.class })
+ static class Config {}
+}
diff --git a/src/test/java/org/springframework/data/elasticsearch/core/aggregation/ElasticsearchTemplateAggregationTests.java b/src/test/java/org/springframework/data/elasticsearch/core/aggregation/ElasticsearchTemplateAggregationTests.java
index 4f0a3dbdf..dc7150264 100644
--- a/src/test/java/org/springframework/data/elasticsearch/core/aggregation/ElasticsearchTemplateAggregationTests.java
+++ b/src/test/java/org/springframework/data/elasticsearch/core/aggregation/ElasticsearchTemplateAggregationTests.java
@@ -34,18 +34,20 @@ 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;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.InnerField;
import org.springframework.data.elasticsearch.annotations.MultiField;
-import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
+import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.IndexCoordinates;
import org.springframework.data.elasticsearch.core.ResultsExtractor;
import org.springframework.data.elasticsearch.core.query.IndexQuery;
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
-import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
+import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
import org.springframework.data.elasticsearch.utils.IndexInitializer;
import org.springframework.test.context.ContextConfiguration;
@@ -58,9 +60,13 @@ import org.springframework.test.context.ContextConfiguration;
* @author Peter-Josef Meisch
*/
@SpringIntegrationTest
-@ContextConfiguration(classes = { ElasticsearchTemplateConfiguration.class })
+@ContextConfiguration(classes = { ElasticsearchTemplateAggregationTests.Config.class })
public class ElasticsearchTemplateAggregationTests {
+ @Configuration
+ @Import({ ElasticsearchRestTemplateConfiguration.class })
+ static class Config {}
+
static final String RIZWAN_IDREES = "Rizwan Idrees";
static final String MOHSIN_HUSEN = "Mohsin Husen";
static final String JONATHAN_YAN = "Jonathan Yan";
@@ -70,12 +76,12 @@ public class ElasticsearchTemplateAggregationTests {
static final int YEAR_2000 = 2000;
static final String INDEX_NAME = "test-index-articles-core-aggregation";
- @Autowired private ElasticsearchTemplate elasticsearchTemplate;
+ @Autowired private ElasticsearchOperations operations;
@BeforeEach
public void before() {
- IndexInitializer.init(elasticsearchTemplate, ArticleEntity.class);
+ IndexInitializer.init(operations, ArticleEntity.class);
IndexQuery article1 = new ArticleEntityBuilder("1").title("article four").subject("computing")
.addAuthor(RIZWAN_IDREES).addAuthor(ARTUR_KONCZAK).addAuthor(MOHSIN_HUSEN).addAuthor(JONATHAN_YAN).score(10)
@@ -91,17 +97,17 @@ public class ElasticsearchTemplateAggregationTests {
.score(40).buildIndex();
IndexCoordinates index = IndexCoordinates.of(INDEX_NAME).withTypes("article");
- elasticsearchTemplate.index(article1, index);
- elasticsearchTemplate.index(article2, index);
- elasticsearchTemplate.index(article3, index);
- elasticsearchTemplate.index(article4, index);
- elasticsearchTemplate.refresh(ArticleEntity.class);
+ operations.index(article1, index);
+ operations.index(article2, index);
+ operations.index(article3, index);
+ operations.index(article4, index);
+ operations.refresh(ArticleEntity.class);
}
@AfterEach
public void after() {
- elasticsearchTemplate.deleteIndex(ArticleEntity.class);
+ operations.deleteIndex(ArticleEntity.class);
}
@Test
@@ -114,7 +120,7 @@ public class ElasticsearchTemplateAggregationTests {
.addAggregation(terms("subjects").field("subject")) //
.build();
// when
- Aggregations aggregations = elasticsearchTemplate.query(searchQuery, new ResultsExtractor() {
+ Aggregations aggregations = operations.query(searchQuery, new ResultsExtractor() {
@Override
public Aggregations extract(SearchResponse response) {
return response.getAggregations();
diff --git a/src/test/java/org/springframework/data/elasticsearch/core/aggregation/ElasticsearchTemplateAggregationTransportTests.java b/src/test/java/org/springframework/data/elasticsearch/core/aggregation/ElasticsearchTemplateAggregationTransportTests.java
new file mode 100644
index 000000000..b0f158f2d
--- /dev/null
+++ b/src/test/java/org/springframework/data/elasticsearch/core/aggregation/ElasticsearchTemplateAggregationTransportTests.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2019 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.data.elasticsearch.core.aggregation;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
+import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
+import org.springframework.test.context.ContextConfiguration;
+
+/**
+ * @author Peter-Josef Meisch
+ */
+@ContextConfiguration(classes = { ElasticsearchTemplateAggregationTransportTests.Config.class })
+public class ElasticsearchTemplateAggregationTransportTests extends ElasticsearchTemplateAggregationTests {
+ @Configuration
+ @Import({ ElasticsearchTemplateConfiguration.class })
+ @EnableElasticsearchRepositories(considerNestedRepositories = true)
+ static class Config {}
+}
diff --git a/src/test/java/org/springframework/data/elasticsearch/core/completion/ElasticsearchTemplateCompletionTests.java b/src/test/java/org/springframework/data/elasticsearch/core/completion/ElasticsearchTemplateCompletionTests.java
index 5a554b07c..03cfd7b25 100644
--- a/src/test/java/org/springframework/data/elasticsearch/core/completion/ElasticsearchTemplateCompletionTests.java
+++ b/src/test/java/org/springframework/data/elasticsearch/core/completion/ElasticsearchTemplateCompletionTests.java
@@ -28,13 +28,16 @@ import org.elasticsearch.search.suggest.SuggestionBuilder;
import org.elasticsearch.search.suggest.completion.CompletionSuggestion;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.CompletionField;
import org.springframework.data.elasticsearch.annotations.Document;
-import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
+import org.springframework.data.elasticsearch.core.AbstractElasticsearchTemplate;
+import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.IndexCoordinates;
import org.springframework.data.elasticsearch.core.query.IndexQuery;
-import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
+import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
import org.springframework.data.elasticsearch.utils.IndexInitializer;
import org.springframework.test.context.ContextConfiguration;
@@ -48,14 +51,18 @@ import org.springframework.test.context.ContextConfiguration;
* @author Peter-Josef Meisch
*/
@SpringIntegrationTest
-@ContextConfiguration(classes = { ElasticsearchTemplateConfiguration.class })
+@ContextConfiguration(classes = { ElasticsearchTemplateCompletionTests.Config.class })
public class ElasticsearchTemplateCompletionTests {
- @Autowired private ElasticsearchTemplate elasticsearchTemplate;
+ @Configuration
+ @Import({ ElasticsearchRestTemplateConfiguration.class })
+ static class Config {}
+
+ @Autowired private ElasticsearchOperations operations;
private void loadCompletionObjectEntities() {
- IndexInitializer.init(elasticsearchTemplate, CompletionEntity.class);
+ IndexInitializer.init(operations, CompletionEntity.class);
List indexQueries = new ArrayList<>();
indexQueries.add(
@@ -67,13 +74,13 @@ public class ElasticsearchTemplateCompletionTests {
indexQueries.add(new CompletionEntityBuilder("4").name("Artur Konczak").suggest(new String[] { "Artur", "Konczak" })
.buildIndex());
- elasticsearchTemplate.bulkIndex(indexQueries, IndexCoordinates.of("test-index-core-completion").withTypes( "completion-type"));
- elasticsearchTemplate.refresh(CompletionEntity.class);
+ operations.bulkIndex(indexQueries, IndexCoordinates.of("test-index-core-completion").withTypes("completion-type"));
+ operations.refresh(CompletionEntity.class);
}
private void loadAnnotatedCompletionObjectEntities() {
- IndexInitializer.init(elasticsearchTemplate, AnnotatedCompletionEntity.class);
+ IndexInitializer.init(operations, AnnotatedCompletionEntity.class);
NonDocumentEntity nonDocumentEntity = new NonDocumentEntity();
nonDocumentEntity.setSomeField1("foo");
@@ -89,14 +96,14 @@ public class ElasticsearchTemplateCompletionTests {
indexQueries.add(new AnnotatedCompletionEntityBuilder("4").name("Artur Konczak")
.suggest(new String[] { "Artur", "Konczak" }).buildIndex());
- elasticsearchTemplate.bulkIndex(indexQueries,
- IndexCoordinates.of("test-index-annotated-completion").withTypes( "annotated-completion-type"));
- elasticsearchTemplate.refresh(AnnotatedCompletionEntity.class);
+ operations.bulkIndex(indexQueries,
+ IndexCoordinates.of("test-index-annotated-completion").withTypes("annotated-completion-type"));
+ operations.refresh(AnnotatedCompletionEntity.class);
}
private void loadAnnotatedCompletionObjectEntitiesWithWeights() {
- IndexInitializer.init(elasticsearchTemplate, AnnotatedCompletionEntity.class);
+ IndexInitializer.init(operations, AnnotatedCompletionEntity.class);
List indexQueries = new ArrayList<>();
indexQueries.add(new AnnotatedCompletionEntityBuilder("1").name("Mewes Kochheim1")
@@ -108,9 +115,9 @@ public class ElasticsearchTemplateCompletionTests {
indexQueries.add(new AnnotatedCompletionEntityBuilder("4").name("Mewes Kochheim4")
.suggest(new String[] { "Mewes Kochheim4" }, Integer.MAX_VALUE).buildIndex());
- elasticsearchTemplate.bulkIndex(indexQueries,
- IndexCoordinates.of("test-index-annotated-completion").withTypes( "annotated-completion-type"));
- elasticsearchTemplate.refresh(AnnotatedCompletionEntity.class);
+ operations.bulkIndex(indexQueries,
+ IndexCoordinates.of("test-index-annotated-completion").withTypes("annotated-completion-type"));
+ operations.refresh(AnnotatedCompletionEntity.class);
}
@Test
@@ -118,10 +125,10 @@ public class ElasticsearchTemplateCompletionTests {
// given
Class entity = CompletionEntity.class;
- elasticsearchTemplate.createIndex(entity);
+ operations.createIndex(entity);
// when
- assertThat(elasticsearchTemplate.putMapping(entity)).isTrue();
+ assertThat(operations.putMapping(entity)).isTrue();
}
@Test
@@ -134,9 +141,9 @@ public class ElasticsearchTemplateCompletionTests {
Fuzziness.AUTO);
// when
- SearchResponse suggestResponse = elasticsearchTemplate.suggest(
+ SearchResponse suggestResponse = ((AbstractElasticsearchTemplate) operations).suggest(
new SuggestBuilder().addSuggestion("test-suggest", completionSuggestionFuzzyBuilder),
- IndexCoordinates.of("test-index-core-completion").withTypes( "completion-type"));
+ IndexCoordinates.of("test-index-core-completion").withTypes("completion-type"));
CompletionSuggestion completionSuggestion = suggestResponse.getSuggest().getSuggestion("test-suggest");
List options = completionSuggestion.getEntries().get(0).getOptions();
@@ -155,9 +162,9 @@ public class ElasticsearchTemplateCompletionTests {
Fuzziness.AUTO);
// when
- SearchResponse suggestResponse = elasticsearchTemplate.suggest(
+ SearchResponse suggestResponse = ((AbstractElasticsearchTemplate) operations).suggest(
new SuggestBuilder().addSuggestion("test-suggest", completionSuggestionFuzzyBuilder),
- IndexCoordinates.of("test-index-core-completion").withTypes( "completion-type"));
+ IndexCoordinates.of("test-index-core-completion").withTypes("completion-type"));
CompletionSuggestion completionSuggestion = suggestResponse.getSuggest().getSuggestion("test-suggest");
List options = completionSuggestion.getEntries().get(0).getOptions();
@@ -176,9 +183,9 @@ public class ElasticsearchTemplateCompletionTests {
Fuzziness.AUTO);
// when
- SearchResponse suggestResponse = elasticsearchTemplate.suggest(
+ SearchResponse suggestResponse = ((AbstractElasticsearchTemplate) operations).suggest(
new SuggestBuilder().addSuggestion("test-suggest", completionSuggestionFuzzyBuilder),
- IndexCoordinates.of("test-index-annotated-completion").withTypes( "annotated-completion-type"));
+ IndexCoordinates.of("test-index-annotated-completion").withTypes("annotated-completion-type"));
CompletionSuggestion completionSuggestion = suggestResponse.getSuggest().getSuggestion("test-suggest");
List options = completionSuggestion.getEntries().get(0).getOptions();
diff --git a/src/test/java/org/springframework/data/elasticsearch/core/completion/ElasticsearchTemplateCompletionTransportTests.java b/src/test/java/org/springframework/data/elasticsearch/core/completion/ElasticsearchTemplateCompletionTransportTests.java
new file mode 100644
index 000000000..239f19e24
--- /dev/null
+++ b/src/test/java/org/springframework/data/elasticsearch/core/completion/ElasticsearchTemplateCompletionTransportTests.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2019 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.data.elasticsearch.core.completion;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
+import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
+import org.springframework.test.context.ContextConfiguration;
+
+/**
+ * @author Peter-Josef Meisch
+ */
+@ContextConfiguration(classes = { ElasticsearchTemplateCompletionTransportTests.Config.class })
+public class ElasticsearchTemplateCompletionTransportTests extends ElasticsearchTemplateCompletionTests {
+ @Configuration
+ @Import({ ElasticsearchTemplateConfiguration.class })
+ @EnableElasticsearchRepositories(considerNestedRepositories = true)
+ static class Config {}
+}
diff --git a/src/test/java/org/springframework/data/elasticsearch/core/completion/ElasticsearchTemplateCompletionWithContextsTests.java b/src/test/java/org/springframework/data/elasticsearch/core/completion/ElasticsearchTemplateCompletionWithContextsTests.java
index b29564e77..75e2a0de2 100644
--- a/src/test/java/org/springframework/data/elasticsearch/core/completion/ElasticsearchTemplateCompletionWithContextsTests.java
+++ b/src/test/java/org/springframework/data/elasticsearch/core/completion/ElasticsearchTemplateCompletionWithContextsTests.java
@@ -35,14 +35,17 @@ import org.elasticsearch.search.suggest.completion.context.CategoryQueryContext;
import org.elasticsearch.search.suggest.completion.context.ContextMapping;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.CompletionContext;
import org.springframework.data.elasticsearch.annotations.CompletionField;
import org.springframework.data.elasticsearch.annotations.Document;
-import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
+import org.springframework.data.elasticsearch.core.AbstractElasticsearchTemplate;
+import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.IndexCoordinates;
import org.springframework.data.elasticsearch.core.query.IndexQuery;
-import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
+import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
import org.springframework.data.elasticsearch.utils.IndexInitializer;
import org.springframework.test.context.ContextConfiguration;
@@ -52,14 +55,18 @@ import org.springframework.test.context.ContextConfiguration;
* @author Peter-Josef Meisch
*/
@SpringIntegrationTest
-@ContextConfiguration(classes = { ElasticsearchTemplateConfiguration.class })
+@ContextConfiguration(classes = { ElasticsearchTemplateCompletionWithContextsTests.Config.class })
public class ElasticsearchTemplateCompletionWithContextsTests {
- @Autowired private ElasticsearchTemplate elasticsearchTemplate;
+ @Configuration
+ @Import({ ElasticsearchRestTemplateConfiguration.class })
+ static class Config {}
+
+ @Autowired private ElasticsearchOperations operations;
private void loadContextCompletionObjectEntities() {
- IndexInitializer.init(elasticsearchTemplate, ContextCompletionEntity.class);
+ IndexInitializer.init(operations, ContextCompletionEntity.class);
NonDocumentEntity nonDocumentEntity = new NonDocumentEntity();
nonDocumentEntity.setSomeField1("foo");
@@ -87,9 +94,9 @@ public class ElasticsearchTemplateCompletionWithContextsTests {
indexQueries.add(new ContextCompletionEntityBuilder("4").name("Artur Konczak")
.suggest(new String[] { "Artur", "Konczak" }, context4).buildIndex());
- elasticsearchTemplate.bulkIndex(indexQueries,
- IndexCoordinates.of("test-index-context-completion").withTypes( "context-completion-type"));
- elasticsearchTemplate.refresh(ContextCompletionEntity.class);
+ operations.bulkIndex(indexQueries,
+ IndexCoordinates.of("test-index-context-completion").withTypes("context-completion-type"));
+ operations.refresh(ContextCompletionEntity.class);
}
@Test
@@ -97,10 +104,10 @@ public class ElasticsearchTemplateCompletionWithContextsTests {
// given
Class> entity = ContextCompletionEntity.class;
- elasticsearchTemplate.createIndex(entity);
+ operations.createIndex(entity);
// when
- assertThat(elasticsearchTemplate.putMapping(entity)).isTrue();
+ assertThat(operations.putMapping(entity)).isTrue();
}
@Test // DATAES-536
@@ -123,9 +130,9 @@ public class ElasticsearchTemplateCompletionWithContextsTests {
((CompletionSuggestionBuilder) completionSuggestionFuzzyBuilder).contexts(contextMap);
// when
- SearchResponse suggestResponse = elasticsearchTemplate.suggest(
+ SearchResponse suggestResponse = ((AbstractElasticsearchTemplate) operations).suggest(
new SuggestBuilder().addSuggestion("test-suggest", completionSuggestionFuzzyBuilder),
- IndexCoordinates.of("test-index-context-completion").withTypes( "context-completion-type"));
+ IndexCoordinates.of("test-index-context-completion").withTypes("context-completion-type"));
assertThat(suggestResponse.getSuggest()).isNotNull();
CompletionSuggestion completionSuggestion = suggestResponse.getSuggest().getSuggestion("test-suggest");
List options = completionSuggestion.getEntries().get(0).getOptions();
@@ -155,9 +162,9 @@ public class ElasticsearchTemplateCompletionWithContextsTests {
((CompletionSuggestionBuilder) completionSuggestionFuzzyBuilder).contexts(contextMap);
// when
- SearchResponse suggestResponse = elasticsearchTemplate.suggest(
+ SearchResponse suggestResponse = ((AbstractElasticsearchTemplate) operations).suggest(
new SuggestBuilder().addSuggestion("test-suggest", completionSuggestionFuzzyBuilder),
- IndexCoordinates.of("test-index-context-completion").withTypes( "context-completion-type"));
+ IndexCoordinates.of("test-index-context-completion").withTypes("context-completion-type"));
assertThat(suggestResponse.getSuggest()).isNotNull();
CompletionSuggestion completionSuggestion = suggestResponse.getSuggest().getSuggestion("test-suggest");
List options = completionSuggestion.getEntries().get(0).getOptions();
@@ -187,9 +194,9 @@ public class ElasticsearchTemplateCompletionWithContextsTests {
((CompletionSuggestionBuilder) completionSuggestionFuzzyBuilder).contexts(contextMap);
// when
- SearchResponse suggestResponse = elasticsearchTemplate.suggest(
+ SearchResponse suggestResponse = ((AbstractElasticsearchTemplate) operations).suggest(
new SuggestBuilder().addSuggestion("test-suggest", completionSuggestionFuzzyBuilder),
- IndexCoordinates.of("test-index-context-completion").withTypes( "context-completion-type"));
+ IndexCoordinates.of("test-index-context-completion").withTypes("context-completion-type"));
assertThat(suggestResponse.getSuggest()).isNotNull();
CompletionSuggestion completionSuggestion = suggestResponse.getSuggest().getSuggestion("test-suggest");
List options = completionSuggestion.getEntries().get(0).getOptions();
diff --git a/src/test/java/org/springframework/data/elasticsearch/core/completion/ElasticsearchTemplateCompletionWithContextsTransportTests.java b/src/test/java/org/springframework/data/elasticsearch/core/completion/ElasticsearchTemplateCompletionWithContextsTransportTests.java
new file mode 100644
index 000000000..8f88d1d56
--- /dev/null
+++ b/src/test/java/org/springframework/data/elasticsearch/core/completion/ElasticsearchTemplateCompletionWithContextsTransportTests.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2019 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.data.elasticsearch.core.completion;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
+import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
+import org.springframework.test.context.ContextConfiguration;
+
+/**
+ * @author Peter-Josef Meisch
+ */
+@ContextConfiguration(classes = { ElasticsearchTemplateCompletionWithContextsTransportTests.Config.class })
+public class ElasticsearchTemplateCompletionWithContextsTransportTests
+ extends ElasticsearchTemplateCompletionWithContextsTests {
+ @Configuration
+ @Import({ ElasticsearchTemplateConfiguration.class })
+ @EnableElasticsearchRepositories(considerNestedRepositories = true)
+ static class Config {}
+}
diff --git a/src/test/java/org/springframework/data/elasticsearch/core/geo/ElasticsearchTemplateGeoTests.java b/src/test/java/org/springframework/data/elasticsearch/core/geo/ElasticsearchTemplateGeoTests.java
index 90200df56..39394a364 100644
--- a/src/test/java/org/springframework/data/elasticsearch/core/geo/ElasticsearchTemplateGeoTests.java
+++ b/src/test/java/org/springframework/data/elasticsearch/core/geo/ElasticsearchTemplateGeoTests.java
@@ -32,16 +32,18 @@ import org.elasticsearch.index.query.QueryBuilders;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.GeoPointField;
-import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
+import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.IndexCoordinates;
import org.springframework.data.elasticsearch.core.query.Criteria;
import org.springframework.data.elasticsearch.core.query.CriteriaQuery;
import org.springframework.data.elasticsearch.core.query.IndexQuery;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
-import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
+import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
import org.springframework.data.elasticsearch.utils.IndexInitializer;
import org.springframework.data.geo.Point;
@@ -59,21 +61,25 @@ import org.springframework.test.context.ContextConfiguration;
* Latitude , max Longitude , max Latitude
*/
@SpringIntegrationTest
-@ContextConfiguration(classes = { ElasticsearchTemplateConfiguration.class })
+@ContextConfiguration(classes = { ElasticsearchTemplateGeoTests.Config.class })
public class ElasticsearchTemplateGeoTests {
+ @Configuration
+ @Import({ ElasticsearchRestTemplateConfiguration.class })
+ static class Config {}
+
private final IndexCoordinates locationMarkerIndex = IndexCoordinates.of("test-index-location-marker-core-geo")
.withTypes("geo-annotation-point-type");
private final IndexCoordinates authorMarkerIndex = IndexCoordinates.of("test-index-author-marker-core-geo")
.withTypes("geo-class-point-type");
- @Autowired private ElasticsearchTemplate elasticsearchTemplate;
+ @Autowired private ElasticsearchOperations operations;
@BeforeEach
public void before() {
- IndexInitializer.init(elasticsearchTemplate, AuthorMarkerEntity.class);
- IndexInitializer.init(elasticsearchTemplate, LocationMarkerEntity.class);
+ IndexInitializer.init(operations, AuthorMarkerEntity.class);
+ IndexInitializer.init(operations, LocationMarkerEntity.class);
}
private void loadClassBaseEntities() {
@@ -83,8 +89,8 @@ public class ElasticsearchTemplateGeoTests {
.add(new AuthorMarkerEntityBuilder("1").name("Franck Marchand").location(45.7806d, 3.0875d).buildIndex());
indexQueries.add(new AuthorMarkerEntityBuilder("2").name("Mohsin Husen").location(51.5171d, 0.1062d).buildIndex());
indexQueries.add(new AuthorMarkerEntityBuilder("3").name("Rizwan Idrees").location(51.5171d, 0.1062d).buildIndex());
- elasticsearchTemplate.bulkIndex(indexQueries, authorMarkerIndex);
- elasticsearchTemplate.refresh(AuthorMarkerEntity.class);
+ operations.bulkIndex(indexQueries, authorMarkerIndex);
+ operations.refresh(AuthorMarkerEntity.class);
}
private void loadAnnotationBaseEntities() {
@@ -115,8 +121,8 @@ public class ElasticsearchTemplateGeoTests {
indexQueries.add(buildIndex(location2));
indexQueries.add(buildIndex(location3));
- elasticsearchTemplate.bulkIndex(indexQueries, locationMarkerIndex);
- elasticsearchTemplate.refresh(LocationMarkerEntity.class);
+ operations.bulkIndex(indexQueries, locationMarkerIndex);
+ operations.refresh(LocationMarkerEntity.class);
}
@Test
@@ -124,10 +130,10 @@ public class ElasticsearchTemplateGeoTests {
// given
Class> entity = AuthorMarkerEntity.class;
- elasticsearchTemplate.createIndex(entity);
+ operations.createIndex(entity);
// when
- assertThat(elasticsearchTemplate.putMapping(entity)).isTrue();
+ assertThat(operations.putMapping(entity)).isTrue();
}
@Test
@@ -139,7 +145,7 @@ public class ElasticsearchTemplateGeoTests {
new Criteria("location").within(new GeoPoint(45.7806d, 3.0875d), "20km"));
// when
- List geoAuthorsForGeoCriteria = elasticsearchTemplate.queryForList(geoLocationCriteriaQuery,
+ List geoAuthorsForGeoCriteria = operations.queryForList(geoLocationCriteriaQuery,
AuthorMarkerEntity.class, authorMarkerIndex);
// then
@@ -156,7 +162,7 @@ public class ElasticsearchTemplateGeoTests {
new Criteria("name").is("Mohsin Husen").and("location").within(new GeoPoint(51.5171d, 0.1062d), "20km"));
// when
- List geoAuthorsForGeoCriteria2 = elasticsearchTemplate.queryForList(geoLocationCriteriaQuery2,
+ List geoAuthorsForGeoCriteria2 = operations.queryForList(geoLocationCriteriaQuery2,
AuthorMarkerEntity.class, authorMarkerIndex);
// then
@@ -172,7 +178,7 @@ public class ElasticsearchTemplateGeoTests {
CriteriaQuery geoLocationCriteriaQuery = new CriteriaQuery(
new Criteria("locationAsString").within(new GeoPoint(51.000000, 0.100000), "1km"));
// when
- List geoAuthorsForGeoCriteria = elasticsearchTemplate.queryForList(geoLocationCriteriaQuery,
+ List geoAuthorsForGeoCriteria = operations.queryForList(geoLocationCriteriaQuery,
LocationMarkerEntity.class, locationMarkerIndex);
// then
@@ -188,7 +194,7 @@ public class ElasticsearchTemplateGeoTests {
new Criteria("locationAsArray").within(new GeoPoint(51.001000, 0.10100), "1km"));
// when
- List geoAuthorsForGeoCriteria = elasticsearchTemplate.queryForList(geoLocationCriteriaQuery,
+ List geoAuthorsForGeoCriteria = operations.queryForList(geoLocationCriteriaQuery,
LocationMarkerEntity.class, locationMarkerIndex);
// then
@@ -203,7 +209,7 @@ public class ElasticsearchTemplateGeoTests {
CriteriaQuery geoLocationCriteriaQuery = new CriteriaQuery(
new Criteria("locationAsArray").within("51.001000, 0.10100", "1km"));
// when
- List geoAuthorsForGeoCriteria = elasticsearchTemplate.queryForList(geoLocationCriteriaQuery,
+ List geoAuthorsForGeoCriteria = operations.queryForList(geoLocationCriteriaQuery,
LocationMarkerEntity.class, locationMarkerIndex);
// then
@@ -218,7 +224,7 @@ public class ElasticsearchTemplateGeoTests {
CriteriaQuery geoLocationCriteriaQuery = new CriteriaQuery(new Criteria("locationAsArray").within("u1044", "3km"));
// when
- List geoAuthorsForGeoCriteria = elasticsearchTemplate.queryForList(geoLocationCriteriaQuery,
+ List geoAuthorsForGeoCriteria = operations.queryForList(geoLocationCriteriaQuery,
LocationMarkerEntity.class, locationMarkerIndex);
// then
@@ -234,7 +240,7 @@ public class ElasticsearchTemplateGeoTests {
.withFilter(QueryBuilders.geoBoundingBoxQuery("locationAsArray").setCorners(52, -1, 50, 1));
// when
- List geoAuthorsForGeoCriteria = elasticsearchTemplate.queryForList(queryBuilder.build(),
+ List geoAuthorsForGeoCriteria = operations.queryForList(queryBuilder.build(),
LocationMarkerEntity.class, locationMarkerIndex);
// then
@@ -250,7 +256,7 @@ public class ElasticsearchTemplateGeoTests {
new Criteria("location").boundedBy(new GeoBox(new GeoPoint(53.5171d, 0), new GeoPoint(49.5171d, 0.2062d))));
// when
- List geoAuthorsForGeoCriteria3 = elasticsearchTemplate.queryForList(geoLocationCriteriaQuery3,
+ List geoAuthorsForGeoCriteria3 = operations.queryForList(geoLocationCriteriaQuery3,
AuthorMarkerEntity.class, authorMarkerIndex);
// then
@@ -268,7 +274,7 @@ public class ElasticsearchTemplateGeoTests {
new Criteria("location").boundedBy(Geohash.stringEncode(0, 53.5171d), Geohash.stringEncode(0.2062d, 49.5171d)));
// when
- List geoAuthorsForGeoCriteria3 = elasticsearchTemplate.queryForList(geoLocationCriteriaQuery3,
+ List geoAuthorsForGeoCriteria3 = operations.queryForList(geoLocationCriteriaQuery3,
AuthorMarkerEntity.class, authorMarkerIndex);
// then
@@ -286,7 +292,7 @@ public class ElasticsearchTemplateGeoTests {
new Criteria("location").boundedBy(new GeoPoint(53.5171d, 0), new GeoPoint(49.5171d, 0.2062d)));
// when
- List geoAuthorsForGeoCriteria3 = elasticsearchTemplate.queryForList(geoLocationCriteriaQuery3,
+ List geoAuthorsForGeoCriteria3 = operations.queryForList(geoLocationCriteriaQuery3,
AuthorMarkerEntity.class, authorMarkerIndex);
// then
@@ -304,7 +310,7 @@ public class ElasticsearchTemplateGeoTests {
new Criteria("location").boundedBy(new Point(53.5171d, 0), new Point(49.5171d, 0.2062d)));
// when
- List geoAuthorsForGeoCriteria3 = elasticsearchTemplate.queryForList(geoLocationCriteriaQuery3,
+ List geoAuthorsForGeoCriteria3 = operations.queryForList(geoLocationCriteriaQuery3,
AuthorMarkerEntity.class, authorMarkerIndex);
// then
@@ -332,18 +338,18 @@ public class ElasticsearchTemplateGeoTests {
.withFilter(QueryBuilders.geoBoundingBoxQuery("locationAsGeoHash").setCorners("u10j46mkfek"));
// when
- List result1 = elasticsearchTemplate.queryForList(location1.build(),
- LocationMarkerEntity.class, locationMarkerIndex);
- List result2 = elasticsearchTemplate.queryForList(location2.build(),
- LocationMarkerEntity.class, locationMarkerIndex);
- List result3 = elasticsearchTemplate.queryForList(location3.build(),
- LocationMarkerEntity.class, locationMarkerIndex);
- List result4 = elasticsearchTemplate.queryForList(location4.build(),
- LocationMarkerEntity.class, locationMarkerIndex);
- List result5 = elasticsearchTemplate.queryForList(location5.build(),
- LocationMarkerEntity.class, locationMarkerIndex);
- List result11 = elasticsearchTemplate.queryForList(location11.build(),
- LocationMarkerEntity.class, locationMarkerIndex);
+ List result1 = operations.queryForList(location1.build(), LocationMarkerEntity.class,
+ locationMarkerIndex);
+ List result2 = operations.queryForList(location2.build(), LocationMarkerEntity.class,
+ locationMarkerIndex);
+ List result3 = operations.queryForList(location3.build(), LocationMarkerEntity.class,
+ locationMarkerIndex);
+ List result4 = operations.queryForList(location4.build(), LocationMarkerEntity.class,
+ locationMarkerIndex);
+ List result5 = operations.queryForList(location5.build(), LocationMarkerEntity.class,
+ locationMarkerIndex);
+ List result11 = operations.queryForList(location11.build(), LocationMarkerEntity.class,
+ locationMarkerIndex);
// then
assertThat(result1).hasSize(3);
diff --git a/src/test/java/org/springframework/data/elasticsearch/core/geo/ElasticsearchTemplateGeoTransportTests.java b/src/test/java/org/springframework/data/elasticsearch/core/geo/ElasticsearchTemplateGeoTransportTests.java
new file mode 100644
index 000000000..b4067334c
--- /dev/null
+++ b/src/test/java/org/springframework/data/elasticsearch/core/geo/ElasticsearchTemplateGeoTransportTests.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2019 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.data.elasticsearch.core.geo;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
+import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
+import org.springframework.test.context.ContextConfiguration;
+
+/**
+ * @author Peter-Josef Meisch
+ */
+@ContextConfiguration(classes = { ElasticsearchTemplateGeoTransportTests.Config.class })
+public class ElasticsearchTemplateGeoTransportTests extends ElasticsearchTemplateGeoTests {
+ @Configuration
+ @Import({ ElasticsearchTemplateConfiguration.class })
+ @EnableElasticsearchRepositories(considerNestedRepositories = true)
+ static class Config {}
+}
diff --git a/src/test/java/org/springframework/data/elasticsearch/core/query/CriteriaQueryTests.java b/src/test/java/org/springframework/data/elasticsearch/core/query/CriteriaQueryTests.java
index 1ae67095e..d99b31b45 100644
--- a/src/test/java/org/springframework/data/elasticsearch/core/query/CriteriaQueryTests.java
+++ b/src/test/java/org/springframework/data/elasticsearch/core/query/CriteriaQueryTests.java
@@ -33,15 +33,17 @@ import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Version;
import org.springframework.data.domain.Page;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.Score;
-import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
+import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.IndexCoordinates;
-import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
+import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
import org.springframework.test.context.ContextConfiguration;
@@ -52,19 +54,24 @@ import org.springframework.test.context.ContextConfiguration;
* @author James Bodkin
*/
@SpringIntegrationTest
-@ContextConfiguration(classes = { ElasticsearchTemplateConfiguration.class })
+@ContextConfiguration(classes = { CriteriaQueryTests.Config.class })
public class CriteriaQueryTests {
- private final IndexCoordinates index = IndexCoordinates.of("test-index-sample-core-query").withTypes( "test-type");
- @Autowired private ElasticsearchTemplate elasticsearchTemplate;
+ @Configuration
+ @Import({ ElasticsearchRestTemplateConfiguration.class })
+ static class Config {}
+
+ private final IndexCoordinates index = IndexCoordinates.of("test-index-sample-core-query").withTypes("test-type");
+
+ @Autowired private ElasticsearchOperations operations;
@BeforeEach
public void before() {
- elasticsearchTemplate.deleteIndex(SampleEntity.class);
- elasticsearchTemplate.createIndex(SampleEntity.class);
- elasticsearchTemplate.putMapping(SampleEntity.class);
- elasticsearchTemplate.refresh(SampleEntity.class);
+ operations.deleteIndex(SampleEntity.class);
+ operations.createIndex(SampleEntity.class);
+ operations.putMapping(SampleEntity.class);
+ operations.refresh(SampleEntity.class);
}
@Test
@@ -80,13 +87,13 @@ public class CriteriaQueryTests {
IndexQuery indexQuery = new IndexQuery();
indexQuery.setId(documentId);
indexQuery.setObject(sampleEntity);
- elasticsearchTemplate.index(indexQuery, index);
- elasticsearchTemplate.refresh(SampleEntity.class);
+ operations.index(indexQuery, index);
+ operations.refresh(SampleEntity.class);
CriteriaQuery criteriaQuery = new CriteriaQuery(
new Criteria("message").contains("test").and("message").contains("some"));
// when
- SampleEntity sampleEntity1 = elasticsearchTemplate.queryForObject(criteriaQuery, SampleEntity.class, index);
+ SampleEntity sampleEntity1 = operations.queryForObject(criteriaQuery, SampleEntity.class, index);
// then
assertThat(sampleEntity1).isNotNull();
@@ -123,13 +130,13 @@ public class CriteriaQueryTests {
indexQuery2.setObject(sampleEntity2);
indexQueries.add(indexQuery2);
- elasticsearchTemplate.bulkIndex(indexQueries, index);
- elasticsearchTemplate.refresh(SampleEntity.class);
+ operations.bulkIndex(indexQueries, index);
+ operations.refresh(SampleEntity.class);
CriteriaQuery criteriaQuery = new CriteriaQuery(
new Criteria("message").contains("some").or("message").contains("test"));
// when
- Page page = elasticsearchTemplate.queryForPage(criteriaQuery, SampleEntity.class, index);
+ Page page = operations.queryForPage(criteriaQuery, SampleEntity.class, index);
// then
assertThat(page).isNotNull();
@@ -154,13 +161,13 @@ public class CriteriaQueryTests {
indexQuery.setObject(sampleEntity);
indexQueries.add(indexQuery);
- elasticsearchTemplate.bulkIndex(indexQueries, index);
- elasticsearchTemplate.refresh(SampleEntity.class);
+ operations.bulkIndex(indexQueries, index);
+ operations.refresh(SampleEntity.class);
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria().and(new Criteria("message").contains("some")));
// when
- Page page = elasticsearchTemplate.queryForPage(criteriaQuery, SampleEntity.class, index);
+ Page page = operations.queryForPage(criteriaQuery, SampleEntity.class, index);
// then
assertThat(page).isNotNull();
@@ -186,12 +193,12 @@ public class CriteriaQueryTests {
indexQuery.setObject(sampleEntity);
indexQueries.add(indexQuery);
- elasticsearchTemplate.bulkIndex(indexQueries, index);
- elasticsearchTemplate.refresh(SampleEntity.class);
+ operations.bulkIndex(indexQueries, index);
+ operations.refresh(SampleEntity.class);
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria().or(new Criteria("message").contains("some")));
// when
- Page page = elasticsearchTemplate.queryForPage(criteriaQuery, SampleEntity.class, index);
+ Page page = operations.queryForPage(criteriaQuery, SampleEntity.class, index);
// then
assertThat(page).isNotNull();
@@ -215,12 +222,12 @@ public class CriteriaQueryTests {
indexQuery.setObject(sampleEntity);
indexQueries.add(indexQuery);
- elasticsearchTemplate.bulkIndex(indexQueries, index);
- elasticsearchTemplate.refresh(SampleEntity.class);
+ operations.bulkIndex(indexQueries, index);
+ operations.refresh(SampleEntity.class);
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("message").is("some message"));
// when
- Page page = elasticsearchTemplate.queryForPage(criteriaQuery, SampleEntity.class, index);
+ Page page = operations.queryForPage(criteriaQuery, SampleEntity.class, index);
// then
assertThat(criteriaQuery.getCriteria().getField().getName()).isEqualTo("message");
@@ -257,12 +264,12 @@ public class CriteriaQueryTests {
indexQuery2.setObject(sampleEntity2);
indexQueries.add(indexQuery2);
- elasticsearchTemplate.bulkIndex(indexQueries, index);
- elasticsearchTemplate.refresh(SampleEntity.class);
+ operations.bulkIndex(indexQueries, index);
+ operations.refresh(SampleEntity.class);
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("message").is("some message"));
// when
- Page page = elasticsearchTemplate.queryForPage(criteriaQuery, SampleEntity.class, index);
+ Page page = operations.queryForPage(criteriaQuery, SampleEntity.class, index);
// then
assertThat(criteriaQuery.getCriteria().getField().getName()).isEqualTo("message");
@@ -299,13 +306,13 @@ public class CriteriaQueryTests {
indexQuery2.setObject(sampleEntity2);
indexQueries.add(indexQuery2);
- elasticsearchTemplate.bulkIndex(indexQueries, index);
- elasticsearchTemplate.refresh(SampleEntity.class);
+ operations.bulkIndex(indexQueries, index);
+ operations.refresh(SampleEntity.class);
Criteria criteria = new Criteria("message").endsWith("end");
CriteriaQuery criteriaQuery = new CriteriaQuery(criteria);
// when
- SampleEntity sampleEntity = elasticsearchTemplate.queryForObject(criteriaQuery, SampleEntity.class, index);
+ SampleEntity sampleEntity = operations.queryForObject(criteriaQuery, SampleEntity.class, index);
// then
assertThat(criteriaQuery.getCriteria().getField().getName()).isEqualTo("message");
@@ -341,13 +348,13 @@ public class CriteriaQueryTests {
indexQuery2.setObject(sampleEntity2);
indexQueries.add(indexQuery2);
- elasticsearchTemplate.bulkIndex(indexQueries, index);
- elasticsearchTemplate.refresh(SampleEntity.class);
+ operations.bulkIndex(indexQueries, index);
+ operations.refresh(SampleEntity.class);
Criteria criteria = new Criteria("message").startsWith("start");
CriteriaQuery criteriaQuery = new CriteriaQuery(criteria);
// when
- SampleEntity sampleEntity = elasticsearchTemplate.queryForObject(criteriaQuery, SampleEntity.class, index);
+ SampleEntity sampleEntity = operations.queryForObject(criteriaQuery, SampleEntity.class, index);
// then
assertThat(criteriaQuery.getCriteria().getField().getName()).isEqualTo("message");
@@ -383,12 +390,12 @@ public class CriteriaQueryTests {
indexQuery2.setObject(sampleEntity2);
indexQueries.add(indexQuery2);
- elasticsearchTemplate.bulkIndex(indexQueries, index);
- elasticsearchTemplate.refresh(SampleEntity.class);
+ operations.bulkIndex(indexQueries, index);
+ operations.refresh(SampleEntity.class);
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("message").contains("contains"));
// when
- SampleEntity sampleEntity = elasticsearchTemplate.queryForObject(criteriaQuery, SampleEntity.class, index);
+ SampleEntity sampleEntity = operations.queryForObject(criteriaQuery, SampleEntity.class, index);
// then
assertThat(criteriaQuery.getCriteria().getField().getName()).isEqualTo("message");
@@ -424,12 +431,12 @@ public class CriteriaQueryTests {
indexQuery2.setObject(sampleEntity2);
indexQueries.add(indexQuery2);
- elasticsearchTemplate.bulkIndex(indexQueries, index);
- elasticsearchTemplate.refresh(SampleEntity.class);
+ operations.bulkIndex(indexQueries, index);
+ operations.refresh(SampleEntity.class);
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("message").expression("+elasticsearch || test"));
// when
- SampleEntity sampleEntity = elasticsearchTemplate.queryForObject(criteriaQuery, SampleEntity.class, index);
+ SampleEntity sampleEntity = operations.queryForObject(criteriaQuery, SampleEntity.class, index);
// then
assertThat(criteriaQuery.getCriteria().getField().getName()).isEqualTo("message");
@@ -465,13 +472,13 @@ public class CriteriaQueryTests {
indexQuery2.setObject(sampleEntity2);
indexQueries.add(indexQuery2);
- elasticsearchTemplate.bulkIndex(indexQueries, index);
- elasticsearchTemplate.refresh(SampleEntity.class);
+ operations.bulkIndex(indexQueries, index);
+ operations.refresh(SampleEntity.class);
CriteriaQuery criteriaQuery = new CriteriaQuery(
new Criteria("message").startsWith("some").endsWith("search").contains("message").is("some message search"));
// when
- SampleEntity sampleEntity = elasticsearchTemplate.queryForObject(criteriaQuery, SampleEntity.class, index);
+ SampleEntity sampleEntity = operations.queryForObject(criteriaQuery, SampleEntity.class, index);
// then
assertThat(criteriaQuery.getCriteria().getField().getName()).isEqualTo("message");
@@ -507,12 +514,12 @@ public class CriteriaQueryTests {
indexQuery2.setObject(sampleEntity2);
indexQueries.add(indexQuery2);
- elasticsearchTemplate.bulkIndex(indexQueries, index);
- elasticsearchTemplate.refresh(SampleEntity.class);
+ operations.bulkIndex(indexQueries, index);
+ operations.refresh(SampleEntity.class);
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("message").is("foo").not());
// when
- Page page = elasticsearchTemplate.queryForPage(criteriaQuery, SampleEntity.class, index);
+ Page page = operations.queryForPage(criteriaQuery, SampleEntity.class, index);
// then
assertThat(criteriaQuery.getCriteria().isNegating()).isTrue();
@@ -551,12 +558,12 @@ public class CriteriaQueryTests {
indexQuery2.setObject(sampleEntity2);
indexQueries.add(indexQuery2);
- elasticsearchTemplate.bulkIndex(indexQueries, index);
- elasticsearchTemplate.refresh(SampleEntity.class);
+ operations.bulkIndex(indexQueries, index);
+ operations.refresh(SampleEntity.class);
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("rate").between(100, 150));
// when
- SampleEntity sampleEntity = elasticsearchTemplate.queryForObject(criteriaQuery, SampleEntity.class, index);
+ SampleEntity sampleEntity = operations.queryForObject(criteriaQuery, SampleEntity.class, index);
// then
assertThat(sampleEntity).isNotNull();
@@ -593,12 +600,12 @@ public class CriteriaQueryTests {
indexQuery2.setObject(sampleEntity2);
indexQueries.add(indexQuery2);
- elasticsearchTemplate.bulkIndex(indexQueries, index);
- elasticsearchTemplate.refresh(SampleEntity.class);
+ operations.bulkIndex(indexQueries, index);
+ operations.refresh(SampleEntity.class);
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("rate").between(350, null));
// when
- Page page = elasticsearchTemplate.queryForPage(criteriaQuery, SampleEntity.class, index);
+ Page page = operations.queryForPage(criteriaQuery, SampleEntity.class, index);
// then
assertThat(page).isNotNull();
@@ -636,12 +643,12 @@ public class CriteriaQueryTests {
indexQuery2.setObject(sampleEntity2);
indexQueries.add(indexQuery2);
- elasticsearchTemplate.bulkIndex(indexQueries, index);
- elasticsearchTemplate.refresh(SampleEntity.class);
+ operations.bulkIndex(indexQueries, index);
+ operations.refresh(SampleEntity.class);
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("rate").between(null, 550));
// when
- Page page = elasticsearchTemplate.queryForPage(criteriaQuery, SampleEntity.class, index);
+ Page page = operations.queryForPage(criteriaQuery, SampleEntity.class, index);
// then
assertThat(page).isNotNull();
@@ -679,12 +686,12 @@ public class CriteriaQueryTests {
indexQuery2.setObject(sampleEntity2);
indexQueries.add(indexQuery2);
- elasticsearchTemplate.bulkIndex(indexQueries, index);
- elasticsearchTemplate.refresh(SampleEntity.class);
+ operations.bulkIndex(indexQueries, index);
+ operations.refresh(SampleEntity.class);
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("rate").lessThanEqual(750));
// when
- Page page = elasticsearchTemplate.queryForPage(criteriaQuery, SampleEntity.class, index);
+ Page page = operations.queryForPage(criteriaQuery, SampleEntity.class, index);
// then
assertThat(page).isNotNull();
@@ -722,12 +729,12 @@ public class CriteriaQueryTests {
indexQuery2.setObject(sampleEntity2);
indexQueries.add(indexQuery2);
- elasticsearchTemplate.bulkIndex(indexQueries, index);
- elasticsearchTemplate.refresh(SampleEntity.class);
+ operations.bulkIndex(indexQueries, index);
+ operations.refresh(SampleEntity.class);
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("rate").greaterThanEqual(950));
// when
- Page page = elasticsearchTemplate.queryForPage(criteriaQuery, SampleEntity.class, index);
+ Page page = operations.queryForPage(criteriaQuery, SampleEntity.class, index);
// then
assertThat(page).isNotNull();
@@ -765,12 +772,12 @@ public class CriteriaQueryTests {
indexQuery2.setObject(sampleEntity2);
indexQueries.add(indexQuery2);
- elasticsearchTemplate.bulkIndex(indexQueries, index);
- elasticsearchTemplate.refresh(SampleEntity.class);
+ operations.bulkIndex(indexQueries, index);
+ operations.refresh(SampleEntity.class);
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("message").contains("foo").boost(1));
// when
- Page page = elasticsearchTemplate.queryForPage(criteriaQuery, SampleEntity.class, index);
+ Page page = operations.queryForPage(criteriaQuery, SampleEntity.class, index);
// then
assertThat(page.getTotalElements()).isGreaterThanOrEqualTo(1);
@@ -786,14 +793,14 @@ public class CriteriaQueryTests {
indexQueries.add(buildIndex(SampleEntity.builder().id("2").message("bc").build()));
indexQueries.add(buildIndex(SampleEntity.builder().id("3").message("ac").build()));
- elasticsearchTemplate.bulkIndex(indexQueries, index);
- elasticsearchTemplate.refresh(SampleEntity.class);
+ operations.bulkIndex(indexQueries, index);
+ operations.refresh(SampleEntity.class);
// when
CriteriaQuery criteriaQuery = new CriteriaQuery(
new Criteria("message").contains("a").or(new Criteria("message").contains("b")));
criteriaQuery.setMinScore(2.0F);
- Page page = elasticsearchTemplate.queryForPage(criteriaQuery, SampleEntity.class, index);
+ Page page = operations.queryForPage(criteriaQuery, SampleEntity.class, index);
// then
assertThat(page.getTotalElements()).isEqualTo(1);
@@ -813,13 +820,13 @@ public class CriteriaQueryTests {
IndexQuery indexQuery = new IndexQuery();
indexQuery.setId(documentId);
indexQuery.setObject(sampleEntity);
- elasticsearchTemplate.index(indexQuery, index);
- elasticsearchTemplate.refresh(SampleEntity.class);
+ operations.index(indexQuery, index);
+ operations.refresh(SampleEntity.class);
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("message").is("Hello World!"));
// when
- SampleEntity sampleEntity1 = elasticsearchTemplate.queryForObject(criteriaQuery, SampleEntity.class, index);
+ SampleEntity sampleEntity1 = operations.queryForObject(criteriaQuery, SampleEntity.class, index);
// then
assertThat(sampleEntity1).isNotNull();
diff --git a/src/test/java/org/springframework/data/elasticsearch/core/query/CriteriaQueryTestsTransport.java b/src/test/java/org/springframework/data/elasticsearch/core/query/CriteriaQueryTestsTransport.java
new file mode 100644
index 000000000..1a18d17ed
--- /dev/null
+++ b/src/test/java/org/springframework/data/elasticsearch/core/query/CriteriaQueryTestsTransport.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2019 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.data.elasticsearch.core.query;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
+import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
+import org.springframework.test.context.ContextConfiguration;
+
+/**
+ * @author Peter-Josef Meisch
+ */
+@ContextConfiguration(classes = { CriteriaQueryTestsTransport.Config.class })
+public class CriteriaQueryTestsTransport extends CriteriaQueryTests {
+ @Configuration
+ @Import({ ElasticsearchTemplateConfiguration.class })
+ @EnableElasticsearchRepositories(considerNestedRepositories = true)
+ static class Config {}
+}
diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/cdi/CdiRepositoryTests.java b/src/test/java/org/springframework/data/elasticsearch/repositories/cdi/CdiRepositoryTests.java
index 59e904e1d..9031540c3 100644
--- a/src/test/java/org/springframework/data/elasticsearch/repositories/cdi/CdiRepositoryTests.java
+++ b/src/test/java/org/springframework/data/elasticsearch/repositories/cdi/CdiRepositoryTests.java
@@ -31,11 +31,10 @@ import java.util.Optional;
import org.apache.webbeans.cditest.CdiTestContainer;
import org.apache.webbeans.cditest.CdiTestContainerLoader;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
@@ -56,7 +55,7 @@ public class CdiRepositoryTests {
private SamplePersonRepository personRepository;
private QualifiedProductRepository qualifiedProductRepository;
- @BeforeClass
+ @BeforeAll
public static void init() throws Exception {
cdiContainer = CdiTestContainerLoader.getCdiContainer();
@@ -64,14 +63,14 @@ public class CdiRepositoryTests {
cdiContainer.bootContainer();
}
- @AfterClass
+ @AfterAll
public static void shutdown() throws Exception {
cdiContainer.stopContexts();
cdiContainer.shutdownContainer();
}
- @Before
+ @BeforeEach
public void setUp() {
CdiRepositoryClient client = cdiContainer.getInstance(CdiRepositoryClient.class);
diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/complex/custommethod/autowiring/ComplexCustomMethodRepositoryTests.java b/src/test/java/org/springframework/data/elasticsearch/repositories/complex/custommethod/autowiring/ComplexCustomMethodRepositoryTests.java
index 3b7273a19..05ed308fd 100644
--- a/src/test/java/org/springframework/data/elasticsearch/repositories/complex/custommethod/autowiring/ComplexCustomMethodRepositoryTests.java
+++ b/src/test/java/org/springframework/data/elasticsearch/repositories/complex/custommethod/autowiring/ComplexCustomMethodRepositoryTests.java
@@ -28,8 +28,8 @@ import org.springframework.context.annotation.Import;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
-import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
-import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
+import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
+import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
import org.springframework.data.elasticsearch.utils.IndexInitializer;
@@ -45,19 +45,17 @@ import org.springframework.test.context.ContextConfiguration;
public class ComplexCustomMethodRepositoryTests {
@Configuration
- @Import({ ElasticsearchTemplateConfiguration.class })
- @EnableElasticsearchRepositories(
- basePackages = { "org.springframework.data.elasticsearch.repositories.complex.custommethod.autowiring" },
- considerNestedRepositories = true)
+ @Import({ ElasticsearchRestTemplateConfiguration.class })
+ @EnableElasticsearchRepositories(considerNestedRepositories = true)
static class Config {}
@Autowired private ComplexElasticsearchRepository complexRepository;
- @Autowired private ElasticsearchTemplate elasticsearchTemplate;
+ @Autowired private ElasticsearchOperations operations;
@BeforeEach
public void before() {
- IndexInitializer.init(elasticsearchTemplate, SampleEntity.class);
+ IndexInitializer.init(operations, SampleEntity.class);
}
@Test
diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/complex/custommethod/autowiring/ComplexCustomMethodRepositoryTransportTests.java b/src/test/java/org/springframework/data/elasticsearch/repositories/complex/custommethod/autowiring/ComplexCustomMethodRepositoryTransportTests.java
new file mode 100644
index 000000000..15885237f
--- /dev/null
+++ b/src/test/java/org/springframework/data/elasticsearch/repositories/complex/custommethod/autowiring/ComplexCustomMethodRepositoryTransportTests.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2019 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.data.elasticsearch.repositories.complex.custommethod.autowiring;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
+import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
+import org.springframework.test.context.ContextConfiguration;
+
+/**
+ * @author Peter-Josef Meisch
+ */
+@ContextConfiguration(classes = { ComplexCustomMethodRepositoryTransportTests.Config.class })
+public class ComplexCustomMethodRepositoryTransportTests extends ComplexCustomMethodRepositoryTests {
+ @Configuration
+ @Import({ ElasticsearchTemplateConfiguration.class })
+ @EnableElasticsearchRepositories(considerNestedRepositories = true)
+ static class Config {}
+}
diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/complex/custommethod/autowiring/ComplexElasticsearchRepositoryImpl.java b/src/test/java/org/springframework/data/elasticsearch/repositories/complex/custommethod/autowiring/ComplexElasticsearchRepositoryImpl.java
index a60369260..74cb89462 100644
--- a/src/test/java/org/springframework/data/elasticsearch/repositories/complex/custommethod/autowiring/ComplexElasticsearchRepositoryImpl.java
+++ b/src/test/java/org/springframework/data/elasticsearch/repositories/complex/custommethod/autowiring/ComplexElasticsearchRepositoryImpl.java
@@ -1,18 +1,18 @@
package org.springframework.data.elasticsearch.repositories.complex.custommethod.autowiring;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
+import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
/**
* @author Artur Konczak
*/
public class ComplexElasticsearchRepositoryImpl implements ComplexElasticsearchRepositoryCustom {
- @Autowired private ElasticsearchTemplate template;
+ @Autowired private ElasticsearchOperations operations;
@Override
public String doSomethingSpecial() {
- assert (template.getElasticsearchConverter() != null);
+ assert (operations.getElasticsearchConverter() != null);
return "2+2=4";
}
}
diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/complex/custommethod/manualwiring/ComplexCustomMethodRepositoryManualWiringTests.java b/src/test/java/org/springframework/data/elasticsearch/repositories/complex/custommethod/manualwiring/ComplexCustomMethodRepositoryManualWiringTests.java
index d1546ec3a..ed1f3172b 100644
--- a/src/test/java/org/springframework/data/elasticsearch/repositories/complex/custommethod/manualwiring/ComplexCustomMethodRepositoryManualWiringTests.java
+++ b/src/test/java/org/springframework/data/elasticsearch/repositories/complex/custommethod/manualwiring/ComplexCustomMethodRepositoryManualWiringTests.java
@@ -20,34 +20,41 @@ import static org.springframework.data.elasticsearch.annotations.FieldType.*;
import lombok.Data;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
-import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
+import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
+import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
+import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
+import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
import org.springframework.data.elasticsearch.utils.IndexInitializer;
import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringRunner;
/**
* @author Artur Konczak
* @author Peter-Josef Meisch
*/
-@RunWith(SpringRunner.class)
-@ContextConfiguration("classpath:complex-custom-method-repository-manual-wiring-test.xml")
+@SpringIntegrationTest
+@ContextConfiguration(classes = { ComplexCustomMethodRepositoryManualWiringTests.Config.class })
public class ComplexCustomMethodRepositoryManualWiringTests {
+ @Configuration
+ @Import({ ElasticsearchRestTemplateConfiguration.class })
+ @EnableElasticsearchRepositories(considerNestedRepositories = true)
+ static class Config {}
+
@Autowired private ComplexElasticsearchRepositoryManualWiring complexRepository;
- @Autowired private ElasticsearchTemplate elasticsearchTemplate;
+ @Autowired private ElasticsearchOperations operations;
- @Before
+ @BeforeEach
public void before() {
- IndexInitializer.init(elasticsearchTemplate, SampleEntity.class);
+ IndexInitializer.init(operations, SampleEntity.class);
}
@Test
diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/complex/custommethod/manualwiring/ComplexCustomMethodRepositoryManualWiringTransportTests.java b/src/test/java/org/springframework/data/elasticsearch/repositories/complex/custommethod/manualwiring/ComplexCustomMethodRepositoryManualWiringTransportTests.java
new file mode 100644
index 000000000..7236ed774
--- /dev/null
+++ b/src/test/java/org/springframework/data/elasticsearch/repositories/complex/custommethod/manualwiring/ComplexCustomMethodRepositoryManualWiringTransportTests.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2019 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.data.elasticsearch.repositories.complex.custommethod.manualwiring;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
+import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
+import org.springframework.test.context.ContextConfiguration;
+
+/**
+ * @author Peter-Josef Meisch
+ */
+@ContextConfiguration(classes = { ComplexCustomMethodRepositoryManualWiringTransportTests.Config.class })
+public class ComplexCustomMethodRepositoryManualWiringTransportTests
+ extends ComplexCustomMethodRepositoryManualWiringTests {
+ @Configuration
+ @Import({ ElasticsearchTemplateConfiguration.class })
+ @EnableElasticsearchRepositories(considerNestedRepositories = true)
+ static class Config {}
+}
diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/complex/custommethod/manualwiring/ComplexElasticsearchRepositoryManualWiringImpl.java b/src/test/java/org/springframework/data/elasticsearch/repositories/complex/custommethod/manualwiring/ComplexElasticsearchRepositoryManualWiringImpl.java
index 8a327393c..825a7aa6d 100644
--- a/src/test/java/org/springframework/data/elasticsearch/repositories/complex/custommethod/manualwiring/ComplexElasticsearchRepositoryManualWiringImpl.java
+++ b/src/test/java/org/springframework/data/elasticsearch/repositories/complex/custommethod/manualwiring/ComplexElasticsearchRepositoryManualWiringImpl.java
@@ -15,24 +15,25 @@
*/
package org.springframework.data.elasticsearch.repositories.complex.custommethod.manualwiring;
-import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
+import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.repositories.complex.custommethod.autowiring.ComplexElasticsearchRepositoryCustom;
/**
* @author Artur Konczak
* @author Mohsin Husen
+ * @author Peter-Josef Meisch
*/
public class ComplexElasticsearchRepositoryManualWiringImpl implements ComplexElasticsearchRepositoryCustom {
- private ElasticsearchTemplate template;
+ private ElasticsearchOperations operations;
+
+ public ComplexElasticsearchRepositoryManualWiringImpl(ElasticsearchOperations operations) {
+ this.operations = operations;
+ }
@Override
public String doSomethingSpecial() {
- assert (template.getElasticsearchConverter() != null);
+ assert (operations.getElasticsearchConverter() != null);
return "3+3=6";
}
-
- public void setTemplate(ElasticsearchTemplate template) {
- this.template = template;
- }
}
diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/custommethod/CustomMethodRepositoryTests.java b/src/test/java/org/springframework/data/elasticsearch/repositories/custommethod/CustomMethodRepositoryTests.java
index 2a4eb13a4..4d91b80f1 100644
--- a/src/test/java/org/springframework/data/elasticsearch/repositories/custommethod/CustomMethodRepositoryTests.java
+++ b/src/test/java/org/springframework/data/elasticsearch/repositories/custommethod/CustomMethodRepositoryTests.java
@@ -19,7 +19,7 @@ import org.junit.jupiter.api.BeforeEach;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
-import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
+import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
import org.springframework.data.elasticsearch.utils.IndexInitializer;
@@ -40,10 +40,10 @@ public class CustomMethodRepositoryTests extends CustomMethodRepositoryBaseTests
considerNestedRepositories = true)
static class Config {}
- @Autowired private ElasticsearchTemplate elasticsearchTemplate;
+ @Autowired private ElasticsearchOperations operations;
@BeforeEach
public void before() {
- IndexInitializer.init(elasticsearchTemplate, SampleEntity.class);
+ IndexInitializer.init(operations, SampleEntity.class);
}
}
diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/doubleid/DoubleIDRepositoryTests.java b/src/test/java/org/springframework/data/elasticsearch/repositories/doubleid/DoubleIDRepositoryTests.java
index bbd290b9e..fd55e5a71 100644
--- a/src/test/java/org/springframework/data/elasticsearch/repositories/doubleid/DoubleIDRepositoryTests.java
+++ b/src/test/java/org/springframework/data/elasticsearch/repositories/doubleid/DoubleIDRepositoryTests.java
@@ -21,19 +21,22 @@ import java.util.Arrays;
import java.util.Optional;
import org.apache.commons.lang.math.RandomUtils;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+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;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Version;
import org.springframework.data.elasticsearch.annotations.Document;
-import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
+import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
+import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
+import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
+import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
import org.springframework.data.elasticsearch.utils.IndexInitializer;
import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringRunner;
/**
* @author Rizwan Idrees
@@ -42,23 +45,28 @@ import org.springframework.test.context.junit4.SpringRunner;
* @author Christoph Strobl
* @author Peter-Josef Meisch
*/
-@RunWith(SpringRunner.class)
-@ContextConfiguration("classpath:/double-id-repository-test.xml")
+@SpringIntegrationTest
+@ContextConfiguration(classes = { DoubleIDRepositoryTests.Config.class })
public class DoubleIDRepositoryTests {
+ @Configuration
+ @Import({ ElasticsearchRestTemplateConfiguration.class })
+ @EnableElasticsearchRepositories(considerNestedRepositories = true)
+ static class Config {}
+
@Autowired private DoubleIDRepository repository;
- @Autowired private ElasticsearchTemplate elasticsearchTemplate;
+ @Autowired private ElasticsearchOperations operations;
- @Before
+ @BeforeEach
public void before() {
- IndexInitializer.init(elasticsearchTemplate, DoubleIDEntity.class);
+ IndexInitializer.init(operations, DoubleIDEntity.class);
}
- @After
+ @AfterEach
public void after() {
- elasticsearchTemplate.deleteIndex(DoubleIDEntity.class);
+ operations.deleteIndex(DoubleIDEntity.class);
}
@Test
diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/doubleid/DoubleIDRepositoryTransportTests.java b/src/test/java/org/springframework/data/elasticsearch/repositories/doubleid/DoubleIDRepositoryTransportTests.java
new file mode 100644
index 000000000..2e42afb0a
--- /dev/null
+++ b/src/test/java/org/springframework/data/elasticsearch/repositories/doubleid/DoubleIDRepositoryTransportTests.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2019 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.data.elasticsearch.repositories.doubleid;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
+import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
+import org.springframework.test.context.ContextConfiguration;
+
+/**
+ * @author Peter-Josef Meisch
+ */
+@ContextConfiguration(classes = { DoubleIDRepositoryTransportTests.Config.class })
+public class DoubleIDRepositoryTransportTests extends DoubleIDRepositoryTests {
+ @Configuration
+ @Import({ ElasticsearchTemplateConfiguration.class })
+ @EnableElasticsearchRepositories(considerNestedRepositories = true)
+ static class Config {}
+}
diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/dynamicindex/DynamicIndexEntityTests.java b/src/test/java/org/springframework/data/elasticsearch/repositories/dynamicindex/DynamicIndexEntityTests.java
index bebf707ff..44ccd10ad 100644
--- a/src/test/java/org/springframework/data/elasticsearch/repositories/dynamicindex/DynamicIndexEntityTests.java
+++ b/src/test/java/org/springframework/data/elasticsearch/repositories/dynamicindex/DynamicIndexEntityTests.java
@@ -17,20 +17,21 @@ package org.springframework.data.elasticsearch.repositories.dynamicindex;
import static org.assertj.core.api.Assertions.*;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
+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;
import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.ImportResource;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
-import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
+import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
+import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
+import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
+import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringRunner;
/**
* DynamicIndexEntityTests
@@ -39,33 +40,43 @@ import org.springframework.test.context.junit4.SpringRunner;
* @author Peter-Josef Meisch
*/
-@RunWith(SpringRunner.class)
-@ContextConfiguration(classes = DynamicIndexEntityTests.TestConfig.class)
+@SpringIntegrationTest
+@ContextConfiguration(classes = { DynamicIndexEntityTests.Config.class })
public class DynamicIndexEntityTests {
+ @Configuration
+ @Import({ ElasticsearchRestTemplateConfiguration.class })
+ @EnableElasticsearchRepositories(considerNestedRepositories = true)
+ static class Config {
+ @Bean
+ public IndexNameProvider indexNameProvider() {
+ return new IndexNameProvider();
+ }
+ }
+
@Autowired private DynamicIndexRepository repository;
- @Autowired private ElasticsearchTemplate template;
+ @Autowired private ElasticsearchOperations operations;
@Autowired private IndexNameProvider indexNameProvider;
- @Before
+ @BeforeEach
public void init() {
deleteIndexes();
- template.createIndex("index1");
- template.createIndex("index2");
+ operations.createIndex("index1");
+ operations.createIndex("index2");
}
- @After
+ @AfterEach
public void teardown() {
deleteIndexes();
}
private void deleteIndexes() {
- template.deleteIndex("index1");
- template.deleteIndex("index2");
+ operations.deleteIndex("index1");
+ operations.deleteIndex("index2");
}
@Test // DATAES-456
@@ -82,16 +93,6 @@ public class DynamicIndexEntityTests {
assertThat(repository.count()).isEqualTo(0L);
}
- @ImportResource(value = "classpath:/dynamic-index-repository-test.xml")
- static class TestConfig {
-
- @Bean
- public IndexNameProvider indexNameProvider() {
- return new IndexNameProvider();
- }
-
- }
-
static class IndexNameProvider {
private String indexName;
diff --git a/src/test/java/org/springframework/data/elasticsearch/repository/query/keywords/QueryKeywordsRestRepositoryTests.java b/src/test/java/org/springframework/data/elasticsearch/repositories/dynamicindex/DynamicIndexEntityTransportTests.java
similarity index 65%
rename from src/test/java/org/springframework/data/elasticsearch/repository/query/keywords/QueryKeywordsRestRepositoryTests.java
rename to src/test/java/org/springframework/data/elasticsearch/repositories/dynamicindex/DynamicIndexEntityTransportTests.java
index 5f73e9e3e..7dadae7c2 100644
--- a/src/test/java/org/springframework/data/elasticsearch/repository/query/keywords/QueryKeywordsRestRepositoryTests.java
+++ b/src/test/java/org/springframework/data/elasticsearch/repositories/dynamicindex/DynamicIndexEntityTransportTests.java
@@ -13,26 +13,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.springframework.data.elasticsearch.repository.query.keywords;
+package org.springframework.data.elasticsearch.repositories.dynamicindex;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
-import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
+import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
import org.springframework.test.context.ContextConfiguration;
/**
- * {@link QueryKeywordsTests} using a Repository backed by an ElasticsearchRestTemplate.
- *
* @author Peter-Josef Meisch
*/
-@ContextConfiguration(classes = { QueryKeywordsRestRepositoryTests.Config.class })
-public class QueryKeywordsRestRepositoryTests extends QueryKeywordsTests {
+@ContextConfiguration(classes = { DynamicIndexEntityTransportTests.Config.class })
+public class DynamicIndexEntityTransportTests extends DynamicIndexEntityTests {
@Configuration
- @Import({ ElasticsearchRestTemplateConfiguration.class })
- @EnableElasticsearchRepositories(
- basePackages = { "org.springframework.data.elasticsearch.repository.query.keywords" },
- considerNestedRepositories = true)
+ @Import({ ElasticsearchTemplateConfiguration.class })
+ @EnableElasticsearchRepositories(considerNestedRepositories = true)
static class Config {}
}
diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/geo/SpringDataGeoRepositoryTests.java b/src/test/java/org/springframework/data/elasticsearch/repositories/geo/SpringDataGeoRepositoryTests.java
index 2ee6fe916..a2de6313e 100644
--- a/src/test/java/org/springframework/data/elasticsearch/repositories/geo/SpringDataGeoRepositoryTests.java
+++ b/src/test/java/org/springframework/data/elasticsearch/repositories/geo/SpringDataGeoRepositoryTests.java
@@ -34,9 +34,9 @@ import org.springframework.context.annotation.Import;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.GeoPointField;
-import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
+import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
-import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
+import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
@@ -57,18 +57,17 @@ import org.springframework.test.context.ContextConfiguration;
public class SpringDataGeoRepositoryTests {
@Configuration
- @Import({ ElasticsearchTemplateConfiguration.class })
- @EnableElasticsearchRepositories(basePackages = { "org.springframework.data.elasticsearch.repositories.geo" },
- considerNestedRepositories = true)
+ @Import({ ElasticsearchRestTemplateConfiguration.class })
+ @EnableElasticsearchRepositories(considerNestedRepositories = true)
static class Config {}
- @Autowired ElasticsearchTemplate template;
+ @Autowired ElasticsearchOperations operations;
@Autowired SpringDataGeoRepository repository;
@BeforeEach
public void init() {
- IndexInitializer.init(template, GeoEntity.class);
+ IndexInitializer.init(operations, GeoEntity.class);
}
@Test
diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/geo/SpringDataGeoRepositoryTransportTests.java b/src/test/java/org/springframework/data/elasticsearch/repositories/geo/SpringDataGeoRepositoryTransportTests.java
new file mode 100644
index 000000000..81c3d3a3e
--- /dev/null
+++ b/src/test/java/org/springframework/data/elasticsearch/repositories/geo/SpringDataGeoRepositoryTransportTests.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2019 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.data.elasticsearch.repositories.geo;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
+import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
+import org.springframework.test.context.ContextConfiguration;
+
+/**
+ * @author Peter-Josef Meisch
+ */
+@ContextConfiguration(classes = { SpringDataGeoRepositoryTransportTests.Config.class })
+public class SpringDataGeoRepositoryTransportTests extends SpringDataGeoRepositoryTests {
+ @Configuration
+ @Import({ ElasticsearchTemplateConfiguration.class })
+ @EnableElasticsearchRepositories(considerNestedRepositories = true)
+ static class Config {}
+}
diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/integer/IntegerIDRepositoryTests.java b/src/test/java/org/springframework/data/elasticsearch/repositories/integer/IntegerIDRepositoryTests.java
index f99fafae9..680e4d374 100644
--- a/src/test/java/org/springframework/data/elasticsearch/repositories/integer/IntegerIDRepositoryTests.java
+++ b/src/test/java/org/springframework/data/elasticsearch/repositories/integer/IntegerIDRepositoryTests.java
@@ -21,18 +21,21 @@ import java.util.Arrays;
import java.util.Optional;
import org.apache.commons.lang.math.RandomUtils;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Version;
import org.springframework.data.elasticsearch.annotations.Document;
-import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
+import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
+import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
+import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
+import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
import org.springframework.data.elasticsearch.utils.IndexInitializer;
import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringRunner;
/**
* @author Rizwan Idrees
@@ -41,17 +44,22 @@ import org.springframework.test.context.junit4.SpringRunner;
* @author Christoph Strobl
* @author Peter-Josef Meisch
*/
-@RunWith(SpringRunner.class)
-@ContextConfiguration("classpath:/integer-id-repository-test.xml")
+@SpringIntegrationTest
+@ContextConfiguration(classes = { IntegerIDRepositoryTests.Config.class })
public class IntegerIDRepositoryTests {
+ @Configuration
+ @Import({ ElasticsearchRestTemplateConfiguration.class })
+ @EnableElasticsearchRepositories(considerNestedRepositories = true)
+ static class Config {}
+
@Autowired private IntegerIDRepository repository;
- @Autowired private ElasticsearchTemplate elasticsearchTemplate;
+ @Autowired private ElasticsearchOperations operations;
- @Before
+ @BeforeEach
public void before() {
- IndexInitializer.init(elasticsearchTemplate, IntegerIDEntity.class);
+ IndexInitializer.init(operations, IntegerIDEntity.class);
}
@Test
diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/integer/IntegerIDRepositoryTransportTests.java b/src/test/java/org/springframework/data/elasticsearch/repositories/integer/IntegerIDRepositoryTransportTests.java
new file mode 100644
index 000000000..451ef33b9
--- /dev/null
+++ b/src/test/java/org/springframework/data/elasticsearch/repositories/integer/IntegerIDRepositoryTransportTests.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2019 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.data.elasticsearch.repositories.integer;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
+import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
+import org.springframework.test.context.ContextConfiguration;
+
+/**
+ * @author Peter-Josef Meisch
+ */
+@ContextConfiguration(classes = { IntegerIDRepositoryTransportTests.Config.class })
+public class IntegerIDRepositoryTransportTests extends IntegerIDRepositoryTests {
+ @Configuration
+ @Import({ ElasticsearchTemplateConfiguration.class })
+ @EnableElasticsearchRepositories(considerNestedRepositories = true)
+ static class Config {}
+}
diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/nestedobject/InnerObjectTests.java b/src/test/java/org/springframework/data/elasticsearch/repositories/nestedobject/InnerObjectTests.java
index 698b7e3fe..4079afc3a 100644
--- a/src/test/java/org/springframework/data/elasticsearch/repositories/nestedobject/InnerObjectTests.java
+++ b/src/test/java/org/springframework/data/elasticsearch/repositories/nestedobject/InnerObjectTests.java
@@ -29,38 +29,46 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.annotations.InnerField;
import org.springframework.data.elasticsearch.annotations.MultiField;
-import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
+import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
+import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
+import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
+import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
import org.springframework.data.elasticsearch.utils.IndexInitializer;
import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringRunner;
/**
* @author Mohsin Husen
* @author Christoph Strobl
* @author Peter-Josef Meisch
*/
-@RunWith(SpringRunner.class)
-@ContextConfiguration("classpath:/repository-test-nested-object-books.xml")
+@SpringIntegrationTest
+@ContextConfiguration(classes = { InnerObjectTests.Config.class })
public class InnerObjectTests {
+ @Configuration
+ @Import({ ElasticsearchRestTemplateConfiguration.class })
+ @EnableElasticsearchRepositories(considerNestedRepositories = true)
+ static class Config {}
+
@Autowired private SampleElasticSearchBookRepository bookRepository;
- @Autowired private ElasticsearchTemplate elasticsearchTemplate;
+ @Autowired private ElasticsearchOperations operations;
- @Before
+ @BeforeEach
public void before() {
- IndexInitializer.init(elasticsearchTemplate, Book.class);
+ IndexInitializer.init(operations, Book.class);
}
@Test
diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/nestedobject/InnerObjectTransportTests.java b/src/test/java/org/springframework/data/elasticsearch/repositories/nestedobject/InnerObjectTransportTests.java
new file mode 100644
index 000000000..62d5ff43e
--- /dev/null
+++ b/src/test/java/org/springframework/data/elasticsearch/repositories/nestedobject/InnerObjectTransportTests.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2019 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.data.elasticsearch.repositories.nestedobject;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
+import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
+import org.springframework.test.context.ContextConfiguration;
+
+/**
+ * @author Peter-Josef Meisch
+ */
+@ContextConfiguration(classes = { InnerObjectTransportTests.Config.class })
+public class InnerObjectTransportTests extends InnerObjectTests {
+ @Configuration
+ @Import({ ElasticsearchTemplateConfiguration.class })
+ @EnableElasticsearchRepositories(considerNestedRepositories = true)
+ static class Config {}
+}
diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/setting/dynamic/DynamicSettingAndMappingEntityRepositoryTests.java b/src/test/java/org/springframework/data/elasticsearch/repositories/setting/dynamic/DynamicSettingAndMappingEntityRepositoryTests.java
index 531b90751..45eb27605 100644
--- a/src/test/java/org/springframework/data/elasticsearch/repositories/setting/dynamic/DynamicSettingAndMappingEntityRepositoryTests.java
+++ b/src/test/java/org/springframework/data/elasticsearch/repositories/setting/dynamic/DynamicSettingAndMappingEntityRepositoryTests.java
@@ -31,11 +31,11 @@ import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Mapping;
import org.springframework.data.elasticsearch.annotations.Setting;
-import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
+import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.IndexCoordinates;
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
-import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
+import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
import org.springframework.data.elasticsearch.repository.ElasticsearchCrudRepository;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
@@ -54,19 +54,17 @@ import org.springframework.test.context.ContextConfiguration;
public class DynamicSettingAndMappingEntityRepositoryTests {
@Configuration
- @Import({ ElasticsearchTemplateConfiguration.class })
- @EnableElasticsearchRepositories(
- basePackages = { "org.springframework.data.elasticsearch.repositories.setting.dynamic" },
- considerNestedRepositories = true)
+ @Import({ ElasticsearchRestTemplateConfiguration.class })
+ @EnableElasticsearchRepositories(considerNestedRepositories = true)
static class Config {}
+ @Autowired private ElasticsearchOperations operations;
+
@Autowired private DynamicSettingAndMappingEntityRepository repository;
- @Autowired private ElasticsearchTemplate elasticsearchTemplate;
-
@BeforeEach
public void before() {
- IndexInitializer.init(elasticsearchTemplate, DynamicSettingAndMappingEntity.class);
+ IndexInitializer.init(operations, DynamicSettingAndMappingEntity.class);
}
@Test // DATAES-64
@@ -76,8 +74,8 @@ public class DynamicSettingAndMappingEntityRepositoryTests {
// delete , create and apply mapping in before method
// then
- assertThat(elasticsearchTemplate.indexExists(DynamicSettingAndMappingEntity.class)).isTrue();
- Map map = elasticsearchTemplate.getSetting(DynamicSettingAndMappingEntity.class);
+ assertThat(operations.indexExists(DynamicSettingAndMappingEntity.class)).isTrue();
+ Map map = operations.getSetting(DynamicSettingAndMappingEntity.class);
assertThat(map.containsKey("index.number_of_replicas")).isTrue();
assertThat(map.containsKey("index.number_of_shards")).isTrue();
assertThat(map.containsKey("index.analysis.analyzer.emailAnalyzer.tokenizer")).isTrue();
@@ -108,10 +106,10 @@ public class DynamicSettingAndMappingEntityRepositoryTests {
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder()
.withQuery(QueryBuilders.termQuery("email", dynamicSettingAndMappingEntity1.getEmail())).build();
- IndexCoordinates index = IndexCoordinates.of("test-index-dynamic-setting-and-mapping").withTypes( "test-setting-type");
- long count = elasticsearchTemplate.count(searchQuery, DynamicSettingAndMappingEntity.class,
- index);
- List entityList = elasticsearchTemplate.queryForList(searchQuery,
+ IndexCoordinates index = IndexCoordinates.of("test-index-dynamic-setting-and-mapping")
+ .withTypes("test-setting-type");
+ long count = operations.count(searchQuery, DynamicSettingAndMappingEntity.class, index);
+ List entityList = operations.queryForList(searchQuery,
DynamicSettingAndMappingEntity.class, index);
// then
@@ -127,7 +125,7 @@ public class DynamicSettingAndMappingEntityRepositoryTests {
// delete , create and apply mapping in before method
// when
- Map mapping = elasticsearchTemplate.getMapping(DynamicSettingAndMappingEntity.class);
+ Map mapping = operations.getMapping(DynamicSettingAndMappingEntity.class);
// then
Map properties = (Map) mapping.get("properties");
@@ -142,9 +140,9 @@ public class DynamicSettingAndMappingEntityRepositoryTests {
public void shouldCreateMappingWithSpecifiedMappings() {
// given
- elasticsearchTemplate.deleteIndex(DynamicSettingAndMappingEntity.class);
- elasticsearchTemplate.createIndex(DynamicSettingAndMappingEntity.class);
- elasticsearchTemplate.refresh(DynamicSettingAndMappingEntity.class);
+ operations.deleteIndex(DynamicSettingAndMappingEntity.class);
+ operations.createIndex(DynamicSettingAndMappingEntity.class);
+ operations.refresh(DynamicSettingAndMappingEntity.class);
// when
String mappings = "{\n" + //
@@ -154,11 +152,11 @@ public class DynamicSettingAndMappingEntityRepositoryTests {
" }\n" + //
" }\n" + //
"}";
- elasticsearchTemplate.putMapping(DynamicSettingAndMappingEntity.class, mappings);
- elasticsearchTemplate.refresh(DynamicSettingAndMappingEntity.class);
+ operations.putMapping(DynamicSettingAndMappingEntity.class, mappings);
+ operations.refresh(DynamicSettingAndMappingEntity.class);
// then
- Map mapping = elasticsearchTemplate.getMapping(DynamicSettingAndMappingEntity.class);
+ Map mapping = operations.getMapping(DynamicSettingAndMappingEntity.class);
Map properties = (Map) mapping.get("properties");
assertThat(mapping).isNotNull();
assertThat(properties).isNotNull();
@@ -173,7 +171,7 @@ public class DynamicSettingAndMappingEntityRepositoryTests {
// given
// then
- Map mapping = elasticsearchTemplate.getMapping(DynamicSettingAndMappingEntity.class);
+ Map mapping = operations.getMapping(DynamicSettingAndMappingEntity.class);
Map properties = (Map) mapping.get("properties");
assertThat(mapping).isNotNull();
assertThat(properties).isNotNull();
diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/setting/dynamic/DynamicSettingAndMappingEntityRepositoryTransportTests.java b/src/test/java/org/springframework/data/elasticsearch/repositories/setting/dynamic/DynamicSettingAndMappingEntityRepositoryTransportTests.java
new file mode 100644
index 000000000..c4e0c0b8c
--- /dev/null
+++ b/src/test/java/org/springframework/data/elasticsearch/repositories/setting/dynamic/DynamicSettingAndMappingEntityRepositoryTransportTests.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2019 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.data.elasticsearch.repositories.setting.dynamic;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
+import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
+import org.springframework.test.context.ContextConfiguration;
+
+/**
+ * @author Peter-Josef Meisch
+ */
+@ContextConfiguration(classes = { DynamicSettingAndMappingEntityRepositoryTransportTests.Config.class })
+public class DynamicSettingAndMappingEntityRepositoryTransportTests
+ extends DynamicSettingAndMappingEntityRepositoryTests {
+ @Configuration
+ @Import({ ElasticsearchTemplateConfiguration.class })
+ @EnableElasticsearchRepositories(considerNestedRepositories = true)
+ static class Config {}
+}
diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/setting/fielddynamic/FieldDynamicMappingEntityRepositoryTests.java b/src/test/java/org/springframework/data/elasticsearch/repositories/setting/fielddynamic/FieldDynamicMappingEntityRepositoryTests.java
index 9693a4050..3ac5c7145 100644
--- a/src/test/java/org/springframework/data/elasticsearch/repositories/setting/fielddynamic/FieldDynamicMappingEntityRepositoryTests.java
+++ b/src/test/java/org/springframework/data/elasticsearch/repositories/setting/fielddynamic/FieldDynamicMappingEntityRepositoryTests.java
@@ -27,8 +27,8 @@ import org.springframework.context.annotation.Import;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Mapping;
-import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
-import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
+import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
+import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
import org.springframework.data.elasticsearch.repository.ElasticsearchCrudRepository;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
@@ -46,19 +46,17 @@ import org.springframework.test.context.ContextConfiguration;
public class FieldDynamicMappingEntityRepositoryTests {
@Configuration
- @Import({ ElasticsearchTemplateConfiguration.class })
- @EnableElasticsearchRepositories(
- basePackages = { "org.springframework.data.elasticsearch.repositories.setting.fielddynamic" },
- considerNestedRepositories = true)
+ @Import({ ElasticsearchRestTemplateConfiguration.class })
+ @EnableElasticsearchRepositories(considerNestedRepositories = true)
static class Config {}
@Autowired private FieldDynamicMappingEntityRepository repository;
- @Autowired private ElasticsearchTemplate elasticsearchTemplate;
+ @Autowired private ElasticsearchOperations operations;
@BeforeEach
public void before() {
- IndexInitializer.init(elasticsearchTemplate, FieldDynamicMappingEntity.class);
+ IndexInitializer.init(operations, FieldDynamicMappingEntity.class);
}
@Test // DATAES-209
@@ -67,7 +65,7 @@ public class FieldDynamicMappingEntityRepositoryTests {
// given
// then
- Map mapping = elasticsearchTemplate.getMapping(FieldDynamicMappingEntity.class);
+ Map mapping = operations.getMapping(FieldDynamicMappingEntity.class);
assertThat(mapping).isNotNull();
Map properties = (Map) mapping.get("properties");
diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/setting/fielddynamic/FieldDynamicMappingEntityRepositoryTransportTests.java b/src/test/java/org/springframework/data/elasticsearch/repositories/setting/fielddynamic/FieldDynamicMappingEntityRepositoryTransportTests.java
new file mode 100644
index 000000000..03a68bcf9
--- /dev/null
+++ b/src/test/java/org/springframework/data/elasticsearch/repositories/setting/fielddynamic/FieldDynamicMappingEntityRepositoryTransportTests.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2019 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.data.elasticsearch.repositories.setting.fielddynamic;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
+import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
+import org.springframework.test.context.ContextConfiguration;
+
+/**
+ * @author Peter-Josef Meisch
+ */
+@ContextConfiguration(classes = { FieldDynamicMappingEntityRepositoryTransportTests.Config.class })
+public class FieldDynamicMappingEntityRepositoryTransportTests extends FieldDynamicMappingEntityRepositoryTests {
+ @Configuration
+ @Import({ ElasticsearchTemplateConfiguration.class })
+ @EnableElasticsearchRepositories(considerNestedRepositories = true)
+ static class Config {}
+}
diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/spel/SpELEntityTests.java b/src/test/java/org/springframework/data/elasticsearch/repositories/spel/SpELEntityTests.java
index fe7acedc8..56d8b9703 100644
--- a/src/test/java/org/springframework/data/elasticsearch/repositories/spel/SpELEntityTests.java
+++ b/src/test/java/org/springframework/data/elasticsearch/repositories/spel/SpELEntityTests.java
@@ -25,10 +25,10 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
-import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
+import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.IndexCoordinates;
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
-import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
+import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
@@ -45,18 +45,18 @@ import org.springframework.test.context.ContextConfiguration;
@ContextConfiguration(classes = { SpELEntityTests.Config.class })
public class SpELEntityTests {
- @Autowired private SpELRepository repository;
-
- @Autowired private ElasticsearchTemplate template;
-
@Configuration
- @Import(ElasticsearchTemplateConfiguration.class)
+ @Import(ElasticsearchRestTemplateConfiguration.class)
@EnableElasticsearchRepositories(considerNestedRepositories = true)
static class Config {}
+ @Autowired private SpELRepository repository;
+
+ @Autowired private ElasticsearchOperations operations;
+
@BeforeEach
public void before() {
- IndexInitializer.init(template, SpELEntity.class);
+ IndexInitializer.init(operations, SpELEntity.class);
}
@Test
@@ -70,7 +70,7 @@ public class SpELEntityTests {
// then
NativeSearchQuery nativeSearchQuery = new NativeSearchQuery(QueryBuilders.matchAllQuery());
- long count = template.count(nativeSearchQuery, IndexCoordinates.of("test-index-abz-entity"));
+ long count = operations.count(nativeSearchQuery, IndexCoordinates.of("test-index-abz-entity"));
assertThat(count).isEqualTo(2);
}
@@ -85,7 +85,7 @@ public class SpELEntityTests {
// then
NativeSearchQuery nativeSearchQuery = new NativeSearchQuery(QueryBuilders.matchAllQuery());
- long count = template.count(nativeSearchQuery, IndexCoordinates.of("test-index-abz-entity"));
+ long count = operations.count(nativeSearchQuery, IndexCoordinates.of("test-index-abz-entity"));
assertThat(count).isEqualTo(1);
}
diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/spel/SpELEntityTransportTests.java b/src/test/java/org/springframework/data/elasticsearch/repositories/spel/SpELEntityTransportTests.java
new file mode 100644
index 000000000..3e4dd6c70
--- /dev/null
+++ b/src/test/java/org/springframework/data/elasticsearch/repositories/spel/SpELEntityTransportTests.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2019 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.data.elasticsearch.repositories.spel;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
+import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
+import org.springframework.test.context.ContextConfiguration;
+
+/**
+ * @author Peter-Josef Meisch
+ */
+@ContextConfiguration(classes = { SpELEntityTransportTests.Config.class })
+public class SpELEntityTransportTests extends SpELEntityTests {
+ @Configuration
+ @Import({ ElasticsearchTemplateConfiguration.class })
+ @EnableElasticsearchRepositories(considerNestedRepositories = true)
+ static class Config {}
+}
diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/synonym/SynonymRepositoryTests.java b/src/test/java/org/springframework/data/elasticsearch/repositories/synonym/SynonymRepositoryTests.java
index b2bb76daf..57c19799c 100644
--- a/src/test/java/org/springframework/data/elasticsearch/repositories/synonym/SynonymRepositoryTests.java
+++ b/src/test/java/org/springframework/data/elasticsearch/repositories/synonym/SynonymRepositoryTests.java
@@ -31,10 +31,10 @@ import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Mapping;
import org.springframework.data.elasticsearch.annotations.Setting;
-import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
+import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.IndexCoordinates;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
-import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
+import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
import org.springframework.data.elasticsearch.repository.ElasticsearchCrudRepository;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
@@ -52,18 +52,17 @@ import org.springframework.test.context.ContextConfiguration;
public class SynonymRepositoryTests {
@Configuration
- @Import({ ElasticsearchTemplateConfiguration.class })
- @EnableElasticsearchRepositories(basePackages = { "org.springframework.data.elasticsearch.repositories.synonym" },
- considerNestedRepositories = true)
+ @Import({ ElasticsearchRestTemplateConfiguration.class })
+ @EnableElasticsearchRepositories(considerNestedRepositories = true)
static class Config {}
@Autowired private SynonymRepository repository;
- @Autowired private ElasticsearchTemplate elasticsearchTemplate;
+ @Autowired private ElasticsearchOperations operations;
@BeforeEach
public void before() {
- IndexInitializer.init(elasticsearchTemplate, SynonymEntity.class);
+ IndexInitializer.init(operations, SynonymEntity.class);
}
@Test
@@ -83,9 +82,9 @@ public class SynonymRepositoryTests {
// then
assertThat(repository.count()).isEqualTo(2L);
- List synonymEntities = elasticsearchTemplate.queryForList(
+ List synonymEntities = operations.queryForList(
new NativeSearchQueryBuilder().withQuery(QueryBuilders.termQuery("text", "british")).build(),
- SynonymEntity.class, IndexCoordinates.of("test-index-synonym").withTypes( "synonym-type"));
+ SynonymEntity.class, IndexCoordinates.of("test-index-synonym").withTypes("synonym-type"));
assertThat(synonymEntities).hasSize(1);
}
diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/synonym/SynonymRepositoryTransportTests.java b/src/test/java/org/springframework/data/elasticsearch/repositories/synonym/SynonymRepositoryTransportTests.java
new file mode 100644
index 000000000..b0e52a913
--- /dev/null
+++ b/src/test/java/org/springframework/data/elasticsearch/repositories/synonym/SynonymRepositoryTransportTests.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2019 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.data.elasticsearch.repositories.synonym;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
+import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
+import org.springframework.test.context.ContextConfiguration;
+
+/**
+ * @author Peter-Josef Meisch
+ */
+@ContextConfiguration(classes = { SynonymRepositoryTransportTests.Config.class })
+public class SynonymRepositoryTransportTests extends SynonymRepositoryTests {
+ @Configuration
+ @Import({ ElasticsearchTemplateConfiguration.class })
+ @EnableElasticsearchRepositories(considerNestedRepositories = true)
+ static class Config {}
+}
diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/uuidkeyed/UUIDElasticsearchRepositoryTests.java b/src/test/java/org/springframework/data/elasticsearch/repositories/uuidkeyed/UUIDElasticsearchRepositoryTests.java
index 27a7608c2..4ad24d3c6 100644
--- a/src/test/java/org/springframework/data/elasticsearch/repositories/uuidkeyed/UUIDElasticsearchRepositoryTests.java
+++ b/src/test/java/org/springframework/data/elasticsearch/repositories/uuidkeyed/UUIDElasticsearchRepositoryTests.java
@@ -44,11 +44,11 @@ import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.annotations.ScriptedField;
-import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
+import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
-import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
+import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
@@ -69,19 +69,18 @@ import org.springframework.test.context.ContextConfiguration;
public class UUIDElasticsearchRepositoryTests {
@Configuration
- @Import({ ElasticsearchTemplateConfiguration.class })
- @EnableElasticsearchRepositories(basePackages = { "org.springframework.data.elasticsearch.repositories.uuidkeyed" },
- considerNestedRepositories = true)
+ @Import({ ElasticsearchRestTemplateConfiguration.class })
+ @EnableElasticsearchRepositories(considerNestedRepositories = true)
static class Config {}
@Autowired private SampleUUIDKeyedElasticsearchRepository repository;
- @Autowired private ElasticsearchTemplate elasticsearchTemplate;
+ @Autowired private ElasticsearchOperations operations;
@BeforeEach
public void before() {
- IndexInitializer.init(elasticsearchTemplate, SampleEntityUUIDKeyed.class);
+ IndexInitializer.init(operations, SampleEntityUUIDKeyed.class);
}
@Test
diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/uuidkeyed/UUIDElasticsearchRepositoryTransportTests.java b/src/test/java/org/springframework/data/elasticsearch/repositories/uuidkeyed/UUIDElasticsearchRepositoryTransportTests.java
new file mode 100644
index 000000000..abbc32a43
--- /dev/null
+++ b/src/test/java/org/springframework/data/elasticsearch/repositories/uuidkeyed/UUIDElasticsearchRepositoryTransportTests.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2019 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.data.elasticsearch.repositories.uuidkeyed;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
+import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
+import org.springframework.test.context.ContextConfiguration;
+
+/**
+ * @author Peter-Josef Meisch
+ */
+@ContextConfiguration(classes = { UUIDElasticsearchRepositoryTransportTests.Config.class })
+public class UUIDElasticsearchRepositoryTransportTests extends UUIDElasticsearchRepositoryTests {
+ @Configuration
+ @Import({ ElasticsearchTemplateConfiguration.class })
+ @EnableElasticsearchRepositories(considerNestedRepositories = true)
+ static class Config {}
+}
diff --git a/src/test/java/org/springframework/data/elasticsearch/repository/config/ReactiveElasticsearchRepositoriesRegistrarTests.java b/src/test/java/org/springframework/data/elasticsearch/repository/config/ReactiveElasticsearchRepositoriesRegistrarTests.java
index c536cebcb..674ab6055 100644
--- a/src/test/java/org/springframework/data/elasticsearch/repository/config/ReactiveElasticsearchRepositoriesRegistrarTests.java
+++ b/src/test/java/org/springframework/data/elasticsearch/repository/config/ReactiveElasticsearchRepositoriesRegistrarTests.java
@@ -23,9 +23,7 @@ import lombok.Data;
import lombok.NoArgsConstructor;
import org.assertj.core.api.Assertions;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
+import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
@@ -35,17 +33,16 @@ import org.springframework.data.elasticsearch.TestUtils;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.core.ReactiveElasticsearchTemplate;
+import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
import org.springframework.data.elasticsearch.repository.ReactiveElasticsearchRepository;
import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringRunner;
/**
* @author Christoph Strobl
- * @currentRead Fool's Fate - Robin Hobb
* @author Peter-Josef Meisch
*/
-@RunWith(SpringRunner.class)
-@ContextConfiguration
+@SpringIntegrationTest
+@ContextConfiguration(classes = { ReactiveElasticsearchRepositoriesRegistrarTests.Config.class })
public class ReactiveElasticsearchRepositoriesRegistrarTests {
@Configuration
diff --git a/src/test/java/org/springframework/data/elasticsearch/repository/config/ReactiveElasticsearchRepositoryConfigurationExtensionUnitTests.java b/src/test/java/org/springframework/data/elasticsearch/repository/config/ReactiveElasticsearchRepositoryConfigurationExtensionUnitTests.java
index 9739f20b0..b3fa4de59 100644
--- a/src/test/java/org/springframework/data/elasticsearch/repository/config/ReactiveElasticsearchRepositoryConfigurationExtensionUnitTests.java
+++ b/src/test/java/org/springframework/data/elasticsearch/repository/config/ReactiveElasticsearchRepositoryConfigurationExtensionUnitTests.java
@@ -19,8 +19,7 @@ import static org.assertj.core.api.Assertions.*;
import java.util.Collection;
-import org.junit.Test;
-
+import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.core.env.Environment;
@@ -37,7 +36,7 @@ import org.springframework.data.repository.reactive.ReactiveCrudRepository;
/**
* @author Christoph Strobl
- * @currentRead Fool's Fate - Robin Hobb
+ * @author Peter-Josef Meisch
*/
public class ReactiveElasticsearchRepositoryConfigurationExtensionUnitTests {
diff --git a/src/test/java/org/springframework/data/elasticsearch/repository/query/keywords/QueryKeywordsRepositoryTests.java b/src/test/java/org/springframework/data/elasticsearch/repository/query/keywords/QueryKeywordsRepositoryTransportTests.java
similarity index 80%
rename from src/test/java/org/springframework/data/elasticsearch/repository/query/keywords/QueryKeywordsRepositoryTests.java
rename to src/test/java/org/springframework/data/elasticsearch/repository/query/keywords/QueryKeywordsRepositoryTransportTests.java
index 034f9955c..59f31af29 100644
--- a/src/test/java/org/springframework/data/elasticsearch/repository/query/keywords/QueryKeywordsRepositoryTests.java
+++ b/src/test/java/org/springframework/data/elasticsearch/repository/query/keywords/QueryKeywordsRepositoryTransportTests.java
@@ -26,13 +26,11 @@ import org.springframework.test.context.ContextConfiguration;
*
* @author Peter-Josef Meisch
*/
-@ContextConfiguration(classes = { QueryKeywordsRepositoryTests.Config.class})
-public class QueryKeywordsRepositoryTests extends QueryKeywordsTests {
+@ContextConfiguration(classes = { QueryKeywordsRepositoryTransportTests.Config.class })
+public class QueryKeywordsRepositoryTransportTests extends QueryKeywordsTests {
@Configuration
@Import({ ElasticsearchTemplateConfiguration.class })
- @EnableElasticsearchRepositories(
- basePackages = { "org.springframework.data.elasticsearch.repository.query.keywords" },
- considerNestedRepositories = true)
+ @EnableElasticsearchRepositories(considerNestedRepositories = true)
static class Config {}
}
diff --git a/src/test/java/org/springframework/data/elasticsearch/repository/query/keywords/QueryKeywordsTests.java b/src/test/java/org/springframework/data/elasticsearch/repository/query/keywords/QueryKeywordsTests.java
index a70d839c5..de43eed5d 100644
--- a/src/test/java/org/springframework/data/elasticsearch/repository/query/keywords/QueryKeywordsTests.java
+++ b/src/test/java/org/springframework/data/elasticsearch/repository/query/keywords/QueryKeywordsTests.java
@@ -31,14 +31,19 @@ import java.util.stream.Collectors;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
+import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
+import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
import org.springframework.data.elasticsearch.utils.IndexInitializer;
+import org.springframework.test.context.ContextConfiguration;
/**
* base class for query keyword tests. Implemented by subclasses using ElasticsearchClient and ElasticsearchRestClient
@@ -49,7 +54,13 @@ import org.springframework.data.elasticsearch.utils.IndexInitializer;
* @author Peter-Josef Meisch
*/
@SpringIntegrationTest
-abstract class QueryKeywordsTests {
+@ContextConfiguration(classes = { QueryKeywordsTests.Config.class })
+class QueryKeywordsTests {
+
+ @Configuration
+ @Import({ ElasticsearchRestTemplateConfiguration.class })
+ @EnableElasticsearchRepositories(considerNestedRepositories = true)
+ static class Config {}
@Autowired private ProductRepository repository;
diff --git a/src/test/resources/complex-custom-method-repository-manual-wiring-test.xml b/src/test/resources/complex-custom-method-repository-manual-wiring-test.xml
deleted file mode 100644
index 5fd597009..000000000
--- a/src/test/resources/complex-custom-method-repository-manual-wiring-test.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/test/resources/double-id-repository-test.xml b/src/test/resources/double-id-repository-test.xml
deleted file mode 100644
index 44f5d70f7..000000000
--- a/src/test/resources/double-id-repository-test.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/test/resources/dynamic-index-repository-test.xml b/src/test/resources/dynamic-index-repository-test.xml
deleted file mode 100644
index 05029c0bc..000000000
--- a/src/test/resources/dynamic-index-repository-test.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/test/resources/elasticsearch-rest-template-test.xml b/src/test/resources/elasticsearch-rest-template-test.xml
deleted file mode 100644
index 8204543b8..000000000
--- a/src/test/resources/elasticsearch-rest-template-test.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/test/resources/elasticsearch-template-test.xml b/src/test/resources/elasticsearch-template-test.xml
deleted file mode 100644
index d9785793a..000000000
--- a/src/test/resources/elasticsearch-template-test.xml
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/test/resources/existing-index-repository-test.xml b/src/test/resources/existing-index-repository-test.xml
deleted file mode 100644
index c9fe5eb79..000000000
--- a/src/test/resources/existing-index-repository-test.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/test/resources/field-dynamic-settings-test.xml b/src/test/resources/field-dynamic-settings-test.xml
deleted file mode 100644
index ac9da11b7..000000000
--- a/src/test/resources/field-dynamic-settings-test.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/test/resources/infrastructure.xml b/src/test/resources/infrastructure.xml
deleted file mode 100644
index d53d9c4a0..000000000
--- a/src/test/resources/infrastructure.xml
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/test/resources/integer-id-repository-test.xml b/src/test/resources/integer-id-repository-test.xml
deleted file mode 100644
index 1e4c354ef..000000000
--- a/src/test/resources/integer-id-repository-test.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/test/resources/repository-non-document-entity.xml b/src/test/resources/repository-non-document-entity.xml
index 64b7fb1a7..e1645c556 100644
--- a/src/test/resources/repository-non-document-entity.xml
+++ b/src/test/resources/repository-non-document-entity.xml
@@ -1,19 +1,21 @@
-
+
-
-
-
+
+
+
-
+
diff --git a/src/test/resources/repository-test-nested-object-books.xml b/src/test/resources/repository-test-nested-object-books.xml
deleted file mode 100644
index d4b40ddb5..000000000
--- a/src/test/resources/repository-test-nested-object-books.xml
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/test/resources/repository-test-nested-object.xml b/src/test/resources/repository-test-nested-object.xml
deleted file mode 100644
index 1aa3e21de..000000000
--- a/src/test/resources/repository-test-nested-object.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/test/resources/synonym-test.xml b/src/test/resources/synonym-test.xml
deleted file mode 100644
index f36931f1f..000000000
--- a/src/test/resources/synonym-test.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-