@Test public void testParseClearScrollRequestWithInvalidJsonThrowsException() throws Exception { ClearScrollRequest clearScrollRequest = new ClearScrollRequest(); try { RestClearScrollAction.buildFromContent(new BytesArray("{invalid_json}"), clearScrollRequest); fail("expected parseContent failure"); } catch (Exception e) { assertThat(e, instanceOf(IllegalArgumentException.class)); assertThat(e.getMessage(), equalTo("Failed to parse request body")); } }
@Test public void testParseClearScrollRequestWithUnknownParamThrowsException() throws Exception { BytesReference invalidContent = XContentFactory.jsonBuilder() .startObject() .array("scroll_id", "value_1", "value_2") .field("unknown", "keyword") .endObject() .bytes(); ClearScrollRequest clearScrollRequest = new ClearScrollRequest(); try { RestClearScrollAction.buildFromContent(invalidContent, clearScrollRequest); fail("expected parseContent failure"); } catch (Exception e) { assertThat(e, instanceOf(IllegalArgumentException.class)); assertThat(e.getMessage(), startsWith("Unknown parameter [unknown]")); } }