|
15 | 15 | */
|
16 | 16 | package org.springframework.data.elasticsearch.client.elc;
|
17 | 17 |
|
18 |
| -import static org.assertj.core.api.Assertions.*; |
| 18 | +import static org.assertj.core.api.Assertions.assertThat; |
19 | 19 |
|
20 | 20 | import co.elastic.clients.json.jackson.JacksonJsonpMapper;
|
21 | 21 |
|
|
24 | 24 | import org.junit.jupiter.api.DisplayName;
|
25 | 25 | import org.junit.jupiter.api.Test;
|
26 | 26 | import org.springframework.data.annotation.Id;
|
| 27 | +import org.springframework.data.domain.Pageable; |
27 | 28 | import org.springframework.data.elasticsearch.annotations.Document;
|
28 | 29 | import org.springframework.data.elasticsearch.annotations.Field;
|
29 | 30 | import org.springframework.data.elasticsearch.annotations.FieldType;
|
@@ -89,6 +90,72 @@ void refreshSetByDeleteRequest() {
|
89 | 90 | assertThat(deleteByQueryRequest.refresh()).isTrue();
|
90 | 91 | }
|
91 | 92 |
|
| 93 | + @Test |
| 94 | + @DisplayName("When maxResults is set (size < maxResults), pageSize should be the minimum of maxResults and pageable size") |
| 95 | + void searchRequestPageSizeSmallerThanMaxResults() { |
| 96 | + var size = 123; |
| 97 | + var maxResults = size * 12; |
| 98 | + |
| 99 | + var query = StringQuery.builder(""" |
| 100 | + { |
| 101 | + "match_all":{} |
| 102 | + } |
| 103 | + """) |
| 104 | + .withPageable(Pageable.ofSize(size)) |
| 105 | + .withMaxResults(maxResults) |
| 106 | + .build(); |
| 107 | + |
| 108 | + var searchRequest = requestConverter.searchRequest(query, null, SampleEntity.class, IndexCoordinates.of("foo"), false, false, null); |
| 109 | + var actualPageSize = searchRequest.size(); |
| 110 | + |
| 111 | + assertThat(actualPageSize).isEqualTo(size); |
| 112 | + assertThat(actualPageSize).isNotEqualTo(maxResults); |
| 113 | + } |
| 114 | + |
| 115 | + @Test |
| 116 | + @DisplayName("When maxResults is set (size == maxResults), pageSize should be equal to maxResults and pageable size") |
| 117 | + void searchRequestPageSizeEqualToMaxResults() { |
| 118 | + var pageSize = 123; |
| 119 | + var maxResults = pageSize; |
| 120 | + |
| 121 | + var query = StringQuery.builder(""" |
| 122 | + { |
| 123 | + "match_all":{} |
| 124 | + } |
| 125 | + """) |
| 126 | + .withPageable(Pageable.ofSize(pageSize)) |
| 127 | + .withMaxResults(maxResults) |
| 128 | + .build(); |
| 129 | + |
| 130 | + var searchRequest = requestConverter.searchRequest(query, null, SampleEntity.class, IndexCoordinates.of("foo"), false, false, null); |
| 131 | + var actualPageSize = searchRequest.size(); |
| 132 | + |
| 133 | + assertThat(actualPageSize).isEqualTo(pageSize); |
| 134 | + assertThat(actualPageSize).isEqualTo(maxResults); |
| 135 | + } |
| 136 | + |
| 137 | + @Test |
| 138 | + @DisplayName("When maxResults is set (size > maxResults), pageSize should be the minimum of maxResults and pageable size") |
| 139 | + void searchRequestPageSizeLargerThanMaxResults() { |
| 140 | + var pageSize = 123; |
| 141 | + var maxResults = 99; |
| 142 | + |
| 143 | + var query = StringQuery.builder(""" |
| 144 | + { |
| 145 | + "match_all":{} |
| 146 | + } |
| 147 | + """) |
| 148 | + .withPageable(Pageable.ofSize(pageSize)) |
| 149 | + .withMaxResults(maxResults) |
| 150 | + .build(); |
| 151 | + |
| 152 | + var searchRequest = requestConverter.searchRequest(query, null, SampleEntity.class, IndexCoordinates.of("foo"), false, false, null); |
| 153 | + var actualPageSize = searchRequest.size(); |
| 154 | + |
| 155 | + assertThat(actualPageSize).isNotEqualTo(pageSize); |
| 156 | + assertThat(actualPageSize).isEqualTo(maxResults); |
| 157 | + } |
| 158 | + |
92 | 159 | @Document(indexName = "does-not-matter")
|
93 | 160 | static class SampleEntity {
|
94 | 161 | @Nullable
|
|
0 commit comments