@Then("^the user should receive a specified JSON content$") public void jsonResponse() throws Exception { assertThat(response.getHeaders("Content-Type")) .extracting(Header::getValue) .containsExactly(org.apache.http.entity.ContentType.APPLICATION_JSON.toString()); DocumentContext jsonPath = JsonPath.parse(response.getEntity().getContent()); assertThat(jsonPath.<String>read("blobId")).isEqualTo(_1M_ZEROED_FILE_BLOB_ID); assertThat(jsonPath.<String>read("type")).isEqualTo("application/octet-stream"); assertThat(jsonPath.<Integer>read("size")).isEqualTo(_1M); }
public void testInitialSearchEntity() throws IOException { String query = "{\"match_all\":{}}"; HttpEntity entity = initialSearchEntity(new BytesArray(query)); assertEquals(ContentType.APPLICATION_JSON.toString(), entity.getContentType().getValue()); assertEquals( "{\"query\":" + query + "}", Streams.copyToString(new InputStreamReader(entity.getContent(), StandardCharsets.UTF_8))); // Invalid XContent fails RuntimeException e = expectThrows( RuntimeException.class, () -> initialSearchEntity(new BytesArray("{}, \"trailing\": {}"))); assertThat(e.getCause().getMessage(), containsString("Unexpected character (',' (code 44))")); e = expectThrows(RuntimeException.class, () -> initialSearchEntity(new BytesArray("{"))); assertThat(e.getCause().getMessage(), containsString("Unexpected end-of-input")); }