use of org.talend.dataprep.api.dataset.RowMetadata in project data-prep by Talend.
the class FillWithStringIfEmptyTest method should_fill_empty_float.
@Test
public void should_fill_empty_float() throws Exception {
// given
final Map<String, String> values = new HashMap<>();
values.put("0000", "David Bowie");
values.put("0001", "");
values.put("0002", "100");
final DataSetRow row = new DataSetRow(values);
final RowMetadata rowMetadata = row.getRowMetadata();
rowMetadata.getById("0001").setType(Type.DOUBLE.getName());
Map<String, String> parameters = //
ActionMetadataTestUtils.parseParameters(this.getClass().getResourceAsStream("fillEmptyStringAction.json"));
parameters.put(AbstractFillWith.DEFAULT_VALUE_PARAMETER, "12.5");
// when
ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
// then
Assert.assertEquals("12.5", row.get("0001"));
Assert.assertEquals("David Bowie", row.get("0000"));
}
use of org.talend.dataprep.api.dataset.RowMetadata in project data-prep by Talend.
the class FillWithStringTest 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", "");
values.put("0002", "Something");
final DataSetRow row = new DataSetRow(values);
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("fillEmptyIntegerAction.json"));
// when
parameters.put(FillIfEmpty.MODE_PARAMETER, FillIfEmpty.OTHER_COLUMN_MODE);
parameters.put(FillIfEmpty.SELECTED_COLUMN_PARAMETER, "0002");
ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
// then
Assert.assertEquals("Something", row.get("0001"));
Assert.assertEquals("David Bowie", row.get("0000"));
}
use of org.talend.dataprep.api.dataset.RowMetadata in project data-prep by Talend.
the class FillWithStringTest method should_fill_empty_float.
@Test
public void should_fill_empty_float() throws Exception {
// given
final Map<String, String> values = new HashMap<>();
values.put("0000", "David Bowie");
values.put("0001", "");
values.put("0002", "100");
final DataSetRow row = new DataSetRow(values);
final RowMetadata rowMetadata = row.getRowMetadata();
rowMetadata.getById("0001").setType(Type.STRING.getName());
Map<String, String> parameters = //
ActionMetadataTestUtils.parseParameters(this.getClass().getResourceAsStream("fillEmptyStringAction.json"));
parameters.put(AbstractFillWith.DEFAULT_VALUE_PARAMETER, "12.5");
// when
ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
// then
Assert.assertEquals("12.5", row.get("0001"));
Assert.assertEquals("David Bowie", row.get("0000"));
}
use of org.talend.dataprep.api.dataset.RowMetadata in project data-prep by Talend.
the class FillWithStringTest method should_not_fill_empty_string.
@Test
public void should_not_fill_empty_string() throws Exception {
// given
final Map<String, String> values = new HashMap<>();
values.put("0000", "David Bowie");
values.put("0001", "not empty");
values.put("0002", "100");
final DataSetRow row = new DataSetRow(values);
final RowMetadata rowMetadata = row.getRowMetadata();
rowMetadata.getById("0001").setType(Type.STRING.getName());
Map<String, String> parameters = //
ActionMetadataTestUtils.parseParameters(this.getClass().getResourceAsStream("fillEmptyStringAction.json"));
// when
ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
// then
Assert.assertEquals("beer", row.get("0001"));
Assert.assertEquals("David Bowie", row.get("0000"));
}
use of org.talend.dataprep.api.dataset.RowMetadata 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"));
}
Aggregations