/** * Expect that a response header matches the supplied header name and hamcrest matcher. * * @param headerName The name of the expected header * @param expectedValueMatcher The Hamcrest matcher that must conform to the value * @return The builder */ public ResponseSpecBuilder expectHeader(String headerName, Matcher<String> expectedValueMatcher) { spec.header(headerName, expectedValueMatcher); return this; }
/** * Expect that a response header matches the supplied name and value. * * @param headerName The name of the expected header * @param expectedValue The value of the expected header * @return The builder */ public ResponseSpecBuilder expectHeader(String headerName, String expectedValue) { spec.header(headerName, expectedValue); return this; }
@Test( groups = {MUST}, description = "LDP servers MUST support the HTTP response headers " + "defined in section 4.2.8 HTTP OPTIONS. ") @SpecTest( specRefUri = LdpTestSuite.SPEC_URI + "#ldpr-get-options", testMethod = METHOD.AUTOMATED, approval = STATUS.WG_APPROVED) public void testGetResponseHeaders() { ResponseSpecification expectResponse = buildBaseRequestSpecification().expect(); expectResponse.header(ALLOW, notNullValue()); // Some headers are expected depending on OPTIONS if (supports(HttpMethod.PATCH)) { expectResponse.header(ACCEPT_PATCH, notNullValue()); } if (supports(HttpMethod.POST)) { expectResponse.header(ACCEPT_POST, notNullValue()); } expectResponse.when().get(getResourceUri()); }
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( groups = {MUST}, description = "LDP servers MUST indicate their support for HTTP Methods " + "by responding to a HTTP OPTIONS request on the LDPR’s URL " + "with the HTTP Method tokens in the HTTP response header Allow. ") @SpecTest( specRefUri = LdpTestSuite.SPEC_URI + "#ldpr-options-allow", testMethod = METHOD.AUTOMATED, approval = STATUS.WG_APPROVED) public void testOptionsAllowHeader() { buildBaseRequestSpecification().expect().statusCode(isSuccessful()).header(ALLOW, notNullValue()) .when().options(getResourceUri()); }
@Override public void perform() { given(). then(). statusCode(Status.OK.getStatusCode()). header("Allow", allOf( not(containsString("POST")), not(containsString("PUT")), not(containsString("DELETE")), not(containsString("PATCH")))). when(). options(testURL.toExternalForm()); } }).inspect(new SetupAuth(null));
@Override public void perform() { given(). then(). statusCode(Status.OK.getStatusCode()). header("Allow", allOf( containsString("GET"), containsString("OPTIONS"), containsString("POST"), containsString("PUT"), containsString("DELETE"), containsString("PATCH"))). when(). options(testURL.toExternalForm()); } }).inspect(new SetupAuth(new User("testuser")));
@Test( groups = {MUST}, description = "LDP servers that support PATCH MUST include an " + "Accept-Patch HTTP response header [RFC5789] on HTTP " + "OPTIONS requests, listing patch document media type(s) " + "supported by the server. ") @SpecTest( specRefUri = LdpTestSuite.SPEC_URI + "#ldpr-patch-acceptpatch", testMethod = METHOD.AUTOMATED, approval = STATUS.WG_APPROVED) public void testAcceptPatchHeader() { if (supports(HttpMethod.PATCH)) { buildBaseRequestSpecification() .expect().statusCode(isSuccessful()).header(ACCEPT_PATCH, notNullValue()) .when().options(getResourceUri()); } }
@Test( groups = {MUST}, description = "LDP server responses MUST use entity tags " + "(either weak or strong ones) as response " + "ETag header values.") @SpecTest( specRefUri = LdpTestSuite.SPEC_URI + "#ldpr-gen-etags", testMethod = METHOD.AUTOMATED, approval = STATUS.WG_APPROVED, comment = "Covers only part of the specification requirement. " + "testETagHeadersGet covers the rest.") public void testETagHeadersHead() { // GET requests buildBaseRequestSpecification() .expect().statusCode(isSuccessful()).header(ETAG, isValidEntityTag()) .when().head(getResourceUri()); }
@Test( groups = {MUST}, description = "LDP server responses MUST use entity tags " + "(either weak or strong ones) as response " + "ETag header values.") @SpecTest( specRefUri = LdpTestSuite.SPEC_URI + "#ldpr-gen-etags", testMethod = METHOD.AUTOMATED, approval = STATUS.WG_APPROVED, comment = "Covers only part of the specification requirement. " + "testETagHeadersHead covers the rest.") public void testETagHeadersGet() { // GET requests buildBaseRequestSpecification() .expect() .statusCode(isSuccessful()) .header(ETAG, isValidEntityTag()) .when() .get(getResourceUri()); }
@Test public void shouldRedirectToResource() throws Exception { given(). redirects(). follow(false). then(). statusCode(Response.Status.TEMPORARY_REDIRECT.getStatusCode()). header("Location", new URL(baseURL, "api/test/200").toExternalForm()). when(). get(baseURL + "api/bookmark/test/200"); }
protected Response expectPut4xxStatus(String invalidProp) { // Get the resource. String resourceUri = getResourceUri(); Response getResponse = buildBaseRequestSpecification() .expect() .statusCode(isSuccessful()) .header(ETAG, isValidEntityTag()) .when() .get(resourceUri); String eTag = getResponse.getHeader(ETAG); Model m = getResponse.as(Model.class, new RdfObjectMapper(resourceUri)); modifyProperty(m, resourceUri, invalidProp); Response putResponse = buildBaseRequestSpecification() .contentType(TEXT_TURTLE) .header(IF_MATCH, eTag) .body(m, new RdfObjectMapper(resourceUri)) .when() .put(resourceUri); if (isSuccessful().matches(putResponse.getStatusCode())) { throw new SkipException(Thread.currentThread().getStackTrace()[1].getMethodName(), "Skipping test because PUT request was successful.", skipLog); } assertThat(putResponse.statusCode(), is4xxRange()); return putResponse; }
.header(ACCEPT, mimeType) .expect() .statusCode(HttpStatus.SC_OK)
.expect() .statusCode(isSuccessful()) .header(ETAG, HeaderMatchers.isValidEntityTag()) .when() .get(location);
@Test( groups = {SHOULD}, description = "LDP servers SHOULD assign the URI for the resource to be created " + "using server application specific rules in the absence of a client hint.") @SpecTest( specRefUri = LdpTestSuite.SPEC_URI + "#ldpc-post-serverassignuri", testMethod = METHOD.AUTOMATED, approval = STATUS.WG_APPROVED) public void testPostNoSlug() { skipIfMethodNotAllowed(HttpMethod.POST); // POST content with no Slug and see if the server assigns a URI. Model model = postContent(); Response postResponse = buildBaseRequestSpecification() .contentType(TEXT_TURTLE) .body(model, new RdfObjectMapper()) .expect() .statusCode(HttpStatus.SC_CREATED) .header(LOCATION, HeaderMatchers.headerPresent()) .when() .post(getResourceUri()); // Delete the resource to clean up. buildBaseRequestSpecification().delete(postResponse.getHeader(LOCATION)); }
@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); }
Response response = buildBaseRequestSpecification() .expect() .statusCode(isSuccessful()).header(ETAG, isValidEntityTag()) .when() .get(resourceUri);
Response response = buildBaseRequestSpecification() .expect() .statusCode(isSuccessful()).header(ETAG, isValidEntityTag()) .when() .get(resourceUri);
.expect() .statusCode(HttpStatus.SC_CREATED) .header(LOCATION, HeaderMatchers.headerPresent()) .when() .post(containerUri);