DATAES-675 - Migrate tests to JUnit 5.

Original PR: #350
This commit is contained in:
Peter-Josef Meisch 2019-12-01 18:31:51 +01:00 committed by GitHub
parent 03fd603909
commit c3714dd6e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
63 changed files with 1018 additions and 859 deletions

View File

@ -289,7 +289,6 @@
<scope>test</scope>
</dependency>
</dependencies>
<build>

View File

@ -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());

View File

@ -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<String, Object> mapping = elasticsearchTemplate.getMapping(PersonMultipleLevelNested.class);
@ -182,9 +182,8 @@ public class NestedObjectTests {
List<IndexQuery> 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);

View File

@ -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 {

View File

@ -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

View File

@ -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<ParentEntity> 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();
}
}
}
}

View File

@ -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<LogEntity> entities = template.queryForList(searchQuery, LogEntity.class, index);
List<LogEntity> 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<LogEntity> entities = template.queryForList(searchQuery, LogEntity.class, index);
}).isInstanceOf(SearchPhaseExecutionException.class);
List<LogEntity> 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<LogEntity> entities = template.queryForList(searchQuery, LogEntity.class, index);
List<LogEntity> entities = operations.queryForList(searchQuery, LogEntity.class, index);
// then
assertThat(entities).isNotNull().hasSize(3);

View File

@ -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 {}
}

View File

@ -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 aggregations = operations.query(searchQuery, new ResultsExtractor<Aggregations>() {
@Override
public Aggregations extract(SearchResponse response) {
return response.getAggregations();

View File

@ -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 {}
}

View File

@ -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<IndexQuery> 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<IndexQuery> 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<CompletionSuggestion.Entry.Option> 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<CompletionSuggestion.Entry.Option> 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<CompletionSuggestion.Entry.Option> options = completionSuggestion.getEntries().get(0).getOptions();

View File

@ -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 {}
}

View File

@ -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<CompletionSuggestion.Entry.Option> 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<CompletionSuggestion.Entry.Option> 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<CompletionSuggestion.Entry.Option> options = completionSuggestion.getEntries().get(0).getOptions();

View File

@ -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 {}
}

View File

@ -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<AuthorMarkerEntity> geoAuthorsForGeoCriteria = elasticsearchTemplate.queryForList(geoLocationCriteriaQuery,
List<AuthorMarkerEntity> 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<AuthorMarkerEntity> geoAuthorsForGeoCriteria2 = elasticsearchTemplate.queryForList(geoLocationCriteriaQuery2,
List<AuthorMarkerEntity> 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<LocationMarkerEntity> geoAuthorsForGeoCriteria = elasticsearchTemplate.queryForList(geoLocationCriteriaQuery,
List<LocationMarkerEntity> 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<LocationMarkerEntity> geoAuthorsForGeoCriteria = elasticsearchTemplate.queryForList(geoLocationCriteriaQuery,
List<LocationMarkerEntity> 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<LocationMarkerEntity> geoAuthorsForGeoCriteria = elasticsearchTemplate.queryForList(geoLocationCriteriaQuery,
List<LocationMarkerEntity> 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<LocationMarkerEntity> geoAuthorsForGeoCriteria = elasticsearchTemplate.queryForList(geoLocationCriteriaQuery,
List<LocationMarkerEntity> 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<LocationMarkerEntity> geoAuthorsForGeoCriteria = elasticsearchTemplate.queryForList(queryBuilder.build(),
List<LocationMarkerEntity> 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<AuthorMarkerEntity> geoAuthorsForGeoCriteria3 = elasticsearchTemplate.queryForList(geoLocationCriteriaQuery3,
List<AuthorMarkerEntity> 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<AuthorMarkerEntity> geoAuthorsForGeoCriteria3 = elasticsearchTemplate.queryForList(geoLocationCriteriaQuery3,
List<AuthorMarkerEntity> 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<AuthorMarkerEntity> geoAuthorsForGeoCriteria3 = elasticsearchTemplate.queryForList(geoLocationCriteriaQuery3,
List<AuthorMarkerEntity> 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<AuthorMarkerEntity> geoAuthorsForGeoCriteria3 = elasticsearchTemplate.queryForList(geoLocationCriteriaQuery3,
List<AuthorMarkerEntity> geoAuthorsForGeoCriteria3 = operations.queryForList(geoLocationCriteriaQuery3,
AuthorMarkerEntity.class, authorMarkerIndex);
// then
@ -332,18 +338,18 @@ public class ElasticsearchTemplateGeoTests {
.withFilter(QueryBuilders.geoBoundingBoxQuery("locationAsGeoHash").setCorners("u10j46mkfek"));
// when
List<LocationMarkerEntity> result1 = elasticsearchTemplate.queryForList(location1.build(),
LocationMarkerEntity.class, locationMarkerIndex);
List<LocationMarkerEntity> result2 = elasticsearchTemplate.queryForList(location2.build(),
LocationMarkerEntity.class, locationMarkerIndex);
List<LocationMarkerEntity> result3 = elasticsearchTemplate.queryForList(location3.build(),
LocationMarkerEntity.class, locationMarkerIndex);
List<LocationMarkerEntity> result4 = elasticsearchTemplate.queryForList(location4.build(),
LocationMarkerEntity.class, locationMarkerIndex);
List<LocationMarkerEntity> result5 = elasticsearchTemplate.queryForList(location5.build(),
LocationMarkerEntity.class, locationMarkerIndex);
List<LocationMarkerEntity> result11 = elasticsearchTemplate.queryForList(location11.build(),
LocationMarkerEntity.class, locationMarkerIndex);
List<LocationMarkerEntity> result1 = operations.queryForList(location1.build(), LocationMarkerEntity.class,
locationMarkerIndex);
List<LocationMarkerEntity> result2 = operations.queryForList(location2.build(), LocationMarkerEntity.class,
locationMarkerIndex);
List<LocationMarkerEntity> result3 = operations.queryForList(location3.build(), LocationMarkerEntity.class,
locationMarkerIndex);
List<LocationMarkerEntity> result4 = operations.queryForList(location4.build(), LocationMarkerEntity.class,
locationMarkerIndex);
List<LocationMarkerEntity> result5 = operations.queryForList(location5.build(), LocationMarkerEntity.class,
locationMarkerIndex);
List<LocationMarkerEntity> result11 = operations.queryForList(location11.build(), LocationMarkerEntity.class,
locationMarkerIndex);
// then
assertThat(result1).hasSize(3);

View File

@ -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 {}
}

View File

@ -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<SampleEntity> page = elasticsearchTemplate.queryForPage(criteriaQuery, SampleEntity.class, index);
Page<SampleEntity> 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<SampleEntity> page = elasticsearchTemplate.queryForPage(criteriaQuery, SampleEntity.class, index);
Page<SampleEntity> 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<SampleEntity> page = elasticsearchTemplate.queryForPage(criteriaQuery, SampleEntity.class, index);
Page<SampleEntity> 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<SampleEntity> page = elasticsearchTemplate.queryForPage(criteriaQuery, SampleEntity.class, index);
Page<SampleEntity> 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<SampleEntity> page = elasticsearchTemplate.queryForPage(criteriaQuery, SampleEntity.class, index);
Page<SampleEntity> 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<SampleEntity> page = elasticsearchTemplate.queryForPage(criteriaQuery, SampleEntity.class, index);
Page<SampleEntity> 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<SampleEntity> page = elasticsearchTemplate.queryForPage(criteriaQuery, SampleEntity.class, index);
Page<SampleEntity> 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<SampleEntity> page = elasticsearchTemplate.queryForPage(criteriaQuery, SampleEntity.class, index);
Page<SampleEntity> 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<SampleEntity> page = elasticsearchTemplate.queryForPage(criteriaQuery, SampleEntity.class, index);
Page<SampleEntity> 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<SampleEntity> page = elasticsearchTemplate.queryForPage(criteriaQuery, SampleEntity.class, index);
Page<SampleEntity> 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<SampleEntity> page = elasticsearchTemplate.queryForPage(criteriaQuery, SampleEntity.class, index);
Page<SampleEntity> 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<SampleEntity> page = elasticsearchTemplate.queryForPage(criteriaQuery, SampleEntity.class, index);
Page<SampleEntity> 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();

View File

@ -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 {}
}

View File

@ -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);

View File

@ -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

View File

@ -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 {}
}

View File

@ -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";
}
}

View File

@ -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

View File

@ -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 {}
}

View File

@ -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;
}
}

View File

@ -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);
}
}

View File

@ -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

View File

@ -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 {}
}

View File

@ -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;

View File

@ -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 {}
}

View File

@ -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

View File

@ -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 {}
}

View File

@ -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

View File

@ -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 {}
}

View File

@ -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

View File

@ -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 {}
}

View File

@ -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<String, Object> map = elasticsearchTemplate.getSetting(DynamicSettingAndMappingEntity.class);
assertThat(operations.indexExists(DynamicSettingAndMappingEntity.class)).isTrue();
Map<String, Object> 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<DynamicSettingAndMappingEntity> 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<DynamicSettingAndMappingEntity> 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<String, Object> mapping = elasticsearchTemplate.getMapping(DynamicSettingAndMappingEntity.class);
Map<String, Object> mapping = operations.getMapping(DynamicSettingAndMappingEntity.class);
// then
Map<String, Object> properties = (Map<String, Object>) 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<String, Object> mapping = elasticsearchTemplate.getMapping(DynamicSettingAndMappingEntity.class);
Map<String, Object> mapping = operations.getMapping(DynamicSettingAndMappingEntity.class);
Map<String, Object> properties = (Map<String, Object>) mapping.get("properties");
assertThat(mapping).isNotNull();
assertThat(properties).isNotNull();
@ -173,7 +171,7 @@ public class DynamicSettingAndMappingEntityRepositoryTests {
// given
// then
Map<String, Object> mapping = elasticsearchTemplate.getMapping(DynamicSettingAndMappingEntity.class);
Map<String, Object> mapping = operations.getMapping(DynamicSettingAndMappingEntity.class);
Map<String, Object> properties = (Map<String, Object>) mapping.get("properties");
assertThat(mapping).isNotNull();
assertThat(properties).isNotNull();

View File

@ -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 {}
}

View File

@ -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<String, Object> mapping = elasticsearchTemplate.getMapping(FieldDynamicMappingEntity.class);
Map<String, Object> mapping = operations.getMapping(FieldDynamicMappingEntity.class);
assertThat(mapping).isNotNull();
Map<String, Object> properties = (Map<String, Object>) mapping.get("properties");

View File

@ -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 {}
}

View File

@ -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);
}

View File

@ -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 {}
}

View File

@ -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<SynonymEntity> synonymEntities = elasticsearchTemplate.queryForList(
List<SynonymEntity> 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);
}

View File

@ -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 {}
}

View File

@ -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

View File

@ -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 {}
}

View File

@ -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

View File

@ -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 {

View File

@ -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 {}
}

View File

@ -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;

View File

@ -1,23 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch https://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<import resource="infrastructure.xml"/>
<bean name="elasticsearchTemplate"
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
<constructor-arg name="client" ref="client"/>
</bean>
<elasticsearch:repositories
base-package="org.springframework.data.elasticsearch.repositories.complex.custommethod.manualwiring"/>
<bean id="complexElasticsearchRepositoryManualWiringImpl"
class="org.springframework.data.elasticsearch.repositories.complex.custommethod.manualwiring.ComplexElasticsearchRepositoryManualWiringImpl">
<property name="template" ref="elasticsearchTemplate"/>
</bean>
</beans>

View File

@ -1,19 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch https://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<import resource="infrastructure.xml"/>
<bean name="elasticsearchTemplate"
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
<constructor-arg name="client" ref="client"/>
</bean>
<elasticsearch:repositories
base-package="org.springframework.data.elasticsearch.repositories.doubleid"
consider-nested-repositories="true"/>
</beans>

View File

@ -1,19 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch https://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<import resource="infrastructure.xml"/>
<bean name="elasticsearchTemplate"
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
<constructor-arg name="client" ref="client"/>
</bean>
<elasticsearch:repositories
base-package="org.springframework.data.elasticsearch.repositories.dynamicindex"
consider-nested-repositories="true"/>
</beans>

View File

@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch https://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
<import resource="infrastructure.xml"/>
<bean name="elasticsearchTemplate"
class="org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate">
<constructor-arg name="client" ref="restClient"/>
</bean>
<elasticsearch:rest-client id="restClient"/>
</beans>

View File

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<import resource="infrastructure.xml"/>
<bean name="elasticsearchTemplate"
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
<constructor-arg name="client" ref="client"/>
</bean>
</beans>

View File

@ -1,19 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch https://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<import resource="infrastructure.xml"/>
<bean name="elasticsearchTemplate"
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
<constructor-arg name="client" ref="client"/>
</bean>
<elasticsearch:repositories
base-package="org.springframework.data.elasticsearch.repositories.existing.index"
consider-nested-repositories="true" />
</beans>

View File

@ -1,19 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch https://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<import resource="infrastructure.xml"/>
<bean name="elasticsearchTemplate"
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
<constructor-arg name="client" ref="client"/>
</bean>
<elasticsearch:repositories
base-package="org.springframework.data.elasticsearch.repositories.setting.fielddynamic"
consider-nested-repositories="true"/>
</beans>

View File

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch https://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
<elasticsearch:node-client id="client" local="true" cluster-name="#{T(java.util.UUID).randomUUID().toString()}"
http-enabled="true" path-data="target/elasticsearchTestData" path-home="src/test/resources/test-home-dir"
path-configuration="node-client-configuration.yml"/>
<!-- ip4 -->
<!--<elasticsearch:transport-client id="client" cluster-name="elasticsearch" cluster-nodes="127.0.0.1:9300" />-->
<!-- ip6 -->
<!--<elasticsearch:transport-client id="client" cluster-name="elasticsearch" cluster-nodes="[::1]:9300" />-->
</beans>

View File

@ -1,19 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch https://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<import resource="infrastructure.xml"/>
<bean name="elasticsearchTemplate"
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
<constructor-arg name="client" ref="client"/>
</bean>
<elasticsearch:repositories
base-package="org.springframework.data.elasticsearch.repositories.integer"
consider-nested-repositories="true" />
</beans>

View File

@ -1,19 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch https://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch https://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<import resource="infrastructure.xml"/>
<elasticsearch:node-client id="client" local="true" cluster-name="#{T(java.util.UUID).randomUUID().toString()}"
http-enabled="true" path-data="target/elasticsearchTestData" path-home="src/test/resources/test-home-dir"
path-configuration="node-client-configuration.yml"/>
<bean name="elasticsearchTemplate"
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
<constructor-arg name="client" ref="client"/>
</bean>
<bean name="elasticsearchTemplate"
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
<constructor-arg name="client" ref="client"/>
</bean>
<elasticsearch:repositories
base-package="org.springframework.data.elasticsearch.repositories.nondocument"
consider-nested-repositories="true"/>
<elasticsearch:repositories
base-package="org.springframework.data.elasticsearch.repositories.nondocument"
consider-nested-repositories="true"/>
</beans>

View File

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch https://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<import resource="infrastructure.xml"/>
<bean name="elasticsearchTemplate"
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
<constructor-arg name="client" ref="client"/>
</bean>
<elasticsearch:repositories base-package="org.springframework.data.elasticsearch.repositories.nestedobject"
consider-nested-repositories="true"/>
</beans>

View File

@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch https://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<import resource="infrastructure.xml"/>
<bean name="elasticsearchTemplate"
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
<constructor-arg name="client" ref="client"/>
</bean>
<elasticsearch:repositories base-package="org.springframework.data.elasticsearch"/>
</beans>

View File

@ -1,19 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch https://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<import resource="infrastructure.xml"/>
<bean name="elasticsearchTemplate"
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
<constructor-arg name="client" ref="client"/>
</bean>
<elasticsearch:repositories
base-package="org.springframework.data.elasticsearch.repositories.synonym"
consider-nested-repositories="true"/>
</beans>