Search in sources :

Example 16 with JsonPath

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));
}
Also used : StandalonePreparation(org.talend.dataprep.StandalonePreparation) EnrichedPreparation(org.talend.dataprep.api.service.api.EnrichedPreparation) Preparation(org.talend.dataprep.api.preparation.Preparation) UserPreparation(org.talend.dataprep.preparation.service.UserPreparation) JsonPath(com.jayway.restassured.path.json.JsonPath) Test(org.junit.Test)

Example 17 with JsonPath

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));
}
Also used : ArrayList(java.util.ArrayList) JsonPath(com.jayway.restassured.path.json.JsonPath) Test(org.junit.Test)

Example 18 with JsonPath

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());
}
Also used : Action(org.talend.dataprep.api.preparation.Action) EntityBuilder.buildAction(org.talend.dataprep.api.service.EntityBuilder.buildAction) HashMap(java.util.HashMap) InputStream(java.io.InputStream) JsonPath(com.jayway.restassured.path.json.JsonPath) PreviewAddParameters(org.talend.dataprep.api.service.api.PreviewAddParameters) PatternFrequency(org.talend.dataprep.api.dataset.statistics.PatternFrequency) StringUtils(org.apache.commons.lang.StringUtils) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) MixedContentMap(org.talend.dataprep.api.preparation.MixedContentMap) Test(org.junit.Test)

Example 19 with JsonPath

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));
}
Also used : JsonPath(com.jayway.restassured.path.json.JsonPath) Application(org.talend.dataprep.transformation.Application) Test(org.junit.Test)

Example 20 with JsonPath

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");
}
Also used : LocalDateTime(java.time.LocalDateTime) Vardperson(se.inera.intyg.webcert.persistence.fragasvar.model.Vardperson) Response(com.jayway.restassured.response.Response) IntygsReferens(se.inera.intyg.webcert.persistence.fragasvar.model.IntygsReferens) FragaSvar(se.inera.intyg.webcert.persistence.fragasvar.model.FragaSvar) JsonPath(com.jayway.restassured.path.json.JsonPath)

Aggregations

JsonPath (com.jayway.restassured.path.json.JsonPath)83 Test (org.junit.Test)56 Response (com.jayway.restassured.response.Response)25 BaseRestTest (integration.BaseRestTest)11 BaseRestIntegrationTest (se.inera.intyg.webcert.web.web.controller.integrationtest.BaseRestIntegrationTest)10 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)9 Matchers.anyString (org.mockito.Matchers.anyString)8 ValidatableResponse (com.jayway.restassured.response.ValidatableResponse)6 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)6 Matchers.containsString (org.hamcrest.Matchers.containsString)6 UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 Ignore (org.junit.Ignore)5 MongoDbSeed (integration.MongoDbSeed)4 HashMap (java.util.HashMap)3 AbstractIntegrationTest (org.codice.ddf.itests.common.AbstractIntegrationTest)2 BaseMatcher (org.hamcrest.BaseMatcher)2 Description (org.hamcrest.Description)2 UserPreparation (org.talend.dataprep.preparation.service.UserPreparation)2 Application (org.talend.dataprep.transformation.Application)2