fixed tests

This commit is contained in:
Mathieu Fortin 2020-04-13 13:02:12 -04:00
parent 745d5edda1
commit c1d547c5f0
5 changed files with 23 additions and 21 deletions

View File

@ -84,7 +84,7 @@
<properties> <properties>
<spring-data-elasticsearch.version>3.2.6.RELEASE</spring-data-elasticsearch.version> <spring-data-elasticsearch.version>3.2.6.RELEASE</spring-data-elasticsearch.version>
<jna.version>4.5.2</jna.version> <jna.version>4.5.2</jna.version>
<elasticsearch.version>7.6.2</elasticsearch.version> <elasticsearch.version>6.8.8</elasticsearch.version>
<fastjson.version>1.2.47</fastjson.version> <fastjson.version>1.2.47</fastjson.version>
<spatial4j.version>0.6</spatial4j.version> <spatial4j.version>0.6</spatial4j.version>
<jts.version>1.13</jts.version> <jts.version>1.13</jts.version>

View File

@ -58,7 +58,7 @@ public class ElasticSearchManualTest {
@Test @Test
public void givenJsonString_whenJavaObject_thenIndexDocument() throws Exception { public void givenJsonString_whenJavaObject_thenIndexDocument() throws Exception {
String jsonObject = "{\"age\":20,\"dateOfBirth\":1471466076564,\"fullName\":\"John Doe\"}"; String jsonObject = "{\"age\":20,\"dateOfBirth\":1471466076564,\"fullName\":\"John Doe\"}";
IndexRequest request = new IndexRequest("people"); IndexRequest request = new IndexRequest("people", "Doe");
request.source(jsonObject, XContentType.JSON); request.source(jsonObject, XContentType.JSON);
IndexResponse response = client.index(request, RequestOptions.DEFAULT); IndexResponse response = client.index(request, RequestOptions.DEFAULT);
@ -71,7 +71,7 @@ public class ElasticSearchManualTest {
@Test @Test
public void givenDocumentId_whenJavaObject_thenDeleteDocument() throws Exception { public void givenDocumentId_whenJavaObject_thenDeleteDocument() throws Exception {
String jsonObject = "{\"age\":10,\"dateOfBirth\":1471455886564,\"fullName\":\"Johan Doe\"}"; String jsonObject = "{\"age\":10,\"dateOfBirth\":1471455886564,\"fullName\":\"Johan Doe\"}";
IndexRequest indexRequest = new IndexRequest("people"); IndexRequest indexRequest = new IndexRequest("people", "Doe");
indexRequest.source(jsonObject, XContentType.JSON); indexRequest.source(jsonObject, XContentType.JSON);
IndexResponse response = client.index(indexRequest, RequestOptions.DEFAULT); IndexResponse response = client.index(indexRequest, RequestOptions.DEFAULT);
@ -79,6 +79,7 @@ public class ElasticSearchManualTest {
DeleteRequest deleteRequest = new DeleteRequest("people"); DeleteRequest deleteRequest = new DeleteRequest("people");
deleteRequest.id(id); deleteRequest.id(id);
deleteRequest.type("Doe");
DeleteResponse deleteResponse = client.delete(deleteRequest, RequestOptions.DEFAULT); DeleteResponse deleteResponse = client.delete(deleteRequest, RequestOptions.DEFAULT);
@ -95,6 +96,8 @@ public class ElasticSearchManualTest {
List<Person> results = Arrays.stream(searchHits) List<Person> results = Arrays.stream(searchHits)
.map(hit -> JSON.parseObject(hit.getSourceAsString(), Person.class)) .map(hit -> JSON.parseObject(hit.getSourceAsString(), Person.class))
.collect(Collectors.toList()); .collect(Collectors.toList());
results.forEach(System.out::println);
} }
@Test @Test
@ -140,6 +143,7 @@ public class ElasticSearchManualTest {
final List<Person> results = Arrays.stream(response.getHits().getHits()) final List<Person> results = Arrays.stream(response.getHits().getHits())
.map(hit -> JSON.parseObject(hit.getSourceAsString(), Person.class)) .map(hit -> JSON.parseObject(hit.getSourceAsString(), Person.class))
.collect(Collectors.toList()); .collect(Collectors.toList());
results.forEach(System.out::println);
} }
@Test @Test
@ -152,7 +156,7 @@ public class ElasticSearchManualTest {
.field("age", "10") .field("age", "10")
.endObject(); .endObject();
IndexRequest indexRequest = new IndexRequest("people"); IndexRequest indexRequest = new IndexRequest("people", "Doe");
indexRequest.source(builder); indexRequest.source(builder);
IndexResponse response = client.index(indexRequest, RequestOptions.DEFAULT); IndexResponse response = client.index(indexRequest, RequestOptions.DEFAULT);

View File

@ -79,8 +79,7 @@ public class GeoQueriesManualTest {
Coordinate topLeft = new Coordinate(74, 31.2); Coordinate topLeft = new Coordinate(74, 31.2);
Coordinate bottomRight = new Coordinate(81.1, 24); Coordinate bottomRight = new Coordinate(81.1, 24);
QueryBuilder qb = QueryBuilders QueryBuilder qb = QueryBuilders
.geoShapeQuery("region", new EnvelopeBuilder(topLeft, bottomRight).buildGeometry()); .geoShapeQuery("region", new EnvelopeBuilder(topLeft, bottomRight));
//.relation(ShapeRelation.WITHIN));
SearchResponse searchResponse = client.prepareSearch(WONDERS_OF_WORLD) SearchResponse searchResponse = client.prepareSearch(WONDERS_OF_WORLD)
.setTypes(WONDERS) .setTypes(WONDERS)

View File

@ -10,23 +10,23 @@ import static org.junit.Assert.assertNotNull;
import java.util.List; import java.util.List;
import com.baeldung.spring.data.es.config.Config;
import com.baeldung.spring.data.es.model.Article;
import com.baeldung.spring.data.es.model.Author;
import com.baeldung.spring.data.es.service.ArticleService;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder; import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.data.elasticsearch.core.query.SearchQuery; import org.springframework.data.elasticsearch.core.query.SearchQuery;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.baeldung.spring.data.es.config.Config;
import com.baeldung.spring.data.es.model.Article;
import com.baeldung.spring.data.es.model.Author;
import com.baeldung.spring.data.es.service.ArticleService;
/** /**
* *
* This Manual test requires: * This Manual test requires:
@ -39,7 +39,7 @@ import com.baeldung.spring.data.es.service.ArticleService;
public class ElasticSearchManualTest { public class ElasticSearchManualTest {
@Autowired @Autowired
private ElasticsearchTemplate elasticsearchTemplate; private ElasticsearchRestTemplate elasticsearchTemplate;
@Autowired @Autowired
private ArticleService articleService; private ArticleService articleService;

View File

@ -14,6 +14,11 @@ import static org.junit.Assert.assertEquals;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import com.baeldung.spring.data.es.config.Config;
import com.baeldung.spring.data.es.model.Article;
import com.baeldung.spring.data.es.model.Author;
import com.baeldung.spring.data.es.service.ArticleService;
import org.apache.lucene.search.join.ScoreMode; import org.apache.lucene.search.join.ScoreMode;
import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
@ -25,23 +30,17 @@ import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.BucketOrder; import org.elasticsearch.search.aggregations.BucketOrder;
import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation; import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation;
import org.elasticsearch.search.aggregations.bucket.terms.StringTerms; import org.elasticsearch.search.aggregations.bucket.terms.StringTerms;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder; import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder; import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.data.elasticsearch.core.query.SearchQuery; import org.springframework.data.elasticsearch.core.query.SearchQuery;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.baeldung.spring.data.es.config.Config;
import com.baeldung.spring.data.es.model.Article;
import com.baeldung.spring.data.es.model.Author;
import com.baeldung.spring.data.es.service.ArticleService;
/** /**
* *
* This Manual test requires: * This Manual test requires:
@ -54,7 +53,7 @@ import com.baeldung.spring.data.es.service.ArticleService;
public class ElasticSearchQueryManualTest { public class ElasticSearchQueryManualTest {
@Autowired @Autowired
private ElasticsearchTemplate elasticsearchTemplate; private ElasticsearchRestTemplate elasticsearchTemplate;
@Autowired @Autowired
private ArticleService articleService; private ArticleService articleService;