Continue consolidating `XContentParser` construction in tests (#22145)
Consolidate more parser creation in tests Moves more parser creation in tests to the `createParser` methods in `ESTestCase`.
This commit is contained in:
parent
b7bcb5bb3a
commit
872984d21a
|
@ -39,7 +39,7 @@ import java.io.OutputStream;
|
|||
*/
|
||||
public class XContentFactory {
|
||||
|
||||
private static int GUESS_HEADER_LENGTH = 20;
|
||||
private static final int GUESS_HEADER_LENGTH = 20;
|
||||
|
||||
/**
|
||||
* Returns a content builder using JSON format ({@link org.elasticsearch.common.xcontent.XContentType#JSON}.
|
||||
|
|
|
@ -72,7 +72,7 @@ public class DocWriteResponseTests extends ESTestCase {
|
|||
builder.startObject();
|
||||
response.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
builder.endObject();
|
||||
try (XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes())) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, builder.bytes())) {
|
||||
assertThat(parser.map(), not(hasKey("forced_refresh")));
|
||||
}
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ public class DocWriteResponseTests extends ESTestCase {
|
|||
builder.startObject();
|
||||
response.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
builder.endObject();
|
||||
try (XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes())) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, builder.bytes())) {
|
||||
assertThat(parser.map(), hasEntry("forced_refresh", true));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ 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.shard.ShardStateMetaData;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.transport.NodeDisconnectedException;
|
||||
|
@ -73,7 +74,7 @@ public class IndicesShardStoreResponseTests extends ESTestCase {
|
|||
contentBuilder.endObject();
|
||||
BytesReference bytes = contentBuilder.bytes();
|
||||
|
||||
try (XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(bytes)) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, bytes)) {
|
||||
Map<String, Object> map = parser.map();
|
||||
List failureList = (List) map.get("failures");
|
||||
assertThat(failureList.size(), equalTo(1));
|
||||
|
|
|
@ -41,10 +41,9 @@ import org.elasticsearch.common.bytes.BytesArray;
|
|||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.io.stream.InputStreamStreamInput;
|
||||
import org.elasticsearch.common.io.stream.OutputStreamStreamOutput;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.index.mapper.AllFieldMapper;
|
||||
import org.elasticsearch.index.mapper.FieldMapper;
|
||||
import org.elasticsearch.index.mapper.MapperParsingException;
|
||||
|
@ -179,7 +178,7 @@ public class TermVectorsUnitTests extends ESTestCase {
|
|||
" {\"fields\" : [\"a\", \"b\",\"c\"], \"offsets\":false, \"positions\":false, \"payloads\":true}");
|
||||
|
||||
TermVectorsRequest tvr = new TermVectorsRequest(null, null, null);
|
||||
XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(inputBytes);
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, inputBytes);
|
||||
TermVectorsRequest.parseRequest(tvr, parser);
|
||||
|
||||
Set<String> fields = tvr.selectedFields();
|
||||
|
@ -200,7 +199,7 @@ public class TermVectorsUnitTests extends ESTestCase {
|
|||
|
||||
inputBytes = new BytesArray(" {\"offsets\":false, \"positions\":false, \"payloads\":true}");
|
||||
tvr = new TermVectorsRequest(null, null, null);
|
||||
parser = XContentFactory.xContent(XContentType.JSON).createParser(inputBytes);
|
||||
parser = createParser(JsonXContent.jsonXContent, inputBytes);
|
||||
TermVectorsRequest.parseRequest(tvr, parser);
|
||||
additionalFields = "";
|
||||
RestTermVectorsAction.addFieldStringsFromParameter(tvr, additionalFields);
|
||||
|
@ -217,7 +216,7 @@ public class TermVectorsUnitTests extends ESTestCase {
|
|||
TermVectorsRequest tvr = new TermVectorsRequest(null, null, null);
|
||||
boolean threwException = false;
|
||||
try {
|
||||
XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(inputBytes);
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, inputBytes);
|
||||
TermVectorsRequest.parseRequest(tvr, parser);
|
||||
} catch (Exception e) {
|
||||
threwException = true;
|
||||
|
|
|
@ -20,19 +20,16 @@
|
|||
package org.elasticsearch.cluster.metadata;
|
||||
|
||||
import org.elasticsearch.common.UUIDs;
|
||||
import org.elasticsearch.common.io.stream.ByteBufferStreamInput;
|
||||
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.index.Index;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
|
@ -69,7 +66,7 @@ public class IndexGraveyardTests extends ESTestCase {
|
|||
builder.startObject();
|
||||
graveyard.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
builder.endObject();
|
||||
XContentParser parser = XContentType.JSON.xContent().createParser(builder.bytes());
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, builder.bytes());
|
||||
parser.nextToken(); // the beginning of the parser
|
||||
assertThat(IndexGraveyard.PROTO.fromXContent(parser), equalTo(graveyard));
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@ import org.elasticsearch.common.util.set.Sets;
|
|||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.index.shard.ShardId;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
@ -53,7 +52,7 @@ public class IndexMetaDataTests extends ESTestCase {
|
|||
builder.startObject();
|
||||
metaData.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
builder.endObject();
|
||||
XContentParser parser = XContentType.JSON.xContent().createParser(builder.bytes());
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, builder.bytes());
|
||||
final IndexMetaData fromXContentMeta = IndexMetaData.PROTO.fromXContent(parser, null);
|
||||
assertEquals(metaData, fromXContentMeta);
|
||||
assertEquals(metaData.hashCode(), fromXContentMeta.hashCode());
|
||||
|
|
|
@ -27,7 +27,6 @@ import org.elasticsearch.common.settings.Settings;
|
|||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.index.Index;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
@ -129,7 +128,7 @@ public class MetaDataTests extends ESTestCase {
|
|||
.field("random", "value")
|
||||
.endObject()
|
||||
.endObject().bytes();
|
||||
XContentParser parser = JsonXContent.jsonXContent.createParser(metadata);
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, metadata);
|
||||
try {
|
||||
MetaData.Builder.fromXContent(parser);
|
||||
fail();
|
||||
|
@ -145,7 +144,7 @@ public class MetaDataTests extends ESTestCase {
|
|||
.field("random", "value")
|
||||
.endObject()
|
||||
.endObject().bytes();
|
||||
XContentParser parser = JsonXContent.jsonXContent.createParser(metadata);
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, metadata);
|
||||
try {
|
||||
IndexMetaData.Builder.fromXContent(parser);
|
||||
fail();
|
||||
|
@ -173,7 +172,7 @@ public class MetaDataTests extends ESTestCase {
|
|||
builder.startObject();
|
||||
originalMeta.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
builder.endObject();
|
||||
XContentParser parser = XContentType.JSON.xContent().createParser(builder.bytes());
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, builder.bytes());
|
||||
final MetaData fromXContentMeta = MetaData.PROTO.fromXContent(parser, null);
|
||||
assertThat(fromXContentMeta.indexGraveyard(), equalTo(originalMeta.indexGraveyard()));
|
||||
}
|
||||
|
|
|
@ -21,8 +21,7 @@ package org.elasticsearch.cluster.metadata;
|
|||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -149,7 +148,7 @@ public class ToAndFromJsonMetaDataTests extends ESTestCase {
|
|||
String metaDataSource = MetaData.Builder.toXContent(metaData);
|
||||
// System.out.println("ToJson: " + metaDataSource);
|
||||
|
||||
MetaData parsedMetaData = MetaData.Builder.fromXContent(XContentFactory.xContent(XContentType.JSON).createParser(metaDataSource));
|
||||
MetaData parsedMetaData = MetaData.Builder.fromXContent(createParser(JsonXContent.jsonXContent, metaDataSource));
|
||||
|
||||
IndexMetaData indexMetaData = parsedMetaData.index("test1");
|
||||
assertThat(indexMetaData.primaryTerm(0), equalTo(1L));
|
||||
|
|
|
@ -23,7 +23,7 @@ import org.elasticsearch.cluster.routing.RecoverySource.StoreRecoverySource;
|
|||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.index.shard.ShardId;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
|
@ -129,7 +129,7 @@ public class AllocationIdTests extends ESTestCase {
|
|||
allocationId = AllocationId.newRelocation(allocationId);
|
||||
}
|
||||
BytesReference bytes = allocationId.toXContent(XContentFactory.jsonBuilder(), ToXContent.EMPTY_PARAMS).bytes();
|
||||
AllocationId parsedAllocationId = AllocationId.fromXContent(XContentFactory.xContent(XContentType.JSON).createParser(bytes));
|
||||
AllocationId parsedAllocationId = AllocationId.fromXContent(createParser(JsonXContent.jsonXContent, bytes));
|
||||
assertEquals(allocationId, parsedAllocationId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,9 +46,8 @@ import org.elasticsearch.common.io.stream.StreamInput;
|
|||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.network.NetworkModule;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
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.IndexNotFoundException;
|
||||
import org.elasticsearch.index.shard.ShardId;
|
||||
import org.elasticsearch.index.shard.ShardNotFoundException;
|
||||
|
@ -486,7 +485,7 @@ public class AllocationCommandsTests extends ESAllocationTestCase {
|
|||
" ,{\"cancel\" : {\"index\" : \"test\", \"shard\" : 4, \"node\" : \"node5\", \"allow_primary\" : true}} \n" +
|
||||
" ]\n" +
|
||||
"}\n";
|
||||
XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(commands);
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, commands);
|
||||
// move two tokens, parser expected to be "on" `commands` field
|
||||
parser.nextToken();
|
||||
parser.nextToken();
|
||||
|
|
|
@ -19,13 +19,6 @@
|
|||
|
||||
package org.elasticsearch.common.geo;
|
||||
|
||||
import org.locationtech.spatial4j.exception.InvalidShapeException;
|
||||
import org.locationtech.spatial4j.shape.Circle;
|
||||
import org.locationtech.spatial4j.shape.Rectangle;
|
||||
import org.locationtech.spatial4j.shape.Shape;
|
||||
import org.locationtech.spatial4j.shape.ShapeCollection;
|
||||
import org.locationtech.spatial4j.shape.jts.JtsGeometry;
|
||||
import org.locationtech.spatial4j.shape.jts.JtsPoint;
|
||||
import com.vividsolutions.jts.geom.Coordinate;
|
||||
import com.vividsolutions.jts.geom.Geometry;
|
||||
import com.vividsolutions.jts.geom.GeometryFactory;
|
||||
|
@ -37,11 +30,19 @@ import com.vividsolutions.jts.geom.Polygon;
|
|||
|
||||
import org.elasticsearch.ElasticsearchParseException;
|
||||
import org.elasticsearch.common.geo.builders.ShapeBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.test.hamcrest.ElasticsearchGeoAssertions;
|
||||
import org.locationtech.spatial4j.exception.InvalidShapeException;
|
||||
import org.locationtech.spatial4j.shape.Circle;
|
||||
import org.locationtech.spatial4j.shape.Rectangle;
|
||||
import org.locationtech.spatial4j.shape.Shape;
|
||||
import org.locationtech.spatial4j.shape.ShapeCollection;
|
||||
import org.locationtech.spatial4j.shape.jts.JtsGeometry;
|
||||
import org.locationtech.spatial4j.shape.jts.JtsPoint;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
@ -59,21 +60,25 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
private static final GeometryFactory GEOMETRY_FACTORY = SPATIAL_CONTEXT.getGeometryFactory();
|
||||
|
||||
public void testParseSimplePoint() throws IOException {
|
||||
String pointGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "Point")
|
||||
XContentBuilder pointGeoJson = XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("type", "Point")
|
||||
.startArray("coordinates").value(100.0).value(0.0).endArray()
|
||||
.endObject().string();
|
||||
.endObject();
|
||||
|
||||
Point expected = GEOMETRY_FACTORY.createPoint(new Coordinate(100.0, 0.0));
|
||||
assertGeometryEquals(new JtsPoint(expected, SPATIAL_CONTEXT), pointGeoJson);
|
||||
}
|
||||
|
||||
public void testParseLineString() throws IOException {
|
||||
String lineGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "LineString")
|
||||
XContentBuilder lineGeoJson = XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("type", "LineString")
|
||||
.startArray("coordinates")
|
||||
.startArray().value(100.0).value(0.0).endArray()
|
||||
.startArray().value(101.0).value(1.0).endArray()
|
||||
.endArray()
|
||||
.endObject().string();
|
||||
.endObject();
|
||||
|
||||
List<Coordinate> lineCoordinates = new ArrayList<>();
|
||||
lineCoordinates.add(new Coordinate(100, 0));
|
||||
|
@ -85,7 +90,9 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testParseMultiLineString() throws IOException {
|
||||
String multilinesGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "MultiLineString")
|
||||
XContentBuilder multilinesGeoJson = XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("type", "MultiLineString")
|
||||
.startArray("coordinates")
|
||||
.startArray()
|
||||
.startArray().value(100.0).value(0.0).endArray()
|
||||
|
@ -96,7 +103,7 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
.startArray().value(103.0).value(3.0).endArray()
|
||||
.endArray()
|
||||
.endArray()
|
||||
.endObject().string();
|
||||
.endObject();
|
||||
|
||||
MultiLineString expected = GEOMETRY_FACTORY.createMultiLineString(new LineString[]{
|
||||
GEOMETRY_FACTORY.createLineString(new Coordinate[]{
|
||||
|
@ -112,10 +119,12 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testParseCircle() throws IOException {
|
||||
String multilinesGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "circle")
|
||||
XContentBuilder multilinesGeoJson = XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("type", "circle")
|
||||
.startArray("coordinates").value(100.0).value(0.0).endArray()
|
||||
.field("radius", "100m")
|
||||
.endObject().string();
|
||||
.endObject();
|
||||
|
||||
Circle expected = SPATIAL_CONTEXT.makeCircle(100.0, 0.0, 360 * 100 / GeoUtils.EARTH_EQUATOR);
|
||||
assertGeometryEquals(expected, multilinesGeoJson);
|
||||
|
@ -123,20 +132,24 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
|
||||
public void testParseMultiDimensionShapes() throws IOException {
|
||||
// multi dimension point
|
||||
String pointGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "Point")
|
||||
XContentBuilder pointGeoJson = XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("type", "Point")
|
||||
.startArray("coordinates").value(100.0).value(0.0).value(15.0).value(18.0).endArray()
|
||||
.endObject().string();
|
||||
.endObject();
|
||||
|
||||
Point expectedPt = GEOMETRY_FACTORY.createPoint(new Coordinate(100.0, 0.0));
|
||||
assertGeometryEquals(new JtsPoint(expectedPt, SPATIAL_CONTEXT), pointGeoJson);
|
||||
|
||||
// multi dimension linestring
|
||||
String lineGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "LineString")
|
||||
XContentBuilder lineGeoJson = XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("type", "LineString")
|
||||
.startArray("coordinates")
|
||||
.startArray().value(100.0).value(0.0).value(15.0).endArray()
|
||||
.startArray().value(101.0).value(1.0).value(18.0).value(19.0).endArray()
|
||||
.endArray()
|
||||
.endObject().string();
|
||||
.endObject();
|
||||
|
||||
List<Coordinate> lineCoordinates = new ArrayList<>();
|
||||
lineCoordinates.add(new Coordinate(100, 0));
|
||||
|
@ -149,12 +162,12 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
|
||||
public void testParseEnvelope() throws IOException {
|
||||
// test #1: envelope with expected coordinate order (TopLeft, BottomRight)
|
||||
String multilinesGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "envelope")
|
||||
XContentBuilder multilinesGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "envelope")
|
||||
.startArray("coordinates")
|
||||
.startArray().value(-50).value(30).endArray()
|
||||
.startArray().value(50).value(-30).endArray()
|
||||
.endArray()
|
||||
.endObject().string();
|
||||
.endObject();
|
||||
|
||||
Rectangle expected = SPATIAL_CONTEXT.makeRectangle(-50, 50, -30, 30);
|
||||
assertGeometryEquals(expected, multilinesGeoJson);
|
||||
|
@ -165,7 +178,7 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
.startArray().value(50).value(30).endArray()
|
||||
.startArray().value(-50).value(-30).endArray()
|
||||
.endArray()
|
||||
.endObject().string();
|
||||
.endObject();
|
||||
|
||||
expected = SPATIAL_CONTEXT.makeRectangle(-50, 50, -30, 30);
|
||||
assertGeometryEquals(expected, multilinesGeoJson);
|
||||
|
@ -177,8 +190,8 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
.startArray().value(-50).value(-30).endArray()
|
||||
.startArray().value(50).value(-39).endArray()
|
||||
.endArray()
|
||||
.endObject().string();
|
||||
XContentParser parser = JsonXContent.jsonXContent.createParser(multilinesGeoJson);
|
||||
.endObject();
|
||||
XContentParser parser = createParser(multilinesGeoJson);
|
||||
parser.nextToken();
|
||||
ElasticsearchGeoAssertions.assertValidException(parser, ElasticsearchParseException.class);
|
||||
|
||||
|
@ -186,14 +199,16 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
multilinesGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "envelope")
|
||||
.startArray("coordinates")
|
||||
.endArray()
|
||||
.endObject().string();
|
||||
parser = JsonXContent.jsonXContent.createParser(multilinesGeoJson);
|
||||
.endObject();
|
||||
parser = createParser(multilinesGeoJson);
|
||||
parser.nextToken();
|
||||
ElasticsearchGeoAssertions.assertValidException(parser, ElasticsearchParseException.class);
|
||||
}
|
||||
|
||||
public void testParsePolygonNoHoles() throws IOException {
|
||||
String polygonGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "Polygon")
|
||||
XContentBuilder polygonGeoJson = XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("type", "Polygon")
|
||||
.startArray("coordinates")
|
||||
.startArray()
|
||||
.startArray().value(100.0).value(1.0).endArray()
|
||||
|
@ -203,7 +218,7 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
.startArray().value(100.0).value(1.0).endArray()
|
||||
.endArray()
|
||||
.endArray()
|
||||
.endObject().string();
|
||||
.endObject();
|
||||
|
||||
List<Coordinate> shellCoordinates = new ArrayList<>();
|
||||
shellCoordinates.add(new Coordinate(100, 0));
|
||||
|
@ -219,50 +234,60 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
|
||||
public void testParseInvalidPoint() throws IOException {
|
||||
// test case 1: create an invalid point object with multipoint data format
|
||||
String invalidPoint1 = XContentFactory.jsonBuilder().startObject().field("type", "point")
|
||||
XContentBuilder invalidPoint1 = XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("type", "point")
|
||||
.startArray("coordinates")
|
||||
.startArray().value(-74.011).value(40.753).endArray()
|
||||
.endArray()
|
||||
.endObject().string();
|
||||
XContentParser parser = JsonXContent.jsonXContent.createParser(invalidPoint1);
|
||||
.endObject();
|
||||
XContentParser parser = createParser(invalidPoint1);
|
||||
parser.nextToken();
|
||||
ElasticsearchGeoAssertions.assertValidException(parser, ElasticsearchParseException.class);
|
||||
|
||||
// test case 2: create an invalid point object with an empty number of coordinates
|
||||
String invalidPoint2 = XContentFactory.jsonBuilder().startObject().field("type", "point")
|
||||
XContentBuilder invalidPoint2 = XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("type", "point")
|
||||
.startArray("coordinates")
|
||||
.endArray()
|
||||
.endObject().string();
|
||||
parser = JsonXContent.jsonXContent.createParser(invalidPoint2);
|
||||
.endObject();
|
||||
parser = createParser(invalidPoint2);
|
||||
parser.nextToken();
|
||||
ElasticsearchGeoAssertions.assertValidException(parser, ElasticsearchParseException.class);
|
||||
}
|
||||
|
||||
public void testParseInvalidMultipoint() throws IOException {
|
||||
// test case 1: create an invalid multipoint object with single coordinate
|
||||
String invalidMultipoint1 = XContentFactory.jsonBuilder().startObject().field("type", "multipoint")
|
||||
XContentBuilder invalidMultipoint1 = XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("type", "multipoint")
|
||||
.startArray("coordinates").value(-74.011).value(40.753).endArray()
|
||||
.endObject().string();
|
||||
XContentParser parser = JsonXContent.jsonXContent.createParser(invalidMultipoint1);
|
||||
.endObject();
|
||||
XContentParser parser = createParser(invalidMultipoint1);
|
||||
parser.nextToken();
|
||||
ElasticsearchGeoAssertions.assertValidException(parser, ElasticsearchParseException.class);
|
||||
|
||||
// test case 2: create an invalid multipoint object with null coordinate
|
||||
String invalidMultipoint2 = XContentFactory.jsonBuilder().startObject().field("type", "multipoint")
|
||||
XContentBuilder invalidMultipoint2 = XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("type", "multipoint")
|
||||
.startArray("coordinates")
|
||||
.endArray()
|
||||
.endObject().string();
|
||||
parser = JsonXContent.jsonXContent.createParser(invalidMultipoint2);
|
||||
.endObject();
|
||||
parser = createParser(invalidMultipoint2);
|
||||
parser.nextToken();
|
||||
ElasticsearchGeoAssertions.assertValidException(parser, ElasticsearchParseException.class);
|
||||
|
||||
// test case 3: create a valid formatted multipoint object with invalid number (0) of coordinates
|
||||
String invalidMultipoint3 = XContentFactory.jsonBuilder().startObject().field("type", "multipoint")
|
||||
XContentBuilder invalidMultipoint3 = XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("type", "multipoint")
|
||||
.startArray("coordinates")
|
||||
.startArray().endArray()
|
||||
.endArray()
|
||||
.endObject().string();
|
||||
parser = JsonXContent.jsonXContent.createParser(invalidMultipoint3);
|
||||
.endObject();
|
||||
parser = createParser(invalidMultipoint3);
|
||||
parser.nextToken();
|
||||
ElasticsearchGeoAssertions.assertValidException(parser, ElasticsearchParseException.class);
|
||||
}
|
||||
|
@ -297,7 +322,7 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
.endArray()
|
||||
.endObject().string();
|
||||
|
||||
XContentParser parser = JsonXContent.jsonXContent.createParser(multiPolygonGeoJson);
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, multiPolygonGeoJson);
|
||||
parser.nextToken();
|
||||
ElasticsearchGeoAssertions.assertValidException(parser, InvalidShapeException.class);
|
||||
}
|
||||
|
@ -317,7 +342,7 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
.endArray()
|
||||
.endObject().string();
|
||||
|
||||
XContentParser parser = JsonXContent.jsonXContent.createParser(polygonGeoJson);
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, polygonGeoJson);
|
||||
parser.nextToken();
|
||||
Shape shape = ShapeBuilder.parse(parser).build();
|
||||
|
||||
|
@ -337,7 +362,7 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
.endArray()
|
||||
.endObject().string();
|
||||
|
||||
parser = JsonXContent.jsonXContent.createParser(polygonGeoJson);
|
||||
parser = createParser(JsonXContent.jsonXContent, polygonGeoJson);
|
||||
parser.nextToken();
|
||||
shape = ShapeBuilder.parse(parser).build();
|
||||
|
||||
|
@ -357,7 +382,7 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
.endArray()
|
||||
.endObject().string();
|
||||
|
||||
parser = JsonXContent.jsonXContent.createParser(polygonGeoJson);
|
||||
parser = createParser(JsonXContent.jsonXContent, polygonGeoJson);
|
||||
parser.nextToken();
|
||||
shape = ShapeBuilder.parse(parser).build();
|
||||
|
||||
|
@ -377,7 +402,7 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
.endArray()
|
||||
.endObject().string();
|
||||
|
||||
parser = JsonXContent.jsonXContent.createParser(polygonGeoJson);
|
||||
parser = createParser(JsonXContent.jsonXContent, polygonGeoJson);
|
||||
parser.nextToken();
|
||||
shape = ShapeBuilder.parse(parser).build();
|
||||
|
||||
|
@ -405,7 +430,7 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
.endArray()
|
||||
.endObject().string();
|
||||
|
||||
XContentParser parser = JsonXContent.jsonXContent.createParser(polygonGeoJson);
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, polygonGeoJson);
|
||||
parser.nextToken();
|
||||
Shape shape = ShapeBuilder.parse(parser).build();
|
||||
|
||||
|
@ -431,7 +456,7 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
.endArray()
|
||||
.endObject().string();
|
||||
|
||||
parser = JsonXContent.jsonXContent.createParser(polygonGeoJson);
|
||||
parser = createParser(JsonXContent.jsonXContent, polygonGeoJson);
|
||||
parser.nextToken();
|
||||
shape = ShapeBuilder.parse(parser).build();
|
||||
|
||||
|
@ -457,7 +482,7 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
.endArray()
|
||||
.endObject().string();
|
||||
|
||||
parser = JsonXContent.jsonXContent.createParser(polygonGeoJson);
|
||||
parser = createParser(JsonXContent.jsonXContent, polygonGeoJson);
|
||||
parser.nextToken();
|
||||
shape = ShapeBuilder.parse(parser).build();
|
||||
|
||||
|
@ -483,7 +508,7 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
.endArray()
|
||||
.endObject().string();
|
||||
|
||||
parser = JsonXContent.jsonXContent.createParser(polygonGeoJson);
|
||||
parser = createParser(JsonXContent.jsonXContent, polygonGeoJson);
|
||||
parser.nextToken();
|
||||
shape = ShapeBuilder.parse(parser).build();
|
||||
|
||||
|
@ -504,7 +529,7 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
.endArray()
|
||||
.endArray()
|
||||
.endObject().string();
|
||||
XContentParser parser = JsonXContent.jsonXContent.createParser(invalidPoly);
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, invalidPoly);
|
||||
parser.nextToken();
|
||||
ElasticsearchGeoAssertions.assertValidException(parser, ElasticsearchParseException.class);
|
||||
|
||||
|
@ -517,7 +542,7 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
.endArray()
|
||||
.endObject().string();
|
||||
|
||||
parser = JsonXContent.jsonXContent.createParser(invalidPoly);
|
||||
parser = createParser(JsonXContent.jsonXContent, invalidPoly);
|
||||
parser.nextToken();
|
||||
ElasticsearchGeoAssertions.assertValidException(parser, ElasticsearchParseException.class);
|
||||
|
||||
|
@ -530,7 +555,7 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
.endArray()
|
||||
.endObject().string();
|
||||
|
||||
parser = JsonXContent.jsonXContent.createParser(invalidPoly);
|
||||
parser = createParser(JsonXContent.jsonXContent, invalidPoly);
|
||||
parser.nextToken();
|
||||
ElasticsearchGeoAssertions.assertValidException(parser, ElasticsearchParseException.class);
|
||||
|
||||
|
@ -543,7 +568,7 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
.endArray()
|
||||
.endObject().string();
|
||||
|
||||
parser = JsonXContent.jsonXContent.createParser(invalidPoly);
|
||||
parser = createParser(JsonXContent.jsonXContent, invalidPoly);
|
||||
parser.nextToken();
|
||||
ElasticsearchGeoAssertions.assertValidException(parser, IllegalArgumentException.class);
|
||||
|
||||
|
@ -554,7 +579,7 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
.endArray()
|
||||
.endObject().string();
|
||||
|
||||
parser = JsonXContent.jsonXContent.createParser(invalidPoly);
|
||||
parser = createParser(JsonXContent.jsonXContent, invalidPoly);
|
||||
parser.nextToken();
|
||||
ElasticsearchGeoAssertions.assertValidException(parser, IllegalArgumentException.class);
|
||||
|
||||
|
@ -563,7 +588,7 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
.startArray("coordinates").endArray()
|
||||
.endObject().string();
|
||||
|
||||
parser = JsonXContent.jsonXContent.createParser(invalidPoly);
|
||||
parser = createParser(JsonXContent.jsonXContent, invalidPoly);
|
||||
parser.nextToken();
|
||||
ElasticsearchGeoAssertions.assertValidException(parser, ElasticsearchParseException.class);
|
||||
|
||||
|
@ -574,13 +599,15 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
.endArray()
|
||||
.endObject().string();
|
||||
|
||||
parser = JsonXContent.jsonXContent.createParser(invalidPoly);
|
||||
parser = createParser(JsonXContent.jsonXContent, invalidPoly);
|
||||
parser.nextToken();
|
||||
ElasticsearchGeoAssertions.assertValidException(parser, ElasticsearchParseException.class);
|
||||
}
|
||||
|
||||
public void testParsePolygonWithHole() throws IOException {
|
||||
String polygonGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "Polygon")
|
||||
XContentBuilder polygonGeoJson = XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("type", "Polygon")
|
||||
.startArray("coordinates")
|
||||
.startArray()
|
||||
.startArray().value(100.0).value(1.0).endArray()
|
||||
|
@ -597,7 +624,7 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
.startArray().value(100.2).value(0.8).endArray()
|
||||
.endArray()
|
||||
.endArray()
|
||||
.endObject().string();
|
||||
.endObject();
|
||||
|
||||
// add 3d point to test ISSUE #10501
|
||||
List<Coordinate> shellCoordinates = new ArrayList<>();
|
||||
|
@ -639,18 +666,20 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
.endArray()
|
||||
.endObject().string();
|
||||
|
||||
XContentParser parser = JsonXContent.jsonXContent.createParser(polygonGeoJson);
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, polygonGeoJson);
|
||||
parser.nextToken();
|
||||
ElasticsearchGeoAssertions.assertValidException(parser, InvalidShapeException.class);
|
||||
}
|
||||
|
||||
public void testParseMultiPoint() throws IOException {
|
||||
String multiPointGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "MultiPoint")
|
||||
XContentBuilder multiPointGeoJson = XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("type", "MultiPoint")
|
||||
.startArray("coordinates")
|
||||
.startArray().value(100.0).value(0.0).endArray()
|
||||
.startArray().value(101.0).value(1.0).endArray()
|
||||
.endArray()
|
||||
.endObject().string();
|
||||
.endObject();
|
||||
|
||||
ShapeCollection expected = shapeCollection(
|
||||
SPATIAL_CONTEXT.makePoint(100, 0),
|
||||
|
@ -660,7 +689,9 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
|
||||
public void testParseMultiPolygon() throws IOException {
|
||||
// test #1: two polygons; one without hole, one with hole
|
||||
String multiPolygonGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "MultiPolygon")
|
||||
XContentBuilder multiPolygonGeoJson = XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("type", "MultiPolygon")
|
||||
.startArray("coordinates")
|
||||
.startArray()//first poly (without holes)
|
||||
.startArray()
|
||||
|
@ -688,7 +719,7 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
.endArray()
|
||||
.endArray()
|
||||
.endArray()
|
||||
.endObject().string();
|
||||
.endObject();
|
||||
|
||||
List<Coordinate> shellCoordinates = new ArrayList<>();
|
||||
shellCoordinates.add(new Coordinate(100, 0));
|
||||
|
@ -727,7 +758,9 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
// test #2: multipolygon; one polygon with one hole
|
||||
// this test converting the multipolygon from a ShapeCollection type
|
||||
// to a simple polygon (jtsGeom)
|
||||
multiPolygonGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "MultiPolygon")
|
||||
multiPolygonGeoJson = XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("type", "MultiPolygon")
|
||||
.startArray("coordinates")
|
||||
.startArray()
|
||||
.startArray()
|
||||
|
@ -737,7 +770,7 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
.startArray().value(100.0).value(0.0).endArray()
|
||||
.startArray().value(100.0).value(1.0).endArray()
|
||||
.endArray()
|
||||
.startArray()// hole
|
||||
.startArray() // hole
|
||||
.startArray().value(100.2).value(0.8).endArray()
|
||||
.startArray().value(100.2).value(0.2).endArray()
|
||||
.startArray().value(100.8).value(0.2).endArray()
|
||||
|
@ -746,7 +779,7 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
.endArray()
|
||||
.endArray()
|
||||
.endArray()
|
||||
.endObject().string();
|
||||
.endObject();
|
||||
|
||||
shellCoordinates = new ArrayList<>();
|
||||
shellCoordinates.add(new Coordinate(100, 1));
|
||||
|
@ -771,7 +804,8 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testParseGeometryCollection() throws IOException {
|
||||
String geometryCollectionGeoJson = XContentFactory.jsonBuilder().startObject()
|
||||
XContentBuilder geometryCollectionGeoJson = XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("type", "GeometryCollection")
|
||||
.startArray("geometries")
|
||||
.startObject()
|
||||
|
@ -786,8 +820,7 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
.startArray("coordinates").value(102.0).value(2.0).endArray()
|
||||
.endObject()
|
||||
.endArray()
|
||||
.endObject()
|
||||
.string();
|
||||
.endObject();
|
||||
|
||||
Shape[] expected = new Shape[2];
|
||||
LineString expectedLineString = GEOMETRY_FACTORY.createLineString(new Coordinate[]{
|
||||
|
@ -803,7 +836,8 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testThatParserExtractsCorrectTypeAndCoordinatesFromArbitraryJson() throws IOException {
|
||||
String pointGeoJson = XContentFactory.jsonBuilder().startObject()
|
||||
XContentBuilder pointGeoJson = XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.startObject("crs")
|
||||
.field("type", "name")
|
||||
.startObject("properties")
|
||||
|
@ -816,7 +850,7 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
.startArray("coordinates").value(100.0).value(0.0).endArray()
|
||||
.startObject("nested").startArray("coordinates").value(200.0).value(0.0).endArray().endObject()
|
||||
.startObject("lala").field("type", "NotAPoint").endObject()
|
||||
.endObject().string();
|
||||
.endObject();
|
||||
|
||||
Point expected = GEOMETRY_FACTORY.createPoint(new Coordinate(100.0, 0.0));
|
||||
assertGeometryEquals(new JtsPoint(expected, SPATIAL_CONTEXT), pointGeoJson);
|
||||
|
@ -824,7 +858,9 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
|
||||
public void testParseOrientationOption() throws IOException {
|
||||
// test 1: valid ccw (right handed system) poly not crossing dateline (with 'right' field)
|
||||
String polygonGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "Polygon")
|
||||
XContentBuilder polygonGeoJson = XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("type", "Polygon")
|
||||
.field("orientation", "right")
|
||||
.startArray("coordinates")
|
||||
.startArray()
|
||||
|
@ -842,16 +878,18 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
.startArray().value(-172.0).value(8.0).endArray()
|
||||
.endArray()
|
||||
.endArray()
|
||||
.endObject().string();
|
||||
.endObject();
|
||||
|
||||
XContentParser parser = JsonXContent.jsonXContent.createParser(polygonGeoJson);
|
||||
XContentParser parser = createParser(polygonGeoJson);
|
||||
parser.nextToken();
|
||||
Shape shape = ShapeBuilder.parse(parser).build();
|
||||
|
||||
ElasticsearchGeoAssertions.assertPolygon(shape);
|
||||
|
||||
// test 2: valid ccw (right handed system) poly not crossing dateline (with 'ccw' field)
|
||||
polygonGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "Polygon")
|
||||
polygonGeoJson = XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("type", "Polygon")
|
||||
.field("orientation", "ccw")
|
||||
.startArray("coordinates")
|
||||
.startArray()
|
||||
|
@ -869,16 +907,18 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
.startArray().value(-172.0).value(8.0).endArray()
|
||||
.endArray()
|
||||
.endArray()
|
||||
.endObject().string();
|
||||
.endObject();
|
||||
|
||||
parser = JsonXContent.jsonXContent.createParser(polygonGeoJson);
|
||||
parser = createParser(polygonGeoJson);
|
||||
parser.nextToken();
|
||||
shape = ShapeBuilder.parse(parser).build();
|
||||
|
||||
ElasticsearchGeoAssertions.assertPolygon(shape);
|
||||
|
||||
// test 3: valid ccw (right handed system) poly not crossing dateline (with 'counterclockwise' field)
|
||||
polygonGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "Polygon")
|
||||
polygonGeoJson = XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("type", "Polygon")
|
||||
.field("orientation", "counterclockwise")
|
||||
.startArray("coordinates")
|
||||
.startArray()
|
||||
|
@ -896,16 +936,18 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
.startArray().value(-172.0).value(8.0).endArray()
|
||||
.endArray()
|
||||
.endArray()
|
||||
.endObject().string();
|
||||
.endObject();
|
||||
|
||||
parser = JsonXContent.jsonXContent.createParser(polygonGeoJson);
|
||||
parser = createParser(polygonGeoJson);
|
||||
parser.nextToken();
|
||||
shape = ShapeBuilder.parse(parser).build();
|
||||
|
||||
ElasticsearchGeoAssertions.assertPolygon(shape);
|
||||
|
||||
// test 4: valid cw (left handed system) poly crossing dateline (with 'left' field)
|
||||
polygonGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "Polygon")
|
||||
polygonGeoJson = XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("type", "Polygon")
|
||||
.field("orientation", "left")
|
||||
.startArray("coordinates")
|
||||
.startArray()
|
||||
|
@ -923,16 +965,18 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
.startArray().value(-178.0).value(8.0).endArray()
|
||||
.endArray()
|
||||
.endArray()
|
||||
.endObject().string();
|
||||
.endObject();
|
||||
|
||||
parser = JsonXContent.jsonXContent.createParser(polygonGeoJson);
|
||||
parser = createParser(polygonGeoJson);
|
||||
parser.nextToken();
|
||||
shape = ShapeBuilder.parse(parser).build();
|
||||
|
||||
ElasticsearchGeoAssertions.assertMultiPolygon(shape);
|
||||
|
||||
// test 5: valid cw multipoly (left handed system) poly crossing dateline (with 'cw' field)
|
||||
polygonGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "Polygon")
|
||||
polygonGeoJson = XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("type", "Polygon")
|
||||
.field("orientation", "cw")
|
||||
.startArray("coordinates")
|
||||
.startArray()
|
||||
|
@ -950,16 +994,18 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
.startArray().value(-178.0).value(8.0).endArray()
|
||||
.endArray()
|
||||
.endArray()
|
||||
.endObject().string();
|
||||
.endObject();
|
||||
|
||||
parser = JsonXContent.jsonXContent.createParser(polygonGeoJson);
|
||||
parser = createParser(polygonGeoJson);
|
||||
parser.nextToken();
|
||||
shape = ShapeBuilder.parse(parser).build();
|
||||
|
||||
ElasticsearchGeoAssertions.assertMultiPolygon(shape);
|
||||
|
||||
// test 6: valid cw multipoly (left handed system) poly crossing dateline (with 'clockwise' field)
|
||||
polygonGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "Polygon")
|
||||
polygonGeoJson = XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
.field("type", "Polygon")
|
||||
.field("orientation", "clockwise")
|
||||
.startArray("coordinates")
|
||||
.startArray()
|
||||
|
@ -977,17 +1023,17 @@ public class GeoJSONShapeParserTests extends ESTestCase {
|
|||
.startArray().value(-178.0).value(8.0).endArray()
|
||||
.endArray()
|
||||
.endArray()
|
||||
.endObject().string();
|
||||
.endObject();
|
||||
|
||||
parser = JsonXContent.jsonXContent.createParser(polygonGeoJson);
|
||||
parser = createParser(polygonGeoJson);
|
||||
parser.nextToken();
|
||||
shape = ShapeBuilder.parse(parser).build();
|
||||
|
||||
ElasticsearchGeoAssertions.assertMultiPolygon(shape);
|
||||
}
|
||||
|
||||
private void assertGeometryEquals(Shape expected, String geoJson) throws IOException {
|
||||
XContentParser parser = JsonXContent.jsonXContent.createParser(geoJson);
|
||||
private void assertGeometryEquals(Shape expected, XContentBuilder geoJson) throws IOException {
|
||||
XContentParser parser = createParser(geoJson);
|
||||
parser.nextToken();
|
||||
ElasticsearchGeoAssertions.assertEquals(expected, ShapeBuilder.parse(parser).build());
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.elasticsearch.common.ParseFieldMatcherSupplier;
|
|||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.xcontent.AbstractObjectParser.NoContextParser;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.hamcrest.Matcher;
|
||||
|
||||
|
@ -80,7 +81,7 @@ public class ConstructingObjectParserTests extends ESTestCase {
|
|||
expected.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
builder = shuffleXContent(builder);
|
||||
BytesReference bytes = builder.bytes();
|
||||
try (XContentParser parser = XContentFactory.xContent(bytes).createParser(bytes)) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, bytes)) {
|
||||
HasCtorArguments parsed = randomFrom(HasCtorArguments.ALL_PARSERS).apply(parser, MATCHER);
|
||||
assertEquals(expected.animal, parsed.animal);
|
||||
assertEquals(expected.vegetable, parsed.vegetable);
|
||||
|
@ -97,7 +98,7 @@ public class ConstructingObjectParserTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testMissingAllConstructorArgs() throws IOException {
|
||||
XContentParser parser = XContentType.JSON.xContent().createParser(
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent,
|
||||
"{\n"
|
||||
+ " \"mineral\": 1\n"
|
||||
+ "}");
|
||||
|
@ -112,7 +113,7 @@ public class ConstructingObjectParserTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testMissingAllConstructorArgsButNotRequired() throws IOException {
|
||||
XContentParser parser = XContentType.JSON.xContent().createParser(
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent,
|
||||
"{\n"
|
||||
+ " \"mineral\": 1\n"
|
||||
+ "}");
|
||||
|
@ -121,7 +122,7 @@ public class ConstructingObjectParserTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testMissingSecondConstructorArg() throws IOException {
|
||||
XContentParser parser = XContentType.JSON.xContent().createParser(
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent,
|
||||
"{\n"
|
||||
+ " \"mineral\": 1,\n"
|
||||
+ " \"animal\": \"cat\"\n"
|
||||
|
@ -132,7 +133,7 @@ public class ConstructingObjectParserTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testMissingSecondConstructorArgButNotRequired() throws IOException {
|
||||
XContentParser parser = XContentType.JSON.xContent().createParser(
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent,
|
||||
"{\n"
|
||||
+ " \"mineral\": 1,\n"
|
||||
+ " \"animal\": \"cat\"\n"
|
||||
|
@ -145,7 +146,7 @@ public class ConstructingObjectParserTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testMissingFirstConstructorArg() throws IOException {
|
||||
XContentParser parser = XContentType.JSON.xContent().createParser(
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent,
|
||||
"{\n"
|
||||
+ " \"mineral\": 1,\n"
|
||||
+ " \"vegetable\": 2\n"
|
||||
|
@ -157,7 +158,7 @@ public class ConstructingObjectParserTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testMissingFirstConstructorArgButNotRequired() throws IOException {
|
||||
XContentParser parser = XContentType.JSON.xContent().createParser(
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent,
|
||||
"{\n"
|
||||
+ " \"mineral\": 1,\n"
|
||||
+ " \"vegetable\": 2\n"
|
||||
|
@ -168,7 +169,7 @@ public class ConstructingObjectParserTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testRepeatedConstructorParam() throws IOException {
|
||||
XContentParser parser = XContentType.JSON.xContent().createParser(
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent,
|
||||
"{\n"
|
||||
+ " \"vegetable\": 1,\n"
|
||||
+ " \"vegetable\": 2\n"
|
||||
|
@ -181,7 +182,7 @@ public class ConstructingObjectParserTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testBadParam() throws IOException {
|
||||
XContentParser parser = XContentType.JSON.xContent().createParser(
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent,
|
||||
"{\n"
|
||||
+ " \"animal\": \"cat\",\n"
|
||||
+ " \"vegetable\": 2,\n"
|
||||
|
@ -195,7 +196,7 @@ public class ConstructingObjectParserTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testBadParamBeforeObjectBuilt() throws IOException {
|
||||
XContentParser parser = XContentType.JSON.xContent().createParser(
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent,
|
||||
"{\n"
|
||||
+ " \"a\": \"supercalifragilisticexpialidocious\",\n"
|
||||
+ " \"animal\": \"cat\"\n,"
|
||||
|
@ -220,7 +221,7 @@ public class ConstructingObjectParserTests extends ESTestCase {
|
|||
ConstructingObjectParser<NoConstructorArgs, ParseFieldMatcherSupplier> parser = new ConstructingObjectParser<>(
|
||||
"constructor_args_required", (a) -> new NoConstructorArgs());
|
||||
try {
|
||||
parser.apply(XContentType.JSON.xContent().createParser("{}"), null);
|
||||
parser.apply(createParser(JsonXContent.jsonXContent, "{}"), null);
|
||||
fail("Expected AssertionError");
|
||||
} catch (AssertionError e) {
|
||||
assertEquals("[constructor_args_required] must configure at least on constructor argument. If it doesn't have any it should "
|
||||
|
@ -255,7 +256,7 @@ public class ConstructingObjectParserTests extends ESTestCase {
|
|||
parser.declareString(ctorArgOptional ? optionalConstructorArg() : constructorArg(), new ParseField("yeah"));
|
||||
|
||||
// ctor arg first so we can test for the bug we found one time
|
||||
XContentParser xcontent = XContentType.JSON.xContent().createParser(
|
||||
XContentParser xcontent = createParser(JsonXContent.jsonXContent,
|
||||
"{\n"
|
||||
+ " \"yeah\": \"!\",\n"
|
||||
+ " \"foo\": \"foo\"\n"
|
||||
|
@ -264,7 +265,7 @@ public class ConstructingObjectParserTests extends ESTestCase {
|
|||
assertTrue(result.fooSet);
|
||||
|
||||
// and ctor arg second just in case
|
||||
xcontent = XContentType.JSON.xContent().createParser(
|
||||
xcontent = createParser(JsonXContent.jsonXContent,
|
||||
"{\n"
|
||||
+ " \"foo\": \"foo\",\n"
|
||||
+ " \"yeah\": \"!\"\n"
|
||||
|
@ -274,7 +275,7 @@ public class ConstructingObjectParserTests extends ESTestCase {
|
|||
|
||||
if (ctorArgOptional) {
|
||||
// and without the constructor arg if we've made it optional
|
||||
xcontent = XContentType.JSON.xContent().createParser(
|
||||
xcontent = createParser(JsonXContent.jsonXContent,
|
||||
"{\n"
|
||||
+ " \"foo\": \"foo\"\n"
|
||||
+ "}");
|
||||
|
@ -284,7 +285,7 @@ public class ConstructingObjectParserTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testIgnoreUnknownFields() throws IOException {
|
||||
XContentParser parser = XContentType.JSON.xContent().createParser(
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent,
|
||||
"{\n"
|
||||
+ " \"test\" : \"foo\",\n"
|
||||
+ " \"junk\" : 2\n"
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.elasticsearch.common.ParsingException;
|
|||
import org.elasticsearch.common.xcontent.AbstractObjectParser.NoContextParser;
|
||||
import org.elasticsearch.common.xcontent.ObjectParser.NamedObjectParser;
|
||||
import org.elasticsearch.common.xcontent.ObjectParser.ValueType;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -41,7 +42,7 @@ public class ObjectParserTests extends ESTestCase {
|
|||
private static final ParseFieldMatcherSupplier STRICT_PARSING = () -> ParseFieldMatcher.STRICT;
|
||||
|
||||
public void testBasics() throws IOException {
|
||||
XContentParser parser = XContentType.JSON.xContent().createParser(
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent,
|
||||
"{\n"
|
||||
+ " \"test\" : \"foo\",\n"
|
||||
+ " \"test_number\" : 2,\n"
|
||||
|
@ -97,17 +98,17 @@ public class ObjectParserTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testObjectOrDefault() throws IOException {
|
||||
XContentParser parser = XContentType.JSON.xContent().createParser("{\"object\" : { \"test\": 2}}");
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, "{\"object\" : { \"test\": 2}}");
|
||||
ObjectParser<StaticTestStruct, ParseFieldMatcherSupplier> objectParser = new ObjectParser<>("foo", StaticTestStruct::new);
|
||||
objectParser.declareInt(StaticTestStruct::setTest, new ParseField("test"));
|
||||
objectParser.declareObjectOrDefault(StaticTestStruct::setObject, objectParser, StaticTestStruct::new, new ParseField("object"));
|
||||
StaticTestStruct s = objectParser.parse(parser, STRICT_PARSING);
|
||||
assertEquals(s.object.test, 2);
|
||||
parser = XContentType.JSON.xContent().createParser("{\"object\" : false }");
|
||||
parser = createParser(JsonXContent.jsonXContent, "{\"object\" : false }");
|
||||
s = objectParser.parse(parser, STRICT_PARSING);
|
||||
assertNull(s.object);
|
||||
|
||||
parser = XContentType.JSON.xContent().createParser("{\"object\" : true }");
|
||||
parser = createParser(JsonXContent.jsonXContent, "{\"object\" : true }");
|
||||
s = objectParser.parse(parser, STRICT_PARSING);
|
||||
assertNotNull(s.object);
|
||||
assertEquals(s.object.test, 0);
|
||||
|
@ -191,7 +192,7 @@ public class ObjectParserTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testExceptions() throws IOException {
|
||||
XContentParser parser = XContentType.JSON.xContent().createParser("{\"test\" : \"foo\"}");
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, "{\"test\" : \"foo\"}");
|
||||
class TestStruct {
|
||||
public void setTest(int test) {
|
||||
}
|
||||
|
@ -208,7 +209,7 @@ public class ObjectParserTests extends ESTestCase {
|
|||
assertTrue(ex.getCause() instanceof NumberFormatException);
|
||||
}
|
||||
|
||||
parser = XContentType.JSON.xContent().createParser("{\"not_supported_field\" : \"foo\"}");
|
||||
parser = createParser(JsonXContent.jsonXContent, "{\"not_supported_field\" : \"foo\"}");
|
||||
try {
|
||||
objectParser.parse(parser, s, STRICT_PARSING);
|
||||
fail("field not supported");
|
||||
|
@ -218,7 +219,7 @@ public class ObjectParserTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testDeprecationFail() throws IOException {
|
||||
XContentParser parser = XContentType.JSON.xContent().createParser("{\"old_test\" : \"foo\"}");
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, "{\"old_test\" : \"foo\"}");
|
||||
class TestStruct {
|
||||
public String test;
|
||||
}
|
||||
|
@ -235,13 +236,13 @@ public class ObjectParserTests extends ESTestCase {
|
|||
|
||||
}
|
||||
assertNull(s.test);
|
||||
parser = XContentType.JSON.xContent().createParser("{\"old_test\" : \"foo\"}");
|
||||
parser = createParser(JsonXContent.jsonXContent, "{\"old_test\" : \"foo\"}");
|
||||
objectParser.parse(parser, s, () -> ParseFieldMatcher.EMPTY);
|
||||
assertEquals("foo", s.test);
|
||||
}
|
||||
|
||||
public void testFailOnValueType() throws IOException {
|
||||
XContentParser parser = XContentType.JSON.xContent().createParser("{\"numeric_value\" : false}");
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, "{\"numeric_value\" : false}");
|
||||
class TestStruct {
|
||||
public String test;
|
||||
}
|
||||
|
@ -258,7 +259,7 @@ public class ObjectParserTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testParseNested() throws IOException {
|
||||
XContentParser parser = XContentType.JSON.xContent().createParser("{ \"test\" : 1, \"object\" : { \"test\": 2}}");
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, "{ \"test\" : 1, \"object\" : { \"test\": 2}}");
|
||||
class TestStruct {
|
||||
public int test;
|
||||
TestStruct object;
|
||||
|
@ -275,7 +276,7 @@ public class ObjectParserTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testParseNestedShortcut() throws IOException {
|
||||
XContentParser parser = XContentType.JSON.xContent().createParser("{ \"test\" : 1, \"object\" : { \"test\": 2}}");
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, "{ \"test\" : 1, \"object\" : { \"test\": 2}}");
|
||||
ObjectParser<StaticTestStruct, ParseFieldMatcherSupplier> objectParser = new ObjectParser<>("foo", StaticTestStruct::new);
|
||||
objectParser.declareInt(StaticTestStruct::setTest, new ParseField("test"));
|
||||
objectParser.declareObject(StaticTestStruct::setObject, objectParser, new ParseField("object"));
|
||||
|
@ -285,7 +286,7 @@ public class ObjectParserTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testEmptyObject() throws IOException {
|
||||
XContentParser parser = XContentType.JSON.xContent().createParser("{\"object\" : {}}");
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, "{\"object\" : {}}");
|
||||
ObjectParser<StaticTestStruct, ParseFieldMatcherSupplier> objectParser = new ObjectParser<>("foo", StaticTestStruct::new);
|
||||
objectParser.declareObject(StaticTestStruct::setObject, objectParser, new ParseField("object"));
|
||||
StaticTestStruct s = objectParser.parse(parser, STRICT_PARSING);
|
||||
|
@ -293,7 +294,7 @@ public class ObjectParserTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testEmptyObjectInArray() throws IOException {
|
||||
XContentParser parser = XContentType.JSON.xContent().createParser("{\"object_array\" : [{}]}");
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, "{\"object_array\" : [{}]}");
|
||||
ObjectParser<StaticTestStruct, ParseFieldMatcherSupplier> objectParser = new ObjectParser<>("foo", StaticTestStruct::new);
|
||||
objectParser.declareObjectArray(StaticTestStruct::setObjectArray, objectParser, new ParseField("object_array"));
|
||||
StaticTestStruct s = objectParser.parse(parser, STRICT_PARSING);
|
||||
|
@ -330,7 +331,7 @@ public class ObjectParserTests extends ESTestCase {
|
|||
test = value;
|
||||
}
|
||||
}
|
||||
XContentParser parser = XContentType.JSON.xContent().createParser("{ \"test\" : \"FOO\" }");
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, "{ \"test\" : \"FOO\" }");
|
||||
ObjectParser<TestStruct, ParseFieldMatcherSupplier> objectParser = new ObjectParser<>("foo");
|
||||
objectParser.declareString((struct, value) -> struct.set(TestEnum.valueOf(value)), new ParseField("test"));
|
||||
TestStruct s = objectParser.parse(parser, new TestStruct(), STRICT_PARSING);
|
||||
|
@ -374,7 +375,7 @@ public class ObjectParserTests extends ESTestCase {
|
|||
builder.field("boolean_field", nullValue);
|
||||
builder.field("string_or_null", nullValue ? null : "5");
|
||||
builder.endObject();
|
||||
XContentParser parser = XContentType.JSON.xContent().createParser(builder.string());
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, builder.string());
|
||||
class TestStruct {
|
||||
int int_field;
|
||||
long long_field;
|
||||
|
@ -466,7 +467,7 @@ public class ObjectParserTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testParseNamedObject() throws IOException {
|
||||
XContentParser parser = XContentType.JSON.xContent().createParser(
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent,
|
||||
"{\"named\": {\n"
|
||||
+ " \"a\": {}"
|
||||
+ "}}");
|
||||
|
@ -477,7 +478,7 @@ public class ObjectParserTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testParseNamedObjectInOrder() throws IOException {
|
||||
XContentParser parser = XContentType.JSON.xContent().createParser(
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent,
|
||||
"{\"named\": [\n"
|
||||
+ " {\"a\": {}}"
|
||||
+ "]}");
|
||||
|
@ -488,7 +489,7 @@ public class ObjectParserTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testParseNamedObjectTwoFieldsInArray() throws IOException {
|
||||
XContentParser parser = XContentType.JSON.xContent().createParser(
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent,
|
||||
"{\"named\": [\n"
|
||||
+ " {\"a\": {}, \"b\": {}}"
|
||||
+ "]}");
|
||||
|
@ -500,7 +501,7 @@ public class ObjectParserTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testParseNamedObjectNoFieldsInArray() throws IOException {
|
||||
XContentParser parser = XContentType.JSON.xContent().createParser(
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent,
|
||||
"{\"named\": [\n"
|
||||
+ " {}"
|
||||
+ "]}");
|
||||
|
@ -512,7 +513,7 @@ public class ObjectParserTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testParseNamedObjectJunkInArray() throws IOException {
|
||||
XContentParser parser = XContentType.JSON.xContent().createParser(
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent,
|
||||
"{\"named\": [\n"
|
||||
+ " \"junk\""
|
||||
+ "]}");
|
||||
|
@ -524,7 +525,7 @@ public class ObjectParserTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testParseNamedObjectInOrderNotSupported() throws IOException {
|
||||
XContentParser parser = XContentType.JSON.xContent().createParser(
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent,
|
||||
"{\"named\": [\n"
|
||||
+ " {\"a\": {}}"
|
||||
+ "]}");
|
||||
|
@ -549,7 +550,7 @@ public class ObjectParserTests extends ESTestCase {
|
|||
}
|
||||
b.endObject();
|
||||
b = shuffleXContent(b);
|
||||
XContentParser parser = XContentType.JSON.xContent().createParser(b.bytes());
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, b.bytes());
|
||||
|
||||
class TestStruct {
|
||||
public String test;
|
||||
|
@ -573,7 +574,7 @@ public class ObjectParserTests extends ESTestCase {
|
|||
}
|
||||
b.endObject();
|
||||
b = shuffleXContent(b);
|
||||
XContentParser parser = XContentType.JSON.xContent().createParser(b.bytes());
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, b.bytes());
|
||||
|
||||
class TestStruct {
|
||||
public String test;
|
||||
|
@ -601,7 +602,7 @@ public class ObjectParserTests extends ESTestCase {
|
|||
}
|
||||
b.endObject();
|
||||
b = shuffleXContent(b);
|
||||
XContentParser parser = XContentType.JSON.xContent().createParser(b.bytes());
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, b.bytes());
|
||||
class TestStruct {
|
||||
public String test;
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
package org.elasticsearch.common.xcontent;
|
||||
|
||||
import org.elasticsearch.ElasticsearchParseException;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -56,8 +57,8 @@ public class XContentParserTests extends ESTestCase {
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <T> List<T> readList(String source) throws IOException {
|
||||
try (XContentParser parser = XContentType.JSON.xContent().createParser(source)) {
|
||||
private <T> List<T> readList(String source) throws IOException {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, source)) {
|
||||
XContentParser.Token token = parser.nextToken();
|
||||
assertThat(token, equalTo(XContentParser.Token.START_OBJECT));
|
||||
token = parser.nextToken();
|
||||
|
@ -89,9 +90,8 @@ public class XContentParserTests extends ESTestCase {
|
|||
assertThat(map.size(), equalTo(0));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static Map<String, String> readMapStrings(String source) throws IOException {
|
||||
try (XContentParser parser = XContentType.JSON.xContent().createParser(source)) {
|
||||
private Map<String, String> readMapStrings(String source) throws IOException {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, source)) {
|
||||
XContentParser.Token token = parser.nextToken();
|
||||
assertThat(token, equalTo(XContentParser.Token.START_OBJECT));
|
||||
token = parser.nextToken();
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.elasticsearch.common.xcontent.XContentFactory;
|
|||
import org.elasticsearch.common.xcontent.XContentGenerator;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
@ -213,7 +214,7 @@ public class XContentBuilderTests extends ESTestCase {
|
|||
|
||||
builder.field("fakefield", terms).endObject().endObject().endObject();
|
||||
|
||||
XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(builder.bytes());
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, builder.bytes());
|
||||
|
||||
XContentBuilder filterBuilder = null;
|
||||
XContentParser.Token token;
|
||||
|
@ -235,7 +236,7 @@ public class XContentBuilderTests extends ESTestCase {
|
|||
}
|
||||
|
||||
assertNotNull(filterBuilder);
|
||||
parser = XContentFactory.xContent(XContentType.JSON).createParser(filterBuilder.bytes());
|
||||
parser = createParser(JsonXContent.jsonXContent, filterBuilder.bytes());
|
||||
assertThat(parser.nextToken(), equalTo(XContentParser.Token.START_OBJECT));
|
||||
assertThat(parser.nextToken(), equalTo(XContentParser.Token.FIELD_NAME));
|
||||
assertThat(parser.currentName(), equalTo("terms"));
|
||||
|
|
|
@ -24,6 +24,7 @@ import org.elasticsearch.common.xcontent.XContentFactory;
|
|||
import org.elasticsearch.common.xcontent.XContentGenerator;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -62,7 +63,7 @@ public class JsonVsCborTests extends ESTestCase {
|
|||
xsonGen.close();
|
||||
jsonGen.close();
|
||||
|
||||
verifySameTokens(createParser(jsonOs.bytes()), createParser(xsonOs.bytes()));
|
||||
verifySameTokens(createParser(JsonXContent.jsonXContent, jsonOs.bytes()), createParser(CborXContent.cborXContent, xsonOs.bytes()));
|
||||
}
|
||||
|
||||
private void verifySameTokens(XContentParser parser1, XContentParser parser2) throws IOException {
|
||||
|
|
|
@ -24,6 +24,7 @@ import org.elasticsearch.common.xcontent.XContentFactory;
|
|||
import org.elasticsearch.common.xcontent.XContentGenerator;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -62,7 +63,8 @@ public class JsonVsSmileTests extends ESTestCase {
|
|||
xsonGen.close();
|
||||
jsonGen.close();
|
||||
|
||||
verifySameTokens(createParser(jsonOs.bytes()), createParser(xsonOs.bytes()));
|
||||
verifySameTokens(createParser(JsonXContent.jsonXContent, jsonOs.bytes()),
|
||||
createParser(SmileXContent.smileXContent, xsonOs.bytes()));
|
||||
}
|
||||
|
||||
private void verifySameTokens(XContentParser parser1, XContentParser parser2) throws IOException {
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.elasticsearch.common.xcontent.XContentFactory;
|
|||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.hamcrest.Matchers;
|
||||
|
||||
|
@ -53,7 +54,7 @@ public class XContentMapValuesTests extends ESTestCase {
|
|||
.endObject();
|
||||
|
||||
Map<String, Object> source;
|
||||
try (XContentParser parser = createParser(builder.string())) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, builder.string())) {
|
||||
source = parser.map();
|
||||
}
|
||||
Map<String, Object> filter = XContentMapValues.filter(source, new String[]{"test1"}, Strings.EMPTY_ARRAY);
|
||||
|
@ -81,7 +82,7 @@ public class XContentMapValuesTests extends ESTestCase {
|
|||
.field("test1", "value1")
|
||||
.endObject();
|
||||
|
||||
try (XContentParser parser = createParser(builder.string())) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, builder.string())) {
|
||||
source = parser.map();
|
||||
}
|
||||
filter = XContentMapValues.filter(source, new String[]{"path1"}, Strings.EMPTY_ARRAY);
|
||||
|
@ -107,7 +108,7 @@ public class XContentMapValuesTests extends ESTestCase {
|
|||
.endObject();
|
||||
|
||||
Map<String, Object> map;
|
||||
try (XContentParser parser = createParser(builder.string())) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, builder.string())) {
|
||||
map = parser.map();
|
||||
}
|
||||
assertThat(XContentMapValues.extractValue("test", map).toString(), equalTo("value"));
|
||||
|
@ -118,7 +119,7 @@ public class XContentMapValuesTests extends ESTestCase {
|
|||
.startObject("path1").startObject("path2").field("test", "value").endObject().endObject()
|
||||
.endObject();
|
||||
|
||||
try (XContentParser parser = createParser(builder.string())) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, builder.string())) {
|
||||
map = parser.map();
|
||||
}
|
||||
assertThat(XContentMapValues.extractValue("path1.path2.test", map).toString(), equalTo("value"));
|
||||
|
@ -140,7 +141,7 @@ public class XContentMapValuesTests extends ESTestCase {
|
|||
.startObject("path1").array("test", "value1", "value2").endObject()
|
||||
.endObject();
|
||||
|
||||
try (XContentParser parser = createParser(builder.string())) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, builder.string())) {
|
||||
map = parser.map();
|
||||
}
|
||||
|
||||
|
@ -159,7 +160,7 @@ public class XContentMapValuesTests extends ESTestCase {
|
|||
.endObject()
|
||||
.endObject();
|
||||
|
||||
try (XContentParser parser = createParser(builder.string())) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, builder.string())) {
|
||||
map = parser.map();
|
||||
}
|
||||
|
||||
|
@ -175,7 +176,7 @@ public class XContentMapValuesTests extends ESTestCase {
|
|||
builder = XContentFactory.jsonBuilder().startObject()
|
||||
.field("xxx.yyy", "value")
|
||||
.endObject();
|
||||
try (XContentParser parser = createParser(builder.string())) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, builder.string())) {
|
||||
map = parser.map();
|
||||
}
|
||||
assertThat(XContentMapValues.extractValue("xxx.yyy", map).toString(), equalTo("value"));
|
||||
|
@ -184,7 +185,7 @@ public class XContentMapValuesTests extends ESTestCase {
|
|||
.startObject("path1.xxx").startObject("path2.yyy").field("test", "value").endObject().endObject()
|
||||
.endObject();
|
||||
|
||||
try (XContentParser parser = createParser(builder.string())) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, builder.string())) {
|
||||
map = parser.map();
|
||||
}
|
||||
assertThat(XContentMapValues.extractValue("path1.xxx.path2.yyy.test", map).toString(), equalTo("value"));
|
||||
|
@ -196,7 +197,7 @@ public class XContentMapValuesTests extends ESTestCase {
|
|||
.endObject();
|
||||
|
||||
Map<String, Object> map;
|
||||
try (XContentParser parser = createParser(builder.string())) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, builder.string())) {
|
||||
map = parser.map();
|
||||
}
|
||||
assertThat(XContentMapValues.extractRawValues("test", map).get(0).toString(), equalTo("value"));
|
||||
|
@ -205,7 +206,7 @@ public class XContentMapValuesTests extends ESTestCase {
|
|||
.field("test.me", "value")
|
||||
.endObject();
|
||||
|
||||
try (XContentParser parser = createParser(builder.string())) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, builder.string())) {
|
||||
map = parser.map();
|
||||
}
|
||||
assertThat(XContentMapValues.extractRawValues("test.me", map).get(0).toString(), equalTo("value"));
|
||||
|
@ -214,7 +215,7 @@ public class XContentMapValuesTests extends ESTestCase {
|
|||
.startObject("path1").startObject("path2").field("test", "value").endObject().endObject()
|
||||
.endObject();
|
||||
|
||||
try (XContentParser parser = createParser(builder.string())) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, builder.string())) {
|
||||
map = parser.map();
|
||||
}
|
||||
assertThat(XContentMapValues.extractRawValues("path1.path2.test", map).get(0).toString(), equalTo("value"));
|
||||
|
@ -223,7 +224,7 @@ public class XContentMapValuesTests extends ESTestCase {
|
|||
.startObject("path1.xxx").startObject("path2.yyy").field("test", "value").endObject().endObject()
|
||||
.endObject();
|
||||
|
||||
try (XContentParser parser = createParser(builder.string())) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, builder.string())) {
|
||||
map = parser.map();
|
||||
}
|
||||
assertThat(XContentMapValues.extractRawValues("path1.xxx.path2.yyy.test", map).get(0).toString(), equalTo("value"));
|
||||
|
@ -475,7 +476,7 @@ public class XContentMapValuesTests extends ESTestCase {
|
|||
.startArray("some_array")
|
||||
.endArray().endObject();
|
||||
|
||||
try (XContentParser parser = createParser(builder.string())) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, builder.string())) {
|
||||
assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken());
|
||||
assertEquals(XContentParser.Token.FIELD_NAME, parser.nextToken());
|
||||
assertEquals("some_array", parser.currentName());
|
||||
|
@ -495,7 +496,7 @@ public class XContentMapValuesTests extends ESTestCase {
|
|||
.value(0)
|
||||
.endArray().endObject();
|
||||
|
||||
try (XContentParser parser = createParser(builder.string())) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, builder.string())) {
|
||||
assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken());
|
||||
assertEquals(XContentParser.Token.FIELD_NAME, parser.nextToken());
|
||||
assertEquals("some_array", parser.currentName());
|
||||
|
@ -515,7 +516,7 @@ public class XContentMapValuesTests extends ESTestCase {
|
|||
.startArray().value(2).endArray()
|
||||
.endArray().endObject();
|
||||
|
||||
try (XContentParser parser = createParser(builder.string())) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, builder.string())) {
|
||||
assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken());
|
||||
assertEquals(XContentParser.Token.FIELD_NAME, parser.nextToken());
|
||||
assertEquals("some_array", parser.currentName());
|
||||
|
@ -536,7 +537,7 @@ public class XContentMapValuesTests extends ESTestCase {
|
|||
.startObject().endObject()
|
||||
.endArray().endObject();
|
||||
|
||||
try (XContentParser parser = createParser(builder.string())) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, builder.string())) {
|
||||
assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken());
|
||||
assertEquals(XContentParser.Token.FIELD_NAME, parser.nextToken());
|
||||
assertEquals("some_array", parser.currentName());
|
||||
|
|
|
@ -24,7 +24,6 @@ import org.elasticsearch.common.UUIDs;
|
|||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
|
@ -56,7 +55,7 @@ public class IndexTests extends ESTestCase {
|
|||
final Index original = new Index(name, uuid);
|
||||
final XContentBuilder builder = JsonXContent.contentBuilder();
|
||||
original.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
XContentParser parser = XContentType.JSON.xContent().createParser(builder.bytes());
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, builder.bytes());
|
||||
parser.nextToken(); // the beginning of the parser
|
||||
assertThat(Index.fromXContent(parser), equalTo(original));
|
||||
}
|
||||
|
|
|
@ -133,7 +133,7 @@ public class CompletionFieldMapperTests extends ESSingleNodeTestCase {
|
|||
XContentBuilder builder = jsonBuilder().startObject();
|
||||
completionFieldMapper.toXContent(builder, ToXContent.EMPTY_PARAMS).endObject();
|
||||
builder.close();
|
||||
Map<String, Object> serializedMap = JsonXContent.jsonXContent.createParser(builder.bytes()).map();
|
||||
Map<String, Object> serializedMap = createParser(JsonXContent.jsonXContent, builder.bytes()).map();
|
||||
Map<String, Object> configMap = (Map<String, Object>) serializedMap.get("completion");
|
||||
assertThat(configMap.get("analyzer").toString(), is("simple"));
|
||||
assertThat(configMap.get("search_analyzer").toString(), is("standard"));
|
||||
|
|
|
@ -76,7 +76,7 @@ public class CopyToMapperTests extends ESSingleNodeTestCase {
|
|||
stringFieldMapper.toXContent(builder, ToXContent.EMPTY_PARAMS).endObject();
|
||||
builder.close();
|
||||
Map<String, Object> serializedMap;
|
||||
try (XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes())) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, builder.bytes())) {
|
||||
serializedMap = parser.map();
|
||||
}
|
||||
Map<String, Object> copyTestMap = (Map<String, Object>) serializedMap.get("copy_test");
|
||||
|
|
|
@ -20,18 +20,15 @@
|
|||
package org.elasticsearch.index.mapper;
|
||||
|
||||
import org.apache.lucene.index.IndexableField;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.compress.CompressedXContent;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
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.plugins.Plugin;
|
||||
import org.elasticsearch.test.ESSingleNodeTestCase;
|
||||
import org.elasticsearch.test.InternalSettingsPlugin;
|
||||
import org.elasticsearch.test.VersionUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
|
@ -82,7 +79,7 @@ public class SourceFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
IndexableField sourceField = doc.rootDoc().getField("_source");
|
||||
Map<String, Object> sourceAsMap;
|
||||
try (XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(new BytesArray(sourceField.binaryValue()))) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, new BytesArray(sourceField.binaryValue()))) {
|
||||
sourceAsMap = parser.map();
|
||||
}
|
||||
assertThat(sourceAsMap.containsKey("path1"), equalTo(true));
|
||||
|
@ -103,7 +100,7 @@ public class SourceFieldMapperTests extends ESSingleNodeTestCase {
|
|||
|
||||
IndexableField sourceField = doc.rootDoc().getField("_source");
|
||||
Map<String, Object> sourceAsMap;
|
||||
try (XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(new BytesArray(sourceField.binaryValue()))) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, new BytesArray(sourceField.binaryValue()))) {
|
||||
sourceAsMap = parser.map();
|
||||
}
|
||||
assertThat(sourceAsMap.containsKey("path1"), equalTo(false));
|
||||
|
|
|
@ -26,7 +26,6 @@ import org.apache.lucene.search.MatchAllDocsQuery;
|
|||
import org.apache.lucene.search.Query;
|
||||
import org.elasticsearch.common.ParseFieldMatcher;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
|
@ -173,25 +172,25 @@ public class BoolQueryBuilderTests extends AbstractQueryTestCase<BoolQueryBuilde
|
|||
// https://github.com/elastic/elasticsearch/issues/7240
|
||||
public void testEmptyBooleanQuery() throws Exception {
|
||||
XContentBuilder contentBuilder = XContentFactory.contentBuilder(randomFrom(XContentType.values()));
|
||||
BytesReference query = contentBuilder.startObject().startObject("bool").endObject().endObject().bytes();
|
||||
Query parsedQuery = parseQuery(query).toQuery(createShardContext());
|
||||
contentBuilder.startObject().startObject("bool").endObject().endObject();
|
||||
Query parsedQuery = parseQuery(createParser(contentBuilder)).toQuery(createShardContext());
|
||||
assertThat(parsedQuery, Matchers.instanceOf(MatchAllDocsQuery.class));
|
||||
}
|
||||
|
||||
public void testDefaultMinShouldMatch() throws Exception {
|
||||
// Queries have a minShouldMatch of 0
|
||||
BooleanQuery bq = (BooleanQuery) parseQuery(boolQuery().must(termQuery("foo", "bar")).buildAsBytes()).toQuery(createShardContext());
|
||||
BooleanQuery bq = (BooleanQuery) parseQuery(boolQuery().must(termQuery("foo", "bar"))).toQuery(createShardContext());
|
||||
assertEquals(0, bq.getMinimumNumberShouldMatch());
|
||||
|
||||
bq = (BooleanQuery) parseQuery(boolQuery().should(termQuery("foo", "bar")).buildAsBytes()).toQuery(createShardContext());
|
||||
bq = (BooleanQuery) parseQuery(boolQuery().should(termQuery("foo", "bar"))).toQuery(createShardContext());
|
||||
assertEquals(0, bq.getMinimumNumberShouldMatch());
|
||||
|
||||
// Filters have a minShouldMatch of 0/1
|
||||
ConstantScoreQuery csq = (ConstantScoreQuery) parseQuery(constantScoreQuery(boolQuery().must(termQuery("foo", "bar"))).buildAsBytes()).toQuery(createShardContext());
|
||||
ConstantScoreQuery csq = (ConstantScoreQuery) parseQuery(constantScoreQuery(boolQuery().must(termQuery("foo", "bar")))).toQuery(createShardContext());
|
||||
bq = (BooleanQuery) csq.getQuery();
|
||||
assertEquals(0, bq.getMinimumNumberShouldMatch());
|
||||
|
||||
csq = (ConstantScoreQuery) parseQuery(constantScoreQuery(boolQuery().should(termQuery("foo", "bar"))).buildAsBytes()).toQuery(createShardContext());
|
||||
csq = (ConstantScoreQuery) parseQuery(constantScoreQuery(boolQuery().should(termQuery("foo", "bar")))).toQuery(createShardContext());
|
||||
bq = (BooleanQuery) csq.getQuery();
|
||||
assertEquals(1, bq.getMinimumNumberShouldMatch());
|
||||
}
|
||||
|
@ -244,16 +243,14 @@ public class BoolQueryBuilderTests extends AbstractQueryTestCase<BoolQueryBuilde
|
|||
boolQuery()
|
||||
.should(termQuery("foo", "bar"))
|
||||
.should(termQuery("foo2", "bar2"))
|
||||
.minimumNumberShouldMatch("3")
|
||||
.buildAsBytes()).toQuery(createShardContext());
|
||||
.minimumNumberShouldMatch("3")).toQuery(createShardContext());
|
||||
assertEquals(3, bq.getMinimumNumberShouldMatch());
|
||||
|
||||
bq = (BooleanQuery) parseQuery(
|
||||
boolQuery()
|
||||
.should(termQuery("foo", "bar"))
|
||||
.should(termQuery("foo2", "bar2"))
|
||||
.minimumNumberShouldMatch(3)
|
||||
.buildAsBytes()).toQuery(createShardContext());
|
||||
.minimumNumberShouldMatch(3)).toQuery(createShardContext());
|
||||
assertEquals(3, bq.getMinimumNumberShouldMatch());
|
||||
}
|
||||
|
||||
|
@ -263,8 +260,7 @@ public class BoolQueryBuilderTests extends AbstractQueryTestCase<BoolQueryBuilde
|
|||
.should(termQuery("foo", "bar"))
|
||||
.should(termQuery("foo2", "bar2"))
|
||||
.minimumNumberShouldMatch("3")
|
||||
.disableCoord(true)
|
||||
.buildAsBytes()).toQuery(createShardContext());
|
||||
.disableCoord(true)).toQuery(createShardContext());
|
||||
assertEquals(3, bq.getMinimumNumberShouldMatch());
|
||||
}
|
||||
|
||||
|
|
|
@ -175,7 +175,7 @@ public class CommonTermsQueryBuilderTests extends AbstractQueryTestCase<CommonTe
|
|||
// see #11730
|
||||
public void testCommonTermsQuery4() throws IOException {
|
||||
boolean disableCoord = randomBoolean();
|
||||
Query parsedQuery = parseQuery(commonTermsQuery("field", "text").disableCoord(disableCoord).buildAsBytes()).toQuery(createShardContext());
|
||||
Query parsedQuery = parseQuery(commonTermsQuery("field", "text").disableCoord(disableCoord)).toQuery(createShardContext());
|
||||
assertThat(parsedQuery, instanceOf(ExtendedCommonTermsQuery.class));
|
||||
ExtendedCommonTermsQuery ectQuery = (ExtendedCommonTermsQuery) parsedQuery;
|
||||
assertThat(ectQuery.isCoordDisabled(), equalTo(disableCoord));
|
||||
|
|
|
@ -38,6 +38,7 @@ 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.json.JsonXContent;
|
||||
import org.elasticsearch.index.VersionType;
|
||||
import org.elasticsearch.index.query.MoreLikeThisQueryBuilder.Item;
|
||||
import org.elasticsearch.search.internal.SearchContext;
|
||||
|
@ -276,7 +277,7 @@ public class MoreLikeThisQueryBuilderTests extends AbstractQueryTestCase<MoreLik
|
|||
}
|
||||
|
||||
public void testMoreLikeThisBuilder() throws Exception {
|
||||
Query parsedQuery = parseQuery(moreLikeThisQuery(new String[]{"name.first", "name.last"}, new String[]{"something"}, null).minTermFreq(1).maxQueryTerms(12).buildAsBytes()).toQuery(createShardContext());
|
||||
Query parsedQuery = parseQuery(moreLikeThisQuery(new String[]{"name.first", "name.last"}, new String[]{"something"}, null).minTermFreq(1).maxQueryTerms(12)).toQuery(createShardContext());
|
||||
assertThat(parsedQuery, instanceOf(MoreLikeThisQuery.class));
|
||||
MoreLikeThisQuery mltQuery = (MoreLikeThisQuery) parsedQuery;
|
||||
assertThat(mltQuery.getMoreLikeFields()[0], equalTo("name.first"));
|
||||
|
@ -296,7 +297,7 @@ public class MoreLikeThisQueryBuilderTests extends AbstractQueryTestCase<MoreLik
|
|||
public void testItemFromXContent() throws IOException {
|
||||
Item expectedItem = generateRandomItem();
|
||||
String json = expectedItem.toXContent(XContentFactory.jsonBuilder(), ToXContent.EMPTY_PARAMS).string();
|
||||
XContentParser parser = XContentFactory.xContent(json).createParser(json);
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, json);
|
||||
Item newItem = Item.parse(parser, ParseFieldMatcher.STRICT, new Item());
|
||||
assertEquals(expectedItem, newItem);
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ public class PrefixQueryBuilderTests extends AbstractQueryTestCase<PrefixQueryBu
|
|||
|
||||
public void testBlendedRewriteMethod() throws IOException {
|
||||
String rewrite = "top_terms_blended_freqs_10";
|
||||
Query parsedQuery = parseQuery(prefixQuery("field", "val").rewrite(rewrite).buildAsBytes()).toQuery(createShardContext());
|
||||
Query parsedQuery = parseQuery(prefixQuery("field", "val").rewrite(rewrite)).toQuery(createShardContext());
|
||||
assertThat(parsedQuery, instanceOf(PrefixQuery.class));
|
||||
PrefixQuery prefixQuery = (PrefixQuery) parsedQuery;
|
||||
assertThat(prefixQuery.getPrefix(), equalTo(new Term("field", "val")));
|
||||
|
|
|
@ -24,7 +24,6 @@ import org.elasticsearch.common.ParsingException;
|
|||
import org.elasticsearch.common.logging.DeprecationLogger;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.util.concurrent.ThreadContext;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
|
||||
|
@ -64,7 +63,7 @@ public class QueryParseContextTests extends ESTestCase {
|
|||
public void testParseTopLevelBuilder() throws IOException {
|
||||
QueryBuilder query = new MatchQueryBuilder("foo", "bar");
|
||||
String requestBody = "{ \"query\" : " + query.toString() + "}";
|
||||
try (XContentParser parser = XContentFactory.xContent(requestBody).createParser(requestBody)) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, requestBody)) {
|
||||
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.STRICT);
|
||||
QueryBuilder actual = context.parseTopLevelQueryBuilder();
|
||||
assertEquals(query, actual);
|
||||
|
@ -73,7 +72,7 @@ public class QueryParseContextTests extends ESTestCase {
|
|||
|
||||
public void testParseTopLevelBuilderEmptyObject() throws IOException {
|
||||
String requestBody = "{}";
|
||||
try (XContentParser parser = XContentFactory.xContent(requestBody).createParser(requestBody)) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, requestBody)) {
|
||||
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.STRICT);
|
||||
QueryBuilder query = context.parseTopLevelQueryBuilder();
|
||||
assertNull(query);
|
||||
|
@ -82,7 +81,7 @@ public class QueryParseContextTests extends ESTestCase {
|
|||
|
||||
public void testParseTopLevelBuilderUnknownParameter() throws IOException {
|
||||
String requestBody = "{ \"foo\" : \"bar\"}";
|
||||
try (XContentParser parser = XContentFactory.xContent(requestBody).createParser(requestBody)) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, requestBody)) {
|
||||
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.STRICT);
|
||||
ParsingException exception = expectThrows(ParsingException.class, () -> context.parseTopLevelQueryBuilder());
|
||||
assertEquals("request does not support [foo]", exception.getMessage());
|
||||
|
@ -92,7 +91,7 @@ public class QueryParseContextTests extends ESTestCase {
|
|||
public void testParseInnerQueryBuilder() throws IOException {
|
||||
QueryBuilder query = new MatchQueryBuilder("foo", "bar");
|
||||
String source = query.toString();
|
||||
try (XContentParser parser = XContentFactory.xContent(source).createParser(source)) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, source)) {
|
||||
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.STRICT);
|
||||
QueryBuilder actual = context.parseInnerQueryBuilder();
|
||||
assertEquals(query, actual);
|
||||
|
@ -101,7 +100,7 @@ public class QueryParseContextTests extends ESTestCase {
|
|||
|
||||
public void testParseInnerQueryBuilderExceptions() throws IOException {
|
||||
String source = "{ \"foo\": \"bar\" }";
|
||||
try (XContentParser parser = JsonXContent.jsonXContent.createParser(source)) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, source)) {
|
||||
parser.nextToken();
|
||||
parser.nextToken(); // don't start with START_OBJECT to provoke exception
|
||||
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.STRICT);
|
||||
|
@ -110,21 +109,21 @@ public class QueryParseContextTests extends ESTestCase {
|
|||
}
|
||||
|
||||
source = "{}";
|
||||
try (XContentParser parser = JsonXContent.jsonXContent.createParser(source)) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, source)) {
|
||||
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.EMPTY);
|
||||
IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () -> context.parseInnerQueryBuilder());
|
||||
assertEquals("query malformed, empty clause found at [1:2]", exception.getMessage());
|
||||
}
|
||||
|
||||
source = "{ \"foo\" : \"bar\" }";
|
||||
try (XContentParser parser = JsonXContent.jsonXContent.createParser(source)) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, source)) {
|
||||
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.STRICT);
|
||||
ParsingException exception = expectThrows(ParsingException.class, () -> context.parseInnerQueryBuilder());
|
||||
assertEquals("[foo] query malformed, no start_object after query name", exception.getMessage());
|
||||
}
|
||||
|
||||
source = "{ \"foo\" : {} }";
|
||||
try (XContentParser parser = JsonXContent.jsonXContent.createParser(source)) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, source)) {
|
||||
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.STRICT);
|
||||
ParsingException exception = expectThrows(ParsingException.class, () -> context.parseInnerQueryBuilder());
|
||||
assertEquals("no [query] registered for [foo]", exception.getMessage());
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.apache.lucene.search.Query;
|
|||
import org.apache.lucene.search.TermQuery;
|
||||
import org.elasticsearch.common.ParseFieldMatcher;
|
||||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.geo.GeoPoint;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.lucene.search.function.CombineFunction;
|
||||
|
@ -35,6 +36,7 @@ import org.elasticsearch.common.lucene.search.function.FiltersFunctionScoreQuery
|
|||
import org.elasticsearch.common.lucene.search.function.FunctionScoreQuery;
|
||||
import org.elasticsearch.common.lucene.search.function.WeightFactorFunction;
|
||||
import org.elasticsearch.common.unit.DistanceUnit;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.query.AbstractQueryBuilder;
|
||||
import org.elasticsearch.index.query.MatchAllQueryBuilder;
|
||||
|
@ -360,7 +362,10 @@ public class FunctionScoreQueryBuilderTests extends AbstractQueryTestCase<Functi
|
|||
assertThat(functionScoreQueryBuilder.maxBoost(), equalTo(10f));
|
||||
|
||||
if (i < XContentType.values().length) {
|
||||
queryBuilder = parseQuery(((AbstractQueryBuilder) queryBuilder).buildAsBytes(XContentType.values()[i]));
|
||||
BytesReference bytes = ((AbstractQueryBuilder) queryBuilder).buildAsBytes(XContentType.values()[i]);
|
||||
try (XContentParser parser = createParser(XContentType.values()[i].xContent(), bytes)) {
|
||||
queryBuilder = parseQuery(parser);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -412,7 +417,10 @@ public class FunctionScoreQueryBuilderTests extends AbstractQueryTestCase<Functi
|
|||
assertThat(functionScoreQueryBuilder.maxBoost(), equalTo(10f));
|
||||
|
||||
if (i < XContentType.values().length) {
|
||||
queryBuilder = parseQuery(((AbstractQueryBuilder) queryBuilder).buildAsBytes(XContentType.values()[i]));
|
||||
BytesReference bytes = ((AbstractQueryBuilder) queryBuilder).buildAsBytes(XContentType.values()[i]);
|
||||
try (XContentParser parser = createParser(XContentType.values()[i].xContent(), bytes)) {
|
||||
queryBuilder = parseQuery(parser);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -550,7 +558,7 @@ public class FunctionScoreQueryBuilderTests extends AbstractQueryTestCase<Functi
|
|||
}
|
||||
|
||||
public void testCustomWeightFactorQueryBuilderWithFunctionScore() throws IOException {
|
||||
Query parsedQuery = parseQuery(functionScoreQuery(termQuery("name.last", "banon"), weightFactorFunction(1.3f)).buildAsBytes())
|
||||
Query parsedQuery = parseQuery(functionScoreQuery(termQuery("name.last", "banon"), weightFactorFunction(1.3f)))
|
||||
.toQuery(createShardContext());
|
||||
assertThat(parsedQuery, instanceOf(FunctionScoreQuery.class));
|
||||
FunctionScoreQuery functionScoreQuery = (FunctionScoreQuery) parsedQuery;
|
||||
|
@ -559,7 +567,7 @@ public class FunctionScoreQueryBuilderTests extends AbstractQueryTestCase<Functi
|
|||
}
|
||||
|
||||
public void testCustomWeightFactorQueryBuilderWithFunctionScoreWithoutQueryGiven() throws IOException {
|
||||
Query parsedQuery = parseQuery(functionScoreQuery(weightFactorFunction(1.3f)).buildAsBytes()).toQuery(createShardContext());
|
||||
Query parsedQuery = parseQuery(functionScoreQuery(weightFactorFunction(1.3f))).toQuery(createShardContext());
|
||||
assertThat(parsedQuery, instanceOf(FunctionScoreQuery.class));
|
||||
FunctionScoreQuery functionScoreQuery = (FunctionScoreQuery) parsedQuery;
|
||||
assertThat(functionScoreQuery.getSubQuery() instanceof MatchAllDocsQuery, equalTo(true));
|
||||
|
|
|
@ -34,7 +34,7 @@ import static org.elasticsearch.common.geo.GeoHashUtils.stringEncode;
|
|||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class GeoPointParsingTests extends ESTestCase {
|
||||
static double TOLERANCE = 1E-5;
|
||||
private static final double TOLERANCE = 1E-5;
|
||||
|
||||
public void testGeoPointReset() throws IOException {
|
||||
double lat = 1 + randomDouble() * 89;
|
||||
|
@ -110,7 +110,7 @@ public class GeoPointParsingTests extends ESTestCase {
|
|||
content.endObject();
|
||||
content.endObject();
|
||||
|
||||
XContentParser parser = JsonXContent.jsonXContent.createParser(content.bytes());
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, content.bytes());
|
||||
parser.nextToken();
|
||||
Exception e = expectThrows(ElasticsearchParseException.class, () -> GeoUtils.parseGeoPoint(parser));
|
||||
assertThat(e.getMessage(), is("field must be either [lat], [lon] or [geohash]"));
|
||||
|
@ -122,7 +122,7 @@ public class GeoPointParsingTests extends ESTestCase {
|
|||
content.field("lat", 0).field("geohash", stringEncode(0d, 0d));
|
||||
content.endObject();
|
||||
|
||||
XContentParser parser = JsonXContent.jsonXContent.createParser(content.bytes());
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, content.bytes());
|
||||
parser.nextToken();
|
||||
|
||||
Exception e = expectThrows(ElasticsearchParseException.class, () -> GeoUtils.parseGeoPoint(parser));
|
||||
|
@ -135,7 +135,7 @@ public class GeoPointParsingTests extends ESTestCase {
|
|||
content.field("lon", 0).field("geohash", stringEncode(0d, 0d));
|
||||
content.endObject();
|
||||
|
||||
XContentParser parser = JsonXContent.jsonXContent.createParser(content.bytes());
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, content.bytes());
|
||||
parser.nextToken();
|
||||
|
||||
Exception e = expectThrows(ElasticsearchParseException.class, () -> GeoUtils.parseGeoPoint(parser));
|
||||
|
@ -148,43 +148,43 @@ public class GeoPointParsingTests extends ESTestCase {
|
|||
content.field("lon", 0).field("lat", 0).field("test", 0);
|
||||
content.endObject();
|
||||
|
||||
XContentParser parser = JsonXContent.jsonXContent.createParser(content.bytes());
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, content.bytes());
|
||||
parser.nextToken();
|
||||
|
||||
Exception e = expectThrows(ElasticsearchParseException.class, () -> GeoUtils.parseGeoPoint(parser));
|
||||
assertThat(e.getMessage(), is("field must be either [lat], [lon] or [geohash]"));
|
||||
}
|
||||
|
||||
private static XContentParser objectLatLon(double lat, double lon) throws IOException {
|
||||
private XContentParser objectLatLon(double lat, double lon) throws IOException {
|
||||
XContentBuilder content = JsonXContent.contentBuilder();
|
||||
content.startObject();
|
||||
content.field("lat", lat).field("lon", lon);
|
||||
content.endObject();
|
||||
XContentParser parser = JsonXContent.jsonXContent.createParser(content.bytes());
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, content.bytes());
|
||||
parser.nextToken();
|
||||
return parser;
|
||||
}
|
||||
|
||||
private static XContentParser arrayLatLon(double lat, double lon) throws IOException {
|
||||
private XContentParser arrayLatLon(double lat, double lon) throws IOException {
|
||||
XContentBuilder content = JsonXContent.contentBuilder();
|
||||
content.startArray().value(lon).value(lat).endArray();
|
||||
XContentParser parser = JsonXContent.jsonXContent.createParser(content.bytes());
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, content.bytes());
|
||||
parser.nextToken();
|
||||
return parser;
|
||||
}
|
||||
|
||||
private static XContentParser stringLatLon(double lat, double lon) throws IOException {
|
||||
private XContentParser stringLatLon(double lat, double lon) throws IOException {
|
||||
XContentBuilder content = JsonXContent.contentBuilder();
|
||||
content.value(Double.toString(lat) + ", " + Double.toString(lon));
|
||||
XContentParser parser = JsonXContent.jsonXContent.createParser(content.bytes());
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, content.bytes());
|
||||
parser.nextToken();
|
||||
return parser;
|
||||
}
|
||||
|
||||
private static XContentParser geohash(double lat, double lon) throws IOException {
|
||||
private XContentParser geohash(double lat, double lon) throws IOException {
|
||||
XContentBuilder content = JsonXContent.contentBuilder();
|
||||
content.value(stringEncode(lon, lat));
|
||||
XContentParser parser = JsonXContent.jsonXContent.createParser(content.bytes());
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, content.bytes());
|
||||
parser.nextToken();
|
||||
return parser;
|
||||
}
|
||||
|
|
|
@ -28,11 +28,13 @@ 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.snapshots.blobstore.BlobStoreIndexShardSnapshot.FileInfo;
|
||||
import org.elasticsearch.index.store.StoreFileMetaData;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
@ -54,7 +56,7 @@ public class FileInfoTests extends ESTestCase {
|
|||
byte[] xcontent = BytesReference.toBytes(shuffleXContent(builder).bytes());
|
||||
|
||||
final BlobStoreIndexShardSnapshot.FileInfo parsedInfo;
|
||||
try (XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(xcontent)) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, xcontent)) {
|
||||
parser.nextToken();
|
||||
parsedInfo = BlobStoreIndexShardSnapshot.FileInfo.fromXContent(parser);
|
||||
}
|
||||
|
@ -115,7 +117,7 @@ public class FileInfoTests extends ESTestCase {
|
|||
if (failure == null) {
|
||||
// No failures should read as usual
|
||||
final BlobStoreIndexShardSnapshot.FileInfo parsedInfo;
|
||||
try (XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(xContent)) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, xContent)) {
|
||||
parser.nextToken();
|
||||
parsedInfo = BlobStoreIndexShardSnapshot.FileInfo.fromXContent(parser);
|
||||
}
|
||||
|
@ -126,14 +128,13 @@ public class FileInfoTests extends ESTestCase {
|
|||
assertEquals("666", parsedInfo.metadata().checksum());
|
||||
assertEquals(Version.LATEST, parsedInfo.metadata().writtenBy());
|
||||
} else {
|
||||
try (XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(xContent)) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, xContent)) {
|
||||
parser.nextToken();
|
||||
BlobStoreIndexShardSnapshot.FileInfo.fromXContent(parser);
|
||||
fail("Should have failed with [" + failure + "]");
|
||||
} catch (ElasticsearchParseException ex) {
|
||||
assertThat(ex.getMessage(), containsString(failure));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
|||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
|
@ -69,7 +68,7 @@ public class IndexIdTests extends ESTestCase {
|
|||
IndexId indexId = new IndexId(randomAsciiOfLength(8), UUIDs.randomBase64UUID());
|
||||
XContentBuilder builder = JsonXContent.contentBuilder();
|
||||
indexId.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
XContentParser parser = XContentType.JSON.xContent().createParser(builder.bytes());
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, builder.bytes());
|
||||
assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken());
|
||||
String name = null;
|
||||
String id = null;
|
||||
|
|
|
@ -23,7 +23,6 @@ import org.elasticsearch.common.UUIDs;
|
|||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.snapshots.SnapshotId;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
@ -56,7 +55,7 @@ public class RepositoryDataTests extends ESTestCase {
|
|||
RepositoryData repositoryData = generateRandomRepoData();
|
||||
XContentBuilder builder = JsonXContent.contentBuilder();
|
||||
repositoryData.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
XContentParser parser = XContentType.JSON.xContent().createParser(builder.bytes());
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, builder.bytes());
|
||||
assertEquals(repositoryData, RepositoryData.fromXContent(parser));
|
||||
}
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ public class AggregationCollectorTests extends ESSingleNodeTestCase {
|
|||
private boolean needsScores(IndexService index, String agg) throws IOException {
|
||||
AggregatorParsers parser = getInstanceFromNode(SearchRequestParsers.class).aggParsers;
|
||||
IndicesQueriesRegistry queriesRegistry = getInstanceFromNode(IndicesQueriesRegistry.class);
|
||||
XContentParser aggParser = JsonXContent.jsonXContent.createParser(agg);
|
||||
XContentParser aggParser = createParser(JsonXContent.jsonXContent, agg);
|
||||
QueryParseContext parseContext = new QueryParseContext(queriesRegistry, aggParser, ParseFieldMatcher.STRICT);
|
||||
aggParser.nextToken();
|
||||
SearchContext context = createSearchContext(index);
|
||||
|
|
|
@ -33,7 +33,7 @@ public class GeoHashGridParserTests extends ESTestCase {
|
|||
|
||||
public void testParseValidFromInts() throws Exception {
|
||||
int precision = randomIntBetween(1, 12);
|
||||
XContentParser stParser = JsonXContent.jsonXContent.createParser(
|
||||
XContentParser stParser = createParser(JsonXContent.jsonXContent,
|
||||
"{\"field\":\"my_loc\", \"precision\":" + precision + ", \"size\": 500, \"shard_size\": 550}");
|
||||
QueryParseContext parseContext = new QueryParseContext(mockRegistry,
|
||||
stParser, ParseFieldMatcher.STRICT);
|
||||
|
@ -45,7 +45,7 @@ public class GeoHashGridParserTests extends ESTestCase {
|
|||
|
||||
public void testParseValidFromStrings() throws Exception {
|
||||
int precision = randomIntBetween(1, 12);
|
||||
XContentParser stParser = JsonXContent.jsonXContent.createParser(
|
||||
XContentParser stParser = createParser(JsonXContent.jsonXContent,
|
||||
"{\"field\":\"my_loc\", \"precision\":\"" + precision + "\", \"size\": \"500\", \"shard_size\": \"550\"}");
|
||||
QueryParseContext parseContext = new QueryParseContext(mockRegistry, stParser, ParseFieldMatcher.STRICT);
|
||||
XContentParser.Token token = stParser.nextToken();
|
||||
|
@ -55,7 +55,7 @@ public class GeoHashGridParserTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testParseErrorOnNonIntPrecision() throws Exception {
|
||||
XContentParser stParser = JsonXContent.jsonXContent.createParser("{\"field\":\"my_loc\", \"precision\":\"2.0\"}");
|
||||
XContentParser stParser = createParser(JsonXContent.jsonXContent, "{\"field\":\"my_loc\", \"precision\":\"2.0\"}");
|
||||
QueryParseContext parseContext = new QueryParseContext(mockRegistry, stParser, ParseFieldMatcher.STRICT);
|
||||
XContentParser.Token token = stParser.nextToken();
|
||||
assertSame(XContentParser.Token.START_OBJECT, token);
|
||||
|
@ -69,7 +69,7 @@ public class GeoHashGridParserTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testParseErrorOnBooleanPrecision() throws Exception {
|
||||
XContentParser stParser = JsonXContent.jsonXContent.createParser("{\"field\":\"my_loc\", \"precision\":false}");
|
||||
XContentParser stParser = createParser(JsonXContent.jsonXContent, "{\"field\":\"my_loc\", \"precision\":false}");
|
||||
QueryParseContext parseContext = new QueryParseContext(mockRegistry, stParser, ParseFieldMatcher.STRICT);
|
||||
XContentParser.Token token = stParser.nextToken();
|
||||
assertSame(XContentParser.Token.START_OBJECT, token);
|
||||
|
@ -82,7 +82,7 @@ public class GeoHashGridParserTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testParseErrorOnPrecisionOutOfRange() throws Exception {
|
||||
XContentParser stParser = JsonXContent.jsonXContent.createParser("{\"field\":\"my_loc\", \"precision\":\"13\"}");
|
||||
XContentParser stParser = createParser(JsonXContent.jsonXContent, "{\"field\":\"my_loc\", \"precision\":\"13\"}");
|
||||
QueryParseContext parseContext = new QueryParseContext(mockRegistry, stParser, ParseFieldMatcher.STRICT);
|
||||
XContentParser.Token token = stParser.nextToken();
|
||||
assertSame(XContentParser.Token.START_OBJECT, token);
|
||||
|
|
|
@ -36,7 +36,6 @@ import org.elasticsearch.index.IndexSettings;
|
|||
import org.elasticsearch.index.query.QueryShardContext;
|
||||
import org.elasticsearch.search.DocValueFormat;
|
||||
import org.elasticsearch.search.SearchParseException;
|
||||
import org.elasticsearch.search.aggregations.bucket.histogram.ExtendedBounds;
|
||||
import org.elasticsearch.search.internal.SearchContext;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.joda.time.DateTimeZone;
|
||||
|
@ -164,7 +163,7 @@ public class ExtendedBoundsTests extends ESTestCase {
|
|||
orig.toXContent(out, ToXContent.EMPTY_PARAMS);
|
||||
out.endObject();
|
||||
|
||||
try (XContentParser in = JsonXContent.jsonXContent.createParser(out.bytes())) {
|
||||
try (XContentParser in = createParser(JsonXContent.jsonXContent, out.bytes())) {
|
||||
XContentParser.Token token = in.currentToken();
|
||||
assertNull(token);
|
||||
|
||||
|
|
|
@ -269,7 +269,7 @@ public class SignificanceHeuristicTests extends ESTestCase {
|
|||
|
||||
IndicesQueriesRegistry registry = new IndicesQueriesRegistry();
|
||||
try {
|
||||
XContentParser stParser = JsonXContent.jsonXContent.createParser(
|
||||
XContentParser stParser = createParser(JsonXContent.jsonXContent,
|
||||
"{\"field\":\"text\", " + faultyHeuristicDefinition + ",\"min_doc_count\":200}");
|
||||
QueryParseContext parseContext = new QueryParseContext(registry, stParser, ParseFieldMatcher.STRICT);
|
||||
stParser.nextToken();
|
||||
|
@ -286,7 +286,7 @@ public class SignificanceHeuristicTests extends ESTestCase {
|
|||
stBuilder.significanceHeuristic(significanceHeuristic).field("text").minDocCount(200);
|
||||
XContentBuilder stXContentBuilder = XContentFactory.jsonBuilder();
|
||||
stBuilder.internalXContent(stXContentBuilder, null);
|
||||
XContentParser stParser = JsonXContent.jsonXContent.createParser(stXContentBuilder.string());
|
||||
XContentParser stParser = createParser(JsonXContent.jsonXContent, stXContentBuilder.string());
|
||||
return parseSignificanceHeuristic(significanceHeuristicParserRegistry, searchContext, stParser);
|
||||
}
|
||||
|
||||
|
@ -308,7 +308,7 @@ public class SignificanceHeuristicTests extends ESTestCase {
|
|||
|
||||
protected SignificanceHeuristic parseFromString(ParseFieldRegistry<SignificanceHeuristicParser> significanceHeuristicParserRegistry,
|
||||
SearchContext searchContext, String heuristicString) throws IOException {
|
||||
XContentParser stParser = JsonXContent.jsonXContent.createParser(
|
||||
XContentParser stParser = createParser(JsonXContent.jsonXContent,
|
||||
"{\"field\":\"text\", " + heuristicString + ", \"min_doc_count\":200}");
|
||||
return parseSignificanceHeuristic(significanceHeuristicParserRegistry, searchContext, stParser);
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ import org.elasticsearch.common.xcontent.XContentFactory;
|
|||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.index.Index;
|
||||
import org.elasticsearch.index.IndexSettings;
|
||||
import org.elasticsearch.index.mapper.ContentPath;
|
||||
|
@ -168,8 +169,8 @@ public class HighlightBuilderTests extends ESTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
private static <T extends Throwable> T expectParseThrows(Class<T> exceptionClass, String highlightElement) throws IOException {
|
||||
XContentParser parser = XContentFactory.xContent(highlightElement).createParser(highlightElement);
|
||||
private <T extends Throwable> T expectParseThrows(Class<T> exceptionClass, String highlightElement) throws IOException {
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, highlightElement);
|
||||
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.STRICT);
|
||||
return expectThrows(exceptionClass, () -> HighlightBuilder.fromXContent(context));
|
||||
}
|
||||
|
@ -378,7 +379,7 @@ public class HighlightBuilderTests extends ESTestCase {
|
|||
String highlightElement = "{\n" +
|
||||
" \"tags_schema\" : \"styled\"\n" +
|
||||
"}\n";
|
||||
XContentParser parser = XContentFactory.xContent(highlightElement).createParser(highlightElement);
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, highlightElement);
|
||||
|
||||
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.EMPTY);
|
||||
HighlightBuilder highlightBuilder = HighlightBuilder.fromXContent(context);
|
||||
|
@ -390,7 +391,7 @@ public class HighlightBuilderTests extends ESTestCase {
|
|||
highlightElement = "{\n" +
|
||||
" \"tags_schema\" : \"default\"\n" +
|
||||
"}\n";
|
||||
parser = XContentFactory.xContent(highlightElement).createParser(highlightElement);
|
||||
parser = createParser(JsonXContent.jsonXContent, highlightElement);
|
||||
|
||||
context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.EMPTY);
|
||||
highlightBuilder = HighlightBuilder.fromXContent(context);
|
||||
|
@ -411,21 +412,21 @@ public class HighlightBuilderTests extends ESTestCase {
|
|||
*/
|
||||
public void testParsingEmptyStructure() throws IOException {
|
||||
String highlightElement = "{ }";
|
||||
XContentParser parser = XContentFactory.xContent(highlightElement).createParser(highlightElement);
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, highlightElement);
|
||||
|
||||
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.EMPTY);
|
||||
HighlightBuilder highlightBuilder = HighlightBuilder.fromXContent(context);
|
||||
assertEquals("expected plain HighlightBuilder", new HighlightBuilder(), highlightBuilder);
|
||||
|
||||
highlightElement = "{ \"fields\" : { } }";
|
||||
parser = XContentFactory.xContent(highlightElement).createParser(highlightElement);
|
||||
parser = createParser(JsonXContent.jsonXContent, highlightElement);
|
||||
|
||||
context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.EMPTY);
|
||||
highlightBuilder = HighlightBuilder.fromXContent(context);
|
||||
assertEquals("defining no field should return plain HighlightBuilder", new HighlightBuilder(), highlightBuilder);
|
||||
|
||||
highlightElement = "{ \"fields\" : { \"foo\" : { } } }";
|
||||
parser = XContentFactory.xContent(highlightElement).createParser(highlightElement);
|
||||
parser = createParser(JsonXContent.jsonXContent, highlightElement);
|
||||
|
||||
context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.EMPTY);
|
||||
highlightBuilder = HighlightBuilder.fromXContent(context);
|
||||
|
|
|
@ -33,6 +33,7 @@ import org.elasticsearch.common.xcontent.XContentFactory;
|
|||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.index.IndexSettings;
|
||||
import org.elasticsearch.index.mapper.ContentPath;
|
||||
import org.elasticsearch.index.mapper.MappedFieldType;
|
||||
|
@ -250,8 +251,8 @@ public class QueryRescoreBuilderTests extends ESTestCase {
|
|||
/**
|
||||
* create a new parser from the rescorer string representation and reset context with it
|
||||
*/
|
||||
private static QueryParseContext createContext(String rescoreElement) throws IOException {
|
||||
XContentParser parser = XContentFactory.xContent(rescoreElement).createParser(rescoreElement);
|
||||
private QueryParseContext createContext(String rescoreElement) throws IOException {
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, rescoreElement);
|
||||
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.STRICT);
|
||||
// move to first token, this is where the internal fromXContent
|
||||
assertTrue(parser.nextToken() == XContentParser.Token.START_OBJECT);
|
||||
|
|
|
@ -28,6 +28,7 @@ import org.elasticsearch.common.xcontent.XContentFactory;
|
|||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
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.QueryParseContext;
|
||||
import org.elasticsearch.index.query.QueryParser;
|
||||
|
@ -108,7 +109,7 @@ public class SearchAfterBuilderTests extends ESTestCase {
|
|||
// ensure that every number type remain the same before/after xcontent (de)serialization.
|
||||
// This is not a problem because the final type of each field value is extracted from associated sort field.
|
||||
// This little trick ensure that equals and hashcode are the same when using the xcontent serialization.
|
||||
private static SearchAfterBuilder randomJsonSearchFromBuilder() throws IOException {
|
||||
private SearchAfterBuilder randomJsonSearchFromBuilder() throws IOException {
|
||||
int numSearchAfter = randomIntBetween(1, 10);
|
||||
XContentBuilder jsonBuilder = XContentFactory.jsonBuilder();
|
||||
jsonBuilder.startObject();
|
||||
|
@ -150,7 +151,7 @@ public class SearchAfterBuilderTests extends ESTestCase {
|
|||
}
|
||||
jsonBuilder.endArray();
|
||||
jsonBuilder.endObject();
|
||||
XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(jsonBuilder.bytes());
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, jsonBuilder.bytes());
|
||||
parser.nextToken();
|
||||
parser.nextToken();
|
||||
parser.nextToken();
|
||||
|
|
|
@ -26,9 +26,8 @@ import org.apache.lucene.search.suggest.document.ContextSuggestField;
|
|||
import org.elasticsearch.common.ParseFieldMatcher;
|
||||
import org.elasticsearch.common.compress.CompressedXContent;
|
||||
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.mapper.DocumentMapper;
|
||||
import org.elasticsearch.index.mapper.FieldMapper;
|
||||
import org.elasticsearch.index.mapper.MappedFieldType;
|
||||
|
@ -191,7 +190,7 @@ public class CategoryContextMappingTests extends ESSingleNodeTestCase {
|
|||
|
||||
public void testQueryContextParsingBasic() throws Exception {
|
||||
XContentBuilder builder = jsonBuilder().value("context1");
|
||||
XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(builder.bytes());
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, builder.bytes());
|
||||
CategoryContextMapping mapping = ContextBuilder.category("cat").build();
|
||||
List<ContextMapping.InternalQueryContext> internalQueryContexts = mapping.parseQueryContext(createParseContext(parser));
|
||||
assertThat(internalQueryContexts.size(), equalTo(1));
|
||||
|
@ -205,7 +204,7 @@ public class CategoryContextMappingTests extends ESSingleNodeTestCase {
|
|||
.value("context1")
|
||||
.value("context2")
|
||||
.endArray();
|
||||
XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(builder.bytes());
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, builder.bytes());
|
||||
CategoryContextMapping mapping = ContextBuilder.category("cat").build();
|
||||
List<ContextMapping.InternalQueryContext> internalQueryContexts = mapping.parseQueryContext(createParseContext(parser));
|
||||
assertThat(internalQueryContexts.size(), equalTo(2));
|
||||
|
@ -223,7 +222,7 @@ public class CategoryContextMappingTests extends ESSingleNodeTestCase {
|
|||
.field("boost", 10)
|
||||
.field("prefix", true)
|
||||
.endObject();
|
||||
XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(builder.bytes());
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, builder.bytes());
|
||||
CategoryContextMapping mapping = ContextBuilder.category("cat").build();
|
||||
List<ContextMapping.InternalQueryContext> internalQueryContexts = mapping.parseQueryContext(createParseContext(parser));
|
||||
assertThat(internalQueryContexts.size(), equalTo(1));
|
||||
|
@ -246,7 +245,7 @@ public class CategoryContextMappingTests extends ESSingleNodeTestCase {
|
|||
.field("prefix", false)
|
||||
.endObject()
|
||||
.endArray();
|
||||
XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(builder.bytes());
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, builder.bytes());
|
||||
CategoryContextMapping mapping = ContextBuilder.category("cat").build();
|
||||
List<ContextMapping.InternalQueryContext> internalQueryContexts = mapping.parseQueryContext(createParseContext(parser));
|
||||
assertThat(internalQueryContexts.size(), equalTo(2));
|
||||
|
@ -271,7 +270,7 @@ public class CategoryContextMappingTests extends ESSingleNodeTestCase {
|
|||
.endObject()
|
||||
.value("context2")
|
||||
.endArray();
|
||||
XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(builder.bytes());
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, builder.bytes());
|
||||
CategoryContextMapping mapping = ContextBuilder.category("cat").build();
|
||||
List<ContextMapping.InternalQueryContext> internalQueryContexts = mapping.parseQueryContext(createParseContext(parser));
|
||||
assertThat(internalQueryContexts.size(), equalTo(2));
|
||||
|
|
|
@ -23,9 +23,8 @@ import org.apache.lucene.index.IndexableField;
|
|||
import org.elasticsearch.common.ParseFieldMatcher;
|
||||
import org.elasticsearch.common.compress.CompressedXContent;
|
||||
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.mapper.DocumentMapper;
|
||||
import org.elasticsearch.index.mapper.FieldMapper;
|
||||
import org.elasticsearch.index.mapper.MappedFieldType;
|
||||
|
@ -204,7 +203,7 @@ public class GeoContextMappingTests extends ESSingleNodeTestCase {
|
|||
|
||||
public void testParsingQueryContextBasic() throws Exception {
|
||||
XContentBuilder builder = jsonBuilder().value("ezs42e44yx96");
|
||||
XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(builder.bytes());
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, builder.bytes());
|
||||
GeoContextMapping mapping = ContextBuilder.geo("geo").build();
|
||||
List<ContextMapping.InternalQueryContext> internalQueryContexts = mapping.parseQueryContext(createParseContext(parser));
|
||||
assertThat(internalQueryContexts.size(), equalTo(1 + 8));
|
||||
|
@ -223,7 +222,7 @@ public class GeoContextMappingTests extends ESSingleNodeTestCase {
|
|||
.field("lat", 23.654242)
|
||||
.field("lon", 90.047153)
|
||||
.endObject();
|
||||
XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(builder.bytes());
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, builder.bytes());
|
||||
GeoContextMapping mapping = ContextBuilder.geo("geo").build();
|
||||
List<ContextMapping.InternalQueryContext> internalQueryContexts = mapping.parseQueryContext(createParseContext(parser));
|
||||
assertThat(internalQueryContexts.size(), equalTo(1 + 8));
|
||||
|
@ -246,7 +245,7 @@ public class GeoContextMappingTests extends ESSingleNodeTestCase {
|
|||
.field("boost", 10)
|
||||
.array("neighbours", 1, 2, 3)
|
||||
.endObject();
|
||||
XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(builder.bytes());
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, builder.bytes());
|
||||
GeoContextMapping mapping = ContextBuilder.geo("geo").build();
|
||||
List<ContextMapping.InternalQueryContext> internalQueryContexts = mapping.parseQueryContext(createParseContext(parser));
|
||||
assertThat(internalQueryContexts.size(), equalTo(1 + 1 + 8 + 1 + 8 + 1 + 8));
|
||||
|
@ -284,7 +283,7 @@ public class GeoContextMappingTests extends ESSingleNodeTestCase {
|
|||
.array("neighbours", 5)
|
||||
.endObject()
|
||||
.endArray();
|
||||
XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(builder.bytes());
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, builder.bytes());
|
||||
GeoContextMapping mapping = ContextBuilder.geo("geo").build();
|
||||
List<ContextMapping.InternalQueryContext> internalQueryContexts = mapping.parseQueryContext(createParseContext(parser));
|
||||
assertThat(internalQueryContexts.size(), equalTo(1 + 1 + 8 + 1 + 8 + 1 + 8 + 1 + 1 + 8));
|
||||
|
@ -327,7 +326,7 @@ public class GeoContextMappingTests extends ESSingleNodeTestCase {
|
|||
.field("lon", 92.112583)
|
||||
.endObject()
|
||||
.endArray();
|
||||
XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(builder.bytes());
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, builder.bytes());
|
||||
GeoContextMapping mapping = ContextBuilder.geo("geo").build();
|
||||
List<ContextMapping.InternalQueryContext> internalQueryContexts = mapping.parseQueryContext(createParseContext(parser));
|
||||
assertThat(internalQueryContexts.size(), equalTo(1 + 1 + 8 + 1 + 8 + 1 + 8));
|
||||
|
|
|
@ -34,7 +34,6 @@ import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
|
|||
import org.elasticsearch.test.ESIntegTestCase.Scope;
|
||||
import org.elasticsearch.test.InternalTestCluster;
|
||||
import org.elasticsearch.test.hamcrest.RegexMatcher;
|
||||
import org.elasticsearch.tribe.TribeIT;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.management.ManagementFactory;
|
||||
|
@ -136,7 +135,7 @@ public class SimpleThreadPoolIT extends ESIntegTestCase {
|
|||
builder.endObject();
|
||||
builder.close();
|
||||
Map<String, Object> poolsMap;
|
||||
try (XContentParser parser = JsonXContent.jsonXContent.createParser(builder.string())) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, builder.string())) {
|
||||
poolsMap = parser.map();
|
||||
}
|
||||
return (Map<String, Object>) ((Map<String, Object>) poolsMap.get("thread_pool")).get(poolName);
|
||||
|
|
|
@ -24,6 +24,7 @@ import org.elasticsearch.common.xcontent.ToXContent;
|
|||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -78,7 +79,7 @@ public class ThreadPoolStatsTests extends ESTestCase {
|
|||
builder.endObject();
|
||||
}
|
||||
|
||||
try (XContentParser parser = XContentType.JSON.xContent().createParser(os.bytes())) {
|
||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, os.bytes())) {
|
||||
XContentParser.Token token = parser.currentToken();
|
||||
assertNull(token);
|
||||
|
||||
|
|
|
@ -135,10 +135,11 @@ public class TemplateQueryBuilderTests extends AbstractQueryTestCase<TemplateQue
|
|||
@Override
|
||||
public void testUnknownField() throws IOException {
|
||||
TemplateQueryBuilder testQuery = createTestQueryBuilder();
|
||||
String testQueryAsString = toXContent(testQuery, randomFrom(XContentType.JSON, XContentType.YAML)).string();
|
||||
XContentType xContentType = randomFrom(XContentType.JSON, XContentType.YAML);
|
||||
String testQueryAsString = toXContent(testQuery, xContentType).string();
|
||||
String queryAsString = testQueryAsString.replace("inline", "bogusField");
|
||||
try {
|
||||
parseQuery(queryAsString);
|
||||
parseQuery(createParser(xContentType.xContent(), queryAsString));
|
||||
fail("IllegalArgumentException expected");
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertThat(e.getMessage(), containsString("[script] unknown field [bogusField], parser not found"));
|
||||
|
|
|
@ -123,7 +123,7 @@ public class RestReindexActionTests extends ESTestCase {
|
|||
b.endObject();
|
||||
request = b.bytes();
|
||||
}
|
||||
try (XContentParser p = JsonXContent.jsonXContent.createParser(request)) {
|
||||
try (XContentParser p = createParser(JsonXContent.jsonXContent, request)) {
|
||||
ReindexRequest r = new ReindexRequest(new SearchRequest(), new IndexRequest());
|
||||
SearchRequestParsers searchParsers = new SearchRequestParsers(new IndicesQueriesRegistry(), null, null, null);
|
||||
RestReindexAction.PARSER.parse(p, r, new ReindexParseContext(searchParsers, ParseFieldMatcher.STRICT));
|
||||
|
|
|
@ -44,7 +44,6 @@ import org.elasticsearch.common.ParseFieldMatcher;
|
|||
import org.elasticsearch.common.ParsingException;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.collect.Tuple;
|
||||
import org.elasticsearch.common.compress.CompressedXContent;
|
||||
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
||||
|
@ -66,6 +65,7 @@ import org.elasticsearch.common.xcontent.XContentGenerator;
|
|||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.index.Index;
|
||||
import org.elasticsearch.index.IndexSettings;
|
||||
|
@ -292,10 +292,10 @@ public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>>
|
|||
QB testQuery = createTestQueryBuilder();
|
||||
XContentBuilder builder = toXContent(testQuery, randomFrom(XContentType.values()));
|
||||
XContentBuilder shuffled = shuffleXContent(builder, shuffleProtectedFields());
|
||||
assertParsedQuery(shuffled.bytes(), testQuery);
|
||||
assertParsedQuery(createParser(shuffled), testQuery);
|
||||
for (Map.Entry<String, QB> alternateVersion : getAlternateVersions().entrySet()) {
|
||||
String queryAsString = alternateVersion.getKey();
|
||||
assertParsedQuery(new BytesArray(queryAsString), alternateVersion.getValue());
|
||||
assertParsedQuery(createParser(JsonXContent.jsonXContent, queryAsString), alternateVersion.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -559,13 +559,13 @@ public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>>
|
|||
/**
|
||||
* Parses the query provided as bytes argument and compares it with the expected result provided as argument as a {@link QueryBuilder}
|
||||
*/
|
||||
private void assertParsedQuery(BytesReference queryAsBytes, QueryBuilder expectedQuery) throws IOException {
|
||||
assertParsedQuery(queryAsBytes, expectedQuery, ParseFieldMatcher.STRICT);
|
||||
private void assertParsedQuery(XContentParser parser, QueryBuilder expectedQuery) throws IOException {
|
||||
assertParsedQuery(parser, expectedQuery, ParseFieldMatcher.STRICT);
|
||||
}
|
||||
|
||||
private void assertParsedQuery(BytesReference queryAsBytes, QueryBuilder expectedQuery, ParseFieldMatcher matcher)
|
||||
private void assertParsedQuery(XContentParser parser, QueryBuilder expectedQuery, ParseFieldMatcher matcher)
|
||||
throws IOException {
|
||||
QueryBuilder newQuery = parseQuery(queryAsBytes, matcher);
|
||||
QueryBuilder newQuery = parseQuery(parser, matcher);
|
||||
assertNotSame(newQuery, expectedQuery);
|
||||
assertEquals(expectedQuery, newQuery);
|
||||
assertEquals(expectedQuery.hashCode(), newQuery.hashCode());
|
||||
|
@ -575,17 +575,16 @@ public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>>
|
|||
return parseQuery(queryAsString, ParseFieldMatcher.STRICT);
|
||||
}
|
||||
|
||||
protected QueryBuilder parseQuery(XContentParser parser) throws IOException {
|
||||
return parseQuery(parser, ParseFieldMatcher.STRICT);
|
||||
}
|
||||
|
||||
protected QueryBuilder parseQuery(AbstractQueryBuilder<?> builder) throws IOException {
|
||||
return parseQuery(createParser(JsonXContent.jsonXContent, builder.buildAsBytes(XContentType.JSON)), ParseFieldMatcher.STRICT);
|
||||
}
|
||||
|
||||
protected QueryBuilder parseQuery(String queryAsString, ParseFieldMatcher matcher) throws IOException {
|
||||
XContentParser parser = createParser(queryAsString);
|
||||
return parseQuery(parser, matcher);
|
||||
}
|
||||
|
||||
protected QueryBuilder parseQuery(BytesReference queryAsBytes) throws IOException {
|
||||
return parseQuery(queryAsBytes, ParseFieldMatcher.STRICT);
|
||||
}
|
||||
|
||||
protected QueryBuilder parseQuery(BytesReference queryAsBytes, ParseFieldMatcher matcher) throws IOException {
|
||||
XContentParser parser = createParser(queryAsBytes);
|
||||
XContentParser parser = createParser(JsonXContent.jsonXContent, queryAsString);
|
||||
return parseQuery(parser, matcher);
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ import com.carrotsearch.randomizedtesting.generators.RandomNumbers;
|
|||
import com.carrotsearch.randomizedtesting.generators.RandomPicks;
|
||||
import com.carrotsearch.randomizedtesting.generators.RandomStrings;
|
||||
import com.carrotsearch.randomizedtesting.rules.TestRuleAdapter;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
@ -47,7 +48,6 @@ import org.elasticsearch.Version;
|
|||
import org.elasticsearch.bootstrap.BootstrapForTesting;
|
||||
import org.elasticsearch.client.Requests;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.io.PathUtils;
|
||||
import org.elasticsearch.common.io.PathUtilsForTesting;
|
||||
|
@ -62,9 +62,9 @@ import org.elasticsearch.common.settings.Settings;
|
|||
import org.elasticsearch.common.transport.TransportAddress;
|
||||
import org.elasticsearch.common.util.MockBigArrays;
|
||||
import org.elasticsearch.common.util.MockPageCacheRecycler;
|
||||
import org.elasticsearch.common.xcontent.XContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.env.Environment;
|
||||
|
@ -100,6 +100,7 @@ import org.junit.internal.AssumptionViolatedException;
|
|||
import org.junit.rules.RuleChain;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.nio.file.DirectoryStream;
|
||||
import java.nio.file.Files;
|
||||
|
@ -883,15 +884,36 @@ public abstract class ESTestCase extends LuceneTestCase {
|
|||
/**
|
||||
* Create a new {@link XContentParser}.
|
||||
*/
|
||||
protected final XContentParser createParser(BytesReference data) throws IOException {
|
||||
return XContentFactory.xContent(data).createParser(data);
|
||||
protected final XContentParser createParser(XContentBuilder builder) throws IOException {
|
||||
return builder.generator().contentType().xContent().createParser(builder.bytes());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link XContentParser}.
|
||||
*/
|
||||
protected final XContentParser createParser(String string) throws IOException {
|
||||
return createParser(new BytesArray(string));
|
||||
protected final XContentParser createParser(XContent xContent, String data) throws IOException {
|
||||
return xContent.createParser(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link XContentParser}.
|
||||
*/
|
||||
protected final XContentParser createParser(XContent xContent, InputStream data) throws IOException {
|
||||
return xContent.createParser(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link XContentParser}.
|
||||
*/
|
||||
protected final XContentParser createParser(XContent xContent, byte[] data) throws IOException {
|
||||
return xContent.createParser(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link XContentParser}.
|
||||
*/
|
||||
protected final XContentParser createParser(XContent xContent, BytesReference data) throws IOException {
|
||||
return xContent.createParser(data);
|
||||
}
|
||||
|
||||
/** Returns the suite failure marker: internal use only! */
|
||||
|
|
|
@ -25,7 +25,10 @@ import org.junit.After;
|
|||
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
public abstract class AbstractParserTestCase extends ESTestCase {
|
||||
/**
|
||||
* Superclass for tests of subclasses of {@link ClientYamlTestFragmentParser}.
|
||||
*/
|
||||
public abstract class AbstractClientYamlTestFragmentParserTestCase extends ESTestCase {
|
||||
|
||||
protected XContentParser parser;
|
||||
|
|
@ -19,13 +19,6 @@
|
|||
package org.elasticsearch.test.rest.yaml.parser;
|
||||
|
||||
import org.elasticsearch.common.xcontent.yaml.YamlXContent;
|
||||
import org.elasticsearch.test.rest.yaml.parser.GreaterThanParser;
|
||||
import org.elasticsearch.test.rest.yaml.parser.IsFalseParser;
|
||||
import org.elasticsearch.test.rest.yaml.parser.IsTrueParser;
|
||||
import org.elasticsearch.test.rest.yaml.parser.LengthParser;
|
||||
import org.elasticsearch.test.rest.yaml.parser.LessThanParser;
|
||||
import org.elasticsearch.test.rest.yaml.parser.MatchParser;
|
||||
import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestSuiteParseContext;
|
||||
import org.elasticsearch.test.rest.yaml.section.GreaterThanAssertion;
|
||||
import org.elasticsearch.test.rest.yaml.section.IsFalseAssertion;
|
||||
import org.elasticsearch.test.rest.yaml.section.IsTrueAssertion;
|
||||
|
@ -40,9 +33,9 @@ import static org.hamcrest.Matchers.equalTo;
|
|||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
|
||||
public class AssertionParsersTests extends AbstractParserTestCase {
|
||||
public class AssertionParsersTests extends AbstractClientYamlTestFragmentParserTestCase {
|
||||
public void testParseIsTrue() throws Exception {
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
"get.fields._timestamp"
|
||||
);
|
||||
|
||||
|
@ -54,7 +47,7 @@ public class AssertionParsersTests extends AbstractParserTestCase {
|
|||
}
|
||||
|
||||
public void testParseIsFalse() throws Exception {
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
"docs.1._source"
|
||||
);
|
||||
|
||||
|
@ -66,7 +59,7 @@ public class AssertionParsersTests extends AbstractParserTestCase {
|
|||
}
|
||||
|
||||
public void testParseGreaterThan() throws Exception {
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
"{ field: 3}"
|
||||
);
|
||||
|
||||
|
@ -79,7 +72,7 @@ public class AssertionParsersTests extends AbstractParserTestCase {
|
|||
}
|
||||
|
||||
public void testParseLessThan() throws Exception {
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
"{ field: 3}"
|
||||
);
|
||||
|
||||
|
@ -92,7 +85,7 @@ public class AssertionParsersTests extends AbstractParserTestCase {
|
|||
}
|
||||
|
||||
public void testParseLength() throws Exception {
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
"{ _id: 22}"
|
||||
);
|
||||
|
||||
|
@ -105,7 +98,7 @@ public class AssertionParsersTests extends AbstractParserTestCase {
|
|||
}
|
||||
|
||||
public void testParseMatchSimpleIntegerValue() throws Exception {
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
"{ field: 10 }"
|
||||
);
|
||||
|
||||
|
@ -119,7 +112,7 @@ public class AssertionParsersTests extends AbstractParserTestCase {
|
|||
}
|
||||
|
||||
public void testParseMatchSimpleStringValue() throws Exception {
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
"{ foo: bar }"
|
||||
);
|
||||
|
||||
|
@ -133,7 +126,7 @@ public class AssertionParsersTests extends AbstractParserTestCase {
|
|||
}
|
||||
|
||||
public void testParseMatchArray() throws Exception {
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
"{'matches': ['test_percolator_1', 'test_percolator_2']}"
|
||||
);
|
||||
|
||||
|
@ -151,7 +144,7 @@ public class AssertionParsersTests extends AbstractParserTestCase {
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testParseMatchSourceValues() throws Exception {
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
"{ _source: { responses.0.hits.total: 3, foo: bar }}"
|
||||
);
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ public class ClientYamlSuiteTestParserTests extends ESTestCase {
|
|||
" index: test_index\n" +
|
||||
"\n");
|
||||
}
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
testSpecBuilder.toString() +
|
||||
"---\n" +
|
||||
"\"Get index mapping\":\n" +
|
||||
|
@ -177,7 +177,7 @@ public class ClientYamlSuiteTestParserTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testParseTestSingleTestSection() throws Exception {
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
"---\n" +
|
||||
"\"Index with ID\":\n" +
|
||||
"\n" +
|
||||
|
@ -275,7 +275,7 @@ public class ClientYamlSuiteTestParserTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testParseTestMultipleTestSections() throws Exception {
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
"---\n" +
|
||||
"\"Missing document (partial doc)\":\n" +
|
||||
"\n" +
|
||||
|
@ -366,7 +366,7 @@ public class ClientYamlSuiteTestParserTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testParseTestDuplicateTestSections() throws Exception {
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
"---\n" +
|
||||
"\"Missing document (script)\":\n" +
|
||||
"\n" +
|
||||
|
|
|
@ -19,11 +19,7 @@
|
|||
package org.elasticsearch.test.rest.yaml.parser;
|
||||
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.common.xcontent.yaml.YamlXContent;
|
||||
import org.elasticsearch.test.rest.yaml.parser.DoSectionParser;
|
||||
import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException;
|
||||
import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestSuiteParseContext;
|
||||
import org.elasticsearch.test.rest.yaml.section.ApiCallSection;
|
||||
import org.elasticsearch.test.rest.yaml.section.DoSection;
|
||||
import org.hamcrest.MatcherAssert;
|
||||
|
@ -38,9 +34,9 @@ import static org.hamcrest.Matchers.is;
|
|||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
public class DoSectionParserTests extends AbstractParserTestCase {
|
||||
public class DoSectionParserTests extends AbstractClientYamlTestFragmentParserTestCase {
|
||||
public void testParseDoSectionNoBody() throws Exception {
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
"get:\n" +
|
||||
" index: test_index\n" +
|
||||
" type: test_type\n" +
|
||||
|
@ -61,7 +57,7 @@ public class DoSectionParserTests extends AbstractParserTestCase {
|
|||
}
|
||||
|
||||
public void testParseDoSectionNoParamsNoBody() throws Exception {
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
"cluster.node_info: {}"
|
||||
);
|
||||
|
||||
|
@ -77,7 +73,7 @@ public class DoSectionParserTests extends AbstractParserTestCase {
|
|||
|
||||
public void testParseDoSectionWithJsonBody() throws Exception {
|
||||
String body = "{ \"include\": { \"field1\": \"v1\", \"field2\": \"v2\" }, \"count\": 1 }";
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
"index:\n" +
|
||||
" index: test_1\n" +
|
||||
" type: test\n" +
|
||||
|
@ -107,7 +103,7 @@ public class DoSectionParserTests extends AbstractParserTestCase {
|
|||
"{ \"index\": { \"_index\":\"test_index2\", \"_type\":\"test_type2\", \"_id\":\"test_id2\" } }\n",
|
||||
"{ \"f1\":\"v2\", \"f2\":47 }\n"
|
||||
};
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
"bulk:\n" +
|
||||
" refresh: true\n" +
|
||||
" body: |\n" +
|
||||
|
@ -134,7 +130,7 @@ public class DoSectionParserTests extends AbstractParserTestCase {
|
|||
"{ \"index\": { \"_index\":\"test_index\", \"_type\":\"test_type\", \"_id\":\"test_id\" } }",
|
||||
"{ \"f1\":\"v1\", \"f2\":42 }",
|
||||
};
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
"bulk:\n" +
|
||||
" refresh: true\n" +
|
||||
" body: \n" +
|
||||
|
@ -159,7 +155,7 @@ public class DoSectionParserTests extends AbstractParserTestCase {
|
|||
}
|
||||
|
||||
public void testParseDoSectionWithYamlBody() throws Exception {
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
"search:\n" +
|
||||
" body:\n" +
|
||||
" \"_source\": [ include.field1, include.field2 ]\n" +
|
||||
|
@ -180,7 +176,7 @@ public class DoSectionParserTests extends AbstractParserTestCase {
|
|||
}
|
||||
|
||||
public void testParseDoSectionWithYamlMultipleBodies() throws Exception {
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
"bulk:\n" +
|
||||
" refresh: true\n" +
|
||||
" body:\n" +
|
||||
|
@ -220,7 +216,7 @@ public class DoSectionParserTests extends AbstractParserTestCase {
|
|||
}
|
||||
|
||||
public void testParseDoSectionWithYamlMultipleBodiesRepeatedProperty() throws Exception {
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
"bulk:\n" +
|
||||
" refresh: true\n" +
|
||||
" body:\n" +
|
||||
|
@ -253,7 +249,7 @@ public class DoSectionParserTests extends AbstractParserTestCase {
|
|||
}
|
||||
|
||||
public void testParseDoSectionWithYamlBodyMultiGet() throws Exception {
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
"mget:\n" +
|
||||
" body:\n" +
|
||||
" docs:\n" +
|
||||
|
@ -278,7 +274,7 @@ public class DoSectionParserTests extends AbstractParserTestCase {
|
|||
}
|
||||
|
||||
public void testParseDoSectionWithBodyStringified() throws Exception {
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
"index:\n" +
|
||||
" index: test_1\n" +
|
||||
" type: test\n" +
|
||||
|
@ -303,7 +299,7 @@ public class DoSectionParserTests extends AbstractParserTestCase {
|
|||
}
|
||||
|
||||
public void testParseDoSectionWithBodiesStringifiedAndNot() throws Exception {
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
"index:\n" +
|
||||
" body:\n" +
|
||||
" - \"{ \\\"_source\\\": true, \\\"query\\\": { \\\"match_all\\\": {} } }\"\n" +
|
||||
|
@ -326,7 +322,7 @@ public class DoSectionParserTests extends AbstractParserTestCase {
|
|||
}
|
||||
|
||||
public void testParseDoSectionWithCatch() throws Exception {
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
"catch: missing\n" +
|
||||
"indices.get_warmer:\n" +
|
||||
" index: test_index\n" +
|
||||
|
@ -344,7 +340,7 @@ public class DoSectionParserTests extends AbstractParserTestCase {
|
|||
}
|
||||
|
||||
public void testParseDoSectionWithHeaders() throws Exception {
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
"headers:\n" +
|
||||
" Authorization: \"thing one\"\n" +
|
||||
" Content-Type: \"application/json\"\n" +
|
||||
|
@ -367,7 +363,7 @@ public class DoSectionParserTests extends AbstractParserTestCase {
|
|||
}
|
||||
|
||||
public void testParseDoSectionWithoutClientCallSection() throws Exception {
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
"catch: missing\n"
|
||||
);
|
||||
|
||||
|
@ -381,7 +377,7 @@ public class DoSectionParserTests extends AbstractParserTestCase {
|
|||
}
|
||||
|
||||
public void testParseDoSectionMultivaluedField() throws Exception {
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
"indices.get_field_mapping:\n" +
|
||||
" index: test_index\n" +
|
||||
" type: test_type\n" +
|
||||
|
@ -403,7 +399,7 @@ public class DoSectionParserTests extends AbstractParserTestCase {
|
|||
}
|
||||
|
||||
public void testParseDoSectionExpectedWarnings() throws Exception {
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
"indices.get_field_mapping:\n" +
|
||||
" index: test_index\n" +
|
||||
" type: test_type\n" +
|
||||
|
@ -427,7 +423,7 @@ public class DoSectionParserTests extends AbstractParserTestCase {
|
|||
"some test warning they are typically pretty long",
|
||||
"some other test warning somtimes they have [in] them")));
|
||||
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
"indices.get_field_mapping:\n" +
|
||||
" index: test_index\n" +
|
||||
"warnings:\n" +
|
||||
|
@ -442,9 +438,9 @@ public class DoSectionParserTests extends AbstractParserTestCase {
|
|||
|
||||
}
|
||||
|
||||
private static void assertJsonEquals(Map<String, Object> actual, String expected) throws IOException {
|
||||
private void assertJsonEquals(Map<String, Object> actual, String expected) throws IOException {
|
||||
Map<String,Object> expectedMap;
|
||||
try (XContentParser parser = JsonXContent.jsonXContent.createParser(expected)) {
|
||||
try (XContentParser parser = createParser(YamlXContent.yamlXContent, expected)) {
|
||||
expectedMap = parser.mapOrdered();
|
||||
}
|
||||
MatcherAssert.assertThat(actual, equalTo(expectedMap));
|
||||
|
|
|
@ -19,18 +19,15 @@
|
|||
package org.elasticsearch.test.rest.yaml.parser;
|
||||
|
||||
import org.elasticsearch.common.xcontent.yaml.YamlXContent;
|
||||
import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException;
|
||||
import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestSuiteParseContext;
|
||||
import org.elasticsearch.test.rest.yaml.parser.SetSectionParser;
|
||||
import org.elasticsearch.test.rest.yaml.section.SetSection;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
|
||||
public class SetSectionParserTests extends AbstractParserTestCase {
|
||||
public class SetSectionParserTests extends AbstractClientYamlTestFragmentParserTestCase {
|
||||
public void testParseSetSectionSingleValue() throws Exception {
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
"{ _id: id }"
|
||||
);
|
||||
|
||||
|
@ -45,7 +42,7 @@ public class SetSectionParserTests extends AbstractParserTestCase {
|
|||
}
|
||||
|
||||
public void testParseSetSectionMultipleValues() throws Exception {
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
"{ _id: id, _type: type, _index: index }"
|
||||
);
|
||||
|
||||
|
@ -62,7 +59,7 @@ public class SetSectionParserTests extends AbstractParserTestCase {
|
|||
}
|
||||
|
||||
public void testParseSetSectionNoValues() throws Exception {
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
"{ }"
|
||||
);
|
||||
|
||||
|
|
|
@ -20,16 +20,14 @@ package org.elasticsearch.test.rest.yaml.parser;
|
|||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.common.xcontent.yaml.YamlXContent;
|
||||
import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestSuiteParseContext;
|
||||
import org.elasticsearch.test.rest.yaml.parser.SetupSectionParser;
|
||||
import org.elasticsearch.test.rest.yaml.section.SetupSection;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
|
||||
public class SetupSectionParserTests extends AbstractParserTestCase {
|
||||
public class SetupSectionParserTests extends AbstractClientYamlTestFragmentParserTestCase {
|
||||
public void testParseSetupSection() throws Exception {
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
" - do:\n" +
|
||||
" index1:\n" +
|
||||
" index: test_1\n" +
|
||||
|
@ -55,7 +53,7 @@ public class SetupSectionParserTests extends AbstractParserTestCase {
|
|||
}
|
||||
|
||||
public void testParseSetupAndSkipSectionNoSkip() throws Exception {
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
" - skip:\n" +
|
||||
" version: \"2.0.0 - 2.3.0\"\n" +
|
||||
" reason: \"Update doesn't return metadata fields, waiting for #3259\"\n" +
|
||||
|
|
|
@ -21,9 +21,6 @@ package org.elasticsearch.test.rest.yaml.parser;
|
|||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.common.xcontent.yaml.YamlXContent;
|
||||
import org.elasticsearch.test.VersionUtils;
|
||||
import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestParseException;
|
||||
import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestSuiteParseContext;
|
||||
import org.elasticsearch.test.rest.yaml.parser.SkipSectionParser;
|
||||
import org.elasticsearch.test.rest.yaml.section.SkipSection;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
@ -33,9 +30,9 @@ import static org.hamcrest.Matchers.is;
|
|||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
public class SkipSectionParserTests extends AbstractParserTestCase {
|
||||
public class SkipSectionParserTests extends AbstractClientYamlTestFragmentParserTestCase {
|
||||
public void testParseSkipSectionVersionNoFeature() throws Exception {
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
"version: \" - 2.1.0\"\n" +
|
||||
"reason: Delete ignores the parent param"
|
||||
);
|
||||
|
@ -52,7 +49,7 @@ public class SkipSectionParserTests extends AbstractParserTestCase {
|
|||
}
|
||||
|
||||
public void testParseSkipSectionAllVersions() throws Exception {
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
"version: \" all \"\n" +
|
||||
"reason: Delete ignores the parent param"
|
||||
);
|
||||
|
@ -69,7 +66,7 @@ public class SkipSectionParserTests extends AbstractParserTestCase {
|
|||
}
|
||||
|
||||
public void testParseSkipSectionFeatureNoVersion() throws Exception {
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
"features: regex"
|
||||
);
|
||||
|
||||
|
@ -85,7 +82,7 @@ public class SkipSectionParserTests extends AbstractParserTestCase {
|
|||
}
|
||||
|
||||
public void testParseSkipSectionFeaturesNoVersion() throws Exception {
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
"features: [regex1,regex2,regex3]"
|
||||
);
|
||||
|
||||
|
@ -103,7 +100,7 @@ public class SkipSectionParserTests extends AbstractParserTestCase {
|
|||
}
|
||||
|
||||
public void testParseSkipSectionBothFeatureAndVersion() throws Exception {
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
"version: \" - 0.90.2\"\n" +
|
||||
"features: regex\n" +
|
||||
"reason: Delete ignores the parent param"
|
||||
|
@ -118,7 +115,7 @@ public class SkipSectionParserTests extends AbstractParserTestCase {
|
|||
}
|
||||
|
||||
public void testParseSkipSectionNoReason() throws Exception {
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
"version: \" - 0.90.2\"\n"
|
||||
);
|
||||
|
||||
|
@ -132,7 +129,7 @@ public class SkipSectionParserTests extends AbstractParserTestCase {
|
|||
}
|
||||
|
||||
public void testParseSkipSectionNoVersionNorFeature() throws Exception {
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
"reason: Delete ignores the parent param\n"
|
||||
);
|
||||
|
||||
|
|
|
@ -31,10 +31,10 @@ import static org.hamcrest.Matchers.notNullValue;
|
|||
/**
|
||||
* Unit tests for the teardown section parser
|
||||
*/
|
||||
public class TeardownSectionParserTests extends AbstractParserTestCase {
|
||||
public class TeardownSectionParserTests extends AbstractClientYamlTestFragmentParserTestCase {
|
||||
|
||||
public void testParseTeardownSection() throws Exception {
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
" - do:\n" +
|
||||
" delete:\n" +
|
||||
" index: foo\n" +
|
||||
|
@ -60,7 +60,7 @@ public class TeardownSectionParserTests extends AbstractParserTestCase {
|
|||
}
|
||||
|
||||
public void testParseWithSkip() throws Exception {
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
" - skip:\n" +
|
||||
" version: \"2.0.0 - 2.3.0\"\n" +
|
||||
" reason: \"there is a reason\"\n" +
|
||||
|
|
|
@ -20,8 +20,7 @@ package org.elasticsearch.test.rest.yaml.parser;
|
|||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.common.xcontent.yaml.YamlXContent;
|
||||
import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestSectionParser;
|
||||
import org.elasticsearch.test.rest.yaml.parser.ClientYamlTestSuiteParseContext;
|
||||
import org.elasticsearch.test.rest.yaml.section.ClientYamlTestSection;
|
||||
import org.elasticsearch.test.rest.yaml.section.DoSection;
|
||||
import org.elasticsearch.test.rest.yaml.section.GreaterThanAssertion;
|
||||
import org.elasticsearch.test.rest.yaml.section.IsFalseAssertion;
|
||||
|
@ -31,7 +30,6 @@ import org.elasticsearch.test.rest.yaml.section.LessThanAssertion;
|
|||
import org.elasticsearch.test.rest.yaml.section.MatchAssertion;
|
||||
import org.elasticsearch.test.rest.yaml.section.SetSection;
|
||||
import org.elasticsearch.test.rest.yaml.section.SkipSection;
|
||||
import org.elasticsearch.test.rest.yaml.section.ClientYamlTestSection;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -40,9 +38,9 @@ import static org.hamcrest.Matchers.instanceOf;
|
|||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
public class TestSectionParserTests extends AbstractParserTestCase {
|
||||
public class TestSectionParserTests extends AbstractClientYamlTestFragmentParserTestCase {
|
||||
public void testParseTestSectionWithDoSection() throws Exception {
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
"\"First test section\": \n" +
|
||||
" - do :\n" +
|
||||
" catch: missing\n" +
|
||||
|
@ -81,7 +79,7 @@ public class TestSectionParserTests extends AbstractParserTestCase {
|
|||
|
||||
|
||||
ClientYamlTestSectionParser testSectionParser = new ClientYamlTestSectionParser();
|
||||
parser = YamlXContent.yamlXContent.createParser(yaml);
|
||||
parser = createParser(YamlXContent.yamlXContent,yaml);
|
||||
ClientYamlTestSection testSection = testSectionParser.parse(new ClientYamlTestSuiteParseContext("api", "suite", parser));
|
||||
|
||||
assertThat(testSection, notNullValue());
|
||||
|
@ -103,7 +101,7 @@ public class TestSectionParserTests extends AbstractParserTestCase {
|
|||
}
|
||||
|
||||
public void testParseTestSectionWithMultipleDoSections() throws Exception {
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
"\"Basic\":\n" +
|
||||
"\n" +
|
||||
" - do:\n" +
|
||||
|
@ -141,7 +139,7 @@ public class TestSectionParserTests extends AbstractParserTestCase {
|
|||
}
|
||||
|
||||
public void testParseTestSectionWithDoSectionsAndAssertions() throws Exception {
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
"\"Basic\":\n" +
|
||||
"\n" +
|
||||
" - do:\n" +
|
||||
|
@ -235,7 +233,7 @@ public class TestSectionParserTests extends AbstractParserTestCase {
|
|||
}
|
||||
|
||||
public void testSmallSection() throws Exception {
|
||||
parser = YamlXContent.yamlXContent.createParser(
|
||||
parser = createParser(YamlXContent.yamlXContent,
|
||||
"\"node_info test\":\n" +
|
||||
" - do:\n" +
|
||||
" cluster.node_info: {}\n" +
|
||||
|
|
|
@ -19,11 +19,8 @@
|
|||
package org.elasticsearch.test.rest.yaml.restspec;
|
||||
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.common.xcontent.yaml.YamlXContent;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.test.rest.yaml.restspec.ClientYamlSuiteRestApiParser;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
|
||||
|
@ -144,7 +141,7 @@ public class ClientYamlSuiteRestApiParserFailingTests extends ESTestCase {
|
|||
}
|
||||
|
||||
private void parseAndExpectFailure(String brokenJson, String expectedErrorMessage) throws Exception {
|
||||
XContentParser parser = JsonXContent.jsonXContent.createParser(brokenJson);
|
||||
XContentParser parser = createParser(YamlXContent.yamlXContent, brokenJson);
|
||||
ClientYamlSuiteRestApiParser restApiParser = new ClientYamlSuiteRestApiParser();
|
||||
|
||||
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> restApiParser.parse("location", parser));
|
||||
|
|
|
@ -18,18 +18,16 @@
|
|||
*/
|
||||
package org.elasticsearch.test.rest.yaml.restspec;
|
||||
|
||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.test.rest.yaml.parser.AbstractParserTestCase;
|
||||
import org.elasticsearch.test.rest.yaml.restspec.ClientYamlSuiteRestApi;
|
||||
import org.elasticsearch.test.rest.yaml.restspec.ClientYamlSuiteRestApiParser;
|
||||
import org.elasticsearch.common.xcontent.yaml.YamlXContent;
|
||||
import org.elasticsearch.test.rest.yaml.parser.AbstractClientYamlTestFragmentParserTestCase;
|
||||
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
|
||||
public class ClientYamlSuiteRestApiParserTests extends AbstractParserTestCase {
|
||||
public class ClientYamlSuiteRestApiParserTests extends AbstractClientYamlTestFragmentParserTestCase {
|
||||
public void testParseRestSpecIndexApi() throws Exception {
|
||||
parser = JsonXContent.jsonXContent.createParser(REST_SPEC_INDEX_API);
|
||||
parser = createParser(YamlXContent.yamlXContent, REST_SPEC_INDEX_API);
|
||||
ClientYamlSuiteRestApi restApi = new ClientYamlSuiteRestApiParser().parse("location", parser);
|
||||
|
||||
assertThat(restApi, notNullValue());
|
||||
|
@ -51,7 +49,7 @@ public class ClientYamlSuiteRestApiParserTests extends AbstractParserTestCase {
|
|||
}
|
||||
|
||||
public void testParseRestSpecGetTemplateApi() throws Exception {
|
||||
parser = JsonXContent.jsonXContent.createParser(REST_SPEC_GET_TEMPLATE_API);
|
||||
parser = createParser(YamlXContent.yamlXContent, REST_SPEC_GET_TEMPLATE_API);
|
||||
ClientYamlSuiteRestApi restApi = new ClientYamlSuiteRestApiParser().parse("location", parser);
|
||||
assertThat(restApi, notNullValue());
|
||||
assertThat(restApi.getName(), equalTo("indices.get_template"));
|
||||
|
@ -68,7 +66,7 @@ public class ClientYamlSuiteRestApiParserTests extends AbstractParserTestCase {
|
|||
}
|
||||
|
||||
public void testParseRestSpecCountApi() throws Exception {
|
||||
parser = JsonXContent.jsonXContent.createParser(REST_SPEC_COUNT_API);
|
||||
parser = createParser(YamlXContent.yamlXContent, REST_SPEC_COUNT_API);
|
||||
ClientYamlSuiteRestApi restApi = new ClientYamlSuiteRestApiParser().parse("location", parser);
|
||||
assertThat(restApi, notNullValue());
|
||||
assertThat(restApi.getName(), equalTo("count"));
|
||||
|
|
Loading…
Reference in New Issue