From 416a3f2baf8ced386f3a14c2fc5397cf3dd07ae9 Mon Sep 17 00:00:00 2001 From: Christoph Strobl Date: Wed, 3 May 2017 15:11:34 +0200 Subject: [PATCH] DATAES-352 - Adapt to API changes in repository interfaces. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We now follow a more consistent naming scheme for the methods in repository that are driven by the following guidelines: * Methods referring to an identifier now all end on …ById(…). * Methods taking or returning a collection are named …All(…) Please see DATACMNS-944 for details. --- .../AbstractElasticsearchRepository.java | 44 ++++++++++------ .../ElasticsearchEntityInformation.java | 7 ++- ...ElasticsearchEntityInformationCreator.java | 7 ++- ...ticsearchEntityInformationCreatorImpl.java | 9 ++-- .../ElasticsearchRepositoryFactory.java | 8 +-- ...MappingElasticsearchEntityInformation.java | 6 +-- .../data/elasticsearch/InnerObjectTests.java | 11 ++-- ...ImmutableElasticsearchRepositoryTests.java | 3 +- .../CustomMethodRepositoryTests.java | 29 ++++++----- .../cdi/CdiProductRepository.java | 3 +- .../repositories/cdi/CdiRepositoryTests.java | 17 +++--- .../geo/SpringDataGeoRepositoryTests.java | 3 +- .../sample/SampleElasticsearchRepository.java | 8 ++- ...ampleUUIDKeyedElasticsearchRepository.java | 8 ++- .../support/DoubleIDRepositoryTests.java | 16 +++--- .../support/IntegerIDRepositoryTests.java | 16 +++--- .../support/QueryKeywordsTests.java | 5 +- .../SimpleElasticsearchRepositoryTests.java | 47 ++++++++--------- .../UUIDElasticsearchRepositoryTests.java | 52 +++++++++---------- 19 files changed, 158 insertions(+), 141 deletions(-) diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/support/AbstractElasticsearchRepository.java b/src/main/java/org/springframework/data/elasticsearch/repository/support/AbstractElasticsearchRepository.java index 7cf126214..58e03949f 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/support/AbstractElasticsearchRepository.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/support/AbstractElasticsearchRepository.java @@ -30,9 +30,18 @@ import org.elasticsearch.index.query.QueryBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.dao.InvalidDataAccessApiUsageException; -import org.springframework.data.domain.*; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; import org.springframework.data.elasticsearch.core.ElasticsearchOperations; -import org.springframework.data.elasticsearch.core.query.*; +import org.springframework.data.elasticsearch.core.query.DeleteQuery; +import org.springframework.data.elasticsearch.core.query.GetQuery; +import org.springframework.data.elasticsearch.core.query.IndexQuery; +import org.springframework.data.elasticsearch.core.query.MoreLikeThisQuery; +import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder; +import org.springframework.data.elasticsearch.core.query.SearchQuery; import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; import org.springframework.util.Assert; @@ -45,6 +54,7 @@ import org.springframework.util.Assert; * @author Ryan Henszey * @author Kevin Leturc * @author Mark Paluch + * @author Christoph Strobl */ public abstract class AbstractElasticsearchRepository implements ElasticsearchRepository { @@ -57,18 +67,18 @@ public abstract class AbstractElasticsearchRepository metadata, ElasticsearchOperations elasticsearchOperations) { this(elasticsearchOperations); - + Assert.notNull(metadata, "ElasticsearchEntityInformation must not be null!"); - + this.entityInformation = metadata; setEntityClass(this.entityInformation.getJavaType()); try { @@ -94,7 +104,7 @@ public abstract class AbstractElasticsearchRepository findOne(ID id) { + public Optional findById(ID id) { GetQuery query = new GetQuery(); query.setId(stringIdRepresentation(id)); return Optional.ofNullable(elasticsearchOperations.queryForObject(query, getEntityClass())); @@ -104,7 +114,7 @@ public abstract class AbstractElasticsearchRepository findAll() { int itemCount = (int) this.count(); if (itemCount == 0) { - return new PageImpl<>(Collections.emptyList()); + return new PageImpl<>(Collections. emptyList()); } return this.findAll(PageRequest.of(0, Math.max(1, itemCount))); } @@ -119,7 +129,7 @@ public abstract class AbstractElasticsearchRepository findAll(Sort sort) { int itemCount = (int) this.count(); if (itemCount == 0) { - return new PageImpl<>(Collections.emptyList()); + return new PageImpl<>(Collections. emptyList()); } SearchQuery query = new NativeSearchQueryBuilder().withQuery(matchAllQuery()) .withPageable(PageRequest.of(0, itemCount, sort)).build(); @@ -127,7 +137,7 @@ public abstract class AbstractElasticsearchRepository findAll(Iterable ids) { + public Iterable findAllById(Iterable ids) { Assert.notNull(ids, "ids can't be null."); SearchQuery query = new NativeSearchQueryBuilder().withIds(stringIdsRepresentation(ids)).build(); return elasticsearchOperations.multiGet(query, getEntityClass()); @@ -165,7 +175,7 @@ public abstract class AbstractElasticsearchRepository Iterable save(Iterable entities) { + public Iterable saveAll(Iterable entities) { Assert.notNull(entities, "Cannot insert 'null' as a List."); List queries = new ArrayList<>(); for (S s : entities) { @@ -177,8 +187,8 @@ public abstract class AbstractElasticsearchRepository(Collections.emptyList()); + return new PageImpl<>(Collections. emptyList()); } searchQuery.setPageable(PageRequest.of(0, count)); return elasticsearchOperations.queryForPage(searchQuery, getEntityClass()); @@ -217,7 +227,7 @@ public abstract class AbstractElasticsearchRepository entities) { + public void deleteAll(Iterable entities) { Assert.notNull(entities, "Cannot delete 'null' list."); for (T entity : entities) { delete(entity); diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/support/ElasticsearchEntityInformation.java b/src/main/java/org/springframework/data/elasticsearch/repository/support/ElasticsearchEntityInformation.java index 490706cfd..4a738c921 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/support/ElasticsearchEntityInformation.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/support/ElasticsearchEntityInformation.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2017 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. @@ -15,8 +15,6 @@ */ package org.springframework.data.elasticsearch.repository.support; -import java.io.Serializable; - import org.springframework.data.repository.core.EntityInformation; /** @@ -24,8 +22,9 @@ import org.springframework.data.repository.core.EntityInformation; * @param * @author Rizwan Idrees * @author Mohsin Husen + * @author Christoph Strobl */ -public interface ElasticsearchEntityInformation extends EntityInformation { +public interface ElasticsearchEntityInformation extends EntityInformation { String getIdAttribute(); diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/support/ElasticsearchEntityInformationCreator.java b/src/main/java/org/springframework/data/elasticsearch/repository/support/ElasticsearchEntityInformationCreator.java index bec17ffb2..3a7570a5c 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/support/ElasticsearchEntityInformationCreator.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/support/ElasticsearchEntityInformationCreator.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2017 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. @@ -15,15 +15,14 @@ */ package org.springframework.data.elasticsearch.repository.support; -import java.io.Serializable; - /** * ElasticsearchEntityInformationCreator * * @author Rizwan Idrees * @author Mohsin Husen + * @author Christoph Strobl */ public interface ElasticsearchEntityInformationCreator { - ElasticsearchEntityInformation getEntityInformation(Class domainClass); + ElasticsearchEntityInformation getEntityInformation(Class domainClass); } diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/support/ElasticsearchEntityInformationCreatorImpl.java b/src/main/java/org/springframework/data/elasticsearch/repository/support/ElasticsearchEntityInformationCreatorImpl.java index 401177759..2d8d03ccb 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/support/ElasticsearchEntityInformationCreatorImpl.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/support/ElasticsearchEntityInformationCreatorImpl.java @@ -15,8 +15,6 @@ */ package org.springframework.data.elasticsearch.repository.support; -import java.io.Serializable; - import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity; import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty; import org.springframework.data.mapping.context.MappingContext; @@ -29,6 +27,7 @@ import org.springframework.util.Assert; * @author Mohsin Husen * @author Oliver Gierke * @author Mark Paluch + * @author Christoph Strobl */ public class ElasticsearchEntityInformationCreatorImpl implements ElasticsearchEntityInformationCreator { @@ -36,15 +35,15 @@ public class ElasticsearchEntityInformationCreatorImpl implements ElasticsearchE public ElasticsearchEntityInformationCreatorImpl( MappingContext, ElasticsearchPersistentProperty> mappingContext) { - + Assert.notNull(mappingContext, "MappingContext must not be null!"); - + this.mappingContext = mappingContext; } @Override @SuppressWarnings("unchecked") - public ElasticsearchEntityInformation getEntityInformation(Class domainClass) { + public ElasticsearchEntityInformation getEntityInformation(Class domainClass) { ElasticsearchPersistentEntity persistentEntity = (ElasticsearchPersistentEntity) mappingContext .getRequiredPersistentEntity(domainClass); diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/support/ElasticsearchRepositoryFactory.java b/src/main/java/org/springframework/data/elasticsearch/repository/support/ElasticsearchRepositoryFactory.java index 2e965c63e..0ac7c7239 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/support/ElasticsearchRepositoryFactory.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/support/ElasticsearchRepositoryFactory.java @@ -17,7 +17,6 @@ package org.springframework.data.elasticsearch.repository.support; import static org.springframework.data.querydsl.QuerydslUtils.*; -import java.io.Serializable; import java.lang.reflect.Method; import java.util.Optional; import java.util.UUID; @@ -47,6 +46,7 @@ import org.springframework.util.Assert; * @author Ryan Henszey * @author Gad Akuka * @author Mark Paluch + * @author Christoph Strobl */ public class ElasticsearchRepositoryFactory extends RepositoryFactorySupport { @@ -54,16 +54,16 @@ public class ElasticsearchRepositoryFactory extends RepositoryFactorySupport { private final ElasticsearchEntityInformationCreator entityInformationCreator; public ElasticsearchRepositoryFactory(ElasticsearchOperations elasticsearchOperations) { - + Assert.notNull(elasticsearchOperations, "ElasticsearchOperations must not be null!"); - + this.elasticsearchOperations = elasticsearchOperations; this.entityInformationCreator = new ElasticsearchEntityInformationCreatorImpl( elasticsearchOperations.getElasticsearchConverter().getMappingContext()); } @Override - public ElasticsearchEntityInformation getEntityInformation(Class domainClass) { + public ElasticsearchEntityInformation getEntityInformation(Class domainClass) { return entityInformationCreator.getEntityInformation(domainClass); } diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/support/MappingElasticsearchEntityInformation.java b/src/main/java/org/springframework/data/elasticsearch/repository/support/MappingElasticsearchEntityInformation.java index 433f77271..c1c52768a 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/support/MappingElasticsearchEntityInformation.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/support/MappingElasticsearchEntityInformation.java @@ -15,7 +15,6 @@ */ package org.springframework.data.elasticsearch.repository.support; -import java.io.Serializable; import java.util.Optional; import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity; @@ -34,9 +33,10 @@ import org.springframework.util.Assert; * @author Ryan Henszey * @author Oliver Gierke * @author Mark Paluch + * @author Christoph Strobl */ -public class MappingElasticsearchEntityInformation - extends PersistentEntityInformation implements ElasticsearchEntityInformation { +public class MappingElasticsearchEntityInformation extends PersistentEntityInformation + implements ElasticsearchEntityInformation { private final ElasticsearchPersistentEntity entityMetadata; private final String indexName; diff --git a/src/test/java/org/springframework/data/elasticsearch/InnerObjectTests.java b/src/test/java/org/springframework/data/elasticsearch/InnerObjectTests.java index cb9be54ae..e42cf3aef 100644 --- a/src/test/java/org/springframework/data/elasticsearch/InnerObjectTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/InnerObjectTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2017 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. @@ -33,17 +33,16 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Mohsin Husen + * @author Christoph Strobl */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:/repository-test-nested-object.xml") public class InnerObjectTests { - @Autowired - private SampleElasticSearchBookRepository bookRepository; + @Autowired private SampleElasticSearchBookRepository bookRepository; - @Autowired - private ElasticsearchTemplate elasticsearchTemplate; + @Autowired private ElasticsearchTemplate elasticsearchTemplate; @Before public void before() { @@ -67,6 +66,6 @@ public class InnerObjectTests { // when bookRepository.save(book); // then - assertThat(bookRepository.findOne(id), is(notNullValue())); + assertThat(bookRepository.findById(id), is(notNullValue())); } } diff --git a/src/test/java/org/springframework/data/elasticsearch/immutable/ImmutableElasticsearchRepositoryTests.java b/src/test/java/org/springframework/data/elasticsearch/immutable/ImmutableElasticsearchRepositoryTests.java index 4ef125e71..94e58e003 100644 --- a/src/test/java/org/springframework/data/elasticsearch/immutable/ImmutableElasticsearchRepositoryTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/immutable/ImmutableElasticsearchRepositoryTests.java @@ -32,6 +32,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * @author Young Gu * @author Oliver Gierke * @author Mark Paluch + * @author Christoph Strobl */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:immutable-repository-test.xml") @@ -59,7 +60,7 @@ public class ImmutableElasticsearchRepositoryTests { assertThat(entity.getId(), is(notNullValue())); // then - Optional entityFromElasticSearch = repository.findOne(entity.getId()); + Optional entityFromElasticSearch = repository.findById(entity.getId()); assertThat(entityFromElasticSearch.isPresent(), is(true)); diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/CustomMethodRepositoryTests.java b/src/test/java/org/springframework/data/elasticsearch/repositories/CustomMethodRepositoryTests.java index ce11efc95..a48e1bc8a 100644 --- a/src/test/java/org/springframework/data/elasticsearch/repositories/CustomMethodRepositoryTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/CustomMethodRepositoryTests.java @@ -47,16 +47,15 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * @author Mohsin Husen * @author Franck Marchand * @author Kevin Leturc + * @author Christoph Strobl */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:custom-method-repository-test.xml") public class CustomMethodRepositoryTests { - @Autowired - private SampleCustomMethodRepository repository; + @Autowired private SampleCustomMethodRepository repository; - @Autowired - private ElasticsearchTemplate elasticsearchTemplate; + @Autowired private ElasticsearchTemplate elasticsearchTemplate; @Before public void before() { @@ -460,8 +459,8 @@ public class CustomMethodRepositoryTests { sampleEntity.setVersion(System.currentTimeMillis()); repository.save(sampleEntity3); // when - Page pageResult = repository.findByMessageContaining("a", new PageRequest(0, 23, new Sort( - new Sort.Order(Sort.Direction.DESC, "message")))); + Page pageResult = repository.findByMessageContaining("a", + new PageRequest(0, 23, new Sort(new Sort.Order(Sort.Direction.DESC, "message")))); // then assertThat(pageResult.getContent().isEmpty(), is(false)); assertThat(pageResult.getContent().get(0).getMessage(), is(sampleEntity3.getMessage())); @@ -541,7 +540,8 @@ public class CustomMethodRepositoryTests { repository.save(sampleEntity); // when - Page page = repository.findByLocationAndMessage(new GeoPoint(45.7806d, 3.0875d), "foo", new PageRequest(0, 10)); + Page page = repository.findByLocationAndMessage(new GeoPoint(45.7806d, 3.0875d), "foo", + new PageRequest(0, 10)); // then assertThat(page, is(notNullValue())); assertThat(page.getTotalElements(), is(equalTo(1L))); @@ -561,7 +561,8 @@ public class CustomMethodRepositoryTests { repository.save(sampleEntity); // when - Page page = repository.findByLocationWithin(new GeoPoint(45.7806d, 3.0875d), "2km", new PageRequest(0, 10)); + Page page = repository.findByLocationWithin(new GeoPoint(45.7806d, 3.0875d), "2km", + new PageRequest(0, 10)); // then assertThat(page, is(notNullValue())); assertThat(page.getTotalElements(), is(equalTo(1L))); @@ -581,7 +582,8 @@ public class CustomMethodRepositoryTests { repository.save(sampleEntity); // when - Page page = repository.findByLocationWithin(new Point(45.7806d, 3.0875d), new Distance(2, Metrics.KILOMETERS), new PageRequest(0, 10)); + Page page = repository.findByLocationWithin(new Point(45.7806d, 3.0875d), + new Distance(2, Metrics.KILOMETERS), new PageRequest(0, 10)); // then assertThat(page, is(notNullValue())); assertThat(page.getTotalElements(), is(equalTo(1L))); @@ -617,7 +619,8 @@ public class CustomMethodRepositoryTests { assertThat(pageAll.getTotalElements(), is(equalTo(2L))); // when - Page page = repository.findByLocationNear(new Box(new Point(46d, 3d), new Point(45d, 4d)), new PageRequest(0, 10)); + Page page = repository.findByLocationNear(new Box(new Point(46d, 3d), new Point(45d, 4d)), + new PageRequest(0, 10)); // then assertThat(page, is(notNullValue())); assertThat(page.getTotalElements(), is(equalTo(1L))); @@ -637,7 +640,8 @@ public class CustomMethodRepositoryTests { repository.save(sampleEntity); // when - Page page = repository.findByLocationNear(new Point(45.7806d, 3.0875d), new Distance(2, Metrics.KILOMETERS), new PageRequest(0, 10)); + Page page = repository.findByLocationNear(new Point(45.7806d, 3.0875d), + new Distance(2, Metrics.KILOMETERS), new PageRequest(0, 10)); // then assertThat(page, is(notNullValue())); assertThat(page.getTotalElements(), is(equalTo(1L))); @@ -650,7 +654,7 @@ public class CustomMethodRepositoryTests { public void shouldAllowReturningJava8StreamInCustomQuery() { // given List entities = createSampleEntities("abc", 30); - repository.save(entities); + repository.saveAll(entities); // when Stream stream = repository.findByType("abc"); @@ -1206,4 +1210,3 @@ public class CustomMethodRepositoryTests { return entities; } } - diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/cdi/CdiProductRepository.java b/src/test/java/org/springframework/data/elasticsearch/repositories/cdi/CdiProductRepository.java index 26286fa08..92a375def 100644 --- a/src/test/java/org/springframework/data/elasticsearch/repositories/cdi/CdiProductRepository.java +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/cdi/CdiProductRepository.java @@ -24,8 +24,9 @@ import org.springframework.data.repository.CrudRepository; * @author Mohsin Husen * @author Oliver Gierke * @author Mark Paluch + * @author Christoph Strobl */ public interface CdiProductRepository extends CrudRepository { - Optional findOne(String id); + Optional findById(String id); } diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/cdi/CdiRepositoryTests.java b/src/test/java/org/springframework/data/elasticsearch/repositories/cdi/CdiRepositoryTests.java index 3b5bd3cd7..a76fa9766 100644 --- a/src/test/java/org/springframework/data/elasticsearch/repositories/cdi/CdiRepositoryTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/cdi/CdiRepositoryTests.java @@ -31,6 +31,7 @@ import org.springframework.data.elasticsearch.entities.Product; /** * @author Mohsin Husen * @author Mark Paluch + * @author Christoph Strobl */ public class CdiRepositoryTests { @@ -70,9 +71,9 @@ public class CdiRepositoryTests { repository.save(bean); - assertTrue(repository.exists(bean.getId())); + assertTrue(repository.existsById(bean.getId())); - Optional retrieved = repository.findOne(bean.getId()); + Optional retrieved = repository.findById(bean.getId()); assertTrue(retrieved.isPresent()); retrieved.ifPresent(product -> { @@ -82,12 +83,12 @@ public class CdiRepositoryTests { assertEquals(1, repository.count()); - assertTrue(repository.exists(bean.getId())); + assertTrue(repository.existsById(bean.getId())); repository.delete(bean); assertEquals(0, repository.count()); - retrieved = repository.findOne(bean.getId()); + retrieved = repository.findById(bean.getId()); assertFalse(retrieved.isPresent()); } @@ -104,9 +105,9 @@ public class CdiRepositoryTests { qualifiedProductRepository.save(bean); - assertTrue(qualifiedProductRepository.exists(bean.getId())); + assertTrue(qualifiedProductRepository.existsById(bean.getId())); - Optional retrieved = qualifiedProductRepository.findOne(bean.getId()); + Optional retrieved = qualifiedProductRepository.findById(bean.getId()); assertTrue(retrieved.isPresent()); retrieved.ifPresent(product -> { @@ -116,12 +117,12 @@ public class CdiRepositoryTests { assertEquals(1, qualifiedProductRepository.count()); - assertTrue(qualifiedProductRepository.exists(bean.getId())); + assertTrue(qualifiedProductRepository.existsById(bean.getId())); qualifiedProductRepository.delete(bean); assertEquals(0, qualifiedProductRepository.count()); - retrieved = qualifiedProductRepository.findOne(bean.getId()); + retrieved = qualifiedProductRepository.findById(bean.getId()); assertFalse(retrieved.isPresent()); } diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/geo/SpringDataGeoRepositoryTests.java b/src/test/java/org/springframework/data/elasticsearch/repositories/geo/SpringDataGeoRepositoryTests.java index f74d7ab2b..cf6ac116b 100644 --- a/src/test/java/org/springframework/data/elasticsearch/repositories/geo/SpringDataGeoRepositoryTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/geo/SpringDataGeoRepositoryTests.java @@ -34,6 +34,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Mark Paluch + * @author Christoph Strobl */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:/repository-spring-data-geo-support.xml") @@ -59,7 +60,7 @@ public class SpringDataGeoRepositoryTests { .pointC(toGeoString(point)).pointD(toGeoArray(point)).build(); // when GeoEntity saved = repository.save(entity); - Optional result = repository.findOne(entity.getId()); + Optional result = repository.findById(entity.getId()); // then assertThat(result.isPresent(), is(true)); diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/sample/SampleElasticsearchRepository.java b/src/test/java/org/springframework/data/elasticsearch/repositories/sample/SampleElasticsearchRepository.java index 009e5650f..d59653431 100644 --- a/src/test/java/org/springframework/data/elasticsearch/repositories/sample/SampleElasticsearchRepository.java +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/sample/SampleElasticsearchRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2017 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. @@ -23,12 +23,16 @@ import org.springframework.data.elasticsearch.repository.ElasticsearchRepository /** * @author Rizwan Idrees * @author Mohsin Husen + * @author Christoph Strobl */ public interface SampleElasticsearchRepository extends ElasticsearchRepository { - long deleteById(String id); + long deleteSampleEntityById(String id); + List deleteByAvailable(boolean available); + List deleteByMessage(String message); + void deleteByType(String type); } diff --git a/src/test/java/org/springframework/data/elasticsearch/repositories/sample/SampleUUIDKeyedElasticsearchRepository.java b/src/test/java/org/springframework/data/elasticsearch/repositories/sample/SampleUUIDKeyedElasticsearchRepository.java index 8f390f716..cafa84406 100644 --- a/src/test/java/org/springframework/data/elasticsearch/repositories/sample/SampleUUIDKeyedElasticsearchRepository.java +++ b/src/test/java/org/springframework/data/elasticsearch/repositories/sample/SampleUUIDKeyedElasticsearchRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2017 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. @@ -23,12 +23,16 @@ import org.springframework.data.elasticsearch.repository.ElasticsearchRepository /** * @author Gad Akuka + * @author Christoph Strobl */ public interface SampleUUIDKeyedElasticsearchRepository extends ElasticsearchRepository { - long deleteById(UUID id); + long deleteSampleEntityUUIDKeyedById(UUID id); + List deleteByAvailable(boolean available); + List deleteByMessage(String message); + void deleteByType(String type); } diff --git a/src/test/java/org/springframework/data/elasticsearch/repository/support/DoubleIDRepositoryTests.java b/src/test/java/org/springframework/data/elasticsearch/repository/support/DoubleIDRepositoryTests.java index a5f5b40fc..f0978454c 100644 --- a/src/test/java/org/springframework/data/elasticsearch/repository/support/DoubleIDRepositoryTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/repository/support/DoubleIDRepositoryTests.java @@ -36,17 +36,15 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * @author Rizwan Idrees * @author Mohsin Husen * @author Mark Paluch + * @author Christoph Strobl */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:/double-id-repository-test.xml") public class DoubleIDRepositoryTests { - @Autowired - private DoubleIDRepository repository; - - @Autowired - private ElasticsearchTemplate elasticsearchTemplate; + @Autowired private DoubleIDRepository repository; + @Autowired private ElasticsearchTemplate elasticsearchTemplate; @Before public void before() { @@ -71,12 +69,12 @@ public class DoubleIDRepositoryTests { sampleEntity2.setVersion(System.currentTimeMillis()); // when - repository.save(Arrays.asList(sampleEntity1, sampleEntity2)); + repository.saveAll(Arrays.asList(sampleEntity1, sampleEntity2)); // then - Optional entity1FromElasticSearch = repository.findOne(documentId1); + Optional entity1FromElasticSearch = repository.findById(documentId1); assertThat(entity1FromElasticSearch.isPresent(), is(true)); - Optional entity2FromElasticSearch = repository.findOne(documentId2); + Optional entity2FromElasticSearch = repository.findById(documentId2); assertThat(entity2FromElasticSearch.isPresent(), is(true)); } @@ -91,7 +89,7 @@ public class DoubleIDRepositoryTests { // when repository.save(sampleEntity); // then - Optional entityFromElasticSearch = repository.findOne(documentId); + Optional entityFromElasticSearch = repository.findById(documentId); assertThat(entityFromElasticSearch.isPresent(), is(true)); } } diff --git a/src/test/java/org/springframework/data/elasticsearch/repository/support/IntegerIDRepositoryTests.java b/src/test/java/org/springframework/data/elasticsearch/repository/support/IntegerIDRepositoryTests.java index 4c566ec8e..b1cb6ca25 100644 --- a/src/test/java/org/springframework/data/elasticsearch/repository/support/IntegerIDRepositoryTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/repository/support/IntegerIDRepositoryTests.java @@ -36,17 +36,15 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * @author Rizwan Idrees * @author Mohsin Husen * @author Mark Paluch + * @author Christoph Strobl */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:/integer-id-repository-test.xml") public class IntegerIDRepositoryTests { - @Autowired - private IntegerIDRepository repository; - - @Autowired - private ElasticsearchTemplate elasticsearchTemplate; + @Autowired private IntegerIDRepository repository; + @Autowired private ElasticsearchTemplate elasticsearchTemplate; @Before public void before() { @@ -71,12 +69,12 @@ public class IntegerIDRepositoryTests { sampleEntity2.setVersion(System.currentTimeMillis()); // when - repository.save(Arrays.asList(sampleEntity1, sampleEntity2)); + repository.saveAll(Arrays.asList(sampleEntity1, sampleEntity2)); // then - Optional entity1FromElasticSearch = repository.findOne(documentId1); + Optional entity1FromElasticSearch = repository.findById(documentId1); assertThat(entity1FromElasticSearch.isPresent(), is(true)); - Optional entity2FromElasticSearch = repository.findOne(documentId2); + Optional entity2FromElasticSearch = repository.findById(documentId2); assertThat(entity2FromElasticSearch.isPresent(), is(true)); } @@ -91,7 +89,7 @@ public class IntegerIDRepositoryTests { // when repository.save(sampleEntity); // then - Optional entityFromElasticSearch = repository.findOne(documentId); + Optional entityFromElasticSearch = repository.findById(documentId); assertThat(entityFromElasticSearch.isPresent(), is(true)); } } diff --git a/src/test/java/org/springframework/data/elasticsearch/repository/support/QueryKeywordsTests.java b/src/test/java/org/springframework/data/elasticsearch/repository/support/QueryKeywordsTests.java index 4fbe48d2f..25eeb7c78 100644 --- a/src/test/java/org/springframework/data/elasticsearch/repository/support/QueryKeywordsTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/repository/support/QueryKeywordsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 the original author or authors. + * Copyright 2016-2017 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. @@ -32,6 +32,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Artur Konczak + * @author Christoph Strobl */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:/repository-query-support.xml") @@ -50,7 +51,7 @@ public class QueryKeywordsTests { elasticsearchTemplate.putMapping(Product.class); elasticsearchTemplate.refresh(Product.class); - repository.save(Arrays.asList( + repository.saveAll(Arrays.asList( Product.builder().id("1").name("Sugar").text("Cane sugar").price(1.0f).available(false).build() , Product.builder().id("2").name("Sugar").text("Cane sugar").price(1.2f).available(true).build() , Product.builder().id("3").name("Sugar").text("Beet sugar").price(1.1f).available(true).build() diff --git a/src/test/java/org/springframework/data/elasticsearch/repository/support/SimpleElasticsearchRepositoryTests.java b/src/test/java/org/springframework/data/elasticsearch/repository/support/SimpleElasticsearchRepositoryTests.java index fc0394923..137b5b7a1 100644 --- a/src/test/java/org/springframework/data/elasticsearch/repository/support/SimpleElasticsearchRepositoryTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/repository/support/SimpleElasticsearchRepositoryTests.java @@ -46,17 +46,15 @@ import com.google.common.collect.Lists; * @author Rizwan Idrees * @author Mohsin Husen * @author Mark Paluch + * @author Christoph Strobl */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:/simple-repository-test.xml") public class SimpleElasticsearchRepositoryTests { - @Autowired - private SampleElasticsearchRepository repository; - - @Autowired - private ElasticsearchTemplate elasticsearchTemplate; + @Autowired private SampleElasticsearchRepository repository; + @Autowired private ElasticsearchTemplate elasticsearchTemplate; @Before public void before() { @@ -81,12 +79,12 @@ public class SimpleElasticsearchRepositoryTests { sampleEntity2.setVersion(System.currentTimeMillis()); // when - repository.save(Arrays.asList(sampleEntity1, sampleEntity2)); + repository.saveAll(Arrays.asList(sampleEntity1, sampleEntity2)); // then - Optional entity1FromElasticSearch = repository.findOne(documentId1); + Optional entity1FromElasticSearch = repository.findById(documentId1); assertThat(entity1FromElasticSearch.isPresent(), is(true)); - Optional entity2FromElasticSearch = repository.findOne(documentId2); + Optional entity2FromElasticSearch = repository.findById(documentId2); assertThat(entity2FromElasticSearch.isPresent(), is(true)); } @@ -101,7 +99,7 @@ public class SimpleElasticsearchRepositoryTests { // when repository.save(sampleEntity); // then - Optional entityFromElasticSearch = repository.findOne(documentId); + Optional entityFromElasticSearch = repository.findById(documentId); assertThat(entityFromElasticSearch.isPresent(), is(true)); } @@ -127,7 +125,7 @@ public class SimpleElasticsearchRepositoryTests { sampleEntity.setVersion(System.currentTimeMillis()); repository.save(sampleEntity); // when - Optional entityFromElasticSearch = repository.findOne(documentId); + Optional entityFromElasticSearch = repository.findById(documentId); // then assertThat(entityFromElasticSearch.isPresent(), is(true)); assertThat(sampleEntity, is((equalTo(sampleEntity)))); @@ -166,9 +164,9 @@ public class SimpleElasticsearchRepositoryTests { sampleEntity.setVersion(System.currentTimeMillis()); repository.save(sampleEntity); // when - repository.delete(documentId); + repository.deleteById(documentId); // then - Optional entityFromElasticSearch = repository.findOne(documentId); + Optional entityFromElasticSearch = repository.findById(documentId); assertThat(entityFromElasticSearch.isPresent(), is(false)); } @@ -227,7 +225,7 @@ public class SimpleElasticsearchRepositoryTests { repository.save(sampleEntity2); // when - Iterable sampleEntities = repository.findAll(Arrays.asList(documentId, documentId2)); + Iterable sampleEntities = repository.findAllById(Arrays.asList(documentId, documentId2)); // then assertNotNull("sample entities cant be null..", sampleEntities); @@ -252,7 +250,7 @@ public class SimpleElasticsearchRepositoryTests { Iterable sampleEntities = Arrays.asList(sampleEntity1, sampleEntity2); // when - repository.save(sampleEntities); + repository.saveAll(sampleEntities); // then Page entities = repository.search(termQuery("id", documentId), new PageRequest(0, 50)); assertNotNull(entities); @@ -269,7 +267,7 @@ public class SimpleElasticsearchRepositoryTests { repository.save(sampleEntity); // when - boolean exist = repository.exists(documentId); + boolean exist = repository.existsById(documentId); // then assertEquals(exist, true); @@ -311,7 +309,7 @@ public class SimpleElasticsearchRepositoryTests { sampleEntity.setVersion(System.currentTimeMillis()); repository.save(sampleEntity); // when - long result = repository.deleteById(documentId); + long result = repository.deleteSampleEntityById(documentId); repository.refresh(); // then @@ -344,7 +342,7 @@ public class SimpleElasticsearchRepositoryTests { sampleEntity3.setMessage("hello world 3"); sampleEntity3.setAvailable(false); sampleEntity3.setVersion(System.currentTimeMillis()); - repository.save(Arrays.asList(sampleEntity1, sampleEntity2, sampleEntity3)); + repository.saveAll(Arrays.asList(sampleEntity1, sampleEntity2, sampleEntity3)); // when List result = repository.deleteByAvailable(true); repository.refresh(); @@ -375,7 +373,7 @@ public class SimpleElasticsearchRepositoryTests { sampleEntity3.setId(documentId); sampleEntity3.setMessage("hello world 3"); sampleEntity3.setVersion(System.currentTimeMillis()); - repository.save(Arrays.asList(sampleEntity1, sampleEntity2, sampleEntity3)); + repository.saveAll(Arrays.asList(sampleEntity1, sampleEntity2, sampleEntity3)); // when List result = repository.deleteByMessage("hello world 3"); repository.refresh(); @@ -406,7 +404,7 @@ public class SimpleElasticsearchRepositoryTests { sampleEntity3.setId(documentId); sampleEntity3.setType("image"); sampleEntity3.setVersion(System.currentTimeMillis()); - repository.save(Arrays.asList(sampleEntity1, sampleEntity2, sampleEntity3)); + repository.saveAll(Arrays.asList(sampleEntity1, sampleEntity2, sampleEntity3)); // when repository.deleteByType("article"); repository.refresh(); @@ -474,10 +472,10 @@ public class SimpleElasticsearchRepositoryTests { Iterable sampleEntities = Arrays.asList(sampleEntity2, sampleEntity2); // when - repository.delete(sampleEntities); + repository.deleteAll(sampleEntities); // then - assertThat(repository.findOne(documentId1).isPresent(), is(false)); - assertThat(repository.findOne(documentId2).isPresent(), is(false)); + assertThat(repository.findById(documentId1).isPresent(), is(false)); + assertThat(repository.findById(documentId2).isPresent(), is(false)); } @Test @@ -525,10 +523,11 @@ public class SimpleElasticsearchRepositoryTests { + "we want real-time search, we want simple multi-tenancy, and we want a solution that is built for the cloud."; List sampleEntities = createSampleEntitiesWithMessage(sampleMessage, 30); - repository.save(sampleEntities); + repository.saveAll(sampleEntities); // when - Page results = repository.searchSimilar(sampleEntities.get(0), new String[]{"message"}, new PageRequest(0, 5)); + Page results = repository.searchSimilar(sampleEntities.get(0), new String[] { "message" }, + new PageRequest(0, 5)); // then assertThat(results.getTotalElements(), is(greaterThanOrEqualTo(1L))); diff --git a/src/test/java/org/springframework/data/elasticsearch/repository/support/UUIDElasticsearchRepositoryTests.java b/src/test/java/org/springframework/data/elasticsearch/repository/support/UUIDElasticsearchRepositoryTests.java index dcefc7809..8582edca3 100644 --- a/src/test/java/org/springframework/data/elasticsearch/repository/support/UUIDElasticsearchRepositoryTests.java +++ b/src/test/java/org/springframework/data/elasticsearch/repository/support/UUIDElasticsearchRepositoryTests.java @@ -46,17 +46,15 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * @author Rizwan Idrees * @author Mohsin Husen * @author Mark Paluch + * @author Christoph Strobl */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:/simple-repository-test.xml") public class UUIDElasticsearchRepositoryTests { - @Autowired - private SampleUUIDKeyedElasticsearchRepository repository; - - @Autowired - private ElasticsearchTemplate elasticsearchTemplate; + @Autowired private SampleUUIDKeyedElasticsearchRepository repository; + @Autowired private ElasticsearchTemplate elasticsearchTemplate; @Before public void before() { @@ -82,12 +80,12 @@ public class UUIDElasticsearchRepositoryTests { sampleEntityUUIDKeyed2.setVersion(System.currentTimeMillis()); // when - repository.save(Arrays.asList(sampleEntityUUIDKeyed1, sampleEntityUUIDKeyed2)); + repository.saveAll(Arrays.asList(sampleEntityUUIDKeyed1, sampleEntityUUIDKeyed2)); // then - Optional entity1FromElasticSearch = repository.findOne(documentId1); + Optional entity1FromElasticSearch = repository.findById(documentId1); assertThat(entity1FromElasticSearch.isPresent(), is(true)); - Optional entity2FromElasticSearch = repository.findOne(documentId2); + Optional entity2FromElasticSearch = repository.findById(documentId2); assertThat(entity2FromElasticSearch.isPresent(), is(true)); } @@ -102,7 +100,7 @@ public class UUIDElasticsearchRepositoryTests { // when repository.save(sampleEntityUUIDKeyed); // then - Optional entityFromElasticSearch = repository.findOne(documentId); + Optional entityFromElasticSearch = repository.findById(documentId); assertThat(entityFromElasticSearch.isPresent(), is(true)); } @@ -116,7 +114,7 @@ public class UUIDElasticsearchRepositoryTests { sampleEntityUUIDKeyed.setVersion(System.currentTimeMillis()); repository.save(sampleEntityUUIDKeyed); // when - Optional entityFromElasticSearch = repository.findOne(documentId); + Optional entityFromElasticSearch = repository.findById(documentId); // then assertThat(entityFromElasticSearch.isPresent(), is(true)); assertThat(sampleEntityUUIDKeyed, is((equalTo(sampleEntityUUIDKeyed)))); @@ -155,9 +153,9 @@ public class UUIDElasticsearchRepositoryTests { sampleEntityUUIDKeyed.setVersion(System.currentTimeMillis()); repository.save(sampleEntityUUIDKeyed); // when - repository.delete(documentId); + repository.deleteById(documentId); // then - Optional entityFromElasticSearch = repository.findOne(documentId); + Optional entityFromElasticSearch = repository.findById(documentId); assertThat(entityFromElasticSearch.isPresent(), is(false)); } @@ -216,7 +214,8 @@ public class UUIDElasticsearchRepositoryTests { repository.save(sampleEntityUUIDKeyed2); // when - LinkedList sampleEntities = (LinkedList) repository.findAll(Arrays.asList(documentId, documentId2)); + LinkedList sampleEntities = (LinkedList) repository + .findAllById(Arrays.asList(documentId, documentId2)); // then assertNotNull("sample entities cant be null..", sampleEntities); @@ -242,7 +241,7 @@ public class UUIDElasticsearchRepositoryTests { Iterable sampleEntities = Arrays.asList(sampleEntityUUIDKeyed1, sampleEntityUUIDKeyed2); // when - repository.save(sampleEntities); + repository.saveAll(sampleEntities); // then Page entities = repository.search(termQuery("id", documentId), new PageRequest(0, 50)); assertNotNull(entities); @@ -259,7 +258,7 @@ public class UUIDElasticsearchRepositoryTests { repository.save(sampleEntityUUIDKeyed); // when - boolean exist = repository.exists(documentId); + boolean exist = repository.existsById(documentId); // then assertEquals(exist, true); @@ -285,7 +284,7 @@ public class UUIDElasticsearchRepositoryTests { sampleEntityUUIDKeyed.setVersion(System.currentTimeMillis()); repository.save(sampleEntityUUIDKeyed); // when - long result = repository.deleteById(documentId); + long result = repository.deleteSampleEntityUUIDKeyedById(documentId); // then SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(termQuery("id", documentId)).build(); Page sampleEntities = repository.search(searchQuery); @@ -316,7 +315,7 @@ public class UUIDElasticsearchRepositoryTests { sampleEntityUUIDKeyed3.setMessage("hello world 3"); sampleEntityUUIDKeyed3.setAvailable(false); sampleEntityUUIDKeyed3.setVersion(System.currentTimeMillis()); - repository.save(Arrays.asList(sampleEntityUUIDKeyed1, sampleEntityUUIDKeyed2, sampleEntityUUIDKeyed3)); + repository.saveAll(Arrays.asList(sampleEntityUUIDKeyed1, sampleEntityUUIDKeyed2, sampleEntityUUIDKeyed3)); // when List result = repository.deleteByAvailable(true); repository.refresh(); @@ -347,7 +346,7 @@ public class UUIDElasticsearchRepositoryTests { sampleEntityUUIDKeyed3.setId(documentId); sampleEntityUUIDKeyed3.setMessage("hello world 3"); sampleEntityUUIDKeyed3.setVersion(System.currentTimeMillis()); - repository.save(Arrays.asList(sampleEntityUUIDKeyed1, sampleEntityUUIDKeyed2, sampleEntityUUIDKeyed3)); + repository.saveAll(Arrays.asList(sampleEntityUUIDKeyed1, sampleEntityUUIDKeyed2, sampleEntityUUIDKeyed3)); // when List result = repository.deleteByMessage("hello world 3"); repository.refresh(); @@ -378,7 +377,7 @@ public class UUIDElasticsearchRepositoryTests { sampleEntityUUIDKeyed3.setId(documentId); sampleEntityUUIDKeyed3.setType("image"); sampleEntityUUIDKeyed3.setVersion(System.currentTimeMillis()); - repository.save(Arrays.asList(sampleEntityUUIDKeyed1, sampleEntityUUIDKeyed2, sampleEntityUUIDKeyed3)); + repository.saveAll(Arrays.asList(sampleEntityUUIDKeyed1, sampleEntityUUIDKeyed2, sampleEntityUUIDKeyed3)); // when repository.deleteByType("article"); repository.refresh(); @@ -388,7 +387,6 @@ public class UUIDElasticsearchRepositoryTests { assertThat(sampleEntities.getTotalElements(), equalTo(2L)); } - @Test public void shouldDeleteEntity() { // given @@ -448,10 +446,10 @@ public class UUIDElasticsearchRepositoryTests { Iterable sampleEntities = Arrays.asList(sampleEntityUUIDKeyed2, sampleEntityUUIDKeyed2); // when - repository.delete(sampleEntities); + repository.deleteAll(sampleEntities); // then - assertThat(repository.findOne(documentId1).isPresent(), is(false)); - assertThat(repository.findOne(documentId2).isPresent(), is(false)); + assertThat(repository.findById(documentId1).isPresent(), is(false)); + assertThat(repository.findById(documentId2).isPresent(), is(false)); } @Test @@ -470,7 +468,8 @@ public class UUIDElasticsearchRepositoryTests { sampleEntityUUIDKeyed2.setMessage("hello"); repository.save(sampleEntityUUIDKeyed2); // when - Iterable sampleEntities = repository.findAll(new Sort(new Sort.Order(Sort.Direction.ASC, "message"))); + Iterable sampleEntities = repository + .findAll(new Sort(new Sort.Order(Sort.Direction.ASC, "message"))); // then assertThat(sampleEntities, is(notNullValue())); } @@ -485,10 +484,11 @@ public class UUIDElasticsearchRepositoryTests { + "we want real-time search, we want simple multi-tenancy, and we want a solution that is built for the cloud."; List sampleEntities = createSampleEntitiesWithMessage(sampleMessage, 30); - repository.save(sampleEntities); + repository.saveAll(sampleEntities); // when - Page results = repository.searchSimilar(sampleEntities.get(0), new String[]{"message"}, new PageRequest(0, 5)); + Page results = repository.searchSimilar(sampleEntities.get(0), new String[] { "message" }, + new PageRequest(0, 5)); // then assertThat(results.getTotalElements(), is(greaterThanOrEqualTo(1L)));