Browse Source

Moving xpack.plugin.core ml response to use new base class (#35157)

* Moving xpack.plugin.core ml response to use new base class

* changing back to streamable
Benjamin Trent 7 years ago
parent
commit
7fb95be8bd

+ 25 - 6
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/PutCalendarActionResponseTests.java

@@ -5,14 +5,16 @@
  */
 package org.elasticsearch.xpack.core.ml.action;
 
+import org.elasticsearch.client.ml.PutCalendarResponse;
 import org.elasticsearch.common.xcontent.XContentParser;
-import org.elasticsearch.test.AbstractStreamableXContentTestCase;
+import org.elasticsearch.protocol.AbstractHlrcStreamableXContentTestCase;
 import org.elasticsearch.xpack.core.ml.calendars.Calendar;
 import org.elasticsearch.xpack.core.ml.calendars.CalendarTests;
 
 import java.io.IOException;
 
-public class PutCalendarActionResponseTests extends AbstractStreamableXContentTestCase<PutCalendarAction.Response> {
+public class PutCalendarActionResponseTests
+    extends AbstractHlrcStreamableXContentTestCase<PutCalendarAction.Response, PutCalendarResponse> {
 
     @Override
     protected PutCalendarAction.Response createTestInstance() {
@@ -20,12 +22,29 @@ public class PutCalendarActionResponseTests extends AbstractStreamableXContentTe
     }
 
     @Override
-    protected PutCalendarAction.Response createBlankInstance() {
-        return new PutCalendarAction.Response();
+    protected PutCalendarAction.Response doParseInstance(XContentParser parser) throws IOException {
+        return new PutCalendarAction.Response(Calendar.LENIENT_PARSER.parse(parser, null).build());
     }
 
     @Override
-    protected PutCalendarAction.Response doParseInstance(XContentParser parser) throws IOException {
-        return new PutCalendarAction.Response(Calendar.LENIENT_PARSER.parse(parser, null).build());
+    protected boolean supportsUnknownFields() {
+        return true;
+    }
+
+    @Override
+    public PutCalendarResponse doHlrcParseInstance(XContentParser parser) throws IOException {
+        return PutCalendarResponse.fromXContent(parser);
+    }
+
+    @Override
+    public PutCalendarAction.Response convertHlrcToInternal(PutCalendarResponse instance) {
+        org.elasticsearch.client.ml.calendars.Calendar hlrcCalendar = instance.getCalendar();
+        Calendar internalCalendar = new Calendar(hlrcCalendar.getId(), hlrcCalendar.getJobIds(), hlrcCalendar.getDescription());
+        return new PutCalendarAction.Response(internalCalendar);
+    }
+
+    @Override
+    protected PutCalendarAction.Response createBlankInstance() {
+        return new PutCalendarAction.Response();
     }
 }