Start centralizing XContentParser creation in tests

Original commit: elastic/x-pack-elasticsearch@65be7ecd27
This commit is contained in:
Nik Everett 2016-12-13 15:52:59 -05:00
parent c3d8fd4191
commit d4939e1972
43 changed files with 144 additions and 170 deletions

View File

@ -6,13 +6,13 @@
package org.elasticsearch.xpack.common.http;
import io.netty.handler.codec.http.HttpHeaders;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.unit.TimeValue;
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 org.elasticsearch.xpack.common.http.auth.HttpAuthRegistry;
import org.elasticsearch.xpack.common.http.auth.basic.BasicAuth;
@ -84,7 +84,7 @@ public class HttpRequestTemplateTests extends ESTestCase {
HttpRequestTemplate template = builder.build();
XContentBuilder xContentBuilder = template.toXContent(jsonBuilder(), ToXContent.EMPTY_PARAMS);
XContentParser xContentParser = JsonXContent.jsonXContent.createParser(xContentBuilder.bytes());
XContentParser xContentParser = createParser(xContentBuilder);
xContentParser.nextToken();
HttpRequestTemplate.Parser parser = new HttpRequestTemplate.Parser(mock(HttpAuthRegistry.class));
@ -139,7 +139,7 @@ public class HttpRequestTemplateTests extends ESTestCase {
HttpRequestTemplate.Parser parser = new HttpRequestTemplate.Parser(registry);
XContentBuilder xContentBuilder = template.toXContent(jsonBuilder(), ToXContent.EMPTY_PARAMS);
XContentParser xContentParser = JsonXContent.jsonXContent.createParser(xContentBuilder.bytes());
XContentParser xContentParser = createParser(xContentBuilder);
xContentParser.nextToken();
HttpRequestTemplate parsed = parser.parse(xContentParser);
@ -195,14 +195,14 @@ public class HttpRequestTemplateTests extends ESTestCase {
private void assertThatManualBuilderEqualsParsingFromUrl(String url, HttpRequestTemplate.Builder builder) throws Exception {
XContentBuilder urlContentBuilder = jsonBuilder().startObject().field("url", url).endObject();
XContentParser urlContentParser = JsonXContent.jsonXContent.createParser(urlContentBuilder.bytes());
XContentParser urlContentParser = createParser(urlContentBuilder);
urlContentParser.nextToken();
HttpRequestTemplate.Parser parser = new HttpRequestTemplate.Parser(mock(HttpAuthRegistry.class));
HttpRequestTemplate urlParsedTemplate = parser.parse(urlContentParser);
XContentBuilder xContentBuilder = builder.build().toXContent(jsonBuilder(), ToXContent.EMPTY_PARAMS);
XContentParser xContentParser = JsonXContent.jsonXContent.createParser(xContentBuilder.bytes());
XContentParser xContentParser = createParser(xContentBuilder);
xContentParser.nextToken();
HttpRequestTemplate parsedTemplate = parser.parse(xContentParser);

View File

@ -12,7 +12,6 @@ import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.common.http.auth.HttpAuthRegistry;
import org.elasticsearch.xpack.common.http.auth.basic.BasicAuth;
@ -140,14 +139,14 @@ public class HttpRequestTests extends ESTestCase {
private void assertThatManualBuilderEqualsParsingFromUrl(String url, HttpRequest.Builder builder) throws Exception {
XContentBuilder urlContentBuilder = jsonBuilder().startObject().field("url", url).endObject();
XContentParser urlContentParser = JsonXContent.jsonXContent.createParser(urlContentBuilder.bytes());
XContentParser urlContentParser = createParser(urlContentBuilder);
urlContentParser.nextToken();
HttpRequest.Parser parser = new HttpRequest.Parser(mock(HttpAuthRegistry.class));
HttpRequest urlParsedRequest = parser.parse(urlContentParser);
XContentBuilder xContentBuilder = builder.build().toXContent(jsonBuilder(), ToXContent.EMPTY_PARAMS);
XContentParser xContentParser = JsonXContent.jsonXContent.createParser(xContentBuilder.bytes());
XContentParser xContentParser = createParser(xContentBuilder);
xContentParser.nextToken();
HttpRequest parsedRequest = parser.parse(xContentParser);

View File

@ -5,7 +5,6 @@
*/
package org.elasticsearch.xpack.common.text;
import org.elasticsearch.common.ParsingException;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
@ -13,9 +12,9 @@ import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.script.CompiledScript;
import org.elasticsearch.script.ExecutableScript;
import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptService;
import org.elasticsearch.script.ScriptType;
import org.elasticsearch.script.Script;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.watcher.Watcher;
import org.junit.Before;
@ -115,7 +114,7 @@ public class TextTemplateTests extends ESTestCase {
builder.field("params", template.getParams());
builder.endObject();
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken();
TextTemplate parsed = TextTemplate.parse(parser);
assertThat(parsed, notNullValue());
@ -127,7 +126,7 @@ public class TextTemplateTests extends ESTestCase {
XContentBuilder builder = jsonBuilder().value(template);
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken();
TextTemplate parsed = TextTemplate.parse(parser);
assertThat(parsed, notNullValue());
@ -139,7 +138,7 @@ public class TextTemplateTests extends ESTestCase {
.field("unknown_field", "value")
.endObject();
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken();
try {
TextTemplate.parse(parser);
@ -156,7 +155,7 @@ public class TextTemplateTests extends ESTestCase {
.startObject("params").endObject()
.endObject();
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken();
try {
TextTemplate.parse(parser);
@ -172,7 +171,7 @@ public class TextTemplateTests extends ESTestCase {
.startObject("params").endObject()
.endObject();
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken();
try {
TextTemplate.parse(parser);

View File

@ -19,7 +19,6 @@ import org.elasticsearch.xpack.security.authc.support.SecuredString;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import static org.elasticsearch.common.xcontent.support.XContentMapValues.extractValue;
@ -66,7 +65,7 @@ public class MonitoringSettingsFilterTests extends MonitoringIntegTestCase {
headers = new Header[0];
}
Response response = getRestClient().performRequest("GET", "/_nodes/settings", headers);
Map<String, Object> responseMap = JsonXContent.jsonXContent.createParser(response.getEntity().getContent()).map();
Map<String, Object> responseMap = createParser(JsonXContent.jsonXContent, response.getEntity().getContent()).map();
@SuppressWarnings("unchecked")
Map<String, Object> nodes = (Map<String, Object>) responseMap.get("nodes");
for (Object node : nodes.values()) {

View File

@ -9,7 +9,6 @@ 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.test.ESTestCase;
import org.elasticsearch.xpack.common.text.TextTemplate;
import org.elasticsearch.xpack.common.text.TextTemplateEngine;
@ -54,7 +53,7 @@ public class EmailTemplateTests extends ESTestCase {
XContentBuilder builder = XContentFactory.jsonBuilder();
emailTemplate.toXContent(builder, ToXContent.EMPTY_PARAMS);
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
XContentParser parser = createParser(builder);
parser.nextToken();
EmailTemplate.Parser emailTemplateParser = new EmailTemplate.Parser();

View File

@ -9,7 +9,6 @@ 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.test.ESTestCase;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
@ -45,7 +44,7 @@ public class EmailTests extends ESTestCase {
XContentBuilder builder = XContentFactory.jsonBuilder();
email.toXContent(builder, ToXContent.EMPTY_PARAMS);
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
XContentParser parser = createParser(builder);
parser.nextToken();
Email parsedEmail = Email.parse(parser);

View File

@ -31,7 +31,7 @@ public class DataAttachmentParserTests extends ESTestCase {
XContentBuilder builder = jsonBuilder().startObject().startObject(id)
.startObject(DataAttachmentParser.TYPE).field("format", randomFrom("yaml", "json")).endObject()
.endObject().endObject();
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
XContentParser parser = createParser(JsonXContent.jsonXContent, builder.bytes());
logger.info("JSON: {}", builder.string());
EmailAttachments emailAttachments = emailAttachmentsParser.parse(parser);

View File

@ -10,7 +10,6 @@ import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.common.http.HttpRequestTemplate;
import org.elasticsearch.xpack.common.http.Scheme;
@ -58,7 +57,7 @@ public class EmailAttachmentParsersTests extends ESTestCase {
.endObject();
logger.info("JSON: {}", builder.string());
XContentParser xContentParser = JsonXContent.jsonXContent.createParser(builder.bytes());
XContentParser xContentParser = createParser(builder);
EmailAttachments attachments = parser.parse(xContentParser);
assertThat(attachments.getAttachments(), hasSize(2));
@ -80,7 +79,7 @@ public class EmailAttachmentParsersTests extends ESTestCase {
String type = randomAsciiOfLength(8);
builder.startObject().startObject("some-id").startObject(type).endObject().endObject().endObject();
XContentParser xContentParser = JsonXContent.jsonXContent.createParser(builder.bytes());
XContentParser xContentParser = createParser(builder);
try {
parser.parse(xContentParser);
fail("Expected random parser of type [" + type + "] to throw an exception");
@ -130,7 +129,7 @@ public class EmailAttachmentParsersTests extends ESTestCase {
builder.endObject();
logger.info("JSON is: " + builder.string());
XContentParser xContentParser = JsonXContent.jsonXContent.createParser(builder.bytes());
XContentParser xContentParser = createParser(builder);
try {
XContentParser.Token token = xContentParser.currentToken();
assertNull(token);

View File

@ -10,7 +10,6 @@ import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.common.http.HttpClient;
import org.elasticsearch.xpack.common.http.HttpRequest;
@ -89,7 +88,7 @@ public class HttpEmailAttachementParserTests extends ESTestCase {
builder.field("inline", true);
}
builder.endObject().endObject().endObject();
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
XContentParser parser = createParser(builder);
EmailAttachments emailAttachments = emailAttachmentsParser.parse(parser);
assertThat(emailAttachments.getAttachments(), hasSize(1));

View File

@ -7,6 +7,7 @@ package org.elasticsearch.xpack.notification.email.attachment;
import com.fasterxml.jackson.core.io.JsonEOFException;
import com.google.common.collect.Maps;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.settings.Settings;
@ -14,7 +15,6 @@ import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.common.http.HttpClient;
import org.elasticsearch.xpack.common.http.HttpMethod;
@ -123,7 +123,7 @@ public class ReportingAttachmentParserTests extends ESTestCase {
}
builder.endObject().endObject().endObject();
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
XContentParser parser = createParser(builder);
EmailAttachments emailAttachments = emailAttachmentsParser.parse(parser);
assertThat(emailAttachments.getAttachments(), hasSize(1));

View File

@ -45,7 +45,7 @@ public class HipChatMessageTests extends ESTestCase {
}
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken();
assertThat(parser.currentToken(), is(XContentParser.Token.START_OBJECT));
@ -204,7 +204,7 @@ public class HipChatMessageTests extends ESTestCase {
}
BytesReference bytes = jsonBuilder.endObject().bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken();
HipChatMessage.Template template = HipChatMessage.Template.parse(parser);
@ -261,7 +261,7 @@ public class HipChatMessageTests extends ESTestCase {
template.toXContent(jsonBuilder, ToXContent.EMPTY_PARAMS);
BytesReference bytes = jsonBuilder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken();
HipChatMessage.Template parsed = HipChatMessage.Template.parse(parser);

View File

@ -9,7 +9,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.json.JsonXContent;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.common.text.TextTemplate;
import org.elasticsearch.xpack.common.text.TextTemplateEngine;
@ -112,7 +111,7 @@ public class SlackMessageTests extends ESTestCase {
expected.toXContent(builder, ToXContent.EMPTY_PARAMS, includeTarget);
}
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
XContentParser parser = createParser(builder);
parser.nextToken();
from = null;
@ -336,7 +335,7 @@ public class SlackMessageTests extends ESTestCase {
}
jsonBuilder.endObject();
XContentParser parser = JsonXContent.jsonXContent.createParser(jsonBuilder.bytes());
XContentParser parser = createParser(jsonBuilder);
parser.nextToken();
assertThat(parser.currentToken(), is(XContentParser.Token.START_OBJECT));
@ -365,7 +364,7 @@ public class SlackMessageTests extends ESTestCase {
XContentBuilder jsonBuilder = jsonBuilder();
template.toXContent(jsonBuilder, ToXContent.EMPTY_PARAMS);
XContentParser parser = JsonXContent.jsonXContent.createParser(jsonBuilder.bytes());
XContentParser parser = createParser(jsonBuilder);
parser.nextToken();
SlackMessage.Template parsed = SlackMessage.Template.parse(parser);

View File

@ -6,6 +6,7 @@
package org.elasticsearch.xpack.watcher.actions.email;
import io.netty.handler.codec.http.HttpHeaders;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.collect.MapBuilder;
@ -287,7 +288,7 @@ public class EmailActionTests extends ESTestCase {
BytesReference bytes = builder.bytes();
logger.info("email action json [{}]", bytes.utf8ToString());
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken();
ExecutableEmailAction executable = new EmailActionFactory(Settings.EMPTY, emailService, engine,
@ -382,7 +383,7 @@ public class EmailActionTests extends ESTestCase {
executable.toXContent(builder, params);
BytesReference bytes = builder.bytes();
logger.info("{}", bytes.utf8ToString());
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken();
ExecutableEmailAction parsed = new EmailActionFactory(Settings.EMPTY, service, engine, emailAttachmentParser)
@ -412,7 +413,7 @@ public class EmailActionTests extends ESTestCase {
EmailAttachmentsParser emailAttachmentsParser = mock(EmailAttachmentsParser.class);
XContentBuilder builder = jsonBuilder().startObject().field("unknown_field", "value").endObject();
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
XContentParser parser = createParser(builder);
parser.nextToken();
try {
new EmailActionFactory(Settings.EMPTY, emailService, engine, emailAttachmentsParser)
@ -446,7 +447,7 @@ public class EmailActionTests extends ESTestCase {
.endObject()
.endObject()
.endObject();
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
XContentParser parser = createParser(builder);
logger.info("JSON: {}", builder.string());
parser.nextToken();
@ -481,7 +482,7 @@ public class EmailActionTests extends ESTestCase {
.endObject()
.endObject()
.endObject();
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
XContentParser parser = createParser(builder);
logger.info("JSON: {}", builder.string());
parser.nextToken();
@ -536,7 +537,7 @@ public class EmailActionTests extends ESTestCase {
.endObject()
.endObject()
.endObject();
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
XContentParser parser = createParser(builder);
parser.nextToken();

View File

@ -5,12 +5,10 @@
*/
package org.elasticsearch.xpack.watcher.actions.hipchat;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.settings.ClusterSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.common.text.TextTemplateEngine;
import org.elasticsearch.xpack.notification.hipchat.HipChatAccount;
@ -43,7 +41,7 @@ public class HipChatActionFactoryTests extends ESTestCase {
HipChatAction action = hipchatAction("_account1", "_body").build();
XContentBuilder jsonBuilder = jsonBuilder().value(action);
XContentParser parser = JsonXContent.jsonXContent.createParser(jsonBuilder.bytes());
XContentParser parser = createParser(jsonBuilder);
parser.nextToken();
ExecutableHipChatAction parsedAction = factory.parseExecutable("_w1", "_a1", parser);
@ -58,7 +56,7 @@ public class HipChatActionFactoryTests extends ESTestCase {
factory = new HipChatActionFactory(Settings.EMPTY, mock(TextTemplateEngine.class), hipchatService);
HipChatAction action = hipchatAction("_unknown", "_body").build();
XContentBuilder jsonBuilder = jsonBuilder().value(action);
XContentParser parser = JsonXContent.jsonXContent.createParser(jsonBuilder.bytes());
XContentParser parser = createParser(jsonBuilder);
parser.nextToken();
expectThrows(IllegalArgumentException.class, () -> factory.parseExecutable("_w1", "_a1", parser));
}

View File

@ -174,7 +174,7 @@ public class HipChatActionTests extends ESTestCase {
BytesReference bytes = builder.bytes();
logger.info("hipchat action json [{}]", bytes.utf8ToString());
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken();
HipChatAction action = HipChatAction.parse("_watch", "_action", parser);
@ -247,7 +247,7 @@ public class HipChatActionTests extends ESTestCase {
action.toXContent(jsonBuilder, ToXContent.EMPTY_PARAMS);
BytesReference bytes = builder.bytes();
logger.info("{}", bytes.utf8ToString());
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken();
HipChatAction parsedAction = HipChatAction.parse("_watch", "_action", parser);
@ -258,7 +258,7 @@ public class HipChatActionTests extends ESTestCase {
public void testParserInvalid() throws Exception {
XContentBuilder builder = jsonBuilder().startObject().field("unknown_field", "value").endObject();
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
XContentParser parser = createParser(builder);
parser.nextToken();
try {
HipChatAction.parse("_watch", "_action", parser);

View File

@ -13,7 +13,6 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.sort.SortOrder;
@ -195,7 +194,7 @@ public class IndexActionTests extends ESIntegTestCase {
InternalClient internalClient = new InternalClient(client.settings(), client.threadPool(), client, null);
IndexActionFactory actionParser = new IndexActionFactory(Settings.EMPTY, internalClient);
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
XContentParser parser = createParser(builder);
parser.nextToken();
ExecutableIndexAction executable = actionParser.parseExecutable(randomAsciiOfLength(5), randomAsciiOfLength(3), parser);
@ -226,7 +225,7 @@ public class IndexActionTests extends ESIntegTestCase {
InternalClient internalClient = new InternalClient(client.settings(), client.threadPool(), client, null);
IndexActionFactory actionParser = new IndexActionFactory(Settings.EMPTY, internalClient);
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
XContentParser parser = createParser(builder);
parser.nextToken();
try {
actionParser.parseExecutable(randomAsciiOfLength(4), randomAsciiOfLength(5), parser);

View File

@ -9,7 +9,6 @@ import org.elasticsearch.common.settings.ClusterSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.common.text.TextTemplateEngine;
import org.elasticsearch.xpack.notification.jira.JiraAccount;
@ -42,7 +41,7 @@ public class JiraActionFactoryTests extends ESTestCase {
JiraAction action = jiraAction("_account1", randomIssueDefaults()).build();
XContentBuilder jsonBuilder = jsonBuilder().value(action);
XContentParser parser = JsonXContent.jsonXContent.createParser(jsonBuilder.bytes());
XContentParser parser = createParser(jsonBuilder);
parser.nextToken();
JiraAction parsedAction = JiraAction.parse("_w1", "_a1", parser);
@ -56,7 +55,7 @@ public class JiraActionFactoryTests extends ESTestCase {
JiraAction action = jiraAction("_unknown", randomIssueDefaults()).build();
XContentBuilder jsonBuilder = jsonBuilder().value(action);
XContentParser parser = JsonXContent.jsonXContent.createParser(jsonBuilder.bytes());
XContentParser parser = createParser(jsonBuilder);
parser.nextToken();
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> factory.parseExecutable("_w1", "_a1", parser));

View File

@ -76,7 +76,7 @@ public class JiraActionTests extends ESTestCase {
BytesReference bytes = builder.bytes();
logger.info("jira action json [{}]", bytes.utf8ToString());
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken();
JiraAction action = JiraAction.parse("_watch", "_action", parser);
@ -94,7 +94,7 @@ public class JiraActionTests extends ESTestCase {
action.toXContent(builder, ToXContent.EMPTY_PARAMS);
BytesReference bytes = builder.bytes();
logger.info("{}", bytes.utf8ToString());
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken();
JiraAction parsedAction = JiraAction.parse("_watch", "_action", parser);
@ -108,7 +108,7 @@ public class JiraActionTests extends ESTestCase {
public void testParserInvalid() throws Exception {
XContentBuilder builder = jsonBuilder().startObject().field("unknown_field", "value").endObject();
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
XContentParser parser = createParser(builder);
parser.nextToken();
ElasticsearchParseException e = expectThrows(ElasticsearchParseException.class, () -> JiraAction.parse("_w", "_a", parser));

View File

@ -11,7 +11,6 @@ import org.elasticsearch.common.SuppressLoggerChecks;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.common.text.TextTemplate;
import org.elasticsearch.xpack.common.text.TextTemplateEngine;
@ -113,7 +112,7 @@ public class LoggingActionTests extends ESTestCase {
}
builder.endObject();
XContentParser xContentParser = JsonXContent.jsonXContent.createParser(builder.bytes());
XContentParser xContentParser = createParser(builder);
xContentParser.nextToken();
ExecutableLoggingAction executable = parser.parseExecutable(randomAsciiOfLength(5), randomAsciiOfLength(3), xContentParser);
@ -138,7 +137,7 @@ public class LoggingActionTests extends ESTestCase {
XContentBuilder builder = jsonBuilder();
executable.toXContent(builder, Attachment.XContent.EMPTY_PARAMS);
XContentParser xContentParser = JsonXContent.jsonXContent.createParser(builder.bytes());
XContentParser xContentParser = createParser(builder);
xContentParser.nextToken();
ExecutableLoggingAction parsedAction = parser.parseExecutable(randomAsciiOfLength(5), randomAsciiOfLength(5), xContentParser);
@ -162,7 +161,7 @@ public class LoggingActionTests extends ESTestCase {
LoggingAction action = actionBuilder.build();
XContentBuilder builder = jsonBuilder().value(action);
XContentParser xContentParser = JsonXContent.jsonXContent.createParser(builder.bytes());
XContentParser xContentParser = createParser(builder);
assertThat(xContentParser.nextToken(), is(XContentParser.Token.START_OBJECT));
ExecutableLoggingAction executable = parser.parseExecutable(randomAsciiOfLength(4), randomAsciiOfLength(5), xContentParser);
@ -179,7 +178,7 @@ public class LoggingActionTests extends ESTestCase {
XContentBuilder builder = jsonBuilder()
.startObject().endObject();
XContentParser xContentParser = JsonXContent.jsonXContent.createParser(builder.bytes());
XContentParser xContentParser = createParser(builder);
xContentParser.nextToken();
try {

View File

@ -9,7 +9,6 @@ import org.elasticsearch.common.settings.ClusterSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.common.text.TextTemplateEngine;
import org.elasticsearch.xpack.notification.pagerduty.PagerDutyAccount;
@ -42,7 +41,7 @@ public class PagerDutyActionFactoryTests extends ESTestCase {
PagerDutyAction action = triggerPagerDutyAction("_account1", "_description").build();
XContentBuilder jsonBuilder = jsonBuilder().value(action);
XContentParser parser = JsonXContent.jsonXContent.createParser(jsonBuilder.bytes());
XContentParser parser = createParser(jsonBuilder);
parser.nextToken();
PagerDutyAction parsedAction = PagerDutyAction.parse("_w1", "_a1", parser);
@ -54,7 +53,7 @@ public class PagerDutyActionFactoryTests extends ESTestCase {
new ClusterSettings(Settings.EMPTY, Collections.singleton(PagerDutyService.PAGERDUTY_ACCOUNT_SETTING))));
PagerDutyAction action = triggerPagerDutyAction("_unknown", "_body").build();
XContentBuilder jsonBuilder = jsonBuilder().value(action);
XContentParser parser = JsonXContent.jsonXContent.createParser(jsonBuilder.bytes());
XContentParser parser = createParser(jsonBuilder);
parser.nextToken();
expectThrows(IllegalArgumentException.class, () ->
factory.parseExecutable("_w1", "_a1", parser));

View File

@ -183,7 +183,7 @@ public class PagerDutyActionTests extends ESTestCase {
BytesReference bytes = builder.bytes();
logger.info("pagerduty action json [{}]", bytes.utf8ToString());
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken();
PagerDutyAction action = PagerDutyAction.parse("_watch", "_action", parser);
@ -231,7 +231,7 @@ public class PagerDutyActionTests extends ESTestCase {
PagerDutyAction action = pagerDutyAction(event).build();
XContentBuilder jsonBuilder = jsonBuilder();
action.toXContent(jsonBuilder, ToXContent.EMPTY_PARAMS);
XContentParser parser = JsonXContent.jsonXContent.createParser(jsonBuilder.bytes());
XContentParser parser = createParser(jsonBuilder);
parser.nextToken();
PagerDutyAction parsedAction = PagerDutyAction.parse("_w1", "_a1", parser);
@ -242,7 +242,7 @@ public class PagerDutyActionTests extends ESTestCase {
public void testParserInvalid() throws Exception {
try {
XContentBuilder builder = jsonBuilder().startObject().field("unknown_field", "value").endObject();
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
XContentParser parser = createParser(builder);
parser.nextToken();
PagerDutyAction.parse("_watch", "_action", parser);
fail("Expected ElasticsearchParseException but did not happen");

View File

@ -5,12 +5,10 @@
*/
package org.elasticsearch.xpack.watcher.actions.slack;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.settings.ClusterSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.common.text.TextTemplateEngine;
import org.elasticsearch.xpack.notification.slack.SlackAccount;
@ -20,8 +18,8 @@ import org.junit.Before;
import java.util.Collections;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.slackAction;
import static org.elasticsearch.xpack.notification.slack.message.SlackMessageTests.createRandomTemplate;
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.slackAction;
import static org.hamcrest.Matchers.is;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ -42,7 +40,7 @@ public class SlackActionFactoryTests extends ESTestCase {
SlackAction action = slackAction("_account1", createRandomTemplate()).build();
XContentBuilder jsonBuilder = jsonBuilder().value(action);
XContentParser parser = JsonXContent.jsonXContent.createParser(jsonBuilder.bytes());
XContentParser parser = createParser(jsonBuilder);
parser.nextToken();
SlackAction parsedAction = SlackAction.parse("_w1", "_a1", parser);
@ -55,7 +53,7 @@ public class SlackActionFactoryTests extends ESTestCase {
factory = new SlackActionFactory(Settings.EMPTY, mock(TextTemplateEngine.class), service);
SlackAction action = slackAction("_unknown", createRandomTemplate()).build();
XContentBuilder jsonBuilder = jsonBuilder().value(action);
XContentParser parser = JsonXContent.jsonXContent.createParser(jsonBuilder.bytes());
XContentParser parser = createParser(jsonBuilder);
parser.nextToken();
expectThrows(IllegalArgumentException.class, () -> factory.parseExecutable("_w1", "_a1", parser));
}

View File

@ -154,7 +154,7 @@ public class SlackActionTests extends ESTestCase {
BytesReference bytes = builder.bytes();
logger.info("slack action json [{}]", bytes.utf8ToString());
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken();
SlackAction action = SlackAction.parse("_watch", "_action", parser);
@ -179,7 +179,7 @@ public class SlackActionTests extends ESTestCase {
action.toXContent(builder, ToXContent.EMPTY_PARAMS);
BytesReference bytes = builder.bytes();
logger.info("{}", bytes.utf8ToString());
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken();
SlackAction parsedAction = SlackAction.parse("_watch", "_action", parser);
@ -191,7 +191,7 @@ public class SlackActionTests extends ESTestCase {
public void testParserInvalid() throws Exception {
XContentBuilder builder = jsonBuilder().startObject().field("unknown_field", "value").endObject();
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
XContentParser parser = createParser(builder);
parser.nextToken();
try {
SlackAction.parse("_watch", "_action", parser);

View File

@ -10,7 +10,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.json.JsonXContent;
import org.elasticsearch.env.Environment;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.http.MockResponse;
@ -46,10 +45,11 @@ import org.hamcrest.Matchers;
import org.joda.time.DateTime;
import org.junit.Before;
import javax.mail.internet.AddressException;
import java.io.IOException;
import java.util.Map;
import javax.mail.internet.AddressException;
import static java.util.Collections.singletonMap;
import static org.elasticsearch.common.unit.TimeValue.timeValueSeconds;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
@ -137,7 +137,7 @@ public class WebhookActionTests extends ESTestCase {
WebhookActionFactory actionParser = webhookFactory(ExecuteScenario.Success.client());
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
XContentParser parser = createParser(builder);
parser.nextToken();
ExecutableWebhookAction executable = actionParser.parseExecutable(randomAsciiOfLength(5), randomAsciiOfLength(5), parser);
@ -163,7 +163,7 @@ public class WebhookActionTests extends ESTestCase {
WebhookActionFactory actionParser = webhookFactory(ExecuteScenario.Success.client());
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
XContentParser parser = createParser(builder);
parser.nextToken();
ExecutableWebhookAction parsedExecutable = actionParser.parseExecutable(watchId, actionId, parser);
@ -189,7 +189,7 @@ public class WebhookActionTests extends ESTestCase {
WebhookActionFactory actionParser = webhookFactory(ExecuteScenario.Success.client());
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
XContentParser parser = createParser(builder);
assertThat(parser.nextToken(), is(XContentParser.Token.START_OBJECT));
ExecutableWebhookAction parsedAction = actionParser.parseExecutable(watchId, actionId, parser);
assertThat(parsedAction.action(), is(action));
@ -204,7 +204,7 @@ public class WebhookActionTests extends ESTestCase {
}
builder.endObject();
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
XContentParser parser = createParser(builder);
parser.nextToken();
WebhookActionFactory actionParser = webhookFactory(ExecuteScenario.Success.client());

View File

@ -180,7 +180,7 @@ public class ArrayCompareConditionTests extends ESTestCase {
.endObject()
.endObject();
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
XContentParser parser = createParser(JsonXContent.jsonXContent, builder.bytes());
parser.nextToken();
ArrayCompareCondition condition = (ArrayCompareCondition) ArrayCompareCondition.parse(ClockMock.frozen(), "_id", parser);
@ -212,7 +212,7 @@ public class ArrayCompareConditionTests extends ESTestCase {
.endObject()
.endObject();
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
XContentParser parser = createParser(JsonXContent.jsonXContent, builder.bytes());
parser.nextToken();
expectedException.expect(ElasticsearchParseException.class);
@ -235,7 +235,7 @@ public class ArrayCompareConditionTests extends ESTestCase {
.endObject()
.endObject();
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
XContentParser parser = createParser(JsonXContent.jsonXContent, builder.bytes());
parser.nextToken();
expectedException.expect(ElasticsearchParseException.class);
@ -260,7 +260,7 @@ public class ArrayCompareConditionTests extends ESTestCase {
.endObject()
.endObject();
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
XContentParser parser = createParser(JsonXContent.jsonXContent, builder.bytes());
parser.nextToken();
expectedException.expect(ElasticsearchParseException.class);
@ -285,7 +285,7 @@ public class ArrayCompareConditionTests extends ESTestCase {
.endObject()
.endObject();
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
XContentParser parser = createParser(JsonXContent.jsonXContent, builder.bytes());
parser.nextToken();
expectedException.expect(ElasticsearchParseException.class);
@ -308,7 +308,7 @@ public class ArrayCompareConditionTests extends ESTestCase {
.endObject()
.endObject();
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
XContentParser parser = createParser(JsonXContent.jsonXContent, builder.bytes());
parser.nextToken();
expectedException.expect(ElasticsearchParseException.class);
@ -333,7 +333,7 @@ public class ArrayCompareConditionTests extends ESTestCase {
.endObject()
.endObject();
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
XContentParser parser = createParser(JsonXContent.jsonXContent, builder.bytes());
parser.nextToken();
expectedException.expect(ElasticsearchParseException.class);

View File

@ -168,7 +168,7 @@ public class CompareConditionTests extends ESTestCase {
builder.endObject();
builder.endObject();
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
XContentParser parser = createParser(JsonXContent.jsonXContent, builder.bytes());
parser.nextToken();
CompareCondition condition = (CompareCondition) CompareCondition.parse(ClockMock.frozen(), "_id", parser);
@ -186,7 +186,7 @@ public class CompareConditionTests extends ESTestCase {
builder.endObject();
builder.endObject();
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
XContentParser parser = createParser(JsonXContent.jsonXContent, builder.bytes());
try {
CompareCondition.parse(ClockMock.frozen(), "_id", parser);
fail("Expected ElasticsearchParseException");
@ -204,7 +204,7 @@ public class CompareConditionTests extends ESTestCase {
builder.endObject();
builder.endObject();
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
XContentParser parser = createParser(JsonXContent.jsonXContent, builder.bytes());
parser.nextToken();
try {
CompareCondition.parse(ClockMock.frozen(), "_id", parser);
@ -224,7 +224,7 @@ public class CompareConditionTests extends ESTestCase {
builder.endObject();
builder.endObject();
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
XContentParser parser = createParser(JsonXContent.jsonXContent, builder.bytes());
parser.nextToken();
try {
CompareCondition.parse(ClockMock.frozen(), "_id", parser);

View File

@ -8,7 +8,6 @@ package org.elasticsearch.xpack.watcher.input;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.test.ESTestCase;
import static java.util.Collections.emptyMap;
@ -19,8 +18,7 @@ public class InputRegistryTests extends ESTestCase {
public void testParseEmptyInput() throws Exception {
InputRegistry registry = new InputRegistry(Settings.EMPTY, emptyMap());
XContentParser parser = JsonXContent.jsonXContent.createParser(
jsonBuilder().startObject().endObject().bytes());
XContentParser parser = createParser(jsonBuilder().startObject().endObject());
parser.nextToken();
try {
registry.parse("_id", parser);
@ -32,8 +30,7 @@ public class InputRegistryTests extends ESTestCase {
public void testParseArrayInput() throws Exception {
InputRegistry registry = new InputRegistry(Settings.EMPTY, emptyMap());
XContentParser parser = JsonXContent.jsonXContent.createParser(
jsonBuilder().startArray().endArray().bytes());
XContentParser parser = createParser(jsonBuilder().startArray().endArray());
parser.nextToken();
try {
registry.parse("_id", parser);

View File

@ -9,7 +9,6 @@ import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.watcher.input.ExecutableInput;
import org.elasticsearch.xpack.watcher.input.Input;
@ -44,7 +43,7 @@ public class SimpleInputTests extends ESTestCase {
XContentBuilder jsonBuilder = jsonBuilder().map(data);
InputFactory parser = new SimpleInputFactory(Settings.builder().build());
XContentParser xContentParser = JsonXContent.jsonXContent.createParser(jsonBuilder.bytes());
XContentParser xContentParser = createParser(jsonBuilder);
xContentParser.nextToken();
ExecutableInput input = parser.parseExecutable("_id", xContentParser);
assertEquals(input.type(), SimpleInput.TYPE);
@ -60,7 +59,7 @@ public class SimpleInputTests extends ESTestCase {
XContentBuilder jsonBuilder = jsonBuilder().value("just a string");
InputFactory parser = new SimpleInputFactory(Settings.builder().build());
XContentParser xContentParser = JsonXContent.jsonXContent.createParser(jsonBuilder.bytes());
XContentParser xContentParser = createParser(jsonBuilder);
xContentParser.nextToken();
try {
parser.parseInput("_id", xContentParser);

View File

@ -6,11 +6,11 @@
package org.elasticsearch.xpack.watcher.test;
import io.netty.util.internal.SystemPropertyUtil;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.admin.indices.alias.Alias;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.support.IndicesOptions;
@ -65,12 +65,10 @@ import org.elasticsearch.xpack.watcher.WatcherLifeCycleService;
import org.elasticsearch.xpack.watcher.WatcherService;
import org.elasticsearch.xpack.watcher.WatcherState;
import org.elasticsearch.xpack.watcher.client.WatcherClient;
import org.elasticsearch.xpack.watcher.execution.ExecutionService;
import org.elasticsearch.xpack.watcher.execution.ExecutionState;
import org.elasticsearch.xpack.watcher.execution.TriggeredWatchStore;
import org.elasticsearch.xpack.watcher.history.HistoryStore;
import org.elasticsearch.xpack.watcher.support.WatcherIndexTemplateRegistry;
import org.elasticsearch.xpack.watcher.support.init.proxy.WatcherClientProxy;
import org.elasticsearch.xpack.watcher.support.xcontent.XContentSource;
import org.elasticsearch.xpack.watcher.trigger.ScheduleTriggerEngineMock;
import org.elasticsearch.xpack.watcher.watch.Watch;
@ -91,7 +89,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
@ -322,7 +319,7 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase
if (rarely()) {
String newIndex = ".watches-alias-index";
BytesReference bytesReference = TemplateUtils.load("/watches.json");
try (XContentParser parser = JsonXContent.jsonXContent.createParser(bytesReference.toBytesRef().bytes)) {
try (XContentParser parser = createParser(JsonXContent.jsonXContent, bytesReference.toBytesRef().bytes)) {
Map<String, Object> parserMap = parser.map();
Map<String, Object> allMappings = (Map<String, Object>) parserMap.get("mappings");
@ -340,7 +337,7 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase
if (rarely()) {
String newIndex = ".triggered-watches-alias-index";
BytesReference bytesReference = TemplateUtils.load("/triggered_watches.json");
try (XContentParser parser = JsonXContent.jsonXContent.createParser(bytesReference.toBytesRef().bytes)) {
try (XContentParser parser = createParser(JsonXContent.jsonXContent, bytesReference.toBytesRef().bytes)) {
Map<String, Object> parserMap = parser.map();
Map<String, Object> allMappings = (Map<String, Object>) parserMap.get("mappings");

View File

@ -10,7 +10,6 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.plugins.Plugin;
@ -142,7 +141,7 @@ public class SearchInputTests extends ESIntegTestCase {
TimeValue timeout = randomBoolean() ? TimeValue.timeValueSeconds(randomInt(10)) : null;
XContentBuilder builder = jsonBuilder().value(
new SearchInput(WatcherTestUtils.templateRequest(source), null, timeout, null));
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
XContentParser parser = createParser(builder);
parser.nextToken();
IndicesQueriesRegistry indicesQueryRegistry = internalCluster().getInstance(IndicesQueriesRegistry.class);

View File

@ -13,7 +13,6 @@ 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.common.xcontent.support.XContentMapValues;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.plugins.Plugin;
@ -212,7 +211,7 @@ public class SearchTransformTests extends ESIntegTestCase {
}
builder.endObject();
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
XContentParser parser = createParser(builder);
parser.nextToken();
SearchRequestParsers searchRequestParsers = internalCluster().getInstance(SearchRequestParsers.class);

View File

@ -69,7 +69,7 @@ public class WatcherSettingsFilterTests extends AbstractWatcherIntegrationTestCa
headers = new Header[0];
}
Response response = getRestClient().performRequest("GET", "/_nodes/settings", headers);
Map<String, Object> responseMap = JsonXContent.jsonXContent.createParser(response.getEntity().getContent()).map();
Map<String, Object> responseMap = createParser(JsonXContent.jsonXContent, response.getEntity().getContent()).map();
Map<String, Object> nodes = (Map<String, Object>) responseMap.get("nodes");
for (Object node : nodes.values()) {
Map<String, Object> settings = (Map<String, Object>) ((Map<String, Object>) node).get("settings");

View File

@ -121,7 +121,7 @@ public class ChainTransformTests extends ESTestCase {
.startObject().field("named", "name4").endObject()
.endArray();
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
XContentParser parser = createParser(JsonXContent.jsonXContent, builder.bytes());
parser.nextToken();
ExecutableChainTransform executable = transformParser.parseExecutable("_id", parser);
assertThat(executable, notNullValue());

View File

@ -9,7 +9,6 @@ import org.elasticsearch.common.settings.Settings;
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.script.CompiledScript;
import org.elasticsearch.script.ExecutableScript;
import org.elasticsearch.script.Script;
@ -147,7 +146,7 @@ public class ScriptTransformTests extends ESTestCase {
builder.startObject("params").field("key", "value").endObject();
builder.endObject();
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
XContentParser parser = createParser(builder);
parser.nextToken();
ExecutableScriptTransform transform = new ScriptTransformFactory(Settings.EMPTY, service).parseExecutable("_id", parser);
Script script = new Script(type, "_lang", "_script", singletonMap("key", "value"));
@ -158,7 +157,7 @@ public class ScriptTransformTests extends ESTestCase {
ScriptService service = mock(ScriptService.class);
XContentBuilder builder = jsonBuilder().value("_script");
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
XContentParser parser = createParser(builder);
parser.nextToken();
ExecutableScriptTransform transform = new ScriptTransformFactory(Settings.EMPTY, service).parseExecutable("_id", parser);
assertThat(transform.transform().getScript(), equalTo(new Script("_script")));

View File

@ -30,7 +30,7 @@ public class CronScheduleTests extends ScheduleTestCase {
public void testParseSingle() throws Exception {
XContentBuilder builder = jsonBuilder().value("0 0/5 * * * ?");
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken();
CronSchedule schedule = new CronSchedule.Parser().parse(parser);
assertThat(schedule.crons(), arrayWithSize(1));
@ -44,7 +44,7 @@ public class CronScheduleTests extends ScheduleTestCase {
"0 0/3 * * * ?"
});
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken();
CronSchedule schedule = new CronSchedule.Parser().parse(parser);
String[] crons = expressions(schedule);
@ -57,7 +57,7 @@ public class CronScheduleTests extends ScheduleTestCase {
public void testParseInvalidBadExpression() throws Exception {
XContentBuilder builder = jsonBuilder().value("0 0/5 * * ?");
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken();
try {
new CronSchedule.Parser().parse(parser);
@ -71,7 +71,7 @@ public class CronScheduleTests extends ScheduleTestCase {
public void testParseInvalidEmpty() throws Exception {
XContentBuilder builder = jsonBuilder();
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken();
try {
new CronSchedule.Parser().parse(parser);
@ -85,7 +85,7 @@ public class CronScheduleTests extends ScheduleTestCase {
public void testParseInvalidObject() throws Exception {
XContentBuilder builder = jsonBuilder().startObject().endObject();
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken();
try {
new CronSchedule.Parser().parse(parser);
@ -99,7 +99,7 @@ public class CronScheduleTests extends ScheduleTestCase {
public void testParseInvalidEmptyArray() throws Exception {
XContentBuilder builder = jsonBuilder().value(new String[0]);
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken();
try {
new CronSchedule.Parser().parse(parser);

View File

@ -62,7 +62,7 @@ public class DailyScheduleTests extends ScheduleTestCase {
public void testParserEmpty() throws Exception {
XContentBuilder builder = jsonBuilder().startObject().endObject();
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken(); // advancing to the start object
DailySchedule schedule = new DailySchedule.Parser().parse(parser);
assertThat(schedule, notNullValue());
@ -80,7 +80,7 @@ public class DailyScheduleTests extends ScheduleTestCase {
.endObject()
.endObject();
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken(); // advancing to the start object
DailySchedule schedule = new DailySchedule.Parser().parse(parser);
assertThat(schedule, notNullValue());
@ -98,7 +98,7 @@ public class DailyScheduleTests extends ScheduleTestCase {
.endObject()
.endObject();
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken(); // advancing to the start object
try {
new DailySchedule.Parser().parse(parser);
@ -115,7 +115,7 @@ public class DailyScheduleTests extends ScheduleTestCase {
.field("at", timeStr)
.endObject();
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken(); // advancing to the start object
DailySchedule schedule = new DailySchedule.Parser().parse(parser);
assertThat(schedule, notNullValue());
@ -129,7 +129,7 @@ public class DailyScheduleTests extends ScheduleTestCase {
.field("at", invalidDayTimeStr())
.endObject();
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken(); // advancing to the start object
try {
new DailySchedule.Parser().parse(parser);
@ -146,7 +146,7 @@ public class DailyScheduleTests extends ScheduleTestCase {
.array("at", (Object[]) times)
.endObject();
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken(); // advancing to the start object
DailySchedule schedule = new DailySchedule.Parser().parse(parser);
assertThat(schedule, notNullValue());
@ -163,7 +163,7 @@ public class DailyScheduleTests extends ScheduleTestCase {
.array("at", (Object[]) times)
.endObject();
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken(); // advancing to the start object
try {
new DailySchedule.Parser().parse(parser);
@ -180,7 +180,7 @@ public class DailyScheduleTests extends ScheduleTestCase {
.array("at", (Object[]) times)
.endObject();
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken(); // advancing to the start object
DailySchedule schedule = new DailySchedule.Parser().parse(parser);
assertThat(schedule, notNullValue());
@ -197,7 +197,7 @@ public class DailyScheduleTests extends ScheduleTestCase {
.array("at", times)
.endObject();
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken(); // advancing to the start object
try {
new DailySchedule.Parser().parse(parser);

View File

@ -73,7 +73,7 @@ public class HourlyScheduleTests extends ScheduleTestCase {
public void testParserEmpty() throws Exception {
XContentBuilder builder = jsonBuilder().startObject().endObject();
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken(); // advancing to the start object
HourlySchedule schedule = new HourlySchedule.Parser().parse(parser);
assertThat(schedule, notNullValue());
@ -88,7 +88,7 @@ public class HourlyScheduleTests extends ScheduleTestCase {
.field("minute", minute)
.endObject();
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken(); // advancing to the start object
HourlySchedule schedule = new HourlySchedule.Parser().parse(parser);
assertThat(schedule, notNullValue());
@ -102,7 +102,7 @@ public class HourlyScheduleTests extends ScheduleTestCase {
.field("minute", invalidMinute())
.endObject();
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken(); // advancing to the start object
try {
new HourlySchedule.Parser().parse(parser);
@ -119,7 +119,7 @@ public class HourlyScheduleTests extends ScheduleTestCase {
.field("minute", String.valueOf(minute))
.endObject();
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken(); // advancing to the start object
HourlySchedule schedule = new HourlySchedule.Parser().parse(parser);
assertThat(schedule, notNullValue());
@ -133,7 +133,7 @@ public class HourlyScheduleTests extends ScheduleTestCase {
.field("minute", String.valueOf(invalidMinute()))
.endObject();
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken(); // advancing to the start object
try {
new HourlySchedule.Parser().parse(parser);
@ -150,7 +150,7 @@ public class HourlyScheduleTests extends ScheduleTestCase {
.field("minute", asIterable(minutes))
.endObject();
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken(); // advancing to the start object
HourlySchedule schedule = new HourlySchedule.Parser().parse(parser);
assertThat(schedule, notNullValue());
@ -167,7 +167,7 @@ public class HourlyScheduleTests extends ScheduleTestCase {
.field("minute", asIterable(minutes))
.endObject();
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken(); // advancing to the start object
try {
new HourlySchedule.Parser().parse(parser);
@ -184,7 +184,7 @@ public class HourlyScheduleTests extends ScheduleTestCase {
.field("minute", Arrays.stream(minutes).mapToObj(p -> Integer.toString(p)).collect(Collectors.toList()))
.endObject();
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken(); // advancing to the start object
HourlySchedule schedule = new HourlySchedule.Parser().parse(parser);
assertThat(schedule, notNullValue());
@ -201,7 +201,7 @@ public class HourlyScheduleTests extends ScheduleTestCase {
.field("minute", Arrays.stream(minutes).mapToObj(p -> Integer.toString(p)).collect(Collectors.toList()))
.endObject();
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken(); // advancing to the start object
try {
new HourlySchedule.Parser().parse(parser);

View File

@ -23,7 +23,7 @@ public class IntervalScheduleTests extends ESTestCase {
long value = randomIntBetween(0, Integer.MAX_VALUE);
XContentBuilder builder = jsonBuilder().value(value);
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken(); // advancing to the start object
IntervalSchedule schedule = new IntervalSchedule.Parser().parse(parser);
assertThat(schedule, notNullValue());
@ -34,7 +34,7 @@ public class IntervalScheduleTests extends ESTestCase {
long value = randomIntBetween(Integer.MIN_VALUE, 0);
XContentBuilder builder = jsonBuilder().value(value);
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken(); // advancing to the start object
try {
new IntervalSchedule.Parser().parse(parser);
@ -49,7 +49,7 @@ public class IntervalScheduleTests extends ESTestCase {
IntervalSchedule.Interval value = randomTimeInterval();
XContentBuilder builder = jsonBuilder().value(value);
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken(); // advancing to the start object
IntervalSchedule schedule = new IntervalSchedule.Parser().parse(parser);
assertThat(schedule, notNullValue());
@ -59,7 +59,7 @@ public class IntervalScheduleTests extends ESTestCase {
public void testParseInvalidString() throws Exception {
XContentBuilder builder = jsonBuilder().value("43S");
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken(); // advancing to the start object
try {
new IntervalSchedule.Parser().parse(parser);
@ -72,7 +72,7 @@ public class IntervalScheduleTests extends ESTestCase {
public void testParseInvalidObject() throws Exception {
XContentBuilder builder = jsonBuilder().startObject().endObject();
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken(); // advancing to the start object
try {
new IntervalSchedule.Parser().parse(parser);

View File

@ -66,7 +66,7 @@ public class MonthlyScheduleTests extends ScheduleTestCase {
public void testParserEmpty() throws Exception {
XContentBuilder builder = jsonBuilder().startObject().endObject();
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken(); // advancing to the start object
MonthlySchedule schedule = new MonthlySchedule.Parser().parse(parser);
assertThat(schedule, notNullValue());
@ -86,7 +86,7 @@ public class MonthlyScheduleTests extends ScheduleTestCase {
.endObject()
.endObject();
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken(); // advancing to the start object
MonthlySchedule schedule = new MonthlySchedule.Parser().parse(parser);
assertThat(schedule, notNullValue());
@ -108,7 +108,7 @@ public class MonthlyScheduleTests extends ScheduleTestCase {
.endObject()
.endObject();
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken(); // advancing to the start object
try {
new MonthlySchedule.Parser().parse(parser);
@ -122,7 +122,7 @@ public class MonthlyScheduleTests extends ScheduleTestCase {
MonthTimes[] times = validMonthTimes();
XContentBuilder builder = jsonBuilder().value(times);
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken(); // advancing to the start object
MonthlySchedule schedule = new MonthlySchedule.Parser().parse(parser);
assertThat(schedule, notNullValue());
@ -140,7 +140,7 @@ public class MonthlyScheduleTests extends ScheduleTestCase {
.array("at", (Object[]) times)
.endObject();
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken(); // advancing to the start object
try {
new MonthlySchedule.Parser().parse(parser);

View File

@ -43,7 +43,7 @@ public class ScheduleRegistryTests extends ScheduleTestCase {
.field(IntervalSchedule.TYPE, interval)
.endObject();
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken();
Schedule schedule = registry.parse("ctx", parser);
assertThat(schedule, notNullValue());
@ -60,7 +60,7 @@ public class ScheduleRegistryTests extends ScheduleTestCase {
.field(CronSchedule.TYPE, cron)
.endObject();
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken();
Schedule schedule = registry.parse("ctx", parser);
assertThat(schedule, notNullValue());
@ -75,7 +75,7 @@ public class ScheduleRegistryTests extends ScheduleTestCase {
.field(HourlySchedule.TYPE, hourly)
.endObject();
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken();
Schedule schedule = registry.parse("ctx", parser);
assertThat(schedule, notNullValue());
@ -90,7 +90,7 @@ public class ScheduleRegistryTests extends ScheduleTestCase {
.field(DailySchedule.TYPE, daily)
.endObject();
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken();
Schedule schedule = registry.parse("ctx", parser);
assertThat(schedule, notNullValue());
@ -105,7 +105,7 @@ public class ScheduleRegistryTests extends ScheduleTestCase {
.field(WeeklySchedule.TYPE, weekly)
.endObject();
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken();
Schedule schedule = registry.parse("ctx", parser);
assertThat(schedule, notNullValue());
@ -120,7 +120,7 @@ public class ScheduleRegistryTests extends ScheduleTestCase {
.field(MonthlySchedule.TYPE, monthly)
.endObject();
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken();
Schedule schedule = registry.parse("ctx", parser);
assertThat(schedule, notNullValue());

View File

@ -9,7 +9,6 @@ package org.elasticsearch.xpack.watcher.trigger.schedule;
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 java.time.Clock;
@ -26,7 +25,7 @@ public class ScheduleTriggerEventTests extends ESTestCase {
jsonBuilder.field(ScheduleTriggerEvent.Field.TRIGGERED_TIME.getPreferredName(), triggeredTime);
jsonBuilder.endObject();
XContentParser parser = JsonXContent.jsonXContent.createParser(jsonBuilder.bytes());
XContentParser parser = createParser(jsonBuilder);
parser.nextToken();
ScheduleTriggerEvent scheduleTriggerEvent = ScheduleTriggerEvent.parse(parser, "_id", "_context", Clock.systemUTC());

View File

@ -65,7 +65,7 @@ public class WeeklyScheduleTests extends ScheduleTestCase {
public void testParserEmpty() throws Exception {
XContentBuilder builder = jsonBuilder().startObject().endObject();
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken(); // advancing to the start object
WeeklySchedule schedule = new WeeklySchedule.Parser().parse(parser);
assertThat(schedule, notNullValue());
@ -84,7 +84,7 @@ public class WeeklyScheduleTests extends ScheduleTestCase {
.endObject()
.endObject();
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken(); // advancing to the start object
WeeklySchedule schedule = new WeeklySchedule.Parser().parse(parser);
assertThat(schedule, notNullValue());
@ -106,7 +106,7 @@ public class WeeklyScheduleTests extends ScheduleTestCase {
.endObject()
.endObject();
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken(); // advancing to the start object
try {
new WeeklySchedule.Parser().parse(parser);
@ -120,7 +120,7 @@ public class WeeklyScheduleTests extends ScheduleTestCase {
WeekTimes[] times = validWeekTimes();
XContentBuilder builder = jsonBuilder().value(times);
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken(); // advancing to the start object
WeeklySchedule schedule = new WeeklySchedule.Parser().parse(parser);
assertThat(schedule, notNullValue());
@ -138,7 +138,7 @@ public class WeeklyScheduleTests extends ScheduleTestCase {
.array("at", (Object[]) times)
.endObject();
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken(); // advancing to the start object
try {
new WeeklySchedule.Parser().parse(parser);

View File

@ -72,7 +72,7 @@ public class YearlyScheduleTests extends ScheduleTestCase {
public void testParserEmpty() throws Exception {
XContentBuilder builder = jsonBuilder().startObject().endObject();
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken(); // advancing to the start object
YearlySchedule schedule = new YearlySchedule.Parser().parse(parser);
assertThat(schedule, notNullValue());
@ -94,7 +94,7 @@ public class YearlyScheduleTests extends ScheduleTestCase {
.endObject()
.endObject();
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken(); // advancing to the start object
YearlySchedule schedule = new YearlySchedule.Parser().parse(parser);
assertThat(schedule, notNullValue());
@ -117,7 +117,7 @@ public class YearlyScheduleTests extends ScheduleTestCase {
.endObject()
.endObject();
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken(); // advancing to the start object
try {
new MonthlySchedule.Parser().parse(parser);
@ -131,7 +131,7 @@ public class YearlyScheduleTests extends ScheduleTestCase {
YearTimes[] times = validYearTimes();
XContentBuilder builder = jsonBuilder().value(times);
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken(); // advancing to the start object
YearlySchedule schedule = new YearlySchedule.Parser().parse(parser);
assertThat(schedule, notNullValue());
@ -150,7 +150,7 @@ public class YearlyScheduleTests extends ScheduleTestCase {
.array("at", (Object[]) times)
.endObject();
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken(); // advancing to the start object
try {
new YearlySchedule.Parser().parse(parser);