Skip to content

Commit

Permalink
Fix ILM status to allow unknown fields (#38043)
Browse files Browse the repository at this point in the history
The ILM status parser did not allow for unknown fields. This commit
fixes that and adds an xContentTester to the response test.

Relates #36938
  • Loading branch information
hub-cap authored Jan 30, 2019
1 parent 14c5715 commit daafcb6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class LifecycleManagementStatusResponse {
private static final String OPERATION_MODE = "operation_mode";
@SuppressWarnings("unchecked")
private static final ConstructingObjectParser<LifecycleManagementStatusResponse, Void> PARSER = new ConstructingObjectParser<>(
OPERATION_MODE, a -> new LifecycleManagementStatusResponse((String) a[0]));
OPERATION_MODE, true, a -> new LifecycleManagementStatusResponse((String) a[0]));

static {
PARSER.declareString(ConstructingObjectParser.constructorArg(), new ParseField(OPERATION_MODE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.elasticsearch.common.xcontent.DeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.test.ESTestCase;
Expand All @@ -30,8 +31,31 @@
import java.util.EnumSet;
import java.util.stream.Collectors;

import static org.elasticsearch.test.AbstractXContentTestCase.xContentTester;

public class LifecycleManagementStatusResponseTests extends ESTestCase {

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

private static XContentBuilder toXContent(LifecycleManagementStatusResponse response, XContentBuilder builder) throws IOException {
builder.startObject();
builder.field("operation_mode", response.getOperationMode());
builder.endObject();
return builder;
}

private static LifecycleManagementStatusResponse createTestInstance() {
return new LifecycleManagementStatusResponse(randomFrom(OperationMode.values()).name());
}

public void testAllValidStatuses() {
EnumSet.allOf(OperationMode.class)
.forEach(e -> assertEquals(new LifecycleManagementStatusResponse(e.name()).getOperationMode(), e));
Expand Down

0 comments on commit daafcb6

Please sign in to comment.