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