Search in sources :

Example 1 with RunnableAction

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

the class MakeLineHeaderTest method should_keep_header_after_modifications.

@Test
public void should_keep_header_after_modifications() {
    // given
    Long rowId = 0L;
    // row 1
    Map<String, String> rowContent = new HashMap<>();
    rowContent.put("0000", "David");
    rowContent.put("0001", "Bowie");
    final DataSetRow row1 = new DataSetRow(rowContent);
    row1.setTdpId(rowId++);
    // row 2
    rowContent = new HashMap<>();
    rowContent.put("0000", "John");
    rowContent.put("0001", "Lennon");
    final DataSetRow row2 = new DataSetRow(rowContent);
    row2.setTdpId(rowId++);
    // row 3
    rowContent = new HashMap<>();
    rowContent.put("0000", "Johnny");
    rowContent.put("0001", "Lennon");
    final DataSetRow row3 = new DataSetRow(rowContent);
    row3.setTdpId(rowId++);
    // when
    final Map<String, String> makeHeaderParameters = new HashMap<>();
    makeHeaderParameters.put(ImplicitParameters.SCOPE.getKey().toLowerCase(), "line");
    makeHeaderParameters.put("row_id", row2.getTdpId().toString());
    final RunnableAction makeHeader = factory.create(action, makeHeaderParameters);
    final Map<String, String> upperCaseParameters = new HashMap<>();
    upperCaseParameters.put(ImplicitParameters.SCOPE.getKey().toLowerCase(), "column");
    upperCaseParameters.put(ImplicitParameters.COLUMN_ID.getKey().toLowerCase(), "0000");
    final RunnableAction upperCase = factory.create(new UpperCase(), upperCaseParameters);
    ActionTestWorkbench.test(Arrays.asList(row1, row2, row3), actionRegistry, makeHeader, upperCase);
    // then
    assertEquals("John", row1.getRowMetadata().getById("0000").getName());
    assertEquals("Lennon", row1.getRowMetadata().getById("0001").getName());
    assertEquals("John", row2.getRowMetadata().getById("0000").getName());
    assertEquals("Lennon", row2.getRowMetadata().getById("0001").getName());
    assertEquals("John", row3.getRowMetadata().getById("0000").getName());
    assertEquals("Lennon", row3.getRowMetadata().getById("0001").getName());
}
Also used : UpperCase(org.talend.dataprep.transformation.actions.text.UpperCase) HashMap(java.util.HashMap) 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 2 with RunnableAction

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

the class FillWithBooleanIfInvalidTest method should_not_fill_non_valid_boolean.

@Test
public void should_not_fill_non_valid_boolean() throws Exception {
    // given
    final Map<String, String> values = new HashMap<>();
    values.put("0000", "David Bowie");
    values.put("0001", "N");
    values.put("0002", "False");
    final DataSetRow row = new DataSetRow(values);
    final RowMetadata rowMetadata = row.getRowMetadata();
    rowMetadata.getById("0002").setType(Type.BOOLEAN.getName());
    Map<String, String> parameters = ActionMetadataTestUtils.parseParameters(this.getClass().getResourceAsStream("fillInvalidBooleanAction.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("False", 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 3 with RunnableAction

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

the class FillWithBooleanIfInvalidTest method should_fill_non_valid_boolean.

@Test
public void should_fill_non_valid_boolean() throws Exception {
    // given
    final Map<String, String> values = new HashMap<>();
    values.put("0000", "David Bowie");
    values.put("0001", "N");
    // invalid boolean
    values.put("0002", "100");
    final DataSetRow row = new DataSetRow(values);
    row.setInvalid("0002");
    final RowMetadata rowMetadata = row.getRowMetadata();
    rowMetadata.getById("0002").setType(Type.BOOLEAN.getName());
    Map<String, String> parameters = ActionMetadataTestUtils.parseParameters(this.getClass().getResourceAsStream("fillInvalidBooleanAction.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("True", 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 4 with RunnableAction

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

the class FillWithStringIfInvalidTest method should_fill_empty_string_other_column.

@Test
public void should_fill_empty_string_other_column() throws Exception {
    // given
    final Map<String, String> values = new HashMap<>();
    values.put("0000", "David Bowie");
    values.put("0001", "DC");
    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());
    rowMetadata.getById("0002").setType(Type.STRING.getName());
    Map<String, String> parameters = // 
    ActionMetadataTestUtils.parseParameters(this.getClass().getResourceAsStream("fillInvalidStringAction.json"));
    // when
    parameters.put(FillIfEmpty.MODE_PARAMETER, FillIfEmpty.OTHER_COLUMN_MODE);
    parameters.put(FillIfEmpty.SELECTED_COLUMN_PARAMETER, "0002");
    final RunnableAction runnableAction = factory.create(action, parameters);
    final ActionContext context = new ActionContext(new TransformationContext(), rowMetadata);
    context.setParameters(parameters);
    runnableAction.getRowAction().apply(row, context);
    // then
    Assert.assertEquals("Something", row.get("0001"));
    Assert.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 5 with RunnableAction

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

the class FillWithStringIfInvalidTest method should_fill_non_valid_string.

@Test
public void should_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", "100");
    final DataSetRow row = new DataSetRow(values);
    row.setInvalid("0002");
    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("beer", 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)

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