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);
}
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()));
}
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"));
}
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));
}
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());
}
Aggregations