|
12 | 12 | import com.carrotsearch.randomizedtesting.RandomizedContext; |
13 | 13 |
|
14 | 14 | import org.elasticsearch.common.bytes.BytesReference; |
15 | | -import org.elasticsearch.xcontent.ToXContentFragment; |
16 | 15 | import org.elasticsearch.xcontent.XContentBuilder; |
17 | 16 | import org.elasticsearch.xcontent.XContentFactory; |
18 | 17 | import org.elasticsearch.xcontent.XContentParser; |
19 | 18 | import org.elasticsearch.xcontent.XContentType; |
20 | 19 |
|
21 | | -import java.io.IOException; |
22 | 20 | import java.util.Map; |
23 | 21 |
|
24 | 22 | import static org.hamcrest.Matchers.equalTo; |
@@ -51,42 +49,4 @@ public void testInsertRandomFieldsAndShuffle() throws Exception { |
51 | 49 | assertThat(mapOrdered.keySet().iterator().next(), not(equalTo("field"))); |
52 | 50 | } |
53 | 51 | } |
54 | | - |
55 | | - private record TestToXContent(String field, String value) implements ToXContentFragment { |
56 | | - |
57 | | - @Override |
58 | | - public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { |
59 | | - return builder.field(field, value); |
60 | | - } |
61 | | - } |
62 | | - |
63 | | - public void testYamlXContentRoundtripSanitization() throws Exception { |
64 | | - var test = new AbstractXContentTestCase<TestToXContent>() { |
65 | | - |
66 | | - @Override |
67 | | - protected TestToXContent createTestInstance() { |
68 | | - // we need to randomly create both a "problematic" and an okay version in order to ensure that the sanitization code |
69 | | - // can draw at least one okay version if polled often enough |
70 | | - return randomBoolean() ? new TestToXContent("a\u0085b", "def") : new TestToXContent("a b", "def"); |
71 | | - } |
72 | | - |
73 | | - @Override |
74 | | - protected TestToXContent doParseInstance(XContentParser parser) throws IOException { |
75 | | - assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken()); |
76 | | - assertEquals(XContentParser.Token.FIELD_NAME, parser.nextToken()); |
77 | | - String name = parser.currentName(); |
78 | | - assertEquals(XContentParser.Token.VALUE_STRING, parser.nextToken()); |
79 | | - String value = parser.text(); |
80 | | - assertEquals(XContentParser.Token.END_OBJECT, parser.nextToken()); |
81 | | - return new TestToXContent(name, value); |
82 | | - }; |
83 | | - |
84 | | - @Override |
85 | | - protected boolean supportsUnknownFields() { |
86 | | - return false; |
87 | | - } |
88 | | - }; |
89 | | - // testFromXContent runs 20 repetitions, enough to hit a YAML xcontent version very likely |
90 | | - test.testFromXContent(); |
91 | | - } |
92 | 52 | } |
0 commit comments