use of org.talend.dataprep.api.service.api.EnrichedPreparation in project data-prep by Talend.
the class APIPreparationConversionsTest method shouldEnrichPreparationWithDataset.
@Test
public void shouldEnrichPreparationWithDataset() {
// given
DataSetMetadata metadata = getDataSetMetadata("super dataset", 1001L);
setupHystrixCommand(DataSetGetMetadata.class, metadata);
final PreparationMessage preparation = getPreparationMessage(metadata.getId());
Folder folder = getFolder("F-753854");
setupHystrixCommand(LocatePreparation.class, folder);
// when
final EnrichedPreparation actual = conversionService.convert(preparation, EnrichedPreparation.class);
// then
assertEquals(metadata.getId(), actual.getSummary().getDataSetId());
assertEquals(metadata.getName(), actual.getSummary().getDataSetName());
assertEquals(metadata.getContent().getNbRecords(), actual.getSummary().getDataSetNbRow());
final List<String> expectedSteps = preparation.getSteps().stream().map(Step::getId).collect(Collectors.toList());
final List<String> actualSteps = actual.getSteps();
assertNotNull(actualSteps);
assertEquals(expectedSteps.size(), expectedSteps.size());
expectedSteps.forEach(s -> assertTrue(actualSteps.contains(s)));
assertEquals(folder, actual.getFolder());
}
use of org.talend.dataprep.api.service.api.EnrichedPreparation in project data-prep by Talend.
the class PreparationAPITest method testSetPreparationHead_TDP_2562.
/**
* Verify a data set is not locked when used by a step that is not used in any preparation.
* see <a href="https://jira.talendforge.org/browse/TDP-2562">TDP-2562</a>
*/
@Test
public void testSetPreparationHead_TDP_2562() throws Exception {
// Three data sets
final String lookupDataSetId = testClient.createDataset("dataset/dataset.csv", "lookup_ds");
final String dataSetId = testClient.createDataset("dataset/dataset_cars.csv", "cars");
String carsPreparationId = testClient.createPreparationFromDataset(dataSetId, "cars_preparation", home.getId());
String action = IOUtils.toString(getClass().getResource("preparations/cars_lookup_action.json"), UTF_8);
testClient.applyAction(carsPreparationId, action.replace("{lookup_ds_id}", lookupDataSetId));
// Try to delete lookup dataset => fail because used
expect().statusCode(CONFLICT.value()).when().delete("/api/datasets/{id}", lookupDataSetId);
EnrichedPreparation preparationDetails = getPreparationDetails(carsPreparationId);
String firstStepId = preparationDetails.getSteps().get(0);
// Now undo
expect().statusCode(OK.value()).when().put("/api/preparations/{id}/head/{headId}", carsPreparationId, firstStepId);
// Try again to delete lookup dataset
expect().statusCode(OK.value()).when().get("/api/datasets/{id}", lookupDataSetId);
}
use of org.talend.dataprep.api.service.api.EnrichedPreparation in project data-prep by Talend.
the class PreparationAPITest method shouldAddMultipleActionStepAfterHead.
@Test
public void shouldAddMultipleActionStepAfterHead() throws Exception {
// / when: 1 AppendStep with 2 actions
final String preparationId = testClient.createPreparationFromFile("dataset/dataset.csv", "testPreparation", home.getId());
// when
testClient.applyActionFromFile(preparationId, "transformation/upper_case_lastname_firstname.json");
// then : it should have appended 2 actions
final EnrichedPreparation preparationMessage = getPreparationDetails(preparationId);
final List<String> steps = preparationMessage.getSteps();
assertThat(steps.size(), is(3));
assertThat(steps.get(0), is(Step.ROOT_STEP.id()));
}
use of org.talend.dataprep.api.service.api.EnrichedPreparation in project data-prep by Talend.
the class PreparationAPITest method testMoveStep.
@Test
public void testMoveStep() throws Exception {
final String datasetId = testClient.createDataset("preview/preview_dataset.csv", "testPreview");
String testPrepId = testClient.createPreparationFromDataset(datasetId, "testPrep", home.getId());
AppendStep appendStep = new AppendStep();
appendStep.setActions(Arrays.asList(buildAction("uppercase", buildParametersMap("column_id", "0002", "column_name", "lastname", "scope", "column")), buildAction("uppercase", buildParametersMap("column_id", "0001", "column_name", "firstname", "scope", "column"))));
appendStepsToPrep(testPrepId, appendStep);
// Adding steps
EnrichedPreparation testPrepDetails = getPreparationDetails(testPrepId);
List<String> stepsCreated = testPrepDetails.getSteps();
String rootStep = stepsCreated.get(0);
String secondStep = stepsCreated.get(2);
// changing steps order
changePreparationStepsOrder(testPrepId, rootStep, secondStep);
EnrichedPreparation testPrepDetailsAfter = getPreparationDetails(testPrepId);
assertEquals(testPrepDetailsAfter.getActions().get(0), testPrepDetails.getActions().get(1));
assertEquals(testPrepDetailsAfter.getActions().get(1), testPrepDetails.getActions().get(0));
}
use of org.talend.dataprep.api.service.api.EnrichedPreparation in project data-prep by Talend.
the class PreparationAPITest method testPreparationContentWithActions.
@Test
public void testPreparationContentWithActions() throws Exception {
// given
final String preparationId = testClient.createPreparationFromFile("dataset/dataset.csv", "testPreparationContentGet", home.getId());
EnrichedPreparation preparation = getPreparationDetails(preparationId);
List<String> steps = preparation.getSteps();
assertThat(steps.size(), is(1));
assertThat(steps.get(0), is(Step.ROOT_STEP.id()));
// when
testClient.applyActionFromFile(preparationId, "transformation/upper_case_firstname.json");
// then
final EnrichedPreparation preparationMessage = getPreparationDetails(preparationId);
steps = preparationMessage.getSteps();
assertThat(steps.size(), is(2));
assertThat(steps.get(0), is(Step.ROOT_STEP.id()));
// Request preparation content at different versions (preparation has 2 steps -> Root + Upper Case).
assertThat(testClient.getPreparation(preparationId).asString(), sameJSONAsFile(PreparationAPITest.class.getResourceAsStream("dataset/expected_dataset_firstname_uppercase_with_column.json")));
assertThat(testClient.getPreparation(preparationId, "head").asString(), sameJSONAsFile(PreparationAPITest.class.getResourceAsStream("dataset/expected_dataset_firstname_uppercase_with_column.json")));
assertThat(testClient.getPreparation(preparationId, steps.get(0)).asString(), sameJSONAsFile(PreparationAPITest.class.getResourceAsStream("dataset/expected_dataset_with_columns.json")));
assertThat(testClient.getPreparation(preparationId, steps.get(1)).asString(), sameJSONAsFile(PreparationAPITest.class.getResourceAsStream("dataset/expected_dataset_firstname_uppercase_with_column.json")));
assertThat(testClient.getPreparation(preparationId, "origin").asString(), sameJSONAsFile(PreparationAPITest.class.getResourceAsStream("dataset/expected_dataset_with_columns.json")));
assertThat(testClient.getPreparation(preparationId, Step.ROOT_STEP.id()).asString(), sameJSONAsFile(PreparationAPITest.class.getResourceAsStream("dataset/expected_dataset_with_columns.json")));
}
Aggregations