@Nonnull public final Response put(@Nonnull AbstractRestRequest request) { //PUT requests can include a body return buildRequest(checkNotNull(request, "request"), true).put(buildUrl(request)); }
/** * 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; }
@Override public void perform() { given(). then(). statusCode(Status.UNAUTHORIZED.getStatusCode()). when(). put(testURL.toExternalForm()); } }).inspect(new SetupAuth(null));
@Override public void perform() { given(). then(). statusCode(Status.OK.getStatusCode()). when(). put(testURL.toExternalForm()); } }).inspect(new SetupAuth(new User("testuser")));
@Test public void setDatasetData_DiRuntime() throws Exception { // given String payload = IOUtils.toString(getClass().getResourceAsStream("jdbc_component_write_properties_on_DI.json")) .replace("{jdbc_url}", dbUrl); // when given().content(payload).contentType(APPLICATION_JSON_UTF8_VALUE) // .expect().statusCode(200).log().ifError() // .put(getVersionPrefix() + "/runtimes/data"); // then Statement statement = db.getConnection().createStatement(); ResultSet countRS = statement.executeQuery("SELECT COUNT(*) AS count FROM users"); countRS.next(); assertEquals(101, countRS.getInt("count")); ResultSet resultSet = statement.executeQuery("SELECT * FROM users WHERE email='david.bowie@awesome.uk'"); while (resultSet.next()) { assertEquals("1", resultSet.getString("id")); assertEquals("David", resultSet.getString("first_name")); assertEquals("Bowie", resultSet.getString("last_name")); assertEquals("david.bowie@awesome.uk", resultSet.getString("email")); assertEquals("male", resultSet.getString("gender")); assertEquals("127.0.0.1", resultSet.getString("ip_address")); } }
@Test @InSequence(3) public void shouldBeAbleToUpdateAttachment() throws Exception { assertNotNull("Previous step failed", uri_attachmentInstance); AttachmentType conf = getUpdateAttachment(); given(). contentType(ATTACHMENT_MEDIA_TYPE). body(conf). then(). statusCode(Status.NO_CONTENT.getStatusCode()). when(). put(uri_attachmentInstance); }
@Test public void shouldReturnBadRequestOnPUTMissingResource() throws Exception { given(). contentType(getBaseMediaType()). content(createUpdateRepresentation()). then(). statusCode(Response.Status.BAD_REQUEST.getStatusCode()). when(). put(createRootURL() + "/{id}", "MISSING"); }
@Test @InSequence(3) public void shouldBeAbleToUpdateUser() throws Exception { assertNotNull("Previous step failed", uri_userInstance); UserType conf = getUpdateUser(); given(). contentType(USER_MEDIA_TYPE). body(conf). then(). statusCode(Status.NO_CONTENT.getStatusCode()). when(). put(uri_userInstance); }
@Test( groups = {SHOULD}, description = "LDP clients SHOULD use the HTTP If-Match header and HTTP ETags " + "to ensure it isn’t modifying a resource that has changed since the " + "client last retrieved its representation. LDP servers SHOULD require " + "the HTTP If-Match header and HTTP ETags to detect collisions.") @SpecTest( specRefUri = LdpTestSuite.SPEC_URI + "#ldpr-put-precond", testMethod = METHOD.AUTOMATED, approval = STATUS.WG_APPROVED, comment = "Covers only part of the specification requirement. " + "testConditionFailedStatusCode, testPreconditionRequiredStatusCode " + "and testPutBadETag covers the rest.") public void testPutRequiresIfMatch() throws URISyntaxException { skipIfMethodNotAllowed(HttpMethod.PUT); String resourceUri = getResourceUri(); Response response = buildBaseRequestSpecification() .expect() .statusCode(isSuccessful()) .header(ETAG, isValidEntityTag()) .when() .get(resourceUri); buildBaseRequestSpecification() .contentType(response.getContentType()) .body(response.asByteArray()) .expect() .statusCode(not(isSuccessful())) .when() .put(resourceUri); }
@Test @InSequence(3) public void shouldBeAbleToUpdateConference() throws Exception { assertNotNull("Previous step failed", uri_conferenceInstance); ConferenceType conf = getUpdateConference(); given(). contentType(CONFERENCE_MEDIA_TYPE). body(conf). then(). statusCode(Status.NO_CONTENT.getStatusCode()). when(). put(uri_conferenceInstance); }
@Test @InSequence(8) public void shouldBeAbleToUpdateSession() throws Exception { assertNotNull("Previous step failed", uri_sessionInstance); // TODO: require merge of models. merge == PATCH. PUT == full replacement SessionType session = getUpdateSession(); given(). contentType(SESSION_MEDIA_TYPE). body(session). then(). statusCode(Status.NO_CONTENT.getStatusCode()). when(). put(uri_sessionInstance); }
@Test( groups = {SHOULD}, dependsOnMethods = {"testPutToCreate"}, description = "LDP servers that allow LDPR creation via PUT SHOULD NOT " + "re-use URIs. For RDF representations (LDP-RSs),the created " + "resource can be thought of as an RDF named graph [rdf11-concepts].") @SpecTest( specRefUri = LdpTestSuite.SPEC_URI + "#ldpc-put-create", testMethod = METHOD.AUTOMATED, approval = STATUS.WG_APPROVED) public void testRestrictPutReUseUri() { String location = putToCreate(); // Delete the resource. buildBaseRequestSpecification() .expect() .statusCode(isSuccessful()) .when() .delete(location); // Try to put to the same URI again. It should fail. Model content = postContent(); buildBaseRequestSpecification() .given() .contentType(TEXT_TURTLE) .body(content, new RdfObjectMapper(location)) .expect() .statusCode(not(isSuccessful())) .when() .put(location); }
@Test( groups = {SHOULD}, description = "LDP servers SHOULD NOT allow HTTP PUT to update an LDPC’s " + "containment triples; if the server receives such a request, it " + "SHOULD respond with a 409 (Conflict) status code.") @SpecTest( specRefUri = LdpTestSuite.SPEC_URI + "#ldpc-put-mbrprops", testMethod = METHOD.AUTOMATED, approval = STATUS.WG_APPROVED) public void testRejectPutModifyingContainmentTriples() { String containerUri = getResourceUri(); Response response = buildBaseRequestSpecification() .header(ACCEPT, TEXT_TURTLE) .expect().statusCode(isSuccessful()) .when().get(containerUri); String eTag = response.getHeader(ETAG); Model model = response.as(Model.class, new RdfObjectMapper(containerUri)); // Try to modify the ldp:contains triple. Resource containerResource = model.getResource(containerUri); containerResource.addProperty(model.createProperty(LDP.contains.stringValue()), model.createResource("#" + System.currentTimeMillis())); RequestSpecification putRequest = buildBaseRequestSpecification().contentType(TEXT_TURTLE); if (eTag != null) { putRequest.header(IF_MATCH, eTag); } putRequest.body(model, new RdfObjectMapper(containerUri)) .expect().statusCode(not(isSuccessful())) .when().put(containerUri); }
.statusCode(HttpStatus.SC_PRECONDITION_FAILED) .when() .put(resourceUri);
.statusCode(HttpStatus.SC_PRECONDITION_FAILED) .when() .put(resourceUri);
.statusCode(200) .when() .put(resource1.stringValue());