|
36 | 36 |
|
37 | 37 | import org.junit.jupiter.api.AfterEach; |
38 | 38 | import org.junit.jupiter.api.BeforeEach; |
| 39 | +import org.junit.jupiter.api.DisplayName; |
39 | 40 | import org.junit.jupiter.api.Test; |
40 | 41 | import org.springframework.beans.factory.annotation.Autowired; |
41 | 42 | import org.springframework.context.annotation.Configuration; |
|
51 | 52 | import org.springframework.data.elasticsearch.annotations.Field; |
52 | 53 | import org.springframework.data.elasticsearch.core.ElasticsearchOperations; |
53 | 54 | import org.springframework.data.elasticsearch.core.IndexOperations; |
| 55 | +import org.springframework.data.elasticsearch.core.SearchPage; |
| 56 | +import org.springframework.data.elasticsearch.core.query.Criteria; |
| 57 | +import org.springframework.data.elasticsearch.core.query.CriteriaQuery; |
54 | 58 | import org.springframework.data.elasticsearch.core.query.NativeSearchQuery; |
55 | 59 | import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder; |
56 | 60 | import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration; |
|
71 | 75 | * @author Murali Chevuri |
72 | 76 | */ |
73 | 77 | @SpringIntegrationTest |
74 | | -@ContextConfiguration(classes = { SimpleElasticsearchRepositoryTests.Config.class }) |
75 | | -public class SimpleElasticsearchRepositoryTests { |
| 78 | +@ContextConfiguration(classes = { SimpleElasticsearchRepositoryIntegrationTests.Config.class }) |
| 79 | +public class SimpleElasticsearchRepositoryIntegrationTests { |
76 | 80 |
|
77 | 81 | @Configuration |
78 | 82 | @Import({ ElasticsearchRestTemplateConfiguration.class }) |
@@ -714,6 +718,24 @@ void shouldNotReturnNullValuesInFindAllById() throws IOException { |
714 | 718 | .containsExactlyInAnyOrder("id-one", "id-two", "id-three"); |
715 | 719 | } |
716 | 720 |
|
| 721 | + @Test // DATAES-934 |
| 722 | + @DisplayName("should use query and return SearchPage") |
| 723 | + void shouldUseQueryAndReturnSearchPage() { |
| 724 | + |
| 725 | + List<SampleEntity> entities = createSampleEntitiesWithMessage("test", 20); |
| 726 | + repository.saveAll(entities); |
| 727 | + |
| 728 | + Criteria criteria = new Criteria("message").is("test"); |
| 729 | + CriteriaQuery query = new CriteriaQuery(new Criteria("message").is("test")); |
| 730 | + query.setPageable(PageRequest.of(0, 8)); |
| 731 | + |
| 732 | + SearchPage<SampleEntity> searchPage = repository.searchQuery(query); |
| 733 | + |
| 734 | + assertThat(searchPage.getTotalElements()).isEqualTo(20l); |
| 735 | + assertThat(searchPage.stream().count()).isEqualTo(8l); |
| 736 | + assertThat(searchPage.nextPageable().getOffset()).isEqualTo(8l); |
| 737 | + } |
| 738 | + |
717 | 739 | private static List<SampleEntity> createSampleEntitiesWithMessage(String message, int numberOfEntities) { |
718 | 740 |
|
719 | 741 | List<SampleEntity> sampleEntities = new ArrayList<>(); |
|
0 commit comments