@Test @RunAsClient @InSequence(13) public void testPrometheusFormatNoBadChars() throws Exception { Header wantPrometheusFormat = new Header("Accept", TEXT_PLAIN); String data = given().header(wantPrometheusFormat).get("/metrics/base").asString(); String[] lines = data.split("\n"); for (String line : lines) { if (line.startsWith("#")) { continue; } String[] tmp = line.split(" "); assertEquals(tmp.length, 2); assertFalse("Line has illegal chars " + line, tmp[0].matches("[-.]")); assertFalse("Found __ in " + line, tmp[0].matches("__")); } }
@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)); }
private final Query queryResource(URL contextURL, String path) throws IOException { Response response= given(). accept(TEXT_TURTLE). baseUri(contextURL.toString()). expect(). statusCode(OK). contentType(TEXT_TURTLE). when(). get(path); return QueryResponseHelper.getQuery(contextURL, path, response.asString()); }
@Test public void testTriggerOnProperty() throws Exception { String callback = "validate"; String propName = "tagId"; Response response = given().accept(ServiceConstants.UI_SPEC_CONTENT_TYPE) // .expect() // .statusCode(200).log().ifError() // .with() // .content(buildTestDataStoreFormData()) // .contentType(ServiceConstants.UI_SPEC_CONTENT_TYPE) // .post(getVersionPrefix() + "/properties/trigger/{callback}/{propName}", callback, propName); assertNotNull(response); String content = response.asString(); assertNotNull(content); }
@Test public void testInitializePropertiesUiSpecs() throws Exception { Response response = given().accept(ServiceConstants.UI_SPEC_CONTENT_TYPE) // .expect() // .statusCode(200).log().ifError() // .with() // .content(buildTestDataSetFormData()) // .contentType(ServiceConstants.UI_SPEC_CONTENT_TYPE) // .post(getVersionPrefix() + "/properties/uispec"); assertNotNull(response); String content = response.asString(); assertEquals(getMockDatasetMainFormUISpecs(), content); }
@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)); } }
private void testGetBase(RDFFormat format) throws Exception { String data = given().header("Accept",format.getDefaultMIMEType()).expect().statusCode(200).when().get(createResourceURI("sepp_huber").stringValue()).asString(); Repository mem = new SailRepository(new MemoryStore()); mem.initialize(); RepositoryConnection con = mem.getConnection(); RepositoryConnection icon = sesameService.getConnection(); try { con.begin(); con.add(new StringReader(data), RestAssured.baseURI + ":" + RestAssured.port + RestAssured.basePath, format); Assert.assertTrue(con.hasStatement(createResourceURI("sepp_huber"),null,null,true)); RepositoryResult<Statement> statements = icon.getStatements(createResourceURI("sepp_huber"), null,null,true); while(statements.hasNext()) { Statement stmt = statements.next(); Assert.assertTrue("statement "+stmt+" not found in results",con.hasStatement(stmt,true)); } con.commit(); icon.commit(); } finally { con.close(); icon.close(); } String invalid = given().header("Accept",format.getDefaultMIMEType()).expect().statusCode(404).when().get(createResourceURI("xyz").stringValue()).asString(); }
@Test public void testInitializePropertiesJsonio() throws Exception { Response response = given().accept(ServiceConstants.UI_SPEC_CONTENT_TYPE) // .expect() // .statusCode(200).log().ifError() // .with() // .content(buildTestDataSetSerProps()) // .contentType(ServiceConstants.JSONIO_CONTENT_TYPE) // .post(getVersionPrefix() + "/properties/uispec"); assertNotNull(response); String content = response.asString(); assertEquals(getMockDatasetMainFormUISpecs(), content); }
@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")); } }
@Test public void testSerializeProperties() throws Exception { Response response = given().accept(ServiceConstants.JSONIO_CONTENT_TYPE) // .expect() // .statusCode(200).log().ifError() // .with().port(localServerPort) // .content(buildTestDataSetFormData()) // .contentType(ServiceConstants.UI_SPEC_CONTENT_TYPE) // .post(getVersionPrefix() + "/properties/serialize"); assertNotNull(response); String content = response.asString(); assertNotNull(content); //take the jsonIO JsonNode jsonNode = mapper.readTree(content); String jsonioProperties = jsonNode.get("properties").asText(); Deserialized<MockDatasetProperties> fromSerializedPersistent = Properties.Helper.fromSerializedPersistent( jsonioProperties, MockDatasetProperties.class); assertNotNull(fromSerializedPersistent); assertNotNull(fromSerializedPersistent.object); MockDatasetProperties deserializedProps = fromSerializedPersistent.object; assertEquals("tata", deserializedProps.tag.getValue()); }
@Test public void testSerializeDeserializeProperties() throws Exception { Response response = given().accept(ServiceConstants.JSONIO_CONTENT_TYPE) // .expect() // .statusCode(200).log().ifError() // .with().port(localServerPort) // .content(buildTestDataSetFormData()) // .contentType(ServiceConstants.UI_SPEC_CONTENT_TYPE) // .post(getVersionPrefix() + "/properties/serialize"); assertNotNull(response); String content = response.asString(); assertNotNull(content); response = given().accept(ServiceConstants.UI_SPEC_CONTENT_TYPE) // .expect() // .statusCode(200).log().ifError() // .with() // .content(content) // .contentType(ServiceConstants.JSONIO_CONTENT_TYPE) // .post(getVersionPrefix() + "/properties/uispec"); assertNotNull(response); assertEquals(getMockDatasetMainFormUISpecs(), response.asString()); }
private List<TodoView> search(String value) { try { return Arrays.asList(objectMapper.readValue(given() .queryParam("searchValue", value) .when() .get(baseUrl() + "/todoviews") .then() .statusCode(200) .extract() .response() .asString(), TodoView[].class)); } catch (IOException e) { throw new RuntimeException(e); } }
private List<TodoView> search(String value) { try { return Arrays.asList(objectMapper.readValue(given() .queryParam("searchValue", value) .when() .get(todoViewServiceBaseUrl() + "/todoviews") .then() .statusCode(200) .extract() .response() .asString(), TodoView[].class)); } catch (IOException e) { throw new RuntimeException(e); } }
@Test(priority = 1) public void testPatchAttrSingle() throws Exception { String request = jsonParser.getJson("/ResourceIT/testPatchAttrSingle.json"); given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .body(request) .patch("/parent/2") .then() .statusCode(HttpStatus.SC_NO_CONTENT) .header(HttpHeaders.CONTENT_LENGTH, (String) null); String actual = given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .get("/parent/2") .then() .statusCode(HttpStatus.SC_OK) .contentType(JSONAPI_CONTENT_TYPE) .extract().response().asString(); JsonApiDocument doc = jsonApiMapper.readJsonApiDocument(actual); Data<Resource> data = doc.getData(); Resource resource = data.getSingleValue(); assertEquals(resource.getAttributes().get("firstName"), "syzygy"); assertEquals(resource.getRelationships().size(), 2); assertEquals(resource.getRelationships().get("children").getData().get().size(), 2); }
String request = jsonParser.getJson("/ResourceIT/testPatchRelSetDirect.json"); given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .header(HttpHeaders.CONTENT_LENGTH, (String) null); String actual = given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .then() .statusCode(HttpStatus.SC_OK) .extract().response().asString();
String request = jsonParser.getJson("/ResourceIT/testPatchSetRel.json"); given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .header(HttpHeaders.CONTENT_LENGTH, (String) null); String actual = given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .then() .statusCode(HttpStatus.SC_OK) .extract().response().asString();
given() .contentType(JSONAPI_CONTENT_TYPE) .accept(JSONAPI_CONTENT_TYPE) .then() .statusCode(HttpStatus.SC_OK) .extract().response().asString(); .then() .statusCode(HttpStatus.SC_OK) .extract().response().asString(); .then() .statusCode(HttpStatus.SC_OK) .extract().response().asString(); .then() .statusCode(HttpStatus.SC_NOT_FOUND) .extract().response().asString(); .then() .statusCode(HttpStatus.SC_OK) .extract().response().asString(); .then() .statusCode(HttpStatus.SC_OK) .extract().response().asString();