Пример #1
0
 private Map<String, Object> parseBody(RestResponse response) throws IOException {
   return XContentFactory.xContent(XContentType.JSON)
       .createParser(
           response.getBody().array(),
           response.getBody().arrayOffset(),
           response.getBody().remaining())
       .map();
 }
Пример #2
0
 @Test
 public void testSimpleApis() throws Exception {
   RestRequest request = new RestRequest(Method.POST, "/test/type1");
   request.setBody(
       ByteBuffer.wrap(
           XContentFactory.jsonBuilder()
               .startObject()
               .field("field", "value")
               .endObject()
               .copiedBytes()));
   RestResponse response = client.execute(request);
   Map<String, Object> map = parseBody(response);
   assertThat(response.getStatus(), equalTo(Status.OK));
   assertThat(map.get("ok").toString(), equalTo("true"));
   assertThat(map.get("_index").toString(), equalTo("test"));
   assertThat(map.get("_type").toString(), equalTo("type1"));
 }