responseBodyToAppend = new Prettifier().getPrettifiedBodyIfPossible(responseOptions, responseBody); } else { responseBodyToAppend = responseBody.asString();
/** * Create a one-side applink without any auth enabled. * * @param request request to create the applink * @return created applink */ @Nonnull public TestApplink.Side createSide(@Nonnull BackdoorCreateSideApplinkRequest request) { JsonPath result = applinksTester.post(request).getBody().jsonPath(); return new DefaultTestApplink.DefaultSide(result.getString("linkId"), instance); }
@Override public byte[] getContent() { return response.getBody().asByteArray(); } }
@Test public void testNotFound() { final ResponseBody response = expect(). statusCode(404). contentType("text/html"). given(). header("Accept", "text/html"). when(). get(ConfigurationService.RESOURCE_PATH + "/foo"). getBody(); //response.print(); final ResponseBody responseJson = expect(). statusCode(404). contentType("application/json"). given(). header("Accept", "application/json"). when(). get(ConfigurationService.RESOURCE_PATH + "/foo"). getBody(); responseJson.print(); Assert.assertEquals(404, responseJson.jsonPath().get("status")); Assert.assertEquals("Not Found", responseJson.jsonPath().get("reason")); }
@Test @InSequence(0) public void shouldBeAbleToLocateConferenceRoot() throws Exception { //uri_conference = new URL(base, "api/conference").toExternalForm(); uri_conference = given(). then(). contentType(BASE_MEDIA_TYPE). statusCode(Status.OK.getStatusCode()). root("root"). body("link.find {it.@rel == 'conference'}.size()", equalTo(1)). when(). get(new URL(base, "api/").toExternalForm()). body(). path("root.link.find {it.@rel == 'conference'}.@href"); }
.contentType(TEXT_TURTLE) .get(container) .body().as(Model.class, new RdfObjectMapper(container));
String field = exp[0]; String validation = exp[1]; assertTrue(CompareField.validate(response.body().prettyPrint(),field,validation), "failed: " + field + validation);
@Test @InSequence(2) public void shouldBeAbleToGetAttachment() throws Exception { assertNotNull("Previous step failed", uri_attachmentInstance); given(). then(). contentType(ATTACHMENT_MEDIA_TYPE). statusCode(Status.OK.getStatusCode()). when(). get(uri_attachmentInstance). body(). path("attachment.link.find {it.@rel == 'session'}.@href"); }
protected void expectPut4xxResponseBody(String invalidProp) { Response putResponse = expectPut4xxStatus(invalidProp); assertThat(putResponse.body().asString(), not(isEmptyOrNullString())); }
/** * Create a reciprocal applink without any auth enabled. * * @param request request to create the applink * @return created applink */ @Nonnull public TestApplink create(@Nonnull BackdoorCreateApplinkRequest request) { Response response = applinksTester.post(request); JsonPath result = response.getBody().jsonPath(); if (result.get("errors") != null) { throw new RuntimeException("Error response " + response.as(RestErrors.class)); } return new DefaultTestApplink.Builder() .from(result.getString("linkId"), instance) .to(result.getString("localId"), request.to) .build(); }
@Override public byte[] getContent() { return response.getBody().asByteArray(); } }
@Test @InSequence(2) public void shouldBeAbleToGetConference() throws Exception { assertNotNull("Previous step failed", uri_conferenceInstance); uri_session = given(). then(). contentType(CONFERENCE_MEDIA_TYPE). statusCode(Status.OK.getStatusCode()). root("conference"). body("link.find {it.@rel == 'bookmark'}.size()", equalTo(1)). body("link.find {it.@rel == 'self'}.size()", equalTo(1)). when(). get(uri_conferenceInstance). body(). path("conference.link.find {it.@rel == 'session'}.@href"); }
protected static UserDTO assertUserExists(String path){ Response response = given() .expect().log().ifError() .statusCode(HttpStatus.SC_OK) .when() .get(getHost() + CONTEXT_PATH + path + JSON_SUFFIX); return deserialize(response.getBody().asString()); } }
JsonPath path = body.jsonPath(); if (path != null) { int successful = path.get("_shards.successful");
.when() .get(response.getHeader(LOCATION)) .body().asByteArray(); assertEquals(expectedMD5, HashUtils.md5sum(binary), "md5sum"); } finally {
@Test public void validate_comments_for_task() throws Exception { // given: MockMvcRequestSpecification request = given() .header("Accept", "application/json"); // when: ResponseOptions response = given().spec(request) .get("/comments/task11"); // then: assertThat(response.statusCode()).isEqualTo(200); assertThat(response.header("Content-Type")).matches("application/json.*"); // and: DocumentContext parsedJson = JsonPath.parse(response.getBody().asString()); assertThatJson(parsedJson).array().contains("['taskId']").isEqualTo("task11"); assertThatJson(parsedJson).array().contains("['comment']").isEqualTo("comment on task11"); assertThatJson(parsedJson).array().contains("['comment']").isEqualTo("new comment on task11"); convertTimeValueToDate(parsedJson.read("$.[0].posted")); convertTimeValueToDate(parsedJson.read("$.[1].posted")); }
JsonPath path = body.jsonPath(); if (path != null) { int successful = path.get("_shards.successful");
.when() .get(location) .body().asByteArray(); assertEquals(expectedMD5, HashUtils.md5sum(binary), "md5sum"); } finally {
JsonPath path = body.jsonPath(); if (path != null) { Boolean created = path.get("created");
JsonPath path = body.jsonPath(); if (path != null) { Boolean created = path.get("created");