Search in sources :

Example 1 with EnrichedPreparation

use of org.talend.dataprep.api.service.api.EnrichedPreparation in project data-prep by Talend.

the class ExportAPITest method testExportCsvFromPreparationStep.

@Test
public void testExportCsvFromPreparationStep() throws Exception {
    // given
    final String preparationId = testClient.createPreparationFromFile("export/export_dataset.csv", "testExport", home.getId());
    testClient.applyActionFromFile(preparationId, "export/upper_case_firstname.json");
    testClient.applyActionFromFile(preparationId, "export/upper_case_lastname.json");
    testClient.applyActionFromFile(preparationId, "export/delete_city.json");
    final String expectedExport = IOUtils.toString(this.getClass().getResourceAsStream("export/expected_export_preparation_uppercase_firstname.csv"), UTF_8);
    final EnrichedPreparation preparationMessage = mapper.readValue(given().get("/api/preparations/{preparation}/details", preparationId).asInputStream(), EnrichedPreparation.class);
    final List<String> steps = preparationMessage.getSteps();
    // when
    final String export = testClient.exportPreparation(preparationId, steps.get(1)).asString();
    // then
    assertEquals(expectedExport, export);
}
Also used : EnrichedPreparation(org.talend.dataprep.api.service.api.EnrichedPreparation) Test(org.junit.Test)

Example 2 with EnrichedPreparation

use of org.talend.dataprep.api.service.api.EnrichedPreparation in project data-prep by Talend.

the class PreparationAPITest method testPreparationsGet.

@Test
public void testPreparationsGet() throws Exception {
    // given
    String tagadaId = testClient.createDataset("dataset/dataset.csv", "tagada");
    String preparationId = testClient.createPreparationFromDataset(tagadaId, "testPreparation", home.getId());
    // when : long format
    Response response1 = when().get("/api/preparations/{preparationId}/details", preparationId);
    // then
    EnrichedPreparation userPreparation = mapper.readerFor(EnrichedPreparation.class).readValue(response1.asInputStream());
    assertThat(userPreparation.getDataSetId(), is(tagadaId));
    assertThat(userPreparation.getAuthor(), is(security.getUserId()));
    assertThat(userPreparation.getId(), is(preparationId));
    assertThat(userPreparation.getActions(), is(empty()));
    assertThat(userPreparation.getFolder().getPath(), is(home.getPath()));
}
Also used : Response(com.jayway.restassured.response.Response) EnrichedPreparation(org.talend.dataprep.api.service.api.EnrichedPreparation) Test(org.junit.Test)

Example 3 with EnrichedPreparation

use of org.talend.dataprep.api.service.api.EnrichedPreparation in project data-prep by Talend.

the class PreparationAPITest method should_save_created_columns_ids_on_update.

@Test
public void should_save_created_columns_ids_on_update() throws Exception {
    // given
    final String preparationId = testClient.createPreparationFromFile("dataset/dataset.csv", "testPreparation", home.getId());
    testClient.applyActionFromFile(preparationId, "transformation/upper_case_lastname.json");
    testClient.applyActionFromFile(preparationId, "transformation/upper_case_firstname.json");
    final List<String> steps = getPreparationDetails(preparationId).getSteps();
    // when : Update first action (transformation/upper_case_lastname / "2b6ae58738239819df3d8c4063e7cb56f53c0d59")
    // with another action that create a column
    final String updateAction = IOUtils.toString(PreparationAPITest.class.getResourceAsStream("transformation/copy_firstname.json"), UTF_8);
    given().contentType(ContentType.JSON).body(updateAction).put("/api/preparations/{preparation}/actions/{action}", preparationId, steps.get(1)).then().statusCode(is(200));
    // then
    final EnrichedPreparation preparation = getPreparationDetails(preparationId);
    final List<String> createdColumns = preparation.getDiff().get(0).getCreatedColumns();
    assertThat(createdColumns, hasSize(1));
    assertThat(createdColumns, hasItem("0006"));
}
Also used : EnrichedPreparation(org.talend.dataprep.api.service.api.EnrichedPreparation) Test(org.junit.Test)

Example 4 with EnrichedPreparation

use of org.talend.dataprep.api.service.api.EnrichedPreparation in project data-prep by Talend.

the class PreparationAPITest method testPreparationUpdatePreview.

@Test
public void testPreparationUpdatePreview() throws Exception {
    // given
    final String preparationId = testClient.createPreparationFromFile("preview/preview_dataset.csv", "testPreview", home.getId());
    testClient.applyActionFromFile(preparationId, "preview/upper_case_lastname.json");
    testClient.applyActionFromFile(preparationId, "preview/upper_case_firstname.json");
    testClient.applyActionFromFile(preparationId, "preview/delete_city.json");
    final EnrichedPreparation preparationMessage = getPreparationDetails(preparationId);
    final List<String> steps = preparationMessage.getSteps();
    final String lastStep = steps.get(steps.size() - 1);
    final String input = // 
    "{" + "   \"preparationId\": \"" + preparationId + // 
    "\",\n" + "   \"currentStepId\": \"" + lastStep + // action 1 + 2 + 3
    "\",\n" + "   \"updateStepId\": \"" + lastStep + // action 3
    "\",\n" + // 
    "   \"tdpIds\": [2, 4, 6]," + // 
    "   \"action\": {" + // 
    "       \"action\": \"delete_on_value\",\n" + // 
    "       \"parameters\": {" + // 
    "           \"column_id\": \"0006\"," + // 
    "           \"value\": {\"token\": \"Coast city\", \"operator\": \"equals\"}," + // 
    "           \"scope\": \"column\"" + // 
    "       }" + // 
    "   }" + "}";
    final InputStream expectedDiffStream = PreparationAPITest.class.getResourceAsStream("preview/expected_update_preview.json");
    // when
    final String diff = given().contentType(ContentType.JSON).body(input).when().post("/api/preparations/preview/update").asString();
    // then
    assertThat(diff, sameJSONAsFile(expectedDiffStream));
}
Also used : EnrichedPreparation(org.talend.dataprep.api.service.api.EnrichedPreparation) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 5 with EnrichedPreparation

use of org.talend.dataprep.api.service.api.EnrichedPreparation in project data-prep by Talend.

the class APIPreparationConversionsTest method shouldDealWithExceptionInDataSetGet.

@Test
public void shouldDealWithExceptionInDataSetGet() {
    // given
    final PreparationMessage preparation = getPreparationMessage("DS-1234");
    when(applicationContext.getBean(eq(DataSetGet.class), any(Object[].class))).thenAnswer(i -> {
        final DataSetGet mock = mock(DataSetGet.class);
        when(mock.execute()).thenThrow(new TDPException(DataSetErrorCodes.DATASET_DOES_NOT_EXIST));
        return mock;
    });
    // when
    final EnrichedPreparation actual = conversionService.convert(preparation, EnrichedPreparation.class);
    // then
    assertNotNull(actual);
    assertNull(actual.getSummary());
    assertNull(actual.getFolder());
}
Also used : TDPException(org.talend.dataprep.exception.TDPException) DataSetGet(org.talend.dataprep.command.dataset.DataSetGet) EnrichedPreparation(org.talend.dataprep.api.service.api.EnrichedPreparation) PreparationMessage(org.talend.dataprep.api.preparation.PreparationMessage) Test(org.junit.Test)

Aggregations

EnrichedPreparation (org.talend.dataprep.api.service.api.EnrichedPreparation)13 Test (org.junit.Test)12 PreparationMessage (org.talend.dataprep.api.preparation.PreparationMessage)4 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)3 Folder (org.talend.dataprep.api.folder.Folder)3 Response (com.jayway.restassured.response.Response)1 InputStream (java.io.InputStream)1 LinkedList (java.util.LinkedList)1 AppendStep (org.talend.dataprep.api.preparation.AppendStep)1 LocatePreparation (org.talend.dataprep.api.service.command.preparation.LocatePreparation)1 DataSetGet (org.talend.dataprep.command.dataset.DataSetGet)1 DataSetGetMetadata (org.talend.dataprep.command.dataset.DataSetGetMetadata)1 TDPException (org.talend.dataprep.exception.TDPException)1 SecurityProxy (org.talend.dataprep.security.SecurityProxy)1