Search in sources :

Example 11 with Action

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

the class PreparationTest method stepsWithAppend.

@Test
public void stepsWithAppend() {
    final String version = versionService.version().getVersionId();
    final List<Action> actions = getSimpleAction("uppercase", "column_name", "lastname");
    final PreparationActions newContent1 = PreparationActions.ROOT_ACTIONS.append(actions);
    repository.add(newContent1);
    final PreparationActions newContent2 = newContent1.append(actions);
    repository.add(newContent2);
    // Steps
    final Step s1 = new Step(Step.ROOT_STEP.id(), newContent1.id(), version);
    repository.add(s1);
    final Step s2 = new Step(s1.id(), newContent2.id(), version);
    repository.add(s2);
    // Preparation
    final Preparation preparation = new Preparation("#54258728", "1234", s2.id(), version);
    preparation.setCreationDate(0L);
    repository.add(preparation);
    assertThat(preparation.id(), Is.is("#54258728"));
}
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 12 with Action

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

the class PreparationTest method initialStep.

@Test
public void initialStep() {
    final String version = versionService.version().getVersionId();
    final List<Action> actions = getSimpleAction("uppercase", "column_name", "lastname");
    final PreparationActions newContent = new PreparationActions(actions, version);
    repository.add(newContent);
    final Step s = new Step(Step.ROOT_STEP.id(), newContent.id(), version);
    repository.add(s);
    Preparation preparation = new Preparation("#48368", "1234", s.id(), version);
    preparation.setCreationDate(0L);
    repository.add(preparation);
    assertThat(preparation.id(), Is.is("#48368"));
}
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 Action

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

the class PreparationTest method getSimpleAction.

public static List<Action> getSimpleAction(final String actionName, final String paramKey, final String paramValue) {
    final Action action = new Action();
    action.setName(actionName);
    action.getParameters().put(paramKey, paramValue);
    final List<Action> actions = new ArrayList<>();
    actions.add(action);
    return actions;
}
Also used : Action(org.talend.dataprep.api.preparation.Action) ArrayList(java.util.ArrayList)

Example 14 with Action

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

the class ActionMetadataTestUtils method parseParameters.

/**
 * Parse the given input stream into a parameter map.
 *
 * @param input the parameters input stream.
 * @return the parsed parameters.
 * @throws IOException if an error occurs.
 */
public static Map<String, String> parseParameters(InputStream input) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new MixedContentMapModule());
    mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    List<Action> parsedAction = ((Actions) mapper.reader(Actions.class).readValue(input)).getActions();
    return parsedAction.get(0).getParameters();
}
Also used : Action(org.talend.dataprep.api.preparation.Action) MixedContentMapModule(org.talend.dataprep.api.preparation.json.MixedContentMapModule) Actions(org.talend.dataprep.api.preparation.Actions) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 15 with Action

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

the class ActionNewColumnToggleCommonTest method shouldNotUpdateSteps.

@Test
public void shouldNotUpdateSteps() {
    // given
    final PreparationRepository repository = mock(PreparationRepository.class);
    final PreparationActions actions = mock(PreparationActions.class);
    final PersistentStep step = mock(PersistentStep.class);
    final Action action = mock(Action.class);
    List<Action> actionsList = new ArrayList<>();
    actionsList.add(action);
    when(step.id()).thenReturn("step-1");
    when(actions.getActions()).thenReturn(actionsList);
    when(action.getName()).thenReturn("action");
    when(repository.list(eq(PreparationActions.class))).thenReturn(Stream.of(actions));
    // Twice "action-1" to pass root preparation action filter.
    // same id
    when(actions.id()).thenReturn("actions-1", "actions-1", "actions-1");
    when(repository.list(eq(PersistentStep.class), any())).thenReturn(Stream.of(step));
    // when
    ActionNewColumnToggleCommon.upgradeActions(repository);
    // then
    verify(repository, times(1)).add(eq(actions));
    verify(repository, never()).add(eq(step));
    verify(step, never()).setContent(any());
}
Also used : PreparationRepository(org.talend.dataprep.preparation.store.PreparationRepository) PersistentStep(org.talend.dataprep.preparation.store.PersistentStep) Action(org.talend.dataprep.api.preparation.Action) ArrayList(java.util.ArrayList) PreparationActions(org.talend.dataprep.api.preparation.PreparationActions) Test(org.junit.Test)

Aggregations

Action (org.talend.dataprep.api.preparation.Action)27 Test (org.junit.Test)14 PreparationActions (org.talend.dataprep.api.preparation.PreparationActions)12 ArrayList (java.util.ArrayList)9 List (java.util.List)7 PreparationRepository (org.talend.dataprep.preparation.store.PreparationRepository)7 Preparation (org.talend.dataprep.api.preparation.Preparation)6 Step (org.talend.dataprep.api.preparation.Step)6 PersistentStep (org.talend.dataprep.preparation.store.PersistentStep)6 IOException (java.io.IOException)4 Collections (java.util.Collections)4 Stream (java.util.stream.Stream)4 ActionDefinition (org.talend.dataprep.api.action.ActionDefinition)4 RunnableAction (org.talend.dataprep.transformation.actions.common.RunnableAction)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Arrays (java.util.Arrays)3 HashMap (java.util.HashMap)3 StringUtils (org.apache.commons.lang.StringUtils)3 InjectMocks (org.mockito.InjectMocks)3 Mock (org.mockito.Mock)3