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"));
}
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"));
}
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);
}
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());
}
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"));
}
Aggregations