use of org.talend.dataprep.transformation.api.action.context.ActionContext in project data-prep by Talend.
the class DateCalendarConverterTest method testCompileShouldComputeToAndFromInternalContextParameters.
@Test
public void testCompileShouldComputeToAndFromInternalContextParameters() {
// Given
final DateCalendarConverter calendarConverter = new DateCalendarConverter();
final DataSetRow row = builder().with(value("toto").type(Type.STRING).name("recipe")).with(value("10/29/1996").type(Type.DATE).name("last update").statistics(getDateTestJsonAsStream("statistics_MM_dd_yyyy.json"))).with(//
value("tata").type(Type.STRING).name("who")).build();
final ActionContext context = new ActionContext(new TransformationContext(), row.getRowMetadata());
context.setActionStatus(ActionContext.ActionStatus.OK);
final Map<String, String> parameters = new HashMap<>();
parameters.put(ImplicitParameters.SCOPE.getKey().toLowerCase(), "column");
parameters.put(COLUMN_ID.getKey(), "0001");
parameters.put(FROM_CALENDAR_TYPE_PARAMETER, DateCalendarConverter.CalendarUnit.ISO.name());
parameters.put(TO_CALENDAR_TYPE_PARAMETER, CalendarUnit.JULIAN_DAY.name());
context.setParameters(parameters);
// When
calendarConverter.compile(context);
// Then
assertTrue(context.get(IS_FROM_CHRONOLOGY_INTERNAL_KEY));
assertFalse(context.get(IS_TO_CHRONOLOGY_INTERNAL_KEY));
}
use of org.talend.dataprep.transformation.api.action.context.ActionContext in project data-prep by Talend.
the class ReplaceOnValueTest method buildPatternActionContext.
private ActionContext buildPatternActionContext(String regex, String replacement, boolean replace) {
ActionContext context = new ActionContext(new TransformationContext());
Map<String, String> parameters = new HashMap<>();
parameters.put(ReplaceOnValue.CELL_VALUE_PARAMETER, regex);
parameters.put(ReplaceOnValue.REPLACE_VALUE_PARAMETER, replacement);
parameters.put(ReplaceOnValue.REPLACE_ENTIRE_CELL_PARAMETER, String.valueOf(replace));
context.setParameters(parameters);
action.compile(context);
return context;
}
use of org.talend.dataprep.transformation.api.action.context.ActionContext 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.api.action.context.ActionContext 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.api.action.context.ActionContext 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"));
}
Aggregations