mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-21 11:32:12 +00:00
parent
4e7f1ccb4b
commit
a438b38f05
@ -20,7 +20,7 @@ import static org.assertj.core.api.Assertions.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.elasticsearch.core.document.Document;
|
||||
|
||||
/**
|
||||
|
@ -34,9 +34,8 @@ import java.util.Map;
|
||||
import org.apache.lucene.search.join.ScoreMode;
|
||||
import org.elasticsearch.index.query.BoolQueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.junit.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.data.annotation.Id;
|
||||
import org.springframework.data.domain.Page;
|
||||
@ -50,9 +49,10 @@ import org.springframework.data.elasticsearch.core.query.GetQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
||||
import org.springframework.data.elasticsearch.core.query.SearchQuery;
|
||||
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
||||
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
||||
import org.springframework.data.elasticsearch.utils.IndexInitializer;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
@ -61,13 +61,13 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
* @author Peter-Josef Meisch
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration("classpath:/elasticsearch-template-test.xml")
|
||||
@SpringIntegrationTest
|
||||
@ContextConfiguration(classes = { ElasticsearchTemplateConfiguration.class })
|
||||
public class NestedObjectTests {
|
||||
|
||||
@Autowired private ElasticsearchTemplate elasticsearchTemplate;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
|
||||
IndexInitializer.init(elasticsearchTemplate, Book.class);
|
||||
|
@ -24,7 +24,7 @@ import java.time.Duration;
|
||||
import javax.net.ssl.SSLContext;
|
||||
|
||||
import org.apache.http.conn.ssl.NoopHostnameVerifier;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
|
||||
/**
|
||||
|
@ -17,7 +17,7 @@ package org.springframework.data.elasticsearch.client;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ClusterNodes}.
|
||||
|
@ -19,7 +19,7 @@ import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link InetSocketAddressParser}.
|
||||
|
@ -19,7 +19,7 @@ import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
/**
|
||||
|
@ -21,8 +21,8 @@ import static org.mockito.Mockito.*;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.elasticsearch.client.ElasticsearchHost;
|
||||
import org.springframework.data.elasticsearch.client.ElasticsearchHost.State;
|
||||
import org.springframework.data.elasticsearch.client.reactive.HostProvider.Verification;
|
||||
@ -32,7 +32,6 @@ import org.springframework.web.reactive.function.client.ClientResponse;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
* @currentRead Golden Fool - Robin Hobb
|
||||
*/
|
||||
public class MultiNodeHostProviderUnitTests {
|
||||
|
||||
@ -43,7 +42,7 @@ public class MultiNodeHostProviderUnitTests {
|
||||
MockDelegatingElasticsearchHostProvider<MultiNodeHostProvider> mock;
|
||||
MultiNodeHostProvider provider;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
|
||||
mock = ReactiveMockClientTestsUtils.multi(HOST_1, HOST_2, HOST_3);
|
||||
|
@ -38,8 +38,8 @@ import org.elasticsearch.action.update.UpdateRequest;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.VersionType;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.reactivestreams.Publisher;
|
||||
import org.springframework.data.elasticsearch.client.reactive.ReactiveMockClientTestsUtils.MockDelegatingElasticsearchHostProvider;
|
||||
@ -51,7 +51,6 @@ import org.springframework.util.StreamUtils;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
* @currentRead Golden Fool - Robin Hobb
|
||||
*/
|
||||
public class ReactiveElasticsearchClientUnitTests {
|
||||
|
||||
@ -60,7 +59,7 @@ public class ReactiveElasticsearchClientUnitTests {
|
||||
MockDelegatingElasticsearchHostProvider<HostProvider> hostProvider;
|
||||
ReactiveElasticsearchClient client;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
|
||||
hostProvider = ReactiveMockClientTestsUtils.provider(HOST).withActiveDefaultHost(HOST);
|
||||
|
@ -20,8 +20,8 @@ import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.elasticsearch.client.ElasticsearchHost;
|
||||
import org.springframework.data.elasticsearch.client.ElasticsearchHost.State;
|
||||
import org.springframework.data.elasticsearch.client.NoReachableHostException;
|
||||
@ -30,7 +30,6 @@ import org.springframework.data.elasticsearch.client.reactive.ReactiveMockClient
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
* @currentRead Golden Fool - Robin Hobb
|
||||
*/
|
||||
public class SingleNodeHostProviderUnitTests {
|
||||
|
||||
@ -39,7 +38,7 @@ public class SingleNodeHostProviderUnitTests {
|
||||
MockDelegatingElasticsearchHostProvider<SingleNodeHostProvider> mock;
|
||||
SingleNodeHostProvider provider;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
|
||||
mock = ReactiveMockClientTestsUtils.single(HOST_1);
|
||||
|
@ -15,14 +15,14 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.client.util;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.elasticsearch.action.delete.DeleteRequest;
|
||||
import org.elasticsearch.action.index.IndexRequest;
|
||||
import org.elasticsearch.client.Request;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link RequestConverters}.
|
||||
@ -38,8 +38,7 @@ public class RequestConvertersTest {
|
||||
|
||||
Request result = RequestConverters.index(request);
|
||||
|
||||
assertThat(result.getParameters())
|
||||
.doesNotContainKeys("if_seq_no", "if_primary_term");
|
||||
assertThat(result.getParameters()).doesNotContainKeys("if_seq_no", "if_primary_term");
|
||||
}
|
||||
|
||||
private IndexRequest createMinimalIndexRequest() {
|
||||
@ -58,8 +57,7 @@ public class RequestConvertersTest {
|
||||
|
||||
Request result = RequestConverters.index(request);
|
||||
|
||||
assertThat(result.getParameters()).containsEntry("if_seq_no", "3")
|
||||
.containsEntry("if_primary_term", "4");
|
||||
assertThat(result.getParameters()).containsEntry("if_seq_no", "3").containsEntry("if_primary_term", "4");
|
||||
}
|
||||
|
||||
@Test // DATAES-652
|
||||
@ -69,8 +67,7 @@ public class RequestConvertersTest {
|
||||
|
||||
Request result = RequestConverters.delete(request);
|
||||
|
||||
assertThat(result.getParameters())
|
||||
.doesNotContainKeys("if_seq_no", "if_primary_term");
|
||||
assertThat(result.getParameters()).doesNotContainKeys("if_seq_no", "if_primary_term");
|
||||
}
|
||||
|
||||
private DeleteRequest createMinimalDeleteRequest() {
|
||||
|
@ -28,7 +28,7 @@ import org.elasticsearch.common.document.DocumentField;
|
||||
import org.elasticsearch.common.text.Text;
|
||||
import org.elasticsearch.index.get.GetResult;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.elasticsearch.core.document.Document;
|
||||
import org.springframework.data.elasticsearch.core.document.DocumentAdapters;
|
||||
import org.springframework.data.elasticsearch.core.document.SearchDocument;
|
||||
|
@ -31,15 +31,15 @@ import org.elasticsearch.ElasticsearchStatusException;
|
||||
import org.elasticsearch.action.index.IndexRequest;
|
||||
import org.elasticsearch.action.update.UpdateRequest;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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;
|
||||
import org.springframework.data.elasticsearch.core.query.UpdateQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.UpdateQueryBuilder;
|
||||
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
|
||||
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
/**
|
||||
@ -56,11 +56,11 @@ import org.springframework.test.util.ReflectionTestUtils;
|
||||
* @author Don Wellington
|
||||
* @author Peter-Josef Meisch
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration("classpath:elasticsearch-rest-template-test.xml")
|
||||
@SpringIntegrationTest
|
||||
@ContextConfiguration(classes = { ElasticsearchRestTemplateConfiguration.class })
|
||||
public class ElasticsearchRestTemplateTests extends ElasticsearchTemplateTests {
|
||||
|
||||
@Test(expected = ElasticsearchStatusException.class)
|
||||
@Test
|
||||
public void shouldThrowExceptionIfDocumentDoesNotExistWhileDoingPartialUpdate() {
|
||||
|
||||
// when
|
||||
@ -68,7 +68,9 @@ public class ElasticsearchRestTemplateTests extends ElasticsearchTemplateTests {
|
||||
indexRequest.source("{}", XContentType.JSON);
|
||||
UpdateQuery updateQuery = new UpdateQueryBuilder().withId(randomNumeric(5)).withClass(SampleEntity.class)
|
||||
.withIndexRequest(indexRequest).build();
|
||||
elasticsearchTemplate.update(updateQuery);
|
||||
assertThatThrownBy(() -> {
|
||||
elasticsearchTemplate.update(updateQuery);
|
||||
}).isInstanceOf(ElasticsearchStatusException.class);
|
||||
}
|
||||
|
||||
@Test // DATAES-227
|
||||
|
@ -53,9 +53,9 @@ import org.elasticsearch.script.ScriptType;
|
||||
import org.elasticsearch.search.sort.FieldSortBuilder;
|
||||
import org.elasticsearch.search.sort.SortBuilders;
|
||||
import org.elasticsearch.search.sort.SortOrder;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
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.data.annotation.Id;
|
||||
import org.springframework.data.annotation.Version;
|
||||
@ -110,7 +110,7 @@ public abstract class ElasticsearchTemplateTests {
|
||||
|
||||
@Autowired protected ElasticsearchOperations elasticsearchTemplate;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
|
||||
deleteIndices();
|
||||
@ -122,7 +122,7 @@ public abstract class ElasticsearchTemplateTests {
|
||||
elasticsearchTemplate.putMapping(SampleEntityUUIDKeyed.class);
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void after() {
|
||||
|
||||
deleteIndices();
|
||||
@ -306,7 +306,7 @@ public abstract class ElasticsearchTemplateTests {
|
||||
assertThat(sampleEntities.getTotalElements()).isGreaterThanOrEqualTo(1);
|
||||
}
|
||||
|
||||
@Test(expected = Exception.class) // DATAES-595
|
||||
@Test // DATAES-595
|
||||
public void shouldThrowExceptionWhenInvalidPreferenceForSearchQuery() {
|
||||
|
||||
// given
|
||||
@ -323,10 +323,9 @@ public abstract class ElasticsearchTemplateTests {
|
||||
.withPreference("_only_nodes:oops").build();
|
||||
|
||||
// when
|
||||
elasticsearchTemplate.queryForPage(searchQueryWithInvalidPreference, SampleEntity.class);
|
||||
|
||||
// then Throw IllegalArgumentException in case of ElasticsearchTemplate and ElasticsearchStatusException in case of
|
||||
// ElasticsearchRestTemplate
|
||||
assertThatThrownBy(() -> {
|
||||
elasticsearchTemplate.queryForPage(searchQueryWithInvalidPreference, SampleEntity.class);
|
||||
}).isInstanceOf(Exception.class);
|
||||
}
|
||||
|
||||
@Test // DATAES-422 - Add support for IndicesOptions in search queries
|
||||
@ -1639,17 +1638,17 @@ public abstract class ElasticsearchTemplateTests {
|
||||
assertThat(page.getContent().get(0).getId()).isEqualTo(indexQuery.getId());
|
||||
}
|
||||
|
||||
@Test(expected = ElasticsearchException.class)
|
||||
@Test
|
||||
public void shouldThrowElasticsearchExceptionWhenNoDocumentSpecified() {
|
||||
|
||||
// given
|
||||
IndexQuery indexQuery = new IndexQuery();
|
||||
final IndexQuery indexQuery = new IndexQuery();
|
||||
indexQuery.setId("2333343434");
|
||||
indexQuery.setIndexName(INDEX_NAME_SAMPLE_ENTITY);
|
||||
indexQuery.setType(TYPE_NAME);
|
||||
|
||||
// when
|
||||
elasticsearchTemplate.index(indexQuery);
|
||||
assertThatThrownBy(() -> elasticsearchTemplate.index(indexQuery)).isInstanceOf(ElasticsearchException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -2136,7 +2135,7 @@ public abstract class ElasticsearchTemplateTests {
|
||||
assertThat(count).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void shouldThrowAnExceptionForGivenCriteriaQueryWhenNoIndexSpecifiedForCountQuery() {
|
||||
|
||||
// given
|
||||
@ -2150,13 +2149,12 @@ public abstract class ElasticsearchTemplateTests {
|
||||
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria());
|
||||
|
||||
// when
|
||||
long count = elasticsearchTemplate.count(criteriaQuery);
|
||||
|
||||
// then
|
||||
assertThat(count).isEqualTo(1);
|
||||
assertThatThrownBy(() -> {
|
||||
long count = elasticsearchTemplate.count(criteriaQuery);
|
||||
}).isInstanceOf(IllegalArgumentException.class);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATAES-67
|
||||
@Test // DATAES-67
|
||||
public void shouldThrowAnExceptionForGivenSearchQueryWhenNoIndexSpecifiedForCountQuery() {
|
||||
|
||||
// given
|
||||
@ -2170,7 +2168,9 @@ public abstract class ElasticsearchTemplateTests {
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).build();
|
||||
|
||||
// when
|
||||
elasticsearchTemplate.count(searchQuery);
|
||||
assertThatThrownBy(() -> {
|
||||
elasticsearchTemplate.count(searchQuery);
|
||||
}).isInstanceOf(IllegalArgumentException.class);
|
||||
}
|
||||
|
||||
@Test // DATAES-71
|
||||
|
@ -16,6 +16,7 @@
|
||||
package org.springframework.data.elasticsearch.core;
|
||||
|
||||
import static org.apache.commons.lang.RandomStringUtils.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldType.*;
|
||||
|
||||
import lombok.Data;
|
||||
@ -23,32 +24,33 @@ import lombok.Data;
|
||||
import org.elasticsearch.action.index.IndexRequest;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.engine.DocumentMissingException;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
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;
|
||||
import org.springframework.data.elasticsearch.core.query.UpdateQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.UpdateQueryBuilder;
|
||||
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
||||
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* @author Peter-Josef Meisch
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration("classpath:elasticsearch-template-test.xml")
|
||||
@SpringIntegrationTest
|
||||
@ContextConfiguration(classes = { ElasticsearchTemplateConfiguration.class })
|
||||
public class ElasticsearchTransportTemplateTests extends ElasticsearchTemplateTests {
|
||||
|
||||
@Test(expected = DocumentMissingException.class)
|
||||
@Test
|
||||
public void shouldThrowExceptionIfDocumentDoesNotExistWhileDoingPartialUpdate() {
|
||||
// when
|
||||
IndexRequest indexRequest = new IndexRequest();
|
||||
indexRequest.source("{}", XContentType.JSON);
|
||||
UpdateQuery updateQuery = new UpdateQueryBuilder().withId(randomNumeric(5)).withClass(SampleEntity.class)
|
||||
.withIndexRequest(indexRequest).build();
|
||||
elasticsearchTemplate.update(updateQuery);
|
||||
assertThatThrownBy(() -> {
|
||||
elasticsearchTemplate.update(updateQuery);
|
||||
}).isInstanceOf(DocumentMissingException.class);
|
||||
}
|
||||
|
||||
@Data
|
||||
|
@ -28,10 +28,8 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.elasticsearch.action.search.SearchPhaseExecutionException;
|
||||
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.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
@ -39,9 +37,10 @@ import org.springframework.data.elasticsearch.annotations.Field;
|
||||
import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
||||
import org.springframework.data.elasticsearch.core.query.SearchQuery;
|
||||
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
||||
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
||||
import org.springframework.data.elasticsearch.utils.IndexInitializer;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* LogEntityTests
|
||||
@ -50,13 +49,13 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
* @author Mohsin Husen
|
||||
* @author Peter-Josef Meisch
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration("classpath:elasticsearch-template-test.xml")
|
||||
@SpringIntegrationTest
|
||||
@ContextConfiguration(classes = { ElasticsearchTemplateConfiguration.class })
|
||||
public class LogEntityTests {
|
||||
|
||||
@Autowired private ElasticsearchTemplate template;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void before() throws ParseException {
|
||||
|
||||
IndexInitializer.init(template, LogEntity.class);
|
||||
@ -89,15 +88,15 @@ public class LogEntityTests {
|
||||
assertThat(entities).isNotNull().hasSize(1);
|
||||
}
|
||||
|
||||
@Test(expected = SearchPhaseExecutionException.class) // DATAES-66
|
||||
@Test // DATAES-66
|
||||
public void shouldThrowExceptionWhenInvalidIPGivenForSearchQuery() {
|
||||
|
||||
// when
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(termQuery("ip", "10.10.10")).build();
|
||||
List<LogEntity> entities = template.queryForList(searchQuery, LogEntity.class);
|
||||
|
||||
// then
|
||||
assertThat(entities).isNotNull().hasSize(1);
|
||||
assertThatThrownBy(() -> {
|
||||
List<LogEntity> entities = template.queryForList(searchQuery, LogEntity.class);
|
||||
}).isInstanceOf(SearchPhaseExecutionException.class);
|
||||
}
|
||||
|
||||
@Test // DATAES-66
|
||||
|
@ -23,7 +23,7 @@ import java.util.TimeZone;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.joda.time.LocalDateTime;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
|
@ -29,9 +29,8 @@ import java.util.List;
|
||||
|
||||
import org.elasticsearch.geo.utils.Geohash;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
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.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
@ -41,28 +40,30 @@ 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.SpringIntegrationTest;
|
||||
import org.springframework.data.elasticsearch.utils.IndexInitializer;
|
||||
import org.springframework.data.geo.Point;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Franck Marchand
|
||||
* @author Artur Konczak
|
||||
* @author Peter-Josef Meisch Basic info: latitude - horizontal lines (equator = 0.0, values -90.0 to 90.0) longitude -
|
||||
* vertical lines (Greenwich = 0.0, values -180 to 180) London [lat,lon] = [51.50985,-0.118082] - geohash =
|
||||
* gcpvj3448 Bouding Box for London = (bbox=-0.489,51.28,0.236,51.686) bbox = left,bottom,right,top bbox = min
|
||||
* Longitude , min Latitude , max Longitude , max Latitude
|
||||
* @author Peter-Josef Meisch <br/>
|
||||
* Basic info: latitude - horizontal lines (equator = 0.0, values -90.0 to 90.0) longitude - vertical lines
|
||||
* (Greenwich = 0.0, values -180 to 180) London [lat,lon] = [51.50985,-0.118082] - geohash = gcpvj3448 Bouding
|
||||
* Box for London = (bbox=-0.489,51.28,0.236,51.686) bbox = left,bottom,right,top bbox = min Longitude , min
|
||||
* Latitude , max Longitude , max Latitude
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration("classpath:elasticsearch-template-test.xml")
|
||||
@SpringIntegrationTest
|
||||
@ContextConfiguration(classes = { ElasticsearchTemplateConfiguration.class })
|
||||
public class ElasticsearchTemplateGeoTests {
|
||||
|
||||
@Autowired private ElasticsearchTemplate elasticsearchTemplate;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
|
||||
IndexInitializer.init(elasticsearchTemplate, AuthorMarkerEntity.class);
|
||||
@ -257,8 +258,8 @@ public class ElasticsearchTemplateGeoTests {
|
||||
|
||||
// given
|
||||
loadClassBaseEntities();
|
||||
CriteriaQuery geoLocationCriteriaQuery3 = new CriteriaQuery(new Criteria("location")
|
||||
.boundedBy(Geohash.stringEncode(0, 53.5171d), Geohash.stringEncode(0.2062d, 49.5171d)));
|
||||
CriteriaQuery geoLocationCriteriaQuery3 = new CriteriaQuery(
|
||||
new Criteria("location").boundedBy(Geohash.stringEncode(0, 53.5171d), Geohash.stringEncode(0.2062d, 49.5171d)));
|
||||
|
||||
// when
|
||||
List<AuthorMarkerEntity> geoAuthorsForGeoCriteria3 = elasticsearchTemplate.queryForList(geoLocationCriteriaQuery3,
|
||||
|
@ -44,25 +44,25 @@ import java.util.Set;
|
||||
|
||||
import org.assertj.core.data.Percentage;
|
||||
import org.json.JSONException;
|
||||
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.data.annotation.Id;
|
||||
import org.springframework.data.annotation.Transient;
|
||||
import org.springframework.data.elasticsearch.annotations.*;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||
import org.springframework.data.elasticsearch.core.completion.Completion;
|
||||
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
||||
import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
||||
import org.springframework.data.elasticsearch.core.query.SearchQuery;
|
||||
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
||||
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
||||
import org.springframework.data.geo.Box;
|
||||
import org.springframework.data.geo.Circle;
|
||||
import org.springframework.data.geo.Point;
|
||||
import org.springframework.data.geo.Polygon;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* @author Stuart Stevenson
|
||||
@ -75,13 +75,13 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
* @author Peter-Josef Meisch
|
||||
* @author Xiao Yu
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration("classpath:elasticsearch-template-test.xml")
|
||||
@SpringIntegrationTest
|
||||
@ContextConfiguration(classes = { ElasticsearchTemplateConfiguration.class })
|
||||
public class MappingBuilderTests extends MappingContextBaseTests {
|
||||
|
||||
@Autowired private ElasticsearchTemplate elasticsearchTemplate;
|
||||
@Autowired private ElasticsearchOperations elasticsearchTemplate;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
|
||||
elasticsearchTemplate.deleteIndex(StockPrice.class);
|
||||
|
@ -4,7 +4,7 @@ import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||
import org.springframework.data.elasticsearch.annotations.InnerField;
|
||||
|
@ -21,16 +21,15 @@ import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
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.DynamicTemplates;
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
||||
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* Dynamic templates tests
|
||||
@ -38,8 +37,8 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
* @author Petr Kukral
|
||||
* @author Peter-Josef Meisch
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration("classpath:elasticsearch-template-test.xml")
|
||||
@SpringIntegrationTest
|
||||
@ContextConfiguration(classes = { ElasticsearchTemplateConfiguration.class })
|
||||
public class SimpleDynamicTemplatesMappingTests extends MappingContextBaseTests {
|
||||
|
||||
@Test // DATAES-568
|
||||
|
@ -23,7 +23,7 @@ import lombok.Data;
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.annotations.DateFormat;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
|
@ -19,7 +19,7 @@ import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.beans.IntrospectionException;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.annotation.Version;
|
||||
import org.springframework.data.elasticsearch.annotations.Score;
|
||||
import org.springframework.data.mapping.MappingException;
|
||||
@ -34,23 +34,23 @@ import org.springframework.util.ReflectionUtils;
|
||||
* @author Mohsin Husen
|
||||
* @author Mark Paluch
|
||||
* @author Oliver Gierke
|
||||
* @author Peter-Josef Meisch
|
||||
*/
|
||||
public class SimpleElasticsearchPersistentEntityTests {
|
||||
|
||||
@Test(expected = MappingException.class)
|
||||
@Test
|
||||
public void shouldThrowExceptionGivenVersionPropertyIsNotLong() throws NoSuchFieldException, IntrospectionException {
|
||||
// given
|
||||
TypeInformation typeInformation = ClassTypeInformation.from(EntityWithWrongVersionType.class);
|
||||
SimpleElasticsearchPersistentEntity<EntityWithWrongVersionType> entity = new SimpleElasticsearchPersistentEntity<>(
|
||||
typeInformation);
|
||||
|
||||
SimpleElasticsearchPersistentProperty persistentProperty = createProperty(entity, "version");
|
||||
|
||||
// when
|
||||
entity.addPersistentProperty(persistentProperty);
|
||||
assertThatThrownBy(() -> {
|
||||
SimpleElasticsearchPersistentProperty persistentProperty = createProperty(entity, "version");
|
||||
}).isInstanceOf(MappingException.class);
|
||||
}
|
||||
|
||||
@Test(expected = MappingException.class)
|
||||
@Test
|
||||
public void shouldThrowExceptionGivenMultipleVersionPropertiesArePresent()
|
||||
throws NoSuchFieldException, IntrospectionException {
|
||||
// given
|
||||
@ -64,7 +64,9 @@ public class SimpleElasticsearchPersistentEntityTests {
|
||||
|
||||
entity.addPersistentProperty(persistentProperty1);
|
||||
// when
|
||||
entity.addPersistentProperty(persistentProperty2);
|
||||
assertThatThrownBy(() -> {
|
||||
entity.addPersistentProperty(persistentProperty2);
|
||||
}).isInstanceOf(MappingException.class);
|
||||
}
|
||||
|
||||
@Test // DATAES-462
|
||||
|
@ -17,7 +17,7 @@ package org.springframework.data.elasticsearch.core.mapping;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
import org.springframework.data.elasticsearch.annotations.Score;
|
||||
import org.springframework.data.mapping.MappingException;
|
||||
|
@ -15,7 +15,9 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.repositories.nondocument;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
@ -29,11 +31,13 @@ import org.springframework.data.elasticsearch.repository.ElasticsearchRepository
|
||||
*/
|
||||
public class NonDocumentEntityTests {
|
||||
|
||||
@Test(expected = BeanCreationException.class)
|
||||
@Test
|
||||
public void shouldNotInitialiseRepositoryWithNonDocument() {
|
||||
// when
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/repository-non-document-entity.xml");
|
||||
ctx.getBean(NonDocumentEntityRepository.class);
|
||||
assertThatThrownBy(() -> {
|
||||
ctx.getBean(NonDocumentEntityRepository.class);
|
||||
}).isInstanceOf(BeanCreationException.class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -18,18 +18,21 @@ package org.springframework.data.elasticsearch.repositories.spel;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
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.core.ElasticsearchTemplate;
|
||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
|
||||
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
||||
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;
|
||||
|
||||
/**
|
||||
* SpELEntityTest
|
||||
@ -37,16 +40,20 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
* @author Artur Konczak
|
||||
* @author Peter-Josef Meisch
|
||||
*/
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration("classpath:/spel-repository-test.xml")
|
||||
@SpringIntegrationTest
|
||||
@ContextConfiguration(classes = { SpELEntityTests.Config.class })
|
||||
public class SpELEntityTests {
|
||||
|
||||
@Autowired private SpELRepository repository;
|
||||
|
||||
@Autowired private ElasticsearchTemplate template;
|
||||
|
||||
@Before
|
||||
@Configuration
|
||||
@Import(ElasticsearchTemplateConfiguration.class)
|
||||
@EnableElasticsearchRepositories(considerNestedRepositories = true)
|
||||
static class Config {}
|
||||
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
IndexInitializer.init(template, SpELEntity.class);
|
||||
}
|
||||
|
@ -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.spel"
|
||||
consider-nested-repositories="true" />
|
||||
|
||||
</beans>
|
Loading…
x
Reference in New Issue
Block a user