@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 public final void givenRequestAcceptsMime_whenResourceIsRetrievedById__thenResponseContentTypeIsMime() { // Given final String uriForResourceCreation = getApi().createAsUri(createNewResource()); // When final Response res = getApi().findOneByUriAsResponse(uriForResourceCreation, null); // Then assertThat(res.getContentType(), StringContains.containsString(marshaller.getMime())); }
@Test( groups = {MUST}, description = "LDP servers MUST respond with status code 412 " + "(Condition Failed) if ETags fail to match when there " + "are no other errors with the request [HTTP11]. LDP " + "servers that require conditional requests MUST respond " + "with status code 428 (Precondition Required) when the " + "absence of a precondition is the only reason for rejecting " + "the request [RFC6585].") @SpecTest( specRefUri = LdpTestSuite.SPEC_URI + "#ldpr-put-precond", testMethod = METHOD.AUTOMATED, approval = STATUS.WG_APPROVED, comment = "Covers only part of the specification requirement. " + "testPutBadETag, testPreconditionRequiredStatusCode " + "and testPutRequiresIfMatch covers the rest.") public void testConditionFailedStatusCode() { skipIfMethodNotAllowed(HttpMethod.PUT); String resourceUri = getResourceUri(); Response response = buildBaseRequestSpecification() .expect() .statusCode(isSuccessful()) .header(ETAG, isValidEntityTag()) .when() .get(resourceUri); String contentType = response.getContentType(); buildBaseRequestSpecification() .contentType(contentType) .header(IF_MATCH, "\"These aren't the ETags you're looking for.\"") .body(response.asByteArray()) .expect() .statusCode(HttpStatus.SC_PRECONDITION_FAILED) .when() .put(resourceUri); }
@Then("^I expect to see \"([^\"]*)\" content$") public void I_expect_to_see_the_content_type(String contentType) throws Throwable { assertTrue( contentType + " content was expected but got " + rs.getContentType(), rs.getContentType().contains(contentType)); }
@Test public void checkXmlContent() { Response res = expect().given().accept(CommonConstant.ACCEPT_XML).get("http://localhost:8081/book"); Assert.assertEquals(CommonConstant.ACCEPT_XML, res.getContentType()); }