Centralize remaining XContentParser creation in tests
Now we're ready to add `NamedXContentRegistry`.
This commit is contained in:
parent
a8b238ebad
commit
1eddff822a
|
@ -20,7 +20,7 @@
|
||||||
package org.elasticsearch.action.fieldstats;
|
package org.elasticsearch.action.fieldstats;
|
||||||
|
|
||||||
import org.elasticsearch.common.bytes.BytesArray;
|
import org.elasticsearch.common.bytes.BytesArray;
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||||
import org.elasticsearch.test.ESTestCase;
|
import org.elasticsearch.test.ESTestCase;
|
||||||
import org.elasticsearch.test.StreamsUtils;
|
import org.elasticsearch.test.StreamsUtils;
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ public class FieldStatsRequestTests extends ESTestCase {
|
||||||
StreamsUtils.copyToBytesFromClasspath("/org/elasticsearch/action/fieldstats/" +
|
StreamsUtils.copyToBytesFromClasspath("/org/elasticsearch/action/fieldstats/" +
|
||||||
"fieldstats-index-constraints-request.json"));
|
"fieldstats-index-constraints-request.json"));
|
||||||
FieldStatsRequest request = new FieldStatsRequest();
|
FieldStatsRequest request = new FieldStatsRequest();
|
||||||
request.source(XContentFactory.xContent(data).createParser(data));
|
request.source(createParser(JsonXContent.jsonXContent, data));
|
||||||
|
|
||||||
assertThat(request.getFields().length, equalTo(5));
|
assertThat(request.getFields().length, equalTo(5));
|
||||||
assertThat(request.getFields()[0], equalTo("field1"));
|
assertThat(request.getFields()[0], equalTo("field1"));
|
||||||
|
|
|
@ -21,6 +21,7 @@ package org.elasticsearch.common.xcontent;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonGenerationException;
|
import com.fasterxml.jackson.core.JsonGenerationException;
|
||||||
import com.fasterxml.jackson.core.JsonGenerator;
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
|
|
||||||
import org.apache.lucene.util.BytesRef;
|
import org.apache.lucene.util.BytesRef;
|
||||||
import org.apache.lucene.util.Constants;
|
import org.apache.lucene.util.Constants;
|
||||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||||
|
@ -268,7 +269,7 @@ public abstract class BaseXContentTestCase extends ESTestCase {
|
||||||
final byte[] randomBytes = randomBytes();
|
final byte[] randomBytes = randomBytes();
|
||||||
BytesReference bytes = builder().startObject().field("binary", randomBytes).endObject().bytes();
|
BytesReference bytes = builder().startObject().field("binary", randomBytes).endObject().bytes();
|
||||||
|
|
||||||
XContentParser parser = xcontentType().xContent().createParser(bytes);
|
XContentParser parser = createParser(xcontentType().xContent(), bytes);
|
||||||
assertSame(parser.nextToken(), Token.START_OBJECT);
|
assertSame(parser.nextToken(), Token.START_OBJECT);
|
||||||
assertSame(parser.nextToken(), Token.FIELD_NAME);
|
assertSame(parser.nextToken(), Token.FIELD_NAME);
|
||||||
assertEquals(parser.currentName(), "binary");
|
assertEquals(parser.currentName(), "binary");
|
||||||
|
@ -284,7 +285,7 @@ public abstract class BaseXContentTestCase extends ESTestCase {
|
||||||
final byte[] randomBytes = randomBytes();
|
final byte[] randomBytes = randomBytes();
|
||||||
BytesReference bytes = builder().startObject().field("binary").value(randomBytes).endObject().bytes();
|
BytesReference bytes = builder().startObject().field("binary").value(randomBytes).endObject().bytes();
|
||||||
|
|
||||||
XContentParser parser = xcontentType().xContent().createParser(bytes);
|
XContentParser parser = createParser(xcontentType().xContent(), bytes);
|
||||||
assertSame(parser.nextToken(), Token.START_OBJECT);
|
assertSame(parser.nextToken(), Token.START_OBJECT);
|
||||||
assertSame(parser.nextToken(), Token.FIELD_NAME);
|
assertSame(parser.nextToken(), Token.FIELD_NAME);
|
||||||
assertEquals(parser.currentName(), "binary");
|
assertEquals(parser.currentName(), "binary");
|
||||||
|
@ -309,7 +310,7 @@ public abstract class BaseXContentTestCase extends ESTestCase {
|
||||||
}
|
}
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
|
|
||||||
XContentParser parser = xcontentType().xContent().createParser(builder.bytes());
|
XContentParser parser = createParser(xcontentType().xContent(), builder.bytes());
|
||||||
assertSame(parser.nextToken(), Token.START_OBJECT);
|
assertSame(parser.nextToken(), Token.START_OBJECT);
|
||||||
assertSame(parser.nextToken(), Token.FIELD_NAME);
|
assertSame(parser.nextToken(), Token.FIELD_NAME);
|
||||||
assertEquals(parser.currentName(), "bin");
|
assertEquals(parser.currentName(), "bin");
|
||||||
|
@ -331,7 +332,7 @@ public abstract class BaseXContentTestCase extends ESTestCase {
|
||||||
}
|
}
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
|
|
||||||
XContentParser parser = xcontentType().xContent().createParser(builder.bytes());
|
XContentParser parser = createParser(xcontentType().xContent(), builder.bytes());
|
||||||
assertSame(parser.nextToken(), Token.START_OBJECT);
|
assertSame(parser.nextToken(), Token.START_OBJECT);
|
||||||
assertSame(parser.nextToken(), Token.FIELD_NAME);
|
assertSame(parser.nextToken(), Token.FIELD_NAME);
|
||||||
assertEquals(parser.currentName(), "utf8");
|
assertEquals(parser.currentName(), "utf8");
|
||||||
|
@ -349,7 +350,7 @@ public abstract class BaseXContentTestCase extends ESTestCase {
|
||||||
final BytesReference random = new BytesArray(randomBytes());
|
final BytesReference random = new BytesArray(randomBytes());
|
||||||
XContentBuilder builder = builder().startObject().field("text", new Text(random)).endObject();
|
XContentBuilder builder = builder().startObject().field("text", new Text(random)).endObject();
|
||||||
|
|
||||||
XContentParser parser = xcontentType().xContent().createParser(builder.bytes());
|
XContentParser parser = createParser(xcontentType().xContent(), builder.bytes());
|
||||||
assertSame(parser.nextToken(), Token.START_OBJECT);
|
assertSame(parser.nextToken(), Token.START_OBJECT);
|
||||||
assertSame(parser.nextToken(), Token.FIELD_NAME);
|
assertSame(parser.nextToken(), Token.FIELD_NAME);
|
||||||
assertEquals(parser.currentName(), "text");
|
assertEquals(parser.currentName(), "text");
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
package org.elasticsearch.threadpool;
|
package org.elasticsearch.threadpool;
|
||||||
|
|
||||||
import org.elasticsearch.Version;
|
import org.elasticsearch.Version;
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
|
||||||
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
|
@ -27,9 +26,7 @@ import org.elasticsearch.common.unit.SizeValue;
|
||||||
import org.elasticsearch.common.unit.TimeValue;
|
import org.elasticsearch.common.unit.TimeValue;
|
||||||
import org.elasticsearch.common.xcontent.ToXContent;
|
import org.elasticsearch.common.xcontent.ToXContent;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
|
||||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
|
||||||
import org.elasticsearch.test.ESTestCase;
|
import org.elasticsearch.test.ESTestCase;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
|
||||||
|
@ -81,11 +78,7 @@ public class ThreadPoolSerializationTests extends ESTestCase {
|
||||||
info.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
info.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
|
|
||||||
BytesReference bytesReference = builder.bytes();
|
Map<String, Object> map = XContentHelper.convertToMap(builder.bytes(), false).v2();
|
||||||
Map<String, Object> map;
|
|
||||||
try (XContentParser parser = XContentFactory.xContent(bytesReference).createParser(bytesReference)) {
|
|
||||||
map = parser.map();
|
|
||||||
}
|
|
||||||
assertThat(map, hasKey("foo"));
|
assertThat(map, hasKey("foo"));
|
||||||
map = (Map<String, Object>) map.get("foo");
|
map = (Map<String, Object>) map.get("foo");
|
||||||
assertThat(map, hasKey("queue_size"));
|
assertThat(map, hasKey("queue_size"));
|
||||||
|
|
Loading…
Reference in New Issue