Skip to content

Commit 0adef95

Browse files
authored
Fix ILM status to allow unknown fields (#38342)
The ILM status parser did not allow for unknown fields. This commit fixes that and adds an xContentTester to the response test. Relates #36938 Backport of #38043
1 parent e78f416 commit 0adef95

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/indexlifecycle/LifecycleManagementStatusResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class LifecycleManagementStatusResponse {
3434
private static final String OPERATION_MODE = "operation_mode";
3535
@SuppressWarnings("unchecked")
3636
private static final ConstructingObjectParser<LifecycleManagementStatusResponse, Void> PARSER = new ConstructingObjectParser<>(
37-
OPERATION_MODE, a -> new LifecycleManagementStatusResponse((String) a[0]));
37+
OPERATION_MODE, true, a -> new LifecycleManagementStatusResponse((String) a[0]));
3838

3939
static {
4040
PARSER.declareString(ConstructingObjectParser.constructorArg(), new ParseField(OPERATION_MODE));

client/rest-high-level/src/test/java/org/elasticsearch/client/indexlifecycle/LifecycleManagementStatusResponseTests.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import org.elasticsearch.common.xcontent.DeprecationHandler;
2323
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
24+
import org.elasticsearch.common.xcontent.XContentBuilder;
2425
import org.elasticsearch.common.xcontent.XContentParser;
2526
import org.elasticsearch.common.xcontent.XContentType;
2627
import org.elasticsearch.test.ESTestCase;
@@ -30,8 +31,31 @@
3031
import java.util.EnumSet;
3132
import java.util.stream.Collectors;
3233

34+
import static org.elasticsearch.test.AbstractXContentTestCase.xContentTester;
35+
3336
public class LifecycleManagementStatusResponseTests extends ESTestCase {
3437

38+
public void testFromXContent() throws IOException {
39+
xContentTester(this::createParser,
40+
LifecycleManagementStatusResponseTests::createTestInstance,
41+
LifecycleManagementStatusResponseTests::toXContent,
42+
LifecycleManagementStatusResponse::fromXContent)
43+
.supportsUnknownFields(true)
44+
.assertToXContentEquivalence(false)
45+
.test();
46+
}
47+
48+
private static XContentBuilder toXContent(LifecycleManagementStatusResponse response, XContentBuilder builder) throws IOException {
49+
builder.startObject();
50+
builder.field("operation_mode", response.getOperationMode());
51+
builder.endObject();
52+
return builder;
53+
}
54+
55+
private static LifecycleManagementStatusResponse createTestInstance() {
56+
return new LifecycleManagementStatusResponse(randomFrom(OperationMode.values()).name());
57+
}
58+
3559
public void testAllValidStatuses() {
3660
EnumSet.allOf(OperationMode.class)
3761
.forEach(e -> assertEquals(new LifecycleManagementStatusResponse(e.name()).getOperationMode(), e));

0 commit comments

Comments
 (0)