From d4939e19723e9e2f165a343557dc643063e74e3c Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Tue, 13 Dec 2016 15:52:59 -0500 Subject: [PATCH] Start centralizing XContentParser creation in tests Original commit: elastic/x-pack-elasticsearch@65be7ecd2715fc836094898422c0cac305cc3979 --- .../common/http/HttpRequestTemplateTests.java | 10 +++++----- .../xpack/common/http/HttpRequestTests.java | 5 ++--- .../xpack/common/text/TextTemplateTests.java | 13 ++++++------- .../MonitoringSettingsFilterTests.java | 3 +-- .../notification/email/EmailTemplateTests.java | 3 +-- .../xpack/notification/email/EmailTests.java | 3 +-- .../attachment/DataAttachmentParserTests.java | 2 +- .../EmailAttachmentParsersTests.java | 7 +++---- .../HttpEmailAttachementParserTests.java | 3 +-- .../ReportingAttachmentParserTests.java | 4 ++-- .../hipchat/HipChatMessageTests.java | 6 +++--- .../slack/message/SlackMessageTests.java | 7 +++---- .../actions/email/EmailActionTests.java | 13 +++++++------ .../hipchat/HipChatActionFactoryTests.java | 6 ++---- .../actions/hipchat/HipChatActionTests.java | 6 +++--- .../actions/index/IndexActionTests.java | 5 ++--- .../actions/jira/JiraActionFactoryTests.java | 5 ++--- .../watcher/actions/jira/JiraActionTests.java | 6 +++--- .../actions/logging/LoggingActionTests.java | 9 ++++----- .../pagerduty/PagerDutyActionFactoryTests.java | 5 ++--- .../pagerduty/PagerDutyActionTests.java | 6 +++--- .../actions/slack/SlackActionFactoryTests.java | 8 +++----- .../actions/slack/SlackActionTests.java | 6 +++--- .../actions/webhook/WebhookActionTests.java | 12 ++++++------ .../condition/ArrayCompareConditionTests.java | 14 +++++++------- .../condition/CompareConditionTests.java | 8 ++++---- .../watcher/input/InputRegistryTests.java | 7 ++----- .../watcher/input/simple/SimpleInputTests.java | 5 ++--- .../AbstractWatcherIntegrationTestCase.java | 9 +++------ .../test/integration/SearchInputTests.java | 3 +-- .../test/integration/SearchTransformTests.java | 3 +-- .../WatcherSettingsFilterTests.java | 2 +- .../transform/chain/ChainTransformTests.java | 2 +- .../transform/script/ScriptTransformTests.java | 5 ++--- .../trigger/schedule/CronScheduleTests.java | 12 ++++++------ .../trigger/schedule/DailyScheduleTests.java | 18 +++++++++--------- .../trigger/schedule/HourlyScheduleTests.java | 18 +++++++++--------- .../schedule/IntervalScheduleTests.java | 10 +++++----- .../trigger/schedule/MonthlyScheduleTests.java | 10 +++++----- .../schedule/ScheduleRegistryTests.java | 12 ++++++------ .../schedule/ScheduleTriggerEventTests.java | 3 +-- .../trigger/schedule/WeeklyScheduleTests.java | 10 +++++----- .../trigger/schedule/YearlyScheduleTests.java | 10 +++++----- 43 files changed, 144 insertions(+), 170 deletions(-) diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/common/http/HttpRequestTemplateTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/common/http/HttpRequestTemplateTests.java index 1161171199b..a4df949e194 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/common/http/HttpRequestTemplateTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/common/http/HttpRequestTemplateTests.java @@ -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); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/common/http/HttpRequestTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/common/http/HttpRequestTests.java index feac2b07076..737a3eee64b 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/common/http/HttpRequestTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/common/http/HttpRequestTests.java @@ -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); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/common/text/TextTemplateTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/common/text/TextTemplateTests.java index 7ae93368376..2fda20271e1 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/common/text/TextTemplateTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/common/text/TextTemplateTests.java @@ -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); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/security/MonitoringSettingsFilterTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/security/MonitoringSettingsFilterTests.java index 99d5d83ff5e..2f823750943 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/security/MonitoringSettingsFilterTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/monitoring/security/MonitoringSettingsFilterTests.java @@ -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 responseMap = JsonXContent.jsonXContent.createParser(response.getEntity().getContent()).map(); + Map responseMap = createParser(JsonXContent.jsonXContent, response.getEntity().getContent()).map(); @SuppressWarnings("unchecked") Map nodes = (Map) responseMap.get("nodes"); for (Object node : nodes.values()) { diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/notification/email/EmailTemplateTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/notification/email/EmailTemplateTests.java index 0dac349e296..ff733bdaf3b 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/notification/email/EmailTemplateTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/notification/email/EmailTemplateTests.java @@ -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(); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/notification/email/EmailTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/notification/email/EmailTests.java index f5d16de9643..9186b05c7d0 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/notification/email/EmailTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/notification/email/EmailTests.java @@ -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); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/notification/email/attachment/DataAttachmentParserTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/notification/email/attachment/DataAttachmentParserTests.java index bc7d2ce1780..f21dfac2f8e 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/notification/email/attachment/DataAttachmentParserTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/notification/email/attachment/DataAttachmentParserTests.java @@ -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); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/notification/email/attachment/EmailAttachmentParsersTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/notification/email/attachment/EmailAttachmentParsersTests.java index 23fd4f40004..b09a855ea69 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/notification/email/attachment/EmailAttachmentParsersTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/notification/email/attachment/EmailAttachmentParsersTests.java @@ -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); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/notification/email/attachment/HttpEmailAttachementParserTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/notification/email/attachment/HttpEmailAttachementParserTests.java index d451417932e..59b352a39d7 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/notification/email/attachment/HttpEmailAttachementParserTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/notification/email/attachment/HttpEmailAttachementParserTests.java @@ -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)); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/notification/email/attachment/ReportingAttachmentParserTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/notification/email/attachment/ReportingAttachmentParserTests.java index c81ffad7789..a390ebf1a43 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/notification/email/attachment/ReportingAttachmentParserTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/notification/email/attachment/ReportingAttachmentParserTests.java @@ -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)); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/notification/hipchat/HipChatMessageTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/notification/hipchat/HipChatMessageTests.java index d48e6875c1d..288beeb8b40 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/notification/hipchat/HipChatMessageTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/notification/hipchat/HipChatMessageTests.java @@ -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); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/notification/slack/message/SlackMessageTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/notification/slack/message/SlackMessageTests.java index 5feb93d39d0..e1da997b751 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/notification/slack/message/SlackMessageTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/notification/slack/message/SlackMessageTests.java @@ -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); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/email/EmailActionTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/email/EmailActionTests.java index 211e446fca3..52afffcf2fa 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/email/EmailActionTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/email/EmailActionTests.java @@ -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(); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/hipchat/HipChatActionFactoryTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/hipchat/HipChatActionFactoryTests.java index 3308753476d..ec630a7e8e6 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/hipchat/HipChatActionFactoryTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/hipchat/HipChatActionFactoryTests.java @@ -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)); } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/hipchat/HipChatActionTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/hipchat/HipChatActionTests.java index f342288a5e4..70bf3385ebb 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/hipchat/HipChatActionTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/hipchat/HipChatActionTests.java @@ -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); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/index/IndexActionTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/index/IndexActionTests.java index 3a9a0b4fb30..2674215891e 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/index/IndexActionTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/index/IndexActionTests.java @@ -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); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/jira/JiraActionFactoryTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/jira/JiraActionFactoryTests.java index 2da970c1345..544df5828c6 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/jira/JiraActionFactoryTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/jira/JiraActionFactoryTests.java @@ -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)); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/jira/JiraActionTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/jira/JiraActionTests.java index cdba9c224f8..c21f7d07f38 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/jira/JiraActionTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/jira/JiraActionTests.java @@ -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)); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/logging/LoggingActionTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/logging/LoggingActionTests.java index 5fe4f86661e..4cf8f6ca350 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/logging/LoggingActionTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/logging/LoggingActionTests.java @@ -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 { diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/pagerduty/PagerDutyActionFactoryTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/pagerduty/PagerDutyActionFactoryTests.java index 9feab67bcc2..b9ed91ad3ee 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/pagerduty/PagerDutyActionFactoryTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/pagerduty/PagerDutyActionFactoryTests.java @@ -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)); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/pagerduty/PagerDutyActionTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/pagerduty/PagerDutyActionTests.java index 153517a83d4..ea69b6a1ed9 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/pagerduty/PagerDutyActionTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/pagerduty/PagerDutyActionTests.java @@ -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"); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/slack/SlackActionFactoryTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/slack/SlackActionFactoryTests.java index 6a1e6740edc..b9b3e7e43b7 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/slack/SlackActionFactoryTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/slack/SlackActionFactoryTests.java @@ -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)); } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/slack/SlackActionTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/slack/SlackActionTests.java index f90f2e9720f..35dcd0aad11 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/slack/SlackActionTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/slack/SlackActionTests.java @@ -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); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/webhook/WebhookActionTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/webhook/WebhookActionTests.java index 04abec30f95..6ad7f9d160c 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/webhook/WebhookActionTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/webhook/WebhookActionTests.java @@ -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()); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/condition/ArrayCompareConditionTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/condition/ArrayCompareConditionTests.java index 8472e3bf7c5..14ec26c70d7 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/condition/ArrayCompareConditionTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/condition/ArrayCompareConditionTests.java @@ -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); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/condition/CompareConditionTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/condition/CompareConditionTests.java index b2091190241..c33a8558999 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/condition/CompareConditionTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/condition/CompareConditionTests.java @@ -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); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/input/InputRegistryTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/input/InputRegistryTests.java index e49b7f9fbf8..83c3457c4f6 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/input/InputRegistryTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/input/InputRegistryTests.java @@ -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); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/input/simple/SimpleInputTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/input/simple/SimpleInputTests.java index 10b27d5420f..844584c47a6 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/input/simple/SimpleInputTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/input/simple/SimpleInputTests.java @@ -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); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java index 26f28b0a30e..018d70b059d 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java @@ -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 parserMap = parser.map(); Map allMappings = (Map) 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 parserMap = parser.map(); Map allMappings = (Map) parserMap.get("mappings"); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/SearchInputTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/SearchInputTests.java index 5216a1b75b6..1d763e4e0db 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/SearchInputTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/SearchInputTests.java @@ -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); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/SearchTransformTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/SearchTransformTests.java index e160cd7616b..619f2078814 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/SearchTransformTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/SearchTransformTests.java @@ -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); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/WatcherSettingsFilterTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/WatcherSettingsFilterTests.java index 345fbb9921e..1241433f850 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/WatcherSettingsFilterTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/WatcherSettingsFilterTests.java @@ -69,7 +69,7 @@ public class WatcherSettingsFilterTests extends AbstractWatcherIntegrationTestCa headers = new Header[0]; } Response response = getRestClient().performRequest("GET", "/_nodes/settings", headers); - Map responseMap = JsonXContent.jsonXContent.createParser(response.getEntity().getContent()).map(); + Map responseMap = createParser(JsonXContent.jsonXContent, response.getEntity().getContent()).map(); Map nodes = (Map) responseMap.get("nodes"); for (Object node : nodes.values()) { Map settings = (Map) ((Map) node).get("settings"); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transform/chain/ChainTransformTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transform/chain/ChainTransformTests.java index 59b77fd3dfd..f367bc5f48b 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transform/chain/ChainTransformTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transform/chain/ChainTransformTests.java @@ -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()); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transform/script/ScriptTransformTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transform/script/ScriptTransformTests.java index 26f4214e20e..3002a55bd38 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transform/script/ScriptTransformTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transform/script/ScriptTransformTests.java @@ -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"))); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/trigger/schedule/CronScheduleTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/trigger/schedule/CronScheduleTests.java index 4f852622f37..69da813e07e 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/trigger/schedule/CronScheduleTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/trigger/schedule/CronScheduleTests.java @@ -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); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/trigger/schedule/DailyScheduleTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/trigger/schedule/DailyScheduleTests.java index 0293ee6a1de..1a4dac718a1 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/trigger/schedule/DailyScheduleTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/trigger/schedule/DailyScheduleTests.java @@ -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); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/trigger/schedule/HourlyScheduleTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/trigger/schedule/HourlyScheduleTests.java index 5f664d1abdd..8f85c89d410 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/trigger/schedule/HourlyScheduleTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/trigger/schedule/HourlyScheduleTests.java @@ -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); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/trigger/schedule/IntervalScheduleTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/trigger/schedule/IntervalScheduleTests.java index 66316fff709..b9f23a88b24 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/trigger/schedule/IntervalScheduleTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/trigger/schedule/IntervalScheduleTests.java @@ -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); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/trigger/schedule/MonthlyScheduleTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/trigger/schedule/MonthlyScheduleTests.java index d1214cf7452..4aa709beda5 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/trigger/schedule/MonthlyScheduleTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/trigger/schedule/MonthlyScheduleTests.java @@ -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); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/trigger/schedule/ScheduleRegistryTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/trigger/schedule/ScheduleRegistryTests.java index 1567577c373..61ece496669 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/trigger/schedule/ScheduleRegistryTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/trigger/schedule/ScheduleRegistryTests.java @@ -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()); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/trigger/schedule/ScheduleTriggerEventTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/trigger/schedule/ScheduleTriggerEventTests.java index e3d09ff564e..822dd02bd19 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/trigger/schedule/ScheduleTriggerEventTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/trigger/schedule/ScheduleTriggerEventTests.java @@ -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()); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/trigger/schedule/WeeklyScheduleTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/trigger/schedule/WeeklyScheduleTests.java index 31f0def6fb2..0078fcc8668 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/trigger/schedule/WeeklyScheduleTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/trigger/schedule/WeeklyScheduleTests.java @@ -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); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/trigger/schedule/YearlyScheduleTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/trigger/schedule/YearlyScheduleTests.java index 3eccea7eefa..8355efb53a2 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/trigger/schedule/YearlyScheduleTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/trigger/schedule/YearlyScheduleTests.java @@ -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);