DATAES-545 - Move off deprecations in Spring Data Commons.

Related ticket: DATACMNS-1496.
This commit is contained in:
Oliver Drotbohm 2019-03-13 19:17:17 +01:00
parent 11ba4c55ad
commit 13d369de20
No known key found for this signature in database
GPG Key ID: 6E42B5787543F690
4 changed files with 65 additions and 64 deletions

View File

@ -55,6 +55,7 @@ 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.domain.Sort.Order;
import org.springframework.data.elasticsearch.ElasticsearchException;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
@ -688,7 +689,7 @@ public class ElasticsearchTemplateTests {
elasticsearchTemplate.index(indexQuery);
elasticsearchTemplate.refresh(SampleEntity.class);
StringQuery stringQuery = new StringQuery(matchAllQuery().toString(), new PageRequest(0, 10));
StringQuery stringQuery = new StringQuery(matchAllQuery().toString(), PageRequest.of(0, 10));
// when
Page<SampleEntity> sampleEntities = elasticsearchTemplate.queryForPage(stringQuery, SampleEntity.class);
@ -712,8 +713,8 @@ public class ElasticsearchTemplateTests {
elasticsearchTemplate.index(indexQuery);
elasticsearchTemplate.refresh(SampleEntity.class);
StringQuery stringQuery = new StringQuery(matchAllQuery().toString(), new PageRequest(0, 10), new Sort(
new Sort.Order(Sort.Direction.ASC, "message")));
StringQuery stringQuery = new StringQuery(matchAllQuery().toString(), PageRequest.of(0, 10), Sort.by(
Order.asc("message")));
// when
Page<SampleEntity> sampleEntities = elasticsearchTemplate.queryForPage(stringQuery, SampleEntity.class);
// then
@ -902,7 +903,7 @@ public class ElasticsearchTemplateTests {
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria());
criteriaQuery.addIndices(INDEX_NAME);
criteriaQuery.addTypes(TYPE_NAME);
criteriaQuery.setPageable(new PageRequest(0, 10));
criteriaQuery.setPageable(PageRequest.of(0, 10));
ScrolledPage<SampleEntity> scroll = (ScrolledPage<SampleEntity>) elasticsearchTemplate.startScroll( 1000, criteriaQuery, SampleEntity.class);
List<SampleEntity> sampleEntities = new ArrayList<>();
@ -924,7 +925,7 @@ public class ElasticsearchTemplateTests {
// then
SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).withIndices(INDEX_NAME)
.withTypes(TYPE_NAME).withPageable(new PageRequest(0, 10)).build();
.withTypes(TYPE_NAME).withPageable(PageRequest.of(0, 10)).build();
ScrolledPage<SampleEntity> scroll = (ScrolledPage<SampleEntity>) elasticsearchTemplate.startScroll(1000, searchQuery, SampleEntity.class);
List<SampleEntity> sampleEntities = new ArrayList<>();
@ -975,7 +976,7 @@ public class ElasticsearchTemplateTests {
criteriaQuery.addIndices(INDEX_NAME);
criteriaQuery.addTypes(TYPE_NAME);
criteriaQuery.addFields("message");
criteriaQuery.setPageable(new PageRequest(0, 10));
criteriaQuery.setPageable(PageRequest.of(0, 10));
Page<SampleEntity> scroll = elasticsearchTemplate.startScroll(1000, criteriaQuery, SampleEntity.class, searchResultMapper);
String scrollId = ((ScrolledPage<?>)scroll).getScrollId();
@ -1006,7 +1007,7 @@ public class ElasticsearchTemplateTests {
.withTypes(TYPE_NAME)
.withFields("message")
.withQuery(matchAllQuery())
.withPageable(new PageRequest(0, 10))
.withPageable(PageRequest.of(0, 10))
.build();
Page<SampleEntity> scroll = elasticsearchTemplate.startScroll(1000, searchQuery, SampleEntity.class, searchResultMapper);
@ -1036,7 +1037,7 @@ public class ElasticsearchTemplateTests {
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria());
criteriaQuery.addIndices(INDEX_NAME);
criteriaQuery.addTypes(TYPE_NAME);
criteriaQuery.setPageable(new PageRequest(0, 10));
criteriaQuery.setPageable(PageRequest.of(0, 10));
Page<SampleEntity> scroll = elasticsearchTemplate.startScroll(1000, criteriaQuery, SampleEntity.class, searchResultMapper);
String scrollId = ((ScrolledPage) scroll).getScrollId();
@ -1060,7 +1061,7 @@ public class ElasticsearchTemplateTests {
// then
SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).withIndices(INDEX_NAME)
.withTypes(TYPE_NAME).withPageable(new PageRequest(0, 10)).build();
.withTypes(TYPE_NAME).withPageable(PageRequest.of(0, 10)).build();
Page<SampleEntity> scroll = elasticsearchTemplate.startScroll(1000, searchQuery, SampleEntity.class,searchResultMapper);
String scrollId = ((ScrolledPage) scroll).getScrollId();
@ -1087,7 +1088,7 @@ public class ElasticsearchTemplateTests {
// then
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria());
criteriaQuery.setPageable(new PageRequest(0, 10));
criteriaQuery.setPageable(PageRequest.of(0, 10));
Page<SampleEntity> scroll = elasticsearchTemplate.startScroll(1000, criteriaQuery, SampleEntity.class);
String scrollId = ((ScrolledPage) scroll).getScrollId();
@ -1114,7 +1115,7 @@ public class ElasticsearchTemplateTests {
// then
SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
.withPageable(new PageRequest(0, 10)).build();
.withPageable(PageRequest.of(0, 10)).build();
Page<SampleEntity> scroll = elasticsearchTemplate.startScroll(1000, searchQuery, SampleEntity.class);
String scrollId = ((ScrolledPage) scroll).getScrollId();
@ -1143,7 +1144,7 @@ public class ElasticsearchTemplateTests {
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria());
criteriaQuery.addIndices(INDEX_NAME);
criteriaQuery.addTypes(TYPE_NAME);
criteriaQuery.setPageable(new PageRequest(0, 10));
criteriaQuery.setPageable(PageRequest.of(0, 10));
CloseableIterator<SampleEntity> stream = elasticsearchTemplate.stream(criteriaQuery, SampleEntity.class);
List<SampleEntity> sampleEntities = new ArrayList<>();
@ -1640,7 +1641,7 @@ public class ElasticsearchTemplateTests {
.withQuery(termQuery("message", "message"))
.withIndices(INDEX_NAME)
.withTypes(TYPE_NAME)
.withPageable(new PageRequest(0, 100))
.withPageable(PageRequest.of(0, 100))
.build();
// then
List<String> ids = elasticsearchTemplate.queryForIds(searchQuery);

View File

@ -24,14 +24,12 @@ import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.domain.Sort.Order;
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
import org.springframework.data.elasticsearch.entities.SampleEntity;
import org.springframework.data.elasticsearch.repositories.custom.SampleCustomMethodRepository;
@ -39,8 +37,6 @@ import org.springframework.data.geo.Box;
import org.springframework.data.geo.Distance;
import org.springframework.data.geo.Metrics;
import org.springframework.data.geo.Point;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Rizwan Idrees
@ -65,7 +61,7 @@ public abstract class CustomMethodRepositoryBaseTests {
sampleEntity.setMessage("some message");
repository.save(sampleEntity);
// when
Page<SampleEntity> page = repository.findByType("test", new PageRequest(0, 10));
Page<SampleEntity> page = repository.findByType("test", PageRequest.of(0, 10));
// then
assertThat(page, is(notNullValue()));
assertThat(page.getTotalElements(), is(greaterThanOrEqualTo(1L)));
@ -81,7 +77,7 @@ public abstract class CustomMethodRepositoryBaseTests {
sampleEntity.setMessage("some message");
repository.save(sampleEntity);
// when
Page<SampleEntity> page = repository.findByTypeNot("test", new PageRequest(0, 10));
Page<SampleEntity> page = repository.findByTypeNot("test", PageRequest.of(0, 10));
// then
assertThat(page, is(notNullValue()));
assertThat(page.getTotalElements(), is(equalTo(1L)));
@ -98,7 +94,7 @@ public abstract class CustomMethodRepositoryBaseTests {
sampleEntity.setMessage(searchTerm);
repository.save(sampleEntity);
// when
Page<SampleEntity> page = repository.findByMessage(searchTerm.toLowerCase(), new PageRequest(0, 10));
Page<SampleEntity> page = repository.findByMessage(searchTerm.toLowerCase(), PageRequest.of(0, 10));
// then
assertThat(page, is(notNullValue()));
assertThat(page.getTotalElements(), is(greaterThanOrEqualTo(1L)));
@ -124,7 +120,7 @@ public abstract class CustomMethodRepositoryBaseTests {
repository.save(sampleEntity2);
// when
Page<SampleEntity> page = repository.findByRateLessThan(10, new PageRequest(0, 10));
Page<SampleEntity> page = repository.findByRateLessThan(10, PageRequest.of(0, 10));
// then
assertThat(page, is(notNullValue()));
assertThat(page.getTotalElements(), is(equalTo(1L)));
@ -142,7 +138,7 @@ public abstract class CustomMethodRepositoryBaseTests {
repository.save(sampleEntity);
// when
Page<SampleEntity> page = repository.findByRateBefore(10, new PageRequest(0, 10));
Page<SampleEntity> page = repository.findByRateBefore(10, PageRequest.of(0, 10));
// then
assertThat(page, is(notNullValue()));
assertThat(page.getTotalElements(), is(equalTo(1L)));
@ -160,7 +156,7 @@ public abstract class CustomMethodRepositoryBaseTests {
repository.save(sampleEntity);
// when
Page<SampleEntity> page = repository.findByRateAfter(10, new PageRequest(0, 10));
Page<SampleEntity> page = repository.findByRateAfter(10, PageRequest.of(0, 10));
// then
assertThat(page, is(notNullValue()));
assertThat(page.getTotalElements(), is(equalTo(1L)));
@ -178,7 +174,7 @@ public abstract class CustomMethodRepositoryBaseTests {
repository.save(sampleEntity);
// when
Page<SampleEntity> page = repository.findByMessageLike("fo", new PageRequest(0, 10));
Page<SampleEntity> page = repository.findByMessageLike("fo", PageRequest.of(0, 10));
// then
assertThat(page, is(notNullValue()));
assertThat(page.getTotalElements(), is(equalTo(1L)));
@ -196,7 +192,7 @@ public abstract class CustomMethodRepositoryBaseTests {
repository.save(sampleEntity);
// when
Page<SampleEntity> page = repository.findByMessageStartingWith("fo", new PageRequest(0, 10));
Page<SampleEntity> page = repository.findByMessageStartingWith("fo", PageRequest.of(0, 10));
// then
assertThat(page, is(notNullValue()));
assertThat(page.getTotalElements(), is(equalTo(1L)));
@ -214,7 +210,7 @@ public abstract class CustomMethodRepositoryBaseTests {
repository.save(sampleEntity);
// when
Page<SampleEntity> page = repository.findByMessageEndingWith("o", new PageRequest(0, 10));
Page<SampleEntity> page = repository.findByMessageEndingWith("o", PageRequest.of(0, 10));
// then
assertThat(page, is(notNullValue()));
assertThat(page.getTotalElements(), is(equalTo(1L)));
@ -232,7 +228,7 @@ public abstract class CustomMethodRepositoryBaseTests {
repository.save(sampleEntity);
// when
Page<SampleEntity> page = repository.findByMessageContaining("fo", new PageRequest(0, 10));
Page<SampleEntity> page = repository.findByMessageContaining("fo", PageRequest.of(0, 10));
// then
assertThat(page, is(notNullValue()));
assertThat(page.getTotalElements(), is(equalTo(1L)));
@ -259,7 +255,7 @@ public abstract class CustomMethodRepositoryBaseTests {
List<String> ids = Arrays.asList(documentId, documentId2);
// when
Page<SampleEntity> page = repository.findByIdIn(ids, new PageRequest(0, 10));
Page<SampleEntity> page = repository.findByIdIn(ids, PageRequest.of(0, 10));
// then
assertThat(page, is(notNullValue()));
assertThat(page.getTotalElements(), is(equalTo(2L)));
@ -286,7 +282,7 @@ public abstract class CustomMethodRepositoryBaseTests {
List<String> ids = Arrays.asList(documentId);
// when
Page<SampleEntity> page = repository.findByIdNotIn(ids, new PageRequest(0, 10));
Page<SampleEntity> page = repository.findByIdNotIn(ids, PageRequest.of(0, 10));
// then
assertThat(page, is(notNullValue()));
assertThat(page.getTotalElements(), is(equalTo(1L)));
@ -313,7 +309,7 @@ public abstract class CustomMethodRepositoryBaseTests {
sampleEntity2.setAvailable(false);
repository.save(sampleEntity2);
// when
Page<SampleEntity> page = repository.findByAvailableTrue(new PageRequest(0, 10));
Page<SampleEntity> page = repository.findByAvailableTrue(PageRequest.of(0, 10));
// then
assertThat(page, is(notNullValue()));
assertThat(page.getTotalElements(), is(equalTo(1L)));
@ -339,7 +335,7 @@ public abstract class CustomMethodRepositoryBaseTests {
sampleEntity2.setAvailable(false);
repository.save(sampleEntity2);
// when
Page<SampleEntity> page = repository.findByAvailableFalse(new PageRequest(0, 10));
Page<SampleEntity> page = repository.findByAvailableFalse(PageRequest.of(0, 10));
// then
assertThat(page, is(notNullValue()));
assertThat(page.getTotalElements(), is(equalTo(1L)));
@ -375,7 +371,7 @@ public abstract class CustomMethodRepositoryBaseTests {
repository.save(sampleEntity3);
// when
Page<SampleEntity> page = repository.findByMessageOrderByTypeAsc("foo", new PageRequest(0, 10));
Page<SampleEntity> page = repository.findByMessageOrderByTypeAsc("foo", PageRequest.of(0, 10));
// then
assertThat(page, is(notNullValue()));
assertThat(page.getTotalElements(), is(equalTo(1L)));
@ -401,7 +397,7 @@ public abstract class CustomMethodRepositoryBaseTests {
sampleEntity2.setAvailable(false);
repository.save(sampleEntity2);
// when
Page<SampleEntity> page = repository.findByAvailable(false, new PageRequest(0, 10));
Page<SampleEntity> page = repository.findByAvailable(false, PageRequest.of(0, 10));
// then
assertThat(page, is(notNullValue()));
assertThat(page.getTotalElements(), is(equalTo(1L)));
@ -419,7 +415,7 @@ public abstract class CustomMethodRepositoryBaseTests {
repository.save(sampleEntity);
}
// when
Page<SampleEntity> pageResult = repository.findByMessage("message", new PageRequest(0, 23));
Page<SampleEntity> pageResult = repository.findByMessage("message", PageRequest.of(0, 23));
// then
assertThat(pageResult.getTotalElements(), is(equalTo(30L)));
assertThat(pageResult.getContent().size(), is(equalTo(23)));
@ -450,7 +446,7 @@ public abstract class CustomMethodRepositoryBaseTests {
repository.save(sampleEntity3);
// when
Page<SampleEntity> pageResult = repository.findByMessageContaining("a",
new PageRequest(0, 23, new Sort(new Sort.Order(Sort.Direction.DESC, "message"))));
PageRequest.of(0, 23, Sort.by(Order.desc("message"))));
// then
assertThat(pageResult.getContent().isEmpty(), is(false));
assertThat(pageResult.getContent().get(0).getMessage(), is(sampleEntity3.getMessage()));
@ -500,7 +496,7 @@ public abstract class CustomMethodRepositoryBaseTests {
repository.save(sampleEntity);
// when
Page<SampleEntity> page = repository.findByLocation(new GeoPoint(45.7806d, 3.0875d), new PageRequest(0, 10));
Page<SampleEntity> page = repository.findByLocation(new GeoPoint(45.7806d, 3.0875d), PageRequest.of(0, 10));
// then
assertThat(page, is(notNullValue()));
assertThat(page.getTotalElements(), is(equalTo(1L)));
@ -531,7 +527,7 @@ public abstract class CustomMethodRepositoryBaseTests {
// when
Page<SampleEntity> page = repository.findByLocationAndMessage(new GeoPoint(45.7806d, 3.0875d), "foo",
new PageRequest(0, 10));
PageRequest.of(0, 10));
// then
assertThat(page, is(notNullValue()));
assertThat(page.getTotalElements(), is(equalTo(1L)));
@ -552,7 +548,7 @@ public abstract class CustomMethodRepositoryBaseTests {
// when
Page<SampleEntity> page = repository.findByLocationWithin(new GeoPoint(45.7806d, 3.0875d), "2km",
new PageRequest(0, 10));
PageRequest.of(0, 10));
// then
assertThat(page, is(notNullValue()));
assertThat(page.getTotalElements(), is(equalTo(1L)));
@ -573,7 +569,7 @@ public abstract class CustomMethodRepositoryBaseTests {
// when
Page<SampleEntity> page = repository.findByLocationWithin(new Point(45.7806d, 3.0875d),
new Distance(2, Metrics.KILOMETERS), new PageRequest(0, 10));
new Distance(2, Metrics.KILOMETERS), PageRequest.of(0, 10));
// then
assertThat(page, is(notNullValue()));
assertThat(page.getTotalElements(), is(equalTo(1L)));
@ -603,14 +599,14 @@ public abstract class CustomMethodRepositoryBaseTests {
repository.save(sampleEntity2);
// when
Page<SampleEntity> pageAll = repository.findAll(new PageRequest(0, 10));
Page<SampleEntity> pageAll = repository.findAll(PageRequest.of(0, 10));
// then
assertThat(pageAll, is(notNullValue()));
assertThat(pageAll.getTotalElements(), is(equalTo(2L)));
// when
Page<SampleEntity> page = repository.findByLocationNear(new Box(new Point(46d, 3d), new Point(45d, 4d)),
new PageRequest(0, 10));
PageRequest.of(0, 10));
// then
assertThat(page, is(notNullValue()));
assertThat(page.getTotalElements(), is(equalTo(1L)));
@ -631,7 +627,7 @@ public abstract class CustomMethodRepositoryBaseTests {
// when
Page<SampleEntity> page = repository.findByLocationNear(new Point(45.7806d, 3.0875d),
new Distance(2, Metrics.KILOMETERS), new PageRequest(0, 10));
new Distance(2, Metrics.KILOMETERS), PageRequest.of(0, 10));
// then
assertThat(page, is(notNullValue()));
assertThat(page.getTotalElements(), is(equalTo(1L)));

View File

@ -15,10 +15,16 @@
*/
package org.springframework.data.elasticsearch.repository.support;
import static org.apache.commons.lang.RandomStringUtils.*;
import static org.elasticsearch.index.query.QueryBuilders.*;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.common.util.CollectionUtils;
import org.junit.Before;
@ -36,11 +42,6 @@ import org.springframework.data.elasticsearch.entities.SampleEntity;
import org.springframework.data.elasticsearch.repositories.sample.SampleElasticsearchRepository;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.apache.commons.lang.RandomStringUtils.*;
import static org.elasticsearch.index.query.QueryBuilders.*;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.springframework.data.domain.Sort.Direction.*;
/**
* @author Rizwan Idrees
@ -130,7 +131,7 @@ public class SimpleElasticsearchRepositoryTests {
Optional<SampleEntity> entityFromElasticSearch = repository.findById(documentId);
// then
assertThat(entityFromElasticSearch.isPresent(), is(true));
assertThat(sampleEntity, is((equalTo(sampleEntity))));
assertThat(sampleEntity, is(equalTo(sampleEntity)));
}
@Test
@ -200,7 +201,7 @@ public class SimpleElasticsearchRepositoryTests {
sampleEntity.setVersion(System.currentTimeMillis());
repository.save(sampleEntity);
// when
Page<SampleEntity> page = repository.search(termQuery("message", "world"), new PageRequest(0, 50));
Page<SampleEntity> page = repository.search(termQuery("message", "world"), PageRequest.of(0, 50));
// then
assertThat(page, is(notNullValue()));
assertThat(page.getNumberOfElements(), is(greaterThanOrEqualTo(1)));
@ -254,7 +255,7 @@ public class SimpleElasticsearchRepositoryTests {
// when
repository.saveAll(sampleEntities);
// then
Page<SampleEntity> entities = repository.search(termQuery("id", documentId), new PageRequest(0, 50));
Page<SampleEntity> entities = repository.search(termQuery("id", documentId), PageRequest.of(0, 50));
assertNotNull(entities);
}
@ -504,7 +505,7 @@ public class SimpleElasticsearchRepositoryTests {
// when
repository.index(sampleEntity);
// then
Page<SampleEntity> entities = repository.search(termQuery("id", documentId), new PageRequest(0, 50));
Page<SampleEntity> entities = repository.search(termQuery("id", documentId), PageRequest.of(0, 50));
assertThat(entities.getTotalElements(), equalTo(1L));
}
@ -523,7 +524,7 @@ public class SimpleElasticsearchRepositoryTests {
sampleEntity2.setMessage("hello");
repository.save(sampleEntity2);
// when
Iterable<SampleEntity> sampleEntities = repository.findAll(new Sort(new Order(ASC, "message")));
Iterable<SampleEntity> sampleEntities = repository.findAll(Sort.by(Order.asc("message")));
// then
assertThat(sampleEntities, is(notNullValue()));
}
@ -542,7 +543,7 @@ public class SimpleElasticsearchRepositoryTests {
// when
Page<SampleEntity> results = repository.searchSimilar(sampleEntities.get(0), new String[] { "message" },
new PageRequest(0, 5));
PageRequest.of(0, 5));
// then
assertThat(results.getTotalElements(), is(greaterThanOrEqualTo(1L)));

View File

@ -15,12 +15,17 @@
*/
package org.springframework.data.elasticsearch.repository.support;
import static org.elasticsearch.index.query.QueryBuilders.*;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -28,6 +33,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Order;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.data.elasticsearch.core.query.SearchQuery;
@ -35,9 +41,6 @@ import org.springframework.data.elasticsearch.entities.SampleEntityUUIDKeyed;
import org.springframework.data.elasticsearch.repositories.sample.SampleUUIDKeyedElasticsearchRepository;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.elasticsearch.index.query.QueryBuilders.*;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
/**
* @author Gad Akuka
@ -116,7 +119,7 @@ public class UUIDElasticsearchRepositoryTests {
Optional<SampleEntityUUIDKeyed> entityFromElasticSearch = repository.findById(documentId);
// then
assertThat(entityFromElasticSearch.isPresent(), is(true));
assertThat(sampleEntityUUIDKeyed, is((equalTo(sampleEntityUUIDKeyed))));
assertThat(sampleEntityUUIDKeyed, is(equalTo(sampleEntityUUIDKeyed)));
}
@Test
@ -186,7 +189,7 @@ public class UUIDElasticsearchRepositoryTests {
sampleEntityUUIDKeyed.setVersion(System.currentTimeMillis());
repository.save(sampleEntityUUIDKeyed);
// when
Page<SampleEntityUUIDKeyed> page = repository.search(termQuery("message", "world"), new PageRequest(0, 50));
Page<SampleEntityUUIDKeyed> page = repository.search(termQuery("message", "world"), PageRequest.of(0, 50));
// then
assertThat(page, is(notNullValue()));
assertThat(page.getNumberOfElements(), is(greaterThanOrEqualTo(1)));
@ -242,7 +245,8 @@ public class UUIDElasticsearchRepositoryTests {
// when
repository.saveAll(sampleEntities);
// then
Page<SampleEntityUUIDKeyed> entities = repository.search(termQuery("id", documentId.toString()), new PageRequest(0, 50));
Page<SampleEntityUUIDKeyed> entities = repository.search(termQuery("id", documentId.toString()),
PageRequest.of(0, 50));
assertNotNull(entities);
}
@ -265,7 +269,7 @@ public class UUIDElasticsearchRepositoryTests {
@Test // DATAES-363
public void shouldReturnFalseGivenDocumentWithIdDoesNotExist() {
// given
UUID documentId = UUID.randomUUID();
@ -479,8 +483,7 @@ public class UUIDElasticsearchRepositoryTests {
sampleEntityUUIDKeyed2.setMessage("hello");
repository.save(sampleEntityUUIDKeyed2);
// when
Iterable<SampleEntityUUIDKeyed> sampleEntities = repository
.findAll(new Sort(new Sort.Order(Sort.Direction.ASC, "message")));
Iterable<SampleEntityUUIDKeyed> sampleEntities = repository.findAll(Sort.by(Order.asc("message")));
// then
assertThat(sampleEntities, is(notNullValue()));
}
@ -499,7 +502,7 @@ public class UUIDElasticsearchRepositoryTests {
// when
Page<SampleEntityUUIDKeyed> results = repository.searchSimilar(sampleEntities.get(0), new String[] { "message" },
new PageRequest(0, 5));
PageRequest.of(0, 5));
// then
assertThat(results.getTotalElements(), is(greaterThanOrEqualTo(1L)));