예제 #1
0
  @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"));
    }
  }
예제 #2
0
 @Test
 public void testParseClearScrollRequest() throws Exception {
   BytesReference content =
       XContentFactory.jsonBuilder()
           .startObject()
           .array("scroll_id", "value_1", "value_2")
           .endObject()
           .bytes();
   ClearScrollRequest clearScrollRequest = new ClearScrollRequest();
   RestClearScrollAction.buildFromContent(content, clearScrollRequest);
   assertThat(clearScrollRequest.scrollIds(), contains("value_1", "value_2"));
 }
예제 #3
0
  @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]"));
    }
  }