|
38 | 38 | import org.elasticsearch.test.ESTestCase;
|
39 | 39 |
|
40 | 40 | import java.io.IOException;
|
| 41 | +import java.math.BigDecimal; |
| 42 | +import java.math.BigInteger; |
41 | 43 | import java.util.Collections;
|
42 | 44 |
|
43 | 45 | import static org.elasticsearch.search.searchafter.SearchAfterBuilder.extractSortType;
|
44 | 46 | import static org.elasticsearch.test.EqualsHashCodeTestUtils.checkEqualsAndHashCode;
|
| 47 | +import static org.hamcrest.Matchers.containsString; |
45 | 48 | import static org.hamcrest.Matchers.equalTo;
|
46 | 49 |
|
47 | 50 | public class SearchAfterBuilderTests extends ESTestCase {
|
@@ -187,6 +190,44 @@ public void testFromXContent() throws Exception {
|
187 | 190 | }
|
188 | 191 | }
|
189 | 192 |
|
| 193 | + public void testFromXContentIllegalType() throws Exception { |
| 194 | + for (XContentType type : XContentType.values()) { |
| 195 | + // BIG_INTEGER |
| 196 | + XContentBuilder xContent = XContentFactory.contentBuilder(type); |
| 197 | + xContent.startObject() |
| 198 | + .startArray("search_after") |
| 199 | + .value(new BigInteger("9223372036854776000")) |
| 200 | + .endArray() |
| 201 | + .endObject(); |
| 202 | + try (XContentParser parser = createParser(xContent)) { |
| 203 | + parser.nextToken(); |
| 204 | + parser.nextToken(); |
| 205 | + parser.nextToken(); |
| 206 | + IllegalArgumentException exc = expectThrows(IllegalArgumentException.class, () -> SearchAfterBuilder.fromXContent(parser)); |
| 207 | + assertThat(exc.getMessage(), containsString("BIG_INTEGER")); |
| 208 | + } |
| 209 | + |
| 210 | + // BIG_DECIMAL |
| 211 | + // ignore json and yaml, they parse floating point numbers as floats/doubles |
| 212 | + if (type == XContentType.JSON || type == XContentType.YAML) { |
| 213 | + continue; |
| 214 | + } |
| 215 | + xContent = XContentFactory.contentBuilder(type); |
| 216 | + xContent.startObject() |
| 217 | + .startArray("search_after") |
| 218 | + .value(new BigDecimal("9223372036854776003.3")) |
| 219 | + .endArray() |
| 220 | + .endObject(); |
| 221 | + try (XContentParser parser = createParser(xContent)) { |
| 222 | + parser.nextToken(); |
| 223 | + parser.nextToken(); |
| 224 | + parser.nextToken(); |
| 225 | + IllegalArgumentException exc = expectThrows(IllegalArgumentException.class, () -> SearchAfterBuilder.fromXContent(parser)); |
| 226 | + assertThat(exc.getMessage(), containsString("BIG_DECIMAL")); |
| 227 | + } |
| 228 | + } |
| 229 | + } |
| 230 | + |
190 | 231 | public void testWithNullArray() throws Exception {
|
191 | 232 | SearchAfterBuilder builder = new SearchAfterBuilder();
|
192 | 233 | try {
|
|
0 commit comments