DATAES-180 - clean up
This commit is contained in:
@@ -22,6 +22,7 @@ import org.elasticsearch.action.get.MultiGetResponse;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
|
||||
|
||||
/**
|
||||
* @author Artur Konczak
|
||||
@@ -47,7 +48,7 @@ public class CustomResultMapper implements ResultsMapper {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Page<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
|
||||
@@ -29,13 +29,14 @@ import org.elasticsearch.search.SearchHitField;
|
||||
import org.elasticsearch.search.SearchHits;
|
||||
import org.elasticsearch.search.aggregations.Aggregation;
|
||||
import org.elasticsearch.search.aggregations.Aggregations;
|
||||
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
|
||||
import org.elasticsearch.search.internal.InternalSearchHitField;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.elasticsearch.core.domain.AggregatedPage;
|
||||
import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
|
||||
import org.springframework.data.elasticsearch.entities.Car;
|
||||
|
||||
/**
|
||||
@@ -68,7 +69,7 @@ public class DefaultResultMapperTests {
|
||||
Aggregations aggregations = mock(Aggregations.class);
|
||||
Iterator<Aggregation> iter = Collections.singletonList(aggregationToReturn).iterator();
|
||||
|
||||
when(aggregations.iterator()).thenReturn(iter);
|
||||
when(aggregations.iterator()).thenReturn(iter).thenReturn(iter);
|
||||
when(aggregations.get("engine")).thenReturn(aggregationToReturn);
|
||||
when(response.getAggregations()).thenReturn(aggregations);
|
||||
|
||||
@@ -76,6 +77,7 @@ public class DefaultResultMapperTests {
|
||||
AggregatedPage<Car> page = (AggregatedPage<Car>) resultMapper.mapResults(response, Car.class, null);
|
||||
|
||||
//Then
|
||||
page.hasFacets();
|
||||
assertThat(page.hasAggregations(), is(true));
|
||||
assertThat(page.getAggregation("engine").getName(), is("Diesel"));
|
||||
}
|
||||
@@ -132,7 +134,7 @@ public class DefaultResultMapperTests {
|
||||
}
|
||||
|
||||
private Aggregation createCarAggregation() {
|
||||
Aggregation aggregation = mock(Aggregation.class);
|
||||
Aggregation aggregation = mock(Terms.class);
|
||||
when(aggregation.getName()).thenReturn("Diesel");
|
||||
return aggregation;
|
||||
}
|
||||
|
||||
@@ -41,9 +41,14 @@ import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.*;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.elasticsearch.ElasticsearchException;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
|
||||
import org.springframework.data.elasticsearch.core.aggregation.impl.AggregatedPageImpl;
|
||||
import org.springframework.data.elasticsearch.core.query.*;
|
||||
import org.springframework.data.elasticsearch.entities.*;
|
||||
import org.springframework.data.util.CloseableIterator;
|
||||
@@ -632,12 +637,12 @@ public class ElasticsearchTemplateTests {
|
||||
// when
|
||||
Page<String> page = elasticsearchTemplate.queryForPage(searchQuery, String.class, new SearchResultMapper() {
|
||||
@Override
|
||||
public <T> Page<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
List<String> values = new ArrayList<String>();
|
||||
for (SearchHit searchHit : response.getHits()) {
|
||||
values.add((String) searchHit.field("message").value());
|
||||
}
|
||||
return new PageImpl<T>((List<T>) values);
|
||||
return new AggregatedPageImpl<T>((List<T>) values);
|
||||
}
|
||||
});
|
||||
// then
|
||||
@@ -791,7 +796,7 @@ public class ElasticsearchTemplateTests {
|
||||
while (hasRecords) {
|
||||
Page<SampleEntity> page = elasticsearchTemplate.scroll(scrollId, 5000L, new SearchResultMapper() {
|
||||
@Override
|
||||
public <T> Page<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
List<SampleEntity> result = new ArrayList<SampleEntity>();
|
||||
for (SearchHit searchHit : response.getHits()) {
|
||||
String message = searchHit.getFields().get("message").getValue();
|
||||
@@ -802,7 +807,7 @@ public class ElasticsearchTemplateTests {
|
||||
}
|
||||
|
||||
if (result.size() > 0) {
|
||||
return new PageImpl<T>((List<T>) result);
|
||||
return new AggregatedPageImpl<T>((List<T>) result);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -843,7 +848,7 @@ public class ElasticsearchTemplateTests {
|
||||
while (hasRecords) {
|
||||
Page<SampleEntity> page = elasticsearchTemplate.scroll(scrollId, 10000L, new SearchResultMapper() {
|
||||
@Override
|
||||
public <T> Page<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
List<SampleEntity> result = new ArrayList<SampleEntity>();
|
||||
for (SearchHit searchHit : response.getHits()) {
|
||||
String message = searchHit.getFields().get("message").getValue();
|
||||
@@ -854,7 +859,7 @@ public class ElasticsearchTemplateTests {
|
||||
}
|
||||
|
||||
if (result.size() > 0) {
|
||||
return new PageImpl<T>((List<T>) result);
|
||||
return new AggregatedPageImpl<T>((List<T>) result);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -892,7 +897,7 @@ public class ElasticsearchTemplateTests {
|
||||
while (hasRecords) {
|
||||
Page<SampleEntity> page = elasticsearchTemplate.scroll(scrollId, 5000L, new SearchResultMapper() {
|
||||
@Override
|
||||
public <T> Page<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
List<SampleEntity> chunk = new ArrayList<SampleEntity>();
|
||||
for (SearchHit searchHit : response.getHits()) {
|
||||
if (response.getHits().getHits().length <= 0) {
|
||||
@@ -904,7 +909,7 @@ public class ElasticsearchTemplateTests {
|
||||
chunk.add(user);
|
||||
}
|
||||
if (chunk.size() > 0) {
|
||||
return new PageImpl<T>((List<T>) chunk);
|
||||
return new AggregatedPageImpl<T>((List<T>) chunk);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -937,7 +942,7 @@ public class ElasticsearchTemplateTests {
|
||||
while (hasRecords) {
|
||||
Page<SampleEntity> page = elasticsearchTemplate.scroll(scrollId, 5000L, new SearchResultMapper() {
|
||||
@Override
|
||||
public <T> Page<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
List<SampleEntity> chunk = new ArrayList<SampleEntity>();
|
||||
for (SearchHit searchHit : response.getHits()) {
|
||||
if (response.getHits().getHits().length <= 0) {
|
||||
@@ -949,7 +954,7 @@ public class ElasticsearchTemplateTests {
|
||||
chunk.add(user);
|
||||
}
|
||||
if (chunk.size() > 0) {
|
||||
return new PageImpl<T>((List<T>) chunk);
|
||||
return new AggregatedPageImpl<T>((List<T>) chunk);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -1243,7 +1248,7 @@ public class ElasticsearchTemplateTests {
|
||||
|
||||
Page<SampleEntity> sampleEntities = elasticsearchTemplate.queryForPage(searchQuery, SampleEntity.class, new SearchResultMapper() {
|
||||
@Override
|
||||
public <T> Page<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
List<SampleEntity> chunk = new ArrayList<SampleEntity>();
|
||||
for (SearchHit searchHit : response.getHits()) {
|
||||
if (response.getHits().getHits().length <= 0) {
|
||||
@@ -1256,7 +1261,7 @@ public class ElasticsearchTemplateTests {
|
||||
chunk.add(user);
|
||||
}
|
||||
if (chunk.size() > 0) {
|
||||
return new PageImpl<T>((List<T>) chunk);
|
||||
return new AggregatedPageImpl<T>((List<T>) chunk);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -1310,7 +1315,7 @@ public class ElasticsearchTemplateTests {
|
||||
// then
|
||||
Page<SampleEntity> page = elasticsearchTemplate.queryForPage(searchQuery, SampleEntity.class, new SearchResultMapper() {
|
||||
@Override
|
||||
public <T> Page<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
List<SampleEntity> values = new ArrayList<SampleEntity>();
|
||||
for (SearchHit searchHit : response.getHits()) {
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
@@ -1318,7 +1323,7 @@ public class ElasticsearchTemplateTests {
|
||||
sampleEntity.setMessage((String) searchHit.getSource().get("message"));
|
||||
values.add(sampleEntity);
|
||||
}
|
||||
return new PageImpl<T>((List<T>) values);
|
||||
return new AggregatedPageImpl<T>((List<T>) values);
|
||||
}
|
||||
});
|
||||
assertThat(page, is(notNullValue()));
|
||||
@@ -1480,7 +1485,7 @@ public class ElasticsearchTemplateTests {
|
||||
.withTypes(TYPE_NAME).withQuery(matchAllQuery()).build();
|
||||
Page<Map> sampleEntities = elasticsearchTemplate.queryForPage(searchQuery, Map.class, new SearchResultMapper() {
|
||||
@Override
|
||||
public <T> Page<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
List<Map> chunk = new ArrayList<Map>();
|
||||
for (SearchHit searchHit : response.getHits()) {
|
||||
if (response.getHits().getHits().length <= 0) {
|
||||
@@ -1495,7 +1500,7 @@ public class ElasticsearchTemplateTests {
|
||||
chunk.add(person);
|
||||
}
|
||||
if (chunk.size() > 0) {
|
||||
return new PageImpl<T>((List<T>) chunk);
|
||||
return new AggregatedPageImpl<T>((List<T>) chunk);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -1994,7 +1999,7 @@ public class ElasticsearchTemplateTests {
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).withTypes("hetro").withIndices(INDEX_1_NAME, INDEX_2_NAME).build();
|
||||
Page<ResultAggregator> page = elasticsearchTemplate.queryForPage(searchQuery, ResultAggregator.class, new SearchResultMapper() {
|
||||
@Override
|
||||
public <T> Page<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
List<ResultAggregator> values = new ArrayList<ResultAggregator>();
|
||||
for (SearchHit searchHit : response.getHits()) {
|
||||
String id = String.valueOf(searchHit.getSource().get("id"));
|
||||
@@ -2002,7 +2007,7 @@ public class ElasticsearchTemplateTests {
|
||||
String lastName = StringUtils.isNotEmpty((String) searchHit.getSource().get("lastName")) ? (String) searchHit.getSource().get("lastName") : "";
|
||||
values.add(new ResultAggregator(id, firstName, lastName));
|
||||
}
|
||||
return new PageImpl<T>((List<T>) values);
|
||||
return new AggregatedPageImpl<T>((List<T>) values);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user