protected void setUrlParam(String key, String value){ spec.param(key, value); }
public void addParameter(String key, String value) { request.param(key, value.replace(" ", "%20")); }
@Test public void testSparseTwoDataFieldValuesNoIncludes() throws Exception { JsonNode responseBody = objectMapper.readTree( RestAssured .given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .param("fields[book]", "title,language") .get("/book").asString()); Assert.assertTrue(responseBody.has("data")); for (JsonNode bookNode : responseBody.get("data")) { Assert.assertTrue(bookNode.has(ATTRIBUTES)); Assert.assertFalse(bookNode.has(RELATIONSHIPS)); JsonNode attributes = bookNode.get(ATTRIBUTES); Assert.assertEquals(attributes.size(), 2); Assert.assertTrue(attributes.has("title")); Assert.assertTrue(attributes.has("language")); } Assert.assertFalse(responseBody.has(INCLUDED)); }
@Test public void testSparseSingleDataFieldValue() throws Exception { JsonNode responseBody = objectMapper.readTree( RestAssured .given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .param("include", "authors") .param("fields[book]", "title") .get("/book").asString()); Assert.assertTrue(responseBody.has("data")); for (JsonNode bookNode : responseBody.get("data")) { Assert.assertTrue(bookNode.has(ATTRIBUTES)); Assert.assertFalse(bookNode.has(RELATIONSHIPS)); JsonNode attributes = bookNode.get(ATTRIBUTES); Assert.assertEquals(attributes.size(), 1); Assert.assertTrue(attributes.has("title")); } Assert.assertTrue(responseBody.has(INCLUDED)); for (JsonNode include : responseBody.get(INCLUDED)) { Assert.assertFalse(include.has(ATTRIBUTES)); Assert.assertFalse(include.has(RELATIONSHIPS)); } }
@Test public void testSparseNoFilters() throws Exception { JsonNode responseBody = objectMapper.readTree( RestAssured .given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .param("include", "authors") .get("/book").asString()); Assert.assertTrue(responseBody.has("data")); for (JsonNode bookNode : responseBody.get("data")) { Assert.assertTrue(bookNode.has(ATTRIBUTES)); JsonNode attributes = bookNode.get(ATTRIBUTES); Assert.assertTrue(attributes.has("title")); Assert.assertTrue(attributes.has("language")); Assert.assertTrue(attributes.has("genre")); Assert.assertTrue(bookNode.has(RELATIONSHIPS)); JsonNode relationships = bookNode.get(RELATIONSHIPS); Assert.assertTrue(relationships.has("authors")); } Assert.assertTrue(responseBody.has(INCLUDED)); for (JsonNode include : responseBody.get(INCLUDED)) { Assert.assertTrue(include.has(ATTRIBUTES)); JsonNode attributes = include.get(ATTRIBUTES); Assert.assertTrue(attributes.has("name")); Assert.assertTrue(include.has(RELATIONSHIPS)); JsonNode relationships = include.get(RELATIONSHIPS); Assert.assertTrue(relationships.has("books")); } }
private String getDataStoreDefinitionPropertiesTitle(Locale locale) throws IOException { Response response = given().accept(ServiceConstants.UI_SPEC_CONTENT_TYPE) // .expect() // .statusCode(200).log().ifError() // .with().port(localServerPort) // .param(LANGUAGE_QUERY_PARAMETER_NAME, locale.toLanguageTag()) .get(getVersionPrefix() + "/properties/{name}", DATA_STORE_DEFINITION_NAME); JsonNode jsonNode = mapper.readTree(response.asInputStream()); return jsonNode.get("jsonSchema").get("title").asText(); }