private Map<String, Object> parseBody(RestResponse response) throws IOException { return XContentFactory.xContent(XContentType.JSON) .createParser( response.bufferForBody().array(), response.bufferForBody().arrayOffset(), response.bufferForBody().remaining()) .map(); }
@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")); }