diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/action/CloseJobAction.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/action/CloseJobAction.java index 94d83f01e53..6481e2883cf 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/action/CloseJobAction.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/action/CloseJobAction.java @@ -32,7 +32,6 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.concurrent.AbstractRunnable; import org.elasticsearch.common.util.concurrent.AtomicArray; import org.elasticsearch.common.xcontent.ObjectParser; -import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; @@ -86,7 +85,7 @@ public class CloseJobAction extends Action implements ToXContent { + public static class Request extends BaseTasksRequest implements ToXContentObject { public static final ParseField TIMEOUT = new ParseField("timeout"); public static final ParseField FORCE = new ParseField("force"); diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/action/GetBucketsAction.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/action/GetBucketsAction.java index 30b8227ac8c..5104c6641a7 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/action/GetBucketsAction.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/action/GetBucketsAction.java @@ -24,7 +24,6 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.ObjectParser; -import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; @@ -62,7 +61,7 @@ public class GetBucketsAction extends Action implements ToXContent { + public static class Request extends MasterNodeRequest implements ToXContentObject { public static Request fromXContent(XContentParser parser) { return parseRequest(null, parser); diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/action/PutDatafeedAction.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/action/PutDatafeedAction.java index 00982e5e797..0c992168ed3 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/action/PutDatafeedAction.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/action/PutDatafeedAction.java @@ -71,7 +71,7 @@ public class PutDatafeedAction extends Action implements ToXContent { + public static class Request extends AcknowledgedRequest implements ToXContentObject { public static Request parseRequest(String datafeedId, XContentParser parser) { DatafeedConfig.Builder datafeed = DatafeedConfig.CONFIG_PARSER.apply(parser, null); diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/action/PutFilterAction.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/action/PutFilterAction.java index d7fdf1d34a3..d115589b196 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/action/PutFilterAction.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/action/PutFilterAction.java @@ -27,6 +27,7 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.ToXContent; +import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; @@ -62,7 +63,7 @@ public class PutFilterAction extends Action implements ToXContent { + public static class Request extends MasterNodeReadRequest implements ToXContentObject { public static Request parseRequest(String filterId, XContentParser parser) { MlFilter.Builder filter = MlFilter.PARSER.apply(parser, null); diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/action/PutJobAction.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/action/PutJobAction.java index cdbaf89d65e..eabf1499fc0 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/action/PutJobAction.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/action/PutJobAction.java @@ -24,7 +24,6 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; @@ -61,7 +60,7 @@ public class PutJobAction extends Action implements ToXContent { + public static class Request extends AcknowledgedRequest implements ToXContentObject { public static Request parseRequest(String jobId, XContentParser parser) { Job.Builder jobBuilder = Job.CONFIG_PARSER.apply(parser, null); diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/action/RevertModelSnapshotAction.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/action/RevertModelSnapshotAction.java index 6d378660f58..f3104af4a96 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/action/RevertModelSnapshotAction.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/action/RevertModelSnapshotAction.java @@ -29,7 +29,7 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.StatusToXContentObject; -import org.elasticsearch.common.xcontent.ToXContent; +import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.RestStatus; @@ -72,7 +72,7 @@ extends Action implements ToXContent { + public static class Request extends AcknowledgedRequest implements ToXContentObject { public static final ParseField SNAPSHOT_ID = new ParseField("snapshot_id"); public static final ParseField DELETE_INTERVENING = new ParseField("delete_intervening_results"); diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/action/StartDatafeedAction.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/action/StartDatafeedAction.java index a7282e48fe0..06cc24c5755 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/action/StartDatafeedAction.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/action/StartDatafeedAction.java @@ -33,7 +33,7 @@ import org.elasticsearch.common.joda.DateMathParser; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.ObjectParser; -import org.elasticsearch.common.xcontent.ToXContent; +import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.mapper.DateFieldMapper; @@ -96,7 +96,7 @@ public class StartDatafeedAction return new Response(); } - public static class Request extends MasterNodeRequest implements ToXContent { + public static class Request extends MasterNodeRequest implements ToXContentObject { public static Request fromXContent(XContentParser parser) { return parseRequest(null, parser); diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/action/StopDatafeedAction.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/action/StopDatafeedAction.java index f0886ae0a85..f047dd8a597 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/action/StopDatafeedAction.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/action/StopDatafeedAction.java @@ -34,6 +34,7 @@ import org.elasticsearch.common.util.concurrent.AbstractRunnable; import org.elasticsearch.common.util.concurrent.AtomicArray; import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.ToXContent; +import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.discovery.MasterNotDiscoveredException; @@ -84,7 +85,7 @@ public class StopDatafeedAction return new Response(); } - public static class Request extends BaseTasksRequest implements ToXContent { + public static class Request extends BaseTasksRequest implements ToXContentObject { public static ObjectParser PARSER = new ObjectParser<>(NAME, Request::new); diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/action/UpdateDatafeedAction.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/action/UpdateDatafeedAction.java index 8a9305119b6..2b64916dea4 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/action/UpdateDatafeedAction.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/action/UpdateDatafeedAction.java @@ -24,7 +24,7 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.xcontent.ToXContent; +import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.threadpool.ThreadPool; @@ -57,7 +57,7 @@ public class UpdateDatafeedAction extends Action implements ToXContent { + public static class Request extends AcknowledgedRequest implements ToXContentObject { public static Request parseRequest(String datafeedId, XContentParser parser) { DatafeedUpdate.Builder update = DatafeedUpdate.PARSER.apply(parser, null); diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/action/UpdateModelSnapshotAction.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/action/UpdateModelSnapshotAction.java index 01b762fc960..323c053395f 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/action/UpdateModelSnapshotAction.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/action/UpdateModelSnapshotAction.java @@ -29,6 +29,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.StatusToXContentObject; import org.elasticsearch.common.xcontent.ToXContent; +import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; @@ -67,7 +68,7 @@ public class UpdateModelSnapshotAction extends Action PARSER = new ObjectParser<>(NAME, Request::new); diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/action/ValidateDetectorAction.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/action/ValidateDetectorAction.java index fa109f37262..bc417798fa6 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/action/ValidateDetectorAction.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/action/ValidateDetectorAction.java @@ -19,7 +19,7 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.xcontent.ToXContent; +import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.threadpool.ThreadPool; @@ -57,7 +57,7 @@ extends Action { @@ -31,11 +30,16 @@ public class PutDatafeedActionRequestTests extends AbstractStreamableXContentTes @Override protected Request createTestInstance() { DatafeedConfig.Builder datafeedConfig = new DatafeedConfig.Builder(datafeedId, randomAlphaOfLength(10)); - datafeedConfig.setIndices(Arrays.asList(randomAlphaOfLength(10))); - datafeedConfig.setTypes(Arrays.asList(randomAlphaOfLength(10))); + datafeedConfig.setIndices(Collections.singletonList(randomAlphaOfLength(10))); + datafeedConfig.setTypes(Collections.singletonList(randomAlphaOfLength(10))); return new Request(datafeedConfig.build()); } + @Override + protected boolean supportsUnknownFields() { + return false; + } + @Override protected Request createBlankInstance() { return new Request(); diff --git a/plugin/src/test/java/org/elasticsearch/xpack/ml/action/PutFilterActionRequestTests.java b/plugin/src/test/java/org/elasticsearch/xpack/ml/action/PutFilterActionRequestTests.java index d73ca7e236a..c851bfb6f5c 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/ml/action/PutFilterActionRequestTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/ml/action/PutFilterActionRequestTests.java @@ -28,6 +28,11 @@ public class PutFilterActionRequestTests extends AbstractStreamableXContentTestC return new PutFilterAction.Request(filter); } + @Override + protected boolean supportsUnknownFields() { + return false; + } + @Override protected Request createBlankInstance() { return new PutFilterAction.Request(); diff --git a/plugin/src/test/java/org/elasticsearch/xpack/ml/action/PutJobActionRequestTests.java b/plugin/src/test/java/org/elasticsearch/xpack/ml/action/PutJobActionRequestTests.java index 4a9e498b6a3..3165266af24 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/ml/action/PutJobActionRequestTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/ml/action/PutJobActionRequestTests.java @@ -5,9 +5,8 @@ */ package org.elasticsearch.xpack.ml.action; -import org.elasticsearch.common.xcontent.NamedXContentRegistry; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.bytes.BytesReference; +import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.test.AbstractStreamableXContentTestCase; @@ -35,6 +34,11 @@ public class PutJobActionRequestTests extends AbstractStreamableXContentTestCase return new Request(); } + @Override + protected boolean supportsUnknownFields() { + return false; + } + @Override protected Request doParseInstance(XContentParser parser) { return Request.parseRequest(jobId, parser); @@ -43,10 +47,8 @@ public class PutJobActionRequestTests extends AbstractStreamableXContentTestCase public void testParseRequest_InvalidCreateSetting() throws IOException { Job.Builder jobConfiguration = buildJobBuilder(jobId, null); jobConfiguration.setLastDataTime(new Date()); - XContentBuilder xContentBuilder = toXContent(jobConfiguration, XContentType.JSON); - XContentParser parser = XContentFactory.xContent(XContentType.JSON) - .createParser(NamedXContentRegistry.EMPTY, xContentBuilder.bytes()); - + BytesReference bytes = XContentHelper.toXContent(jobConfiguration, XContentType.JSON, false); + XContentParser parser = createParser(XContentType.JSON.xContent(), bytes); expectThrows(IllegalArgumentException.class, () -> Request.parseRequest(jobId, parser)); } } diff --git a/plugin/src/test/java/org/elasticsearch/xpack/ml/action/RevertModelSnapshotActionRequestTests.java b/plugin/src/test/java/org/elasticsearch/xpack/ml/action/RevertModelSnapshotActionRequestTests.java index 40c4ce4d329..be1073a99b4 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/ml/action/RevertModelSnapshotActionRequestTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/ml/action/RevertModelSnapshotActionRequestTests.java @@ -21,6 +21,11 @@ public class RevertModelSnapshotActionRequestTests extends AbstractStreamableXCo return request; } + @Override + protected boolean supportsUnknownFields() { + return false; + } + @Override protected Request createBlankInstance() { return new RevertModelSnapshotAction.Request(); diff --git a/plugin/src/test/java/org/elasticsearch/xpack/ml/action/StartDatafeedActionRequestTests.java b/plugin/src/test/java/org/elasticsearch/xpack/ml/action/StartDatafeedActionRequestTests.java index b1ba1fbd4b2..f5edbab7b99 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/ml/action/StartDatafeedActionRequestTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/ml/action/StartDatafeedActionRequestTests.java @@ -28,6 +28,11 @@ public class StartDatafeedActionRequestTests extends AbstractStreamableXContentT return new Request(params); } + @Override + protected boolean supportsUnknownFields() { + return false; + } + @Override protected Request createBlankInstance() { return new Request(); diff --git a/plugin/src/test/java/org/elasticsearch/xpack/ml/action/StopDatafeedActionRequestTests.java b/plugin/src/test/java/org/elasticsearch/xpack/ml/action/StopDatafeedActionRequestTests.java index 7df3f05dc95..df7b82eaf44 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/ml/action/StopDatafeedActionRequestTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/ml/action/StopDatafeedActionRequestTests.java @@ -41,6 +41,11 @@ public class StopDatafeedActionRequestTests extends AbstractStreamableXContentTe return request; } + @Override + protected boolean supportsUnknownFields() { + return false; + } + @Override protected Request createBlankInstance() { return new Request(); diff --git a/plugin/src/test/java/org/elasticsearch/xpack/ml/action/UpdateDatafeedActionRequestTests.java b/plugin/src/test/java/org/elasticsearch/xpack/ml/action/UpdateDatafeedActionRequestTests.java index 7ebc12e5165..e5edf5ee74c 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/ml/action/UpdateDatafeedActionRequestTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/ml/action/UpdateDatafeedActionRequestTests.java @@ -32,6 +32,11 @@ public class UpdateDatafeedActionRequestTests extends AbstractStreamableXContent return new Request(DatafeedUpdateTests.createRandomized(datafeedId)); } + @Override + protected boolean supportsUnknownFields() { + return false; + } + @Override protected Request createBlankInstance() { return new Request(); diff --git a/plugin/src/test/java/org/elasticsearch/xpack/ml/action/UpdateModelSnapshotActionRequestTests.java b/plugin/src/test/java/org/elasticsearch/xpack/ml/action/UpdateModelSnapshotActionRequestTests.java index f4efdc5abe0..76ddf3fcbaa 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/ml/action/UpdateModelSnapshotActionRequestTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/ml/action/UpdateModelSnapshotActionRequestTests.java @@ -30,6 +30,11 @@ public class UpdateModelSnapshotActionRequestTests return request; } + @Override + protected boolean supportsUnknownFields() { + return false; + } + @Override protected Request createBlankInstance() { return new Request(); diff --git a/plugin/src/test/java/org/elasticsearch/xpack/ml/action/ValidateDetectorActionRequestTests.java b/plugin/src/test/java/org/elasticsearch/xpack/ml/action/ValidateDetectorActionRequestTests.java index 0ea90f79329..fc301714a04 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/ml/action/ValidateDetectorActionRequestTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/ml/action/ValidateDetectorActionRequestTests.java @@ -23,6 +23,11 @@ public class ValidateDetectorActionRequestTests extends AbstractStreamableXConte return new Request(detector.build()); } + @Override + protected boolean supportsUnknownFields() { + return false; + } + @Override protected Request createBlankInstance() { return new Request(); diff --git a/plugin/src/test/java/org/elasticsearch/xpack/ml/job/config/JobTests.java b/plugin/src/test/java/org/elasticsearch/xpack/ml/job/config/JobTests.java index 53c25fca109..6f5c296b08b 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/ml/job/config/JobTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/ml/job/config/JobTests.java @@ -7,11 +7,12 @@ package org.elasticsearch.xpack.ml.job.config; import com.carrotsearch.randomizedtesting.generators.CodepointSetGenerator; import org.elasticsearch.Version; +import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.NamedXContentRegistry; -import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.test.AbstractSerializingTestCase; @@ -405,9 +406,8 @@ public class JobTests extends AbstractSerializingTestCase { // Assert parsing a job without version works as expected XContentType xContentType = randomFrom(XContentType.values()); - XContentBuilder xContentBuilder = toXContent(job, xContentType); - - try(XContentParser parser = createParser(XContentFactory.xContent(xContentType), xContentBuilder.bytes())) { + BytesReference bytes = XContentHelper.toXContent(job, xContentType, false); + try(XContentParser parser = createParser(xContentType.xContent(), bytes)) { Job parsed = parseInstance(parser); assertThat(parsed, equalTo(job)); } diff --git a/plugin/src/test/java/org/elasticsearch/xpack/ml/job/results/AnomalyRecordTests.java b/plugin/src/test/java/org/elasticsearch/xpack/ml/job/results/AnomalyRecordTests.java index 4eb9fc63178..376ccd4631b 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/ml/job/results/AnomalyRecordTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/ml/job/results/AnomalyRecordTests.java @@ -5,10 +5,12 @@ */ package org.elasticsearch.xpack.ml.job.results; +import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.test.AbstractSerializingTestCase; @@ -101,8 +103,8 @@ public class AnomalyRecordTests extends AbstractSerializingTestCase map = parser.map(); List serialisedByFieldValues = (List) map.get(record.getByFieldName()); assertEquals(Collections.singletonList(record.getByFieldValue()), serialisedByFieldValues); @@ -133,8 +135,8 @@ public class AnomalyRecordTests extends AbstractSerializingTestCase map = parser.map(); List serialisedCarMakeFieldValues = (List) map.get("car-make"); assertEquals(Arrays.asList("ford", "VW"), serialisedCarMakeFieldValues); @@ -150,8 +152,8 @@ public class AnomalyRecordTests extends AbstractSerializingTestCase { public void testToXContentIncludesNameValueField() throws IOException { Influencer influencer = createTestInstance("foo"); - XContentBuilder builder = toXContent(influencer, XContentType.JSON); - XContentParser parser = createParser(builder); + BytesReference bytes = XContentHelper.toXContent(influencer, XContentType.JSON, false); + XContentParser parser = createParser(XContentType.JSON.xContent(), bytes); String serialisedFieldName = (String) parser.map().get(influencer.getInfluencerFieldName()); assertNotNull(serialisedFieldName); assertEquals(influencer.getInfluencerFieldValue(), serialisedFieldName); @@ -54,8 +56,8 @@ public class InfluencerTests extends AbstractSerializingTestCase { public void testToXContentDoesNotIncludeNameValueFieldWhenReservedWord() throws IOException { Influencer influencer = new Influencer("foo", Influencer.INFLUENCER_SCORE.getPreferredName(), "bar", new Date(), 300L); - XContentBuilder builder = toXContent(influencer, XContentType.JSON); - XContentParser parser = createParser(builder); + BytesReference bytes = XContentHelper.toXContent(influencer, XContentType.JSON, false); + XContentParser parser = createParser(XContentType.JSON.xContent(), bytes); Object serialisedFieldValue = parser.map().get(Influencer.INFLUENCER_SCORE.getPreferredName()); assertNotNull(serialisedFieldValue); assertNotEquals("bar", serialisedFieldValue); diff --git a/plugin/src/test/java/org/elasticsearch/xpack/persistent/PersistentTasksCustomMetaDataTests.java b/plugin/src/test/java/org/elasticsearch/xpack/persistent/PersistentTasksCustomMetaDataTests.java index 57a6a2e2812..82e945f63b1 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/persistent/PersistentTasksCustomMetaDataTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/persistent/PersistentTasksCustomMetaDataTests.java @@ -12,12 +12,12 @@ import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.metadata.MetaData.Custom; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.UUIDs; +import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.io.stream.NamedWriteableRegistry.Entry; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.ToXContent; -import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; @@ -27,8 +27,8 @@ import org.elasticsearch.xpack.persistent.PersistentTasksCustomMetaData.Assignme import org.elasticsearch.xpack.persistent.PersistentTasksCustomMetaData.Builder; import org.elasticsearch.xpack.persistent.PersistentTasksCustomMetaData.PersistentTask; import org.elasticsearch.xpack.persistent.TestPersistentTasksPlugin.Status; -import org.elasticsearch.xpack.persistent.TestPersistentTasksPlugin.TestPersistentTasksExecutor; import org.elasticsearch.xpack.persistent.TestPersistentTasksPlugin.TestParams; +import org.elasticsearch.xpack.persistent.TestPersistentTasksPlugin.TestPersistentTasksExecutor; import java.io.IOException; import java.util.ArrayList; @@ -114,27 +114,13 @@ public class PersistentTasksCustomMetaDataTests extends AbstractDiffableSerializ return PersistentTasksCustomMetaData.fromXContent(parser); } +/* @Override protected XContentBuilder toXContent(Custom instance, XContentType contentType) throws IOException { return toXContent(instance, contentType, new ToXContent.MapParams( Collections.singletonMap(MetaData.CONTEXT_MODE_PARAM, MetaData.XContentContext.API.toString()))); } - - protected XContentBuilder toXContent(Custom instance, XContentType contentType, ToXContent.MapParams params) throws IOException { - // We need all attribute to be serialized/de-serialized for testing - XContentBuilder builder = XContentFactory.contentBuilder(contentType); - if (randomBoolean()) { - builder.prettyPrint(); - } - if (instance.isFragment()) { - builder.startObject(); - } - instance.toXContent(builder, params); - if (instance.isFragment()) { - builder.endObject(); - } - return builder; - } +*/ private String addRandomTask(Builder builder) { String taskId = UUIDs.base64UUID(); @@ -166,10 +152,9 @@ public class PersistentTasksCustomMetaDataTests extends AbstractDiffableSerializ Collections.singletonMap(MetaData.CONTEXT_MODE_PARAM, randomFrom(CONTEXT_MODE_SNAPSHOT, CONTEXT_MODE_GATEWAY))); XContentType xContentType = randomFrom(XContentType.values()); - XContentBuilder builder = toXContent(testInstance, xContentType, params); - XContentBuilder shuffled = shuffleXContent(builder); + BytesReference shuffled = toShuffledXContent(testInstance, xContentType, params, false); - XContentParser parser = createParser(XContentFactory.xContent(xContentType), shuffled.bytes()); + XContentParser parser = createParser(XContentFactory.xContent(xContentType), shuffled); PersistentTasksCustomMetaData newInstance = doParseInstance(parser); assertNotSame(newInstance, testInstance);