Fix expectation on parsing exception (#31108)

The structure of the expected exception slightly changed, the change adapts the
assertions accordingly.

Closes #31104
This commit is contained in:
Christoph Büscher 2018-06-06 09:58:16 +02:00 committed by GitHub
parent 1cee45e768
commit 0c9d4cb417
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -131,22 +131,19 @@ public class RatedRequestsTests extends ESTestCase {
}
}
@AwaitsFix(bugUrl="https://github.com/elastic/elasticsearch/issues/31104")
public void testXContentParsingIsNotLenient() throws IOException {
RatedRequest testItem = createTestItem(randomBoolean());
XContentType xContentType = randomFrom(XContentType.values());
BytesReference originalBytes = toShuffledXContent(testItem, xContentType, ToXContent.EMPTY_PARAMS, randomBoolean());
BytesReference withRandomFields = insertRandomFields(xContentType, originalBytes, null, random());
try (XContentParser parser = createParser(xContentType.xContent(), withRandomFields)) {
Exception exception = expectThrows(Exception.class, () -> RatedRequest.fromXContent(parser));
if (exception instanceof XContentParseException) {
XContentParseException xcpe = (XContentParseException) exception;
assertThat(xcpe.getCause().getMessage(), containsString("unknown field"));
assertThat(xcpe.getCause().getMessage(), containsString("parser not found"));
}
if (exception instanceof XContentParseException) {
Throwable exception = expectThrows(XContentParseException.class, () -> RatedRequest.fromXContent(parser));
if (exception.getCause() != null) {
assertThat(exception.getMessage(), containsString("[request] failed to parse field"));
exception = exception.getCause();
}
assertThat(exception.getMessage(), containsString("unknown field"));
assertThat(exception.getMessage(), containsString("parser not found"));
}
}