@Test public void failChild() throws Exception { String expected = jsonParser.getJson("/ResourceIT/failChild.json"); given().when().get("/parent/1/unknown").then().statusCode(HttpStatus.SC_NOT_FOUND) .body(equalTo(expected)); }
@Test public void testChild() throws Exception { String expected = jsonParser.getJson("/ResourceIT/testChild.json"); given().when().get("/parent/1/children/1").then().statusCode(HttpStatus.SC_OK) .body(equalTo(expected)); }
@Test public void failFieldRequest() throws Exception { String expected = jsonParser.getJson("/ResourceIT/failFieldRequest.json"); given().when().get("/parent/1/id").then().statusCode(HttpStatus.SC_NOT_FOUND) .body(equalTo(expected)); }
@Test public void failRootCollection() throws Exception { String expected = jsonParser.getJson("/ResourceIT/failRootCollection.json"); given().when().get("/unknown").then().statusCode(HttpStatus.SC_NOT_FOUND) .body(equalTo(expected)); }
@Test(priority = 12) public void failDeleteParent() { given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .delete("/parent/678") .then() .statusCode(HttpStatus.SC_NOT_FOUND); }
@Test(priority = 8) public void testGetRelEmptyColl() { String expected = jsonParser.getJson("/ResourceIT/testGetRelEmptyColl.json"); given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .get("/parent/4/relationships/children") .then() .statusCode(HttpStatus.SC_OK) .body(equalTo(expected)); }
@Test(dataProvider = "like_queries") public void testSpecialCharacterLikeQuery(String filterParam, int noOfRecords) throws Exception { String actual = given().when().get(String.format("/book?%s", filterParam)).then().statusCode(HttpStatus.SC_OK) .extract().body().asString(); JsonApiDocument doc = jsonApiMapper.readJsonApiDocument(actual); assertEquals(doc.getData().get().size(), noOfRecords); }
@Test(priority = 11) public void testNoDeleteExcludedRelationship() throws Exception { given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .body("{\"data\":{\"type\":\"excludedRelationship\",\"id\":\"1\"}}") .delete("/parent/4/children/4/relationships/excludedRelationship") .then() .statusCode(HttpStatus.SC_NOT_FOUND); }
@Test(priority = 11) public void testForbiddenDeleteEmptyCollectionRelationship() throws Exception { given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .body("{\"data\":[]}") .delete("/parent/4/children/4/relationships/parents") .then() .statusCode(HttpStatus.SC_FORBIDDEN); }
@Test public void testRootCollectionId() { String expected = jsonParser.getJson("/ResourceIT/testRootCollectionId.json"); String actual = given().when().get("/parent/1").then().statusCode(HttpStatus.SC_OK) .extract().body().asString(); assertEquals(actual, expected); }
@Test(priority = 2) public void testAuditWithDuplicateLineageEntry() { String request = jsonParser.getJson("/AuditIT/updateAuditEntityLineageDup.req.json"); given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .body(request) .patch("/auditEntity/2/otherEntity/1") .then() .statusCode(HttpStatus.SC_NO_CONTENT); Assert.assertTrue(logger.logMessages.contains("Updated value (for id: 1): update id 1 through id 2")); }
@Test(priority = -1) public void testRootCollection() throws Exception { String actual = given().when().get("/parent").then().statusCode(HttpStatus.SC_OK) .extract().body().asString(); JsonApiDocument doc = jsonApiMapper.readJsonApiDocument(actual); assertEquals(doc.getData().get().size(), 4); }
@Test public void createParentBadUri() { String request = jsonParser.getJson("/ResourceIT/createParentBadUri.json"); given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .body(request) .post("/parent/678") .then() .statusCode(HttpStatus.SC_NOT_FOUND); }
@Test public void testPrivilegeEscalation() throws Exception { String request = jsonParser.getJson("/ResourceIT/testUserRoleModification.req.json"); given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .body(request) .patch("/user/1") .then() .statusCode(HttpStatus.SC_FORBIDDEN); }
@Test(priority = 3) public void testPatchAttrList() throws Exception { String request = jsonParser.getJson("/ResourceIT/testPatchAttrList.json"); given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .body(request) .patch("/parent/3") .then() .statusCode(HttpStatus.SC_BAD_REQUEST); }
@Test(priority = 10) public void testPatchRelNoUpdateDirect() throws Exception { String request = jsonParser.getJson("/ResourceIT/testPatchRelNoUpdateDirect.json"); given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .body(request) .patch("/parent/4/relationships/children") .then() .statusCode(HttpStatus.SC_NO_CONTENT) .header(HttpHeaders.CONTENT_LENGTH, (String) null); }
@Test(priority = 6) public void testPatchRelNoUpdateSingle() { String request = jsonParser.getJson("/ResourceIT/testPatchRelNoUpdateSingle.json"); given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .body(request) .patch("/parent/4") .then() .statusCode(HttpStatus.SC_NO_CONTENT) .header(HttpHeaders.CONTENT_LENGTH, (String) null); }
@Test(priority = 2) public void testPatchAttrNoUpdateSingle() { String request = jsonParser.getJson("/ResourceIT/testPatchAttrNoUpdateSingle.json"); given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .body(request) .patch("/parent/2") .then() .statusCode(HttpStatus.SC_NO_CONTENT) .body(isEmptyOrNullString()); }
@Test(priority = 8) public void testGetNestedSingleInclude() throws IOException { String expected = jsonParser.getJson("/ResourceIT/testGetNestedSingleInclude.json"); String actual = given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .get("/parent/2?include=children.friends") .then() .statusCode(HttpStatus.SC_OK) .extract().body().asString(); assertEqualDocuments(actual, expected); }
@Test(priority = 8) public void testGetWithTrailingSlash() { String expected = jsonParser.getJson("/ResourceIT/testGetWithTrailingSlash.json"); String actual = given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .get("/parent/") .then() .statusCode(HttpStatus.SC_OK) .extract().body().asString(); assertEqualDocuments(actual, expected); }