use of com.jayway.restassured.path.json.JsonPath in project data-prep by Talend.
the class PreparationAPITest method testPreparationUpdate.
// ------------------------------------------------------------------------------------------------------------------
// ----------------------------------------------------LIFECYCLE-----------------------------------------------------
// ------------------------------------------------------------------------------------------------------------------
@Test
public void testPreparationUpdate() throws Exception {
// given
String tagadaId = testClient.createDataset("dataset/dataset.csv", "tagada");
final String preparationId = testClient.createPreparationFromDataset(tagadaId, "original_name", home.getId());
JsonPath longFormat = when().get("/api/preparations/?format=long").jsonPath();
assertThat(longFormat.getList("name").size(), is(1));
assertThat(longFormat.getList("name").get(0), is("original_name"));
assertThat(longFormat.getList("id").size(), is(1));
assertThat(longFormat.getList("id").get(0), is(preparationId));
Preparation preparation = new Preparation();
preparation.setId(preparationId);
String newName = "updated_name";
preparation.setName(newName);
// when
given().contentType(ContentType.JSON).body(preparation).put("/api/preparations/{id}", preparationId).asString();
// then
longFormat = when().get("/api/preparations/?format=long").jsonPath();
assertThat(longFormat.getList("name").size(), is(1));
assertThat(longFormat.getList("name").get(0), is(newName));
}
use of com.jayway.restassured.path.json.JsonPath in project data-prep by Talend.
the class PreparationAPITest method testPreparationGet.
@Test
public void testPreparationGet() throws Exception {
// when
final String datasetId = testClient.createDataset("dataset/dataset.csv", "great dataset");
final String preparationId = testClient.createPreparationFromDataset(datasetId, "1234", home.getId());
// then
final JsonPath longFormat = given().get("/api/preparations/{id}/details", preparationId).jsonPath();
assertThat(longFormat.getString("dataSetId"), is(datasetId));
assertThat(longFormat.getString("author"), is(security.getUserId()));
assertThat(longFormat.getString("id"), is(preparationId));
assertThat(longFormat.getList("actions").size(), is(0));
assertNotNull(longFormat.getMap("rowMetadata"));
assertNotNull(longFormat.getMap("rowMetadata").get("columns"));
ArrayList rowMetaData = (ArrayList) longFormat.getMap("rowMetadata").get("columns");
assertThat(rowMetaData.size(), is(6));
assertThat(longFormat.getString("allowFullRun"), is("false"));
// make sure the "steps" node is a string array
final List<String> steps = longFormat.getList("steps");
assertThat(steps.size(), is(1));
}
use of com.jayway.restassured.path.json.JsonPath in project data-prep by Talend.
the class PreparationAPITest method testPreparationPreviewOnPreparationWithTrimAction_TDP_5057.
/**
* Verify a calculate time since preview after a trim step on a preparation
* see <a href="https://jira.talendforge.org/browse/TDP-5057">TDP-5057</a>
*/
@Test
public void testPreparationPreviewOnPreparationWithTrimAction_TDP_5057() throws IOException {
// Create a dataset from csv
final String datasetId = testClient.createDataset("preview/best_sad_songs_of_all_time.csv", "testPreview");
// Create a preparation
String preparationId = testClient.createPreparationFromDataset(datasetId, "testPrep", home.getId());
// apply trim action on the 8nd column to make this column date valid
Map<String, String> trimParameters = new HashMap<>();
trimParameters.put("create_new_column", "false");
trimParameters.put("padding_character", "whitespace");
trimParameters.put("scope", "column");
trimParameters.put("column_id", "0008");
trimParameters.put("column_name", "Added At");
trimParameters.put("row_id", "null");
testClient.applyAction(preparationId, Trim.TRIM_ACTION_NAME, trimParameters);
// check column is date valid after trim action
InputStream inputStream = testClient.getPreparation(preparationId).asInputStream();
mapper.getDeserializationConfig().without(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
RowMetadata preparationContent = mapper.readValue(inputStream, Data.class).metadata;
List<PatternFrequency> patternFrequencies = preparationContent.getColumns().get(8).getStatistics().getPatternFrequencies();
assertTrue(patternFrequencies.stream().map(//
PatternFrequency::getPattern).anyMatch("yyyy-MM-dd"::equals));
// create a preview of calculate time since action
PreviewAddParameters previewAddParameters = new PreviewAddParameters();
previewAddParameters.setDatasetId(datasetId);
previewAddParameters.setPreparationId(preparationId);
previewAddParameters.setTdpIds(Arrays.asList(1, 2, 3, 4, 5, 6, 7));
Action calculateTimeUntilAction = new Action();
calculateTimeUntilAction.setName(ComputeTimeSince.TIME_SINCE_ACTION_NAME);
MixedContentMap actionParameters = new MixedContentMap();
actionParameters.put("create_new_column", "true");
actionParameters.put("time_unit", "HOURS");
actionParameters.put("since_when", "now_server_side");
actionParameters.put("scope", "column");
actionParameters.put("column_id", "0008");
actionParameters.put("column_name", "Added At");
calculateTimeUntilAction.setParameters(actionParameters);
previewAddParameters.setActions(Collections.singletonList(calculateTimeUntilAction));
JsonPath jsonPath = given().contentType(//
ContentType.JSON).body(//
previewAddParameters).expect().statusCode(200).log().ifError().when().post(//
"/api/preparations/preview/add").jsonPath();
// check non empty value for the new column
assertEquals(//
"new preview column should contains values according to calculate time since action", //
0, jsonPath.getList("records.0009").stream().map(String::valueOf).filter(StringUtils::isBlank).count());
}
use of com.jayway.restassured.path.json.JsonPath in project data-prep by Talend.
the class SuggestionTest method suggestLimitDefault.
@Test
public void suggestLimitDefault() throws Exception {
// given
final String columnMetadata = IOUtils.toString(Application.class.getResourceAsStream("suggestions/date_column.json"), UTF_8);
// when
final String response = //
given().contentType(//
JSON).body(//
columnMetadata).when().post(//
"/suggest/column").asString();
// then
final JsonPath json = JsonPath.from(response);
// Default for "limit" is 5.
assertThat(json.getList("").size(), is(5));
}
use of com.jayway.restassured.path.json.JsonPath in project webcert by sklintyg.
the class ReceiveMedicalCertificateAnswerIT method createQuestion.
private int createQuestion(String typ, String intygId, String personnummer) {
LocalDateTime now = LocalDateTime.now();
FragaSvar fs = new FragaSvar();
fs.setAmne(Amne.ARBETSTIDSFORLAGGNING);
fs.setFrageText("Frågetext");
fs.setIntygsReferens(new IntygsReferens(intygId, typ, Personnummer.createPersonnummer(personnummer).get(), "Api Restman", now));
fs.setStatus(Status.PENDING_INTERNAL_ACTION);
fs.setFrageSkickadDatum(now);
fs.setMeddelandeRubrik("Meddelanderubrik");
fs.setFrageStallare(FrageStallare.WEBCERT.getKod());
fs.setFrageSigneringsDatum(now);
fs.setVardAktorNamn("Vardaktor");
fs.setVardAktorHsaId("Test-hsa-id");
fs.setExternReferens("FK-REF-1");
Vardperson vardperson = new Vardperson();
vardperson.setEnhetsId("IFV1239877878-1042");
vardperson.setArbetsplatsKod("0000000");
vardperson.setEnhetsnamn("blub");
vardperson.setHsaId("IFV1239877878-1049");
vardperson.setVardgivarId("TESTVG");
vardperson.setVardgivarnamn("VG TEST SYD");
vardperson.setNamn("Hr Doktor");
fs.setVardperson(vardperson);
Response response = given().log().all().contentType(ContentType.JSON).body(fs).expect().statusCode(200).when().post("testability/fragasvar").then().extract().response();
JsonPath model = new JsonPath(response.body().asString());
return model.get("internReferens");
}
Aggregations