protected Response postNonRDFSource(String slug, String file, String mimeType) throws IOException { // Make sure we can post binary resources return buildBaseRequestSpecification() .header(SLUG, slug) .body(IOUtils.toByteArray(getClass().getResourceAsStream("/" + file))) .contentType(mimeType) .expect() .statusCode(HttpStatus.SC_CREATED) .header(LOCATION, HeaderMatchers.headerPresent()) .when() .post(container); }
@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); }
Response getResponse = buildBaseRequestSpecification() .expect() .statusCode(isSuccessful()) .header(ETAG, isValidEntityTag()) .when() .contentType(getResponse.contentType()) .body(getResponse.asByteArray()) .when() .put(resourceUri); .contentType(getResponse.contentType()) .body(getResponse.asByteArray()) .when() .put(resourceUri);
@Test public void testCreateBuilding() throws InterruptedException { // given String payload = "{\"name\":\"testBuilding\"}"; // expect String createdId = given() .body(payload) .contentType("application/json") .when() .post("/building") .then() .statusCode(201) .extract().header("X-Created-Id"); // and when() .get("/building/" + createdId) .then() .statusCode(200) .body("name", is("testBuilding")); }
protected static void assertCreateUser(User user){ given() .contentType("application/json;charset=UTF-8") .accept("application/json") .body(user) .expect().log().ifError() .statusCode(HttpStatus.SC_CREATED) .when() .post(getHost() + CONTEXT_PATH + "/users"); }
@Test public void testCreateAndSearchThenUpdateAndSearchThenDeleteAndSearch() throws Exception { String id = given() .contentType(contentType) .body(objectMapper.writeValueAsString(new CreateTodoRequest("testcreate", false, 0))) .when() .post(todoServiceBaseUrl() + "/todos") given() .contentType(contentType) .body(objectMapper.writeValueAsString(new UpdateTodoRequest("testupdate", false, 0))) .when() .put(todoServiceBaseUrl() + "/todos/{id}", id) }); given() .when() .delete(todoServiceBaseUrl() + "/todos/{id}", id)
@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); }
public static Response sendHttpPost(String contentType, String payload, String httpPostCommand, boolean responseLog) { if (responseLog) { return given() .contentType(contentType) .body(payload) .log().all() .expect() .log().all() .when() .post(httpPostCommand); } return given() .contentType(contentType) .body(payload) // .log().all() .when() .post(httpPostCommand); }
@Test public void testCreateAndSearchThenUpdateAndSearchThenDeleteAndSearch() throws Exception { String id = given() .contentType(contentType) .body(objectMapper.writeValueAsString(new CreateTodoRequest("testcreate", false, 0))) .when() .post(baseUrl() + "/todos") given() .contentType(contentType) .body(objectMapper.writeValueAsString(new UpdateTodoRequest("testupdate", false, 0))) .when() .put(baseUrl() + "/todos/{id}", id) }); given() .when() .delete(baseUrl() + "/todos/{id}", id)
@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); }
private String post(Model content, String slug) { RequestSpecification spec = buildBaseRequestSpecification().contentType(TEXT_TURTLE); if (slug != null) { spec.header(SLUG, slug); } Response post = spec.body(content, new RdfObjectMapper()).expect() .statusCode(HttpStatus.SC_CREATED).when() .post(getResourceUri()); String location = post.getHeader(LOCATION); assertNotNull(location, MSG_LOC_NOTFOUND); return location; }
@Test public void testAddTenantToBuilding() throws InterruptedException { // given final String buildingId = "id1"; buildingEntityGateway.save(BuildingFactory.create().createBuilding(buildingId, "building1")); String payload = "{\"name\":\"testTenant\"}"; // expect when() .get("/building/{0}", buildingId) .then() .statusCode(200) .body("tenants.size()", is(0)); given() .body(payload) .contentType("application/json") .when() .post("/building/{0}/tenant", buildingId) .then() .statusCode(201); // and when() .get("/building/{0}", buildingId) .then() .statusCode(200) .body("tenants.size()", is(1)) .body("tenants[0].name", is("testTenant")); }
@Test public void createChildNonRootable() { String request = jsonParser.getJson("/ResourceIT/createChildNonRootable.json"); given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .body(request) .post("/child") .then() .statusCode(HttpStatus.SC_NOT_FOUND); }
/** * Attempts to create a new resource using PUT. * * @return the location of the created resource * @see #testPutToCreate() * @see #testRestrictPutReUseUri() */ protected String putToCreate() { // Build a unique URI for the PUT request. URI target = UriBuilder.fromUri(getResourceUri()) .path(UUID.randomUUID().toString()).build(); Model model = postContent(); Response response = buildBaseRequestSpecification().contentType(TEXT_TURTLE) .body(model, new RdfObjectMapper("")).expect() .statusCode(HttpStatus.SC_CREATED).when().put(target); String location = response.getHeader(LOCATION); if (location == null) { return target.toString(); } return location; }
@Test(priority = 34) public void testPostToRecord() { String createRoot = jsonParser.getJson("/ResourceIT/createOneToOneRoot.json"); given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .body(createRoot) .post("/oneToOneRoot/1") .then() .statusCode(HttpStatus.SC_BAD_REQUEST); }
public static Response sendHttpPost(String contentType, String payload, String httpPostCommand, boolean responseLog) { if (responseLog) { return given() .contentType(contentType) .body(payload) .log().all() .expect() .log().all() .when() .post(httpPostCommand); } return given() .contentType(contentType) .body(payload) // .log().all() .when() .post(httpPostCommand); }
@Test public void assignedIdWithoutProvidedId() { String request = jsonParser.getJson("/ResourceIT/assignedIdWithoutId.req.json"); given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .body(request) .post("/assignedIdString") .then() .statusCode(HttpStatus.SC_BAD_REQUEST); }
@Test @InSequence(3) public void shouldBeAbleToRemoveRelation() throws Exception { given(). contentType(BASE_JSON_MEDIA_TYPE). body(new ResourceLink("test", URI.create("http://test.org/api/test/" + TARGET_ID + "/"))). then(). statusCode(Status.NO_CONTENT.getStatusCode()). when(). delete(baseURL + "api/rel/{sourceObj}/{source}/{rel}/{targetObj}/", "sourceobject", SOURCE_ID, type, "targetobject"); }
@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")); }