Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Delete Watch to allow unknown fields #37435

Merged
merged 2 commits into from
Jan 15, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
import java.io.IOException;
import java.util.Objects;

public class DeleteWatchResponse implements ToXContentObject {
public class DeleteWatchResponse {

private static final ObjectParser<DeleteWatchResponse, Void> PARSER
= new ObjectParser<>("x_pack_delete_watch_response", DeleteWatchResponse::new);
= new ObjectParser<>("x_pack_delete_watch_response", true, DeleteWatchResponse::new);
static {
PARSER.declareString(DeleteWatchResponse::setId, new ParseField("_id"));
PARSER.declareLong(DeleteWatchResponse::setVersion, new ParseField("_version"));
Expand Down Expand Up @@ -89,15 +89,6 @@ public int hashCode() {
return Objects.hash(id, version, found);
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
return builder.startObject()
.field("_id", id)
.field("_version", version)
.field("found", found)
.endObject();
}

public static DeleteWatchResponse fromXContent(XContentParser parser) throws IOException {
return PARSER.parse(parser, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,37 @@
*/
package org.elasticsearch.client.watcher;

import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.test.AbstractXContentTestCase;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.test.ESTestCase;

import java.io.IOException;

public class DeleteWatchResponseTests extends AbstractXContentTestCase<DeleteWatchResponse> {
import static org.elasticsearch.test.AbstractXContentTestCase.xContentTester;

@Override
protected DeleteWatchResponse createTestInstance() {
String id = randomAlphaOfLength(10);
long version = randomLongBetween(1, 10);
boolean found = randomBoolean();
return new DeleteWatchResponse(id, version, found);
public class DeleteWatchResponseTests extends ESTestCase {

public void testFromXContent() throws IOException {
xContentTester(this::createParser,
DeleteWatchResponseTests::createTestInstance,
DeleteWatchResponseTests::toXContent,
DeleteWatchResponse::fromXContent)
.supportsUnknownFields(true)
.assertToXContentEquivalence(false)
.test();
}

@Override
protected DeleteWatchResponse doParseInstance(XContentParser parser) throws IOException {
return DeleteWatchResponse.fromXContent(parser);
private static XContentBuilder toXContent(DeleteWatchResponse response, XContentBuilder builder) throws IOException {
return builder.startObject()
.field("_id", response.getId())
.field("_version", response.getVersion())
.field("found", response.isFound())
.endObject();
}

@Override
protected boolean supportsUnknownFields() {
return false;
private static DeleteWatchResponse createTestInstance() {
String id = randomAlphaOfLength(10);
long version = randomLongBetween(1, 10);
boolean found = randomBoolean();
return new DeleteWatchResponse(id, version, found);
}
}