|
@@ -19,12 +19,14 @@
|
|
|
|
|
|
package org.elasticsearch.index.rankeval;
|
|
|
|
|
|
+import org.elasticsearch.common.bytes.BytesReference;
|
|
|
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
|
|
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
|
|
import org.elasticsearch.common.xcontent.ToXContent;
|
|
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
|
|
import org.elasticsearch.common.xcontent.XContentParser;
|
|
|
+import org.elasticsearch.common.xcontent.XContentType;
|
|
|
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
|
|
import org.elasticsearch.index.query.MatchAllQueryBuilder;
|
|
|
import org.elasticsearch.index.query.QueryBuilder;
|
|
@@ -47,6 +49,8 @@ import java.util.Map.Entry;
|
|
|
import java.util.function.Supplier;
|
|
|
|
|
|
import static org.elasticsearch.test.EqualsHashCodeTestUtils.checkEqualsAndHashCode;
|
|
|
+import static org.elasticsearch.test.XContentTestUtils.insertRandomFields;
|
|
|
+import static org.hamcrest.Matchers.startsWith;
|
|
|
|
|
|
public class RankEvalSpecTests extends ESTestCase {
|
|
|
|
|
@@ -123,6 +127,17 @@ public class RankEvalSpecTests extends ESTestCase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public void testXContentParsingIsNotLenient() throws IOException {
|
|
|
+ RankEvalSpec testItem = createTestItem();
|
|
|
+ XContentType xContentType = randomFrom(XContentType.values());
|
|
|
+ BytesReference originalBytes = toShuffledXContent(testItem, xContentType, ToXContent.EMPTY_PARAMS, randomBoolean());
|
|
|
+ BytesReference withRandomFields = insertRandomFields(xContentType, originalBytes, null, random());
|
|
|
+ try (XContentParser parser = createParser(xContentType.xContent(), withRandomFields)) {
|
|
|
+ Exception exception = expectThrows(Exception.class, () -> RankEvalSpec.parse(parser));
|
|
|
+ assertThat(exception.getMessage(), startsWith("[rank_eval] failed to parse field"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public void testSerialization() throws IOException {
|
|
|
RankEvalSpec original = createTestItem();
|
|
|
RankEvalSpec deserialized = copy(original);
|