Search in sources :

Example 16 with RunnableAction

use of org.talend.dataprep.transformation.actions.common.RunnableAction in project data-prep by Talend.

the class FillWithNumericIfInvalidTest method should_fill_non_valid_integer.

@Test
public void should_fill_non_valid_integer() throws Exception {
    // given
    final Map<String, String> values = new HashMap<>();
    values.put("0000", "David Bowie");
    values.put("0001", "N");
    values.put("0002", "Something");
    final DataSetRow row = new DataSetRow(values);
    row.setInvalid("0001");
    final RowMetadata rowMetadata = row.getRowMetadata();
    rowMetadata.getById("0001").setType(Type.INTEGER.getName());
    Map<String, String> parameters = ActionMetadataTestUtils.parseParameters(this.getClass().getResourceAsStream("fillInvalidIntegerAction.json"));
    // when
    final RunnableAction runnableAction = factory.create(action, parameters);
    final ActionContext context = new ActionContext(new TransformationContext(), rowMetadata);
    context.setParameters(parameters);
    runnableAction.getRowAction().apply(row, context);
    // then
    assertEquals("25", row.get("0001"));
    assertEquals("David Bowie", row.get("0000"));
}
Also used : HashMap(java.util.HashMap) RunnableAction(org.talend.dataprep.transformation.actions.common.RunnableAction) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) ActionContext(org.talend.dataprep.transformation.api.action.context.ActionContext) TransformationContext(org.talend.dataprep.transformation.api.action.context.TransformationContext) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)

Example 17 with RunnableAction

use of org.talend.dataprep.transformation.actions.common.RunnableAction in project data-prep by Talend.

the class FillWithStringIfInvalidTest method should_not_fill_non_valid_string.

@Test
public void should_not_fill_non_valid_string() throws Exception {
    // given
    final Map<String, String> values = new HashMap<>();
    values.put("0000", "David Bowie");
    values.put("0001", "N");
    values.put("0002", "wine");
    final DataSetRow row = new DataSetRow(values);
    final RowMetadata rowMetadata = row.getRowMetadata();
    rowMetadata.getById("0002").setType(Type.STRING.getName());
    Map<String, String> parameters = ActionMetadataTestUtils.parseParameters(this.getClass().getResourceAsStream("fillInvalidStringAction.json"));
    parameters.put(ImplicitParameters.COLUMN_ID.getKey().toLowerCase(), "0002");
    // when
    final RunnableAction runnableAction = factory.create(action, parameters);
    final ActionContext context = new ActionContext(new TransformationContext(), rowMetadata);
    context.setParameters(parameters);
    runnableAction.getRowAction().apply(row, context);
    // then
    assertEquals("wine", row.get("0002"));
    assertEquals("David Bowie", row.get("0000"));
}
Also used : HashMap(java.util.HashMap) RunnableAction(org.talend.dataprep.transformation.actions.common.RunnableAction) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) ActionContext(org.talend.dataprep.transformation.api.action.context.ActionContext) TransformationContext(org.talend.dataprep.transformation.api.action.context.TransformationContext) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)

Example 18 with RunnableAction

use of org.talend.dataprep.transformation.actions.common.RunnableAction in project data-prep by Talend.

the class DeleteColumnTest method shouldDeleteAllColumns.

@Test
public void shouldDeleteAllColumns() throws Exception {
    // given
    final Map<String, String> values = new HashMap<>();
    values.put("0001", "1");
    values.put("0002", "Wolf");
    final DataSetRow row = new DataSetRow(rowMetadata, values);
    final Map<String, String> values2 = new HashMap<>();
    values.put("0001", "2");
    values.put("0002", "Lion");
    final DataSetRow row2 = new DataSetRow(rowMetadata, values2);
    // when
    parameters.put(ImplicitParameters.COLUMN_ID.getKey().toLowerCase(), "0002");
    final RunnableAction action1 = factory.create(action, parameters);
    parameters.put(ImplicitParameters.COLUMN_ID.getKey().toLowerCase(), "0001");
    final RunnableAction action2 = factory.create(action, parameters);
    ActionTestWorkbench.test(row, actionRegistry, action1, action2);
    ActionTestWorkbench.test(row2, actionRegistry, action1, action2);
    // then
    final int rowSize = row.getRowMetadata().getColumns().size();
    final int row2Size = row2.getRowMetadata().getColumns().size();
    assertEquals(0, rowSize);
    assertEquals(0, row2Size);
}
Also used : RunnableAction(org.talend.dataprep.transformation.actions.common.RunnableAction) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)

Example 19 with RunnableAction

use of org.talend.dataprep.transformation.actions.common.RunnableAction in project data-prep by Talend.

the class ClearInvalidTest method should_not_clear_invalid_date.

@Test
public void should_not_clear_invalid_date() {
    // given
    final Map<String, String> values = new HashMap<>();
    values.put("0001", "David Bowie");
    values.put("0002", "20-09-1975");
    values.put("0003", "Something");
    final DataSetRow row = new DataSetRow(values);
    final RowMetadata rowMetadata = row.getRowMetadata();
    rowMetadata.getById("0002").setType(Type.DATE.getName());
    final Map<String, Object> expectedValues = new LinkedHashMap<>();
    expectedValues.put("0001", "David Bowie");
    expectedValues.put("0002", "20-09-1975");
    expectedValues.put("0003", "Something");
    // when
    final RunnableAction runnableAction = factory.create(action, parameters);
    final ActionContext context = new ActionContext(new TransformationContext(), rowMetadata);
    context.setParameters(parameters);
    runnableAction.getRowAction().apply(row, context);
    // then
    assertEquals(expectedValues, row.values());
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) RunnableAction(org.talend.dataprep.transformation.actions.common.RunnableAction) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) ActionContext(org.talend.dataprep.transformation.api.action.context.ActionContext) TransformationContext(org.talend.dataprep.transformation.api.action.context.TransformationContext) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)

Example 20 with RunnableAction

use of org.talend.dataprep.transformation.actions.common.RunnableAction in project data-prep by Talend.

the class DeleteInvalidTest method should_delete_because_non_valid.

@Test
public void should_delete_because_non_valid() {
    // given
    final Map<String, String> values = new HashMap<>();
    values.put("0000", "David Bowie");
    values.put("0001", "N");
    values.put("0002", "Something");
    final DataSetRow row = new DataSetRow(values);
    row.setInvalid("0001");
    final RowMetadata rowMetadata = row.getRowMetadata();
    rowMetadata.getById("0001").setType(Type.STRING.getName());
    // when
    final RunnableAction runnableAction = factory.create(action, parameters);
    final ActionContext context = new ActionContext(new TransformationContext(), rowMetadata);
    context.setParameters(parameters);
    runnableAction.getRowAction().apply(row, context);
    // then
    assertTrue(row.isDeleted());
    assertEquals("David Bowie", row.get("0000"));
}
Also used : HashMap(java.util.HashMap) RunnableAction(org.talend.dataprep.transformation.actions.common.RunnableAction) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) ActionContext(org.talend.dataprep.transformation.api.action.context.ActionContext) TransformationContext(org.talend.dataprep.transformation.api.action.context.TransformationContext) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)

Aggregations

RunnableAction (org.talend.dataprep.transformation.actions.common.RunnableAction)32 Test (org.junit.Test)23 TransformationContext (org.talend.dataprep.transformation.api.action.context.TransformationContext)22 ActionContext (org.talend.dataprep.transformation.api.action.context.ActionContext)21 DataSetRow (org.talend.dataprep.api.dataset.row.DataSetRow)20 RowMetadata (org.talend.dataprep.api.dataset.RowMetadata)18 HashMap (java.util.HashMap)15 AbstractMetadataBaseTest (org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)14 DataSetRowAction (org.talend.dataprep.transformation.api.action.DataSetRowAction)6 ActionDefinition (org.talend.dataprep.api.action.ActionDefinition)4 ColumnMetadata (org.talend.dataprep.api.dataset.ColumnMetadata)4 Action (org.talend.dataprep.api.preparation.Action)4 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)3 List (java.util.List)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Before (org.junit.Before)3 DataSet (org.talend.dataprep.api.dataset.DataSet)3 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)3 CoreMatchers (org.hamcrest.CoreMatchers)2