|
@@ -38,10 +38,13 @@ import org.elasticsearch.search.MultiValueMode;
|
|
|
import org.elasticsearch.test.ESTestCase;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.BigInteger;
|
|
|
import java.util.Collections;
|
|
|
|
|
|
import static org.elasticsearch.search.searchafter.SearchAfterBuilder.extractSortType;
|
|
|
import static org.elasticsearch.test.EqualsHashCodeTestUtils.checkEqualsAndHashCode;
|
|
|
+import static org.hamcrest.Matchers.containsString;
|
|
|
import static org.hamcrest.Matchers.equalTo;
|
|
|
|
|
|
public class SearchAfterBuilderTests extends ESTestCase {
|
|
@@ -187,6 +190,44 @@ public class SearchAfterBuilderTests extends ESTestCase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public void testFromXContentIllegalType() throws Exception {
|
|
|
+ for (XContentType type : XContentType.values()) {
|
|
|
+ // BIG_INTEGER
|
|
|
+ XContentBuilder xContent = XContentFactory.contentBuilder(type);
|
|
|
+ xContent.startObject()
|
|
|
+ .startArray("search_after")
|
|
|
+ .value(new BigInteger("9223372036854776000"))
|
|
|
+ .endArray()
|
|
|
+ .endObject();
|
|
|
+ try (XContentParser parser = createParser(xContent)) {
|
|
|
+ parser.nextToken();
|
|
|
+ parser.nextToken();
|
|
|
+ parser.nextToken();
|
|
|
+ IllegalArgumentException exc = expectThrows(IllegalArgumentException.class, () -> SearchAfterBuilder.fromXContent(parser));
|
|
|
+ assertThat(exc.getMessage(), containsString("BIG_INTEGER"));
|
|
|
+ }
|
|
|
+
|
|
|
+ // BIG_DECIMAL
|
|
|
+ // ignore json and yaml, they parse floating point numbers as floats/doubles
|
|
|
+ if (type == XContentType.JSON || type == XContentType.YAML) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ xContent = XContentFactory.contentBuilder(type);
|
|
|
+ xContent.startObject()
|
|
|
+ .startArray("search_after")
|
|
|
+ .value(new BigDecimal("9223372036854776003.3"))
|
|
|
+ .endArray()
|
|
|
+ .endObject();
|
|
|
+ try (XContentParser parser = createParser(xContent)) {
|
|
|
+ parser.nextToken();
|
|
|
+ parser.nextToken();
|
|
|
+ parser.nextToken();
|
|
|
+ IllegalArgumentException exc = expectThrows(IllegalArgumentException.class, () -> SearchAfterBuilder.fromXContent(parser));
|
|
|
+ assertThat(exc.getMessage(), containsString("BIG_DECIMAL"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public void testWithNullArray() throws Exception {
|
|
|
SearchAfterBuilder builder = new SearchAfterBuilder();
|
|
|
try {
|