Search in sources :

Example 11 with PreparationActions

use of org.talend.dataprep.api.preparation.PreparationActions in project data-prep by Talend.

the class SplitReplaceOnValueActionTest method shouldSplitActions.

@Test
public void shouldSplitActions() {
    // when
    task.run();
    // then
    final List<PreparationActions> prepActionsList = repository.list(PreparationActions.class).collect(Collectors.toList());
    int actionUpdated = 0;
    int actionNotUpdated = 0;
    for (PreparationActions prepActions : prepActionsList) {
        for (Action action : prepActions.getActions()) {
            if (REPLACE_CELL_VALUE.equals(action.getName())) {
                final Map<String, String> parameters = action.getParameters();
                assertTrue(parameters.containsKey("new_value"));
                assertTrue(parameters.containsKey("original_value"));
                assertFalse(parameters.containsKey(CELL_VALUE));
                assertFalse(parameters.containsKey(REPLACE_VALUE));
                actionUpdated++;
            } else {
                actionNotUpdated++;
            }
        }
    }
    assertEquals(1, actionUpdated);
    assertEquals(33, actionNotUpdated);
}
Also used : Action(org.talend.dataprep.api.preparation.Action) PreparationActions(org.talend.dataprep.api.preparation.PreparationActions) Test(org.junit.Test)

Example 12 with PreparationActions

use of org.talend.dataprep.api.preparation.PreparationActions in project data-prep by Talend.

the class PreparationTest method initialStepWithAppend.

@Test
public void initialStepWithAppend() {
    final String version = versionService.version().getVersionId();
    final List<Action> actions = getSimpleAction("uppercase", "column_name", "lastname");
    final PreparationActions newContent = PreparationActions.ROOT_ACTIONS.append(actions);
    repository.add(newContent);
    final Step s = new Step(Step.ROOT_STEP.id(), newContent.id(), version);
    repository.add(s);
    final Preparation preparation = new Preparation("#5438743", "1234", s.id(), version);
    preparation.setCreationDate(0L);
    repository.add(preparation);
    assertThat(preparation.id(), Is.is("#5438743"));
}
Also used : Action(org.talend.dataprep.api.preparation.Action) Preparation(org.talend.dataprep.api.preparation.Preparation) PreparationActions(org.talend.dataprep.api.preparation.PreparationActions) Step(org.talend.dataprep.api.preparation.Step) Test(org.junit.Test) ServiceBaseTest(org.talend.ServiceBaseTest)

Example 13 with PreparationActions

use of org.talend.dataprep.api.preparation.PreparationActions in project data-prep by Talend.

the class APIPreparationConversionsTest method getPreparationMessage.

private PreparationMessage getPreparationMessage(String dataSetId) {
    final PreparationMessage preparation = new PreparationMessage();
    preparation.setDataSetId(dataSetId);
    List<Step> steps = new ArrayList<>(12);
    Step parentStep = preparation.getSteps().get(0);
    for (int i = 0; i < 12; i++) {
        final Step step = new Step(parentStep.id(), new PreparationActions().id(), "2.1");
        steps.add(step);
        parentStep = step;
    }
    preparation.setSteps(steps);
    return preparation;
}
Also used : ArrayList(java.util.ArrayList) PreparationMessage(org.talend.dataprep.api.preparation.PreparationMessage) PreparationActions(org.talend.dataprep.api.preparation.PreparationActions) Step(org.talend.dataprep.api.preparation.Step)

Example 14 with PreparationActions

use of org.talend.dataprep.api.preparation.PreparationActions in project data-prep by Talend.

the class PreparationCleanerTest method shouldNotRemovePreparationActions_sharedByMultiplePreparation.

@Test
public void shouldNotRemovePreparationActions_sharedByMultiplePreparation() throws Exception {
    // given
    final String version = "1.2.3";
    final PreparationActions content = new PreparationActions();
    List<Action> actions = new ArrayList<>();
    content.append(actions);
    content.setAppVersion(version);
    when(repository.list(PreparationActions.class)).thenReturn(Stream.of(content));
    when(repository.get(content.id(), PreparationActions.class)).thenReturn(content);
    // 2 preparations, with each, one step that shares the same action
    final Step stepFirstPreparation = new Step(Step.ROOT_STEP.getId(), content.getId(), version);
    final Step stepSecondPreparation = new Step(Step.ROOT_STEP.getId(), content.getId(), version);
    // add the steps to the repository
    when(repository.exist(eq(PersistentStep.class), eq(TqlBuilder.eq("contentId", content.id())))).thenReturn(true);
    when(repository.list(Step.class)).thenReturn(Stream.of(stepFirstPreparation, stepSecondPreparation));
    when(repository.list(eq(PersistentStep.class))).thenReturn(Stream.of(stepFirstPreparation, stepSecondPreparation).map(s -> {
        final PersistentStep persistentStep = new PersistentStep();
        persistentStep.setId(s.id());
        persistentStep.setContent(s.getContent());
        return persistentStep;
    }));
    Preparation firstPreparation = new Preparation("1", null, stepFirstPreparation.getId(), version);
    firstPreparation.setSteps(Collections.singletonList(stepFirstPreparation));
    Preparation secondPreparation = new Preparation("2", null, stepSecondPreparation.getId(), version);
    secondPreparation.setSteps(Collections.singletonList(stepSecondPreparation));
    // add the preparations to the repository
    when(repository.list(Preparation.class)).thenReturn(Stream.of(firstPreparation, secondPreparation));
    // when
    cleaner.removeOrphanSteps();
    // then
    verify(repository, never()).remove(eq(content));
}
Also used : InjectMocks(org.mockito.InjectMocks) Preparation(org.talend.dataprep.api.preparation.Preparation) Arrays(java.util.Arrays) TqlBuilder(org.talend.tql.api.TqlBuilder) Mock(org.mockito.Mock) BaseMaintenanceTest(org.talend.dataprep.maintenance.BaseMaintenanceTest) PersistentStep(org.talend.dataprep.preparation.store.PersistentStep) Test(org.junit.Test) Step(org.talend.dataprep.api.preparation.Step) PreparationRepository(org.talend.dataprep.preparation.store.PreparationRepository) ArrayList(java.util.ArrayList) Mockito(org.mockito.Mockito) List(java.util.List) Stream(java.util.stream.Stream) PreparationActions(org.talend.dataprep.api.preparation.PreparationActions) Action(org.talend.dataprep.api.preparation.Action) Collections(java.util.Collections) PersistentStep(org.talend.dataprep.preparation.store.PersistentStep) Action(org.talend.dataprep.api.preparation.Action) Preparation(org.talend.dataprep.api.preparation.Preparation) ArrayList(java.util.ArrayList) PreparationActions(org.talend.dataprep.api.preparation.PreparationActions) PersistentStep(org.talend.dataprep.preparation.store.PersistentStep) Step(org.talend.dataprep.api.preparation.Step) BaseMaintenanceTest(org.talend.dataprep.maintenance.BaseMaintenanceTest) Test(org.junit.Test)

Example 15 with PreparationActions

use of org.talend.dataprep.api.preparation.PreparationActions in project data-prep by Talend.

the class PreparationCleanerTest method shouldNotRemovePreparationActions_ownedByOnePreparation.

@Test
public void shouldNotRemovePreparationActions_ownedByOnePreparation() throws Exception {
    // given
    final String version = "1.2.3";
    final PreparationActions content = new PreparationActions();
    List<Action> actions = new ArrayList<>();
    content.append(actions);
    content.setAppVersion(version);
    when(repository.list(PreparationActions.class)).thenReturn(Stream.of(content));
    when(repository.get(content.id(), PreparationActions.class)).thenReturn(content);
    // 2 preparations, with each, one step that shares the same action
    final Step stepFirstPreparation = new Step(Step.ROOT_STEP.getId(), content.getId(), version);
    final Step stepSecondPreparation = new Step(Step.ROOT_STEP.getId(), content.getId(), version);
    // add the steps to the repository
    when(repository.list(Step.class)).thenReturn(Stream.of(stepFirstPreparation, stepSecondPreparation));
    when(repository.list(eq(PersistentStep.class))).thenReturn(Stream.of(stepFirstPreparation, stepSecondPreparation).map(s -> {
        final PersistentStep persistentStep = new PersistentStep();
        persistentStep.setId(s.id());
        persistentStep.setContent(s.getContent());
        return persistentStep;
    }));
    Preparation firstPreparation = new Preparation("1", null, stepFirstPreparation.getId(), version);
    firstPreparation.setSteps(Collections.singletonList(stepFirstPreparation));
    Preparation secondPreparation = new Preparation("2", null, stepSecondPreparation.getId(), version);
    secondPreparation.setSteps(Collections.singletonList(stepSecondPreparation));
    // add the preparations to the repository
    when(repository.exist(eq(PersistentStep.class), any())).thenReturn(true);
    // Remove first preparation
    when(repository.list(Preparation.class)).thenReturn(Stream.of(secondPreparation));
    // when
    cleaner.removeOrphanSteps();
    // then
    // when the first preparation is removed, the shared action is not deleted
    verify(repository, never()).remove(eq(content));
}
Also used : InjectMocks(org.mockito.InjectMocks) Preparation(org.talend.dataprep.api.preparation.Preparation) Arrays(java.util.Arrays) TqlBuilder(org.talend.tql.api.TqlBuilder) Mock(org.mockito.Mock) BaseMaintenanceTest(org.talend.dataprep.maintenance.BaseMaintenanceTest) PersistentStep(org.talend.dataprep.preparation.store.PersistentStep) Test(org.junit.Test) Step(org.talend.dataprep.api.preparation.Step) PreparationRepository(org.talend.dataprep.preparation.store.PreparationRepository) ArrayList(java.util.ArrayList) Mockito(org.mockito.Mockito) List(java.util.List) Stream(java.util.stream.Stream) PreparationActions(org.talend.dataprep.api.preparation.PreparationActions) Action(org.talend.dataprep.api.preparation.Action) Collections(java.util.Collections) PersistentStep(org.talend.dataprep.preparation.store.PersistentStep) Action(org.talend.dataprep.api.preparation.Action) Preparation(org.talend.dataprep.api.preparation.Preparation) ArrayList(java.util.ArrayList) PreparationActions(org.talend.dataprep.api.preparation.PreparationActions) PersistentStep(org.talend.dataprep.preparation.store.PersistentStep) Step(org.talend.dataprep.api.preparation.Step) BaseMaintenanceTest(org.talend.dataprep.maintenance.BaseMaintenanceTest) Test(org.junit.Test)

Aggregations

PreparationActions (org.talend.dataprep.api.preparation.PreparationActions)17 Test (org.junit.Test)14 Action (org.talend.dataprep.api.preparation.Action)13 Step (org.talend.dataprep.api.preparation.Step)11 ArrayList (java.util.ArrayList)8 PersistentStep (org.talend.dataprep.preparation.store.PersistentStep)8 PreparationRepository (org.talend.dataprep.preparation.store.PreparationRepository)8 Preparation (org.talend.dataprep.api.preparation.Preparation)7 List (java.util.List)5 Stream (java.util.stream.Stream)5 Arrays (java.util.Arrays)4 Collections (java.util.Collections)4 InjectMocks (org.mockito.InjectMocks)4 Mock (org.mockito.Mock)4 Mockito (org.mockito.Mockito)4 BaseMaintenanceTest (org.talend.dataprep.maintenance.BaseMaintenanceTest)4 TqlBuilder (org.talend.tql.api.TqlBuilder)4 ServiceBaseTest (org.talend.ServiceBaseTest)3 RowMetadata (org.talend.dataprep.api.dataset.RowMetadata)2 DataSetRow (org.talend.dataprep.api.dataset.row.DataSetRow)2