|
35 | 35 | import org.opensearch.common.collect.Tuple;
|
36 | 36 | import org.opensearch.common.document.DocumentField;
|
37 | 37 | import org.opensearch.common.io.stream.BytesStreamOutput;
|
| 38 | +import org.opensearch.common.xcontent.LoggingDeprecationHandler; |
38 | 39 | import org.opensearch.common.xcontent.XContentType;
|
| 40 | +import org.opensearch.common.xcontent.json.JsonXContent; |
| 41 | +import org.opensearch.core.common.ParsingException; |
39 | 42 | import org.opensearch.core.common.Strings;
|
40 | 43 | import org.opensearch.core.common.bytes.BytesArray;
|
41 | 44 | import org.opensearch.core.common.bytes.BytesReference;
|
42 | 45 | import org.opensearch.core.xcontent.MediaType;
|
43 | 46 | import org.opensearch.core.xcontent.MediaTypeRegistry;
|
| 47 | +import org.opensearch.core.xcontent.NamedXContentRegistry; |
44 | 48 | import org.opensearch.core.xcontent.ToXContent;
|
45 | 49 | import org.opensearch.core.xcontent.XContentParser;
|
46 | 50 | import org.opensearch.index.mapper.IdFieldMapper;
|
@@ -220,6 +224,22 @@ public void testEqualsAndHashcode() {
|
220 | 224 | );
|
221 | 225 | }
|
222 | 226 |
|
| 227 | + public void testFomXContentEmbeddedFoundParsingException() throws IOException { |
| 228 | + String json = "{\"_index\":\"foo\",\"_id\":\"bar\"}"; |
| 229 | + try ( |
| 230 | + XContentParser parser = JsonXContent.jsonXContent.createParser( |
| 231 | + NamedXContentRegistry.EMPTY, |
| 232 | + LoggingDeprecationHandler.INSTANCE, |
| 233 | + json |
| 234 | + ) |
| 235 | + ) { |
| 236 | + ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser); |
| 237 | + ParsingException parsingException = assertThrows(ParsingException.class, () -> GetResult.fromXContentEmbedded(parser)); |
| 238 | + assertEquals("Missing required field [found]", parsingException.getMessage()); |
| 239 | + } |
| 240 | + |
| 241 | + } |
| 242 | + |
223 | 243 | public static GetResult copyGetResult(GetResult getResult) {
|
224 | 244 | return new GetResult(
|
225 | 245 | getResult.getIndex(),
|
|
0 commit comments