/** * NOTE: expectations about the response status provided using this method <i>may</i> be overridden * by expectations provided by subsequently invoking {@link #specification(ResponseSpecification)} or any * variant of {@code expectStatus()}. * * @param status expected status * @return this builder instance */ @Nonnull public B expectStatus(@Nonnull Response.Status status) { specification(expect().statusCode(checkNotNull(status, "status").getStatusCode())); return self(); }
@Test public void shouldReturnNotFoundOnUnknownType() throws Exception { given(). then(). statusCode(Response.Status.NOT_FOUND.getStatusCode()). when(). get(baseURL + "api/bookmark/missing/200"); }
@Override public void perform() { given(). then(). statusCode(Status.UNAUTHORIZED.getStatusCode()). when(). get(whoAmIURL.toExternalForm()); } }).inspect(new SetupAuth(null));
@Test public void testGetIcon_imageTypeNotFound() throws Exception { given().expect() // .statusCode(404) // .log().ifValidationFails() // .get(getVersionPrefix() + "/properties/{name}/icon/{type}", DATA_STORE_DEFINITION_NAME, DefinitionImageType.SVG_ICON); }
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 @InSequence(4) public void shouldNotBeAbleToFindRelationAfterDelete() throws Exception { given(). then(). statusCode(Status.NO_CONTENT.getStatusCode()). when(). get(baseURL + "api/rel/{sourceObj}/{source}/{rel}/{targetObj}", "sourceobject", SOURCE_ID, type, "targetobject"); } }
@Test public void getJdbcProperties() throws java.io.IOException { // when Response response = given().accept(ServiceConstants.UI_SPEC_CONTENT_TYPE) // .expect().statusCode(200).log().ifError() // .get(getVersionPrefix() + "/properties/{definitionName}", DATA_STORE_DEFINITION_NAME); // then ObjectNode jdbcProperties = mapper.readerFor(ObjectNode.class).readValue(response.asInputStream()); // should resemble jdbc_data_store_form.json assertNotNull(jdbcProperties.get("jsonSchema")); assertNotNull(jdbcProperties.get("properties")); assertNotNull(jdbcProperties.get("uiSchema")); assertEquals("JDBCDatastore", jdbcProperties.get("properties").get("@definitionName").textValue()); }
@Override public void perform() { given(). then(). statusCode(Status.OK.getStatusCode()). when(). get(testURL.toExternalForm()); } }).inspect(new SetupAuth(null));
@Test( groups = {MUST}, description = "LDP servers MUST support the HTTP OPTIONS method. ") @SpecTest( specRefUri = LdpTestSuite.SPEC_URI + "#ldpr-options-must", testMethod = METHOD.AUTOMATED, approval = STATUS.WG_APPROVED) public void testOptions() { buildBaseRequestSpecification().expect().statusCode(isSuccessful()).when().options(getResourceUri()); }
@Test public void shouldProvideOptions() throws Exception { given(). then(). statusCode(Response.Status.OK.getStatusCode()). headers("Allow", containsString("GET")). headers("Allow", not(containsString("POST"))). when(). options(baseURL + "api/test"); } }
@Test public void testGetConnectors_badDefinition() throws Exception { given().expect() // .statusCode(400) // .log().ifValidationFails() // // TODO: check returned error .body(Matchers.containsString("definitionClass")) // .get(getVersionPrefix() + "/properties/{name}/connectors", DATA_SET_DEFINITION_NAME); }
@Override public void perform() { given(). then(). statusCode(Status.OK.getStatusCode()). when(). post(testURL.toExternalForm()); } }).inspect(new SetupAuth(new User("testuser")));
@Test( groups = {MUST}, description = "LDP servers MUST support the HTTP HEAD method. ") @SpecTest( specRefUri = LdpTestSuite.SPEC_URI + "#ldpr-head-must", testMethod = METHOD.AUTOMATED, approval = STATUS.WG_APPROVED) public void testHead() { assertTrue(supports(HttpMethod.HEAD), "HTTP HEAD is not listed in the Allow response header on HTTP OPTIONS requests for resource <" + getResourceUri() + ">"); buildBaseRequestSpecification().expect().statusCode(isSuccessful()).when().head(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"); }
@Test public void testGetIcon_svgImageTypeFound() throws Exception { given().expect() // .statusCode(200).log().ifError() // .body(Matchers.containsString("</svg>")) // .contentType(IMAGE_SVG_VALUE) // .get(getVersionPrefix() + "/properties/{name}/icon/{type}", DATA_SET_DEFINITION_NAME, DefinitionImageType.SVG_ICON); }
@Override public void perform() { given(). then(). statusCode(Status.UNAUTHORIZED.getStatusCode()). when(). delete(testURL.toExternalForm()); } }).inspect(new SetupAuth(null));
protected void expectPut4xxConstrainedBy(String invalidProp) { Response putResponse = expectPut4xxStatus(invalidProp); final String uri = getResourceUri(); String constrainedBy = getFirstLinkForRelation(uri, LINK_REL_CONSTRAINEDBY, uri, putResponse); assertNotNull(constrainedBy, "Response did not contain a Link header with rel=\"http://www.w3.org/ns/ldp#constrainedBy\""); // Make sure we can GET the constrainedBy link. buildBaseRequestSpecification() .expect() .statusCode(isSuccessful()) .when() .get(constrainedBy); }
@Test @InSequence(11) public void verifyNotFoundForDeletedUser() throws Exception { assertNotNull("Previous step failed", uri_userInstance); given(). then(). // Few Containers support custom 404 media types. 404's are overwritten by default error page. //contentType(USER_MEDIA_TYPE). statusCode(Status.NOT_FOUND.getStatusCode()). when(). get(uri_userInstance); }
@Test public void testGetVersion() throws Exception { Response r = given().accept(APPLICATION_JSON_UTF8_VALUE) // .expect() // .statusCode(200).log().ifError() // .with().port(localServerPort) // .get(getVersionPrefix() + "/version"); r.then() // .statusCode(HttpStatus.OK.value()).log().ifError() // .contentType(APPLICATION_JSON_UTF8_VALUE); // We don't care what values are returned as long as they are filled. JsonPath jsonPathEvaluator = r.jsonPath(); assertThat(jsonPathEvaluator.get("version"), allOf(notNullValue(), not(equalTo(VersionDto.N_A)))); assertThat(jsonPathEvaluator.get("commit"), allOf(notNullValue(), not(equalTo(VersionDto.N_A)))); assertThat(jsonPathEvaluator.get("time"), allOf(notNullValue(), not(equalTo(VersionDto.N_A)))); } }
@Override public void perform() { given(). then(). statusCode(Status.OK.getStatusCode()). when(). options(testURL.toExternalForm()); } }).inspect(new SetupAuth(null));