Search in sources :

Example 6 with EnrichedPreparation

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());
}
Also used : EnrichedPreparation(org.talend.dataprep.api.service.api.EnrichedPreparation) PreparationMessage(org.talend.dataprep.api.preparation.PreparationMessage) Folder(org.talend.dataprep.api.folder.Folder) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) Test(org.junit.Test)

Example 7 with EnrichedPreparation

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);
}
Also used : EnrichedPreparation(org.talend.dataprep.api.service.api.EnrichedPreparation) Test(org.junit.Test)

Example 8 with EnrichedPreparation

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()));
}
Also used : EnrichedPreparation(org.talend.dataprep.api.service.api.EnrichedPreparation) Test(org.junit.Test)

Example 9 with EnrichedPreparation

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));
}
Also used : EnrichedPreparation(org.talend.dataprep.api.service.api.EnrichedPreparation) AppendStep(org.talend.dataprep.api.preparation.AppendStep) Test(org.junit.Test)

Example 10 with EnrichedPreparation

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")));
}
Also used : EnrichedPreparation(org.talend.dataprep.api.service.api.EnrichedPreparation) 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