use of org.talend.dataprep.transformation.api.action.context.ActionContext 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"));
}
use of org.talend.dataprep.transformation.api.action.context.ActionContext in project data-prep by Talend.
the class ClearInvalidTest method should_not_clear_because_valid.
@Test
public void should_not_clear_because_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);
final RowMetadata rowMetadata = row.getRowMetadata();
rowMetadata.getById("0001").setType(Type.STRING.getName());
final Map<String, Object> expectedValues = new HashMap<>();
expectedValues.put("0000", "David Bowie");
expectedValues.put("0001", "N");
expectedValues.put("0002", "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.api.action.context.ActionContext in project data-prep by Talend.
the class ClearInvalidTest method test_apply_inplace.
@Test
public void test_apply_inplace() {
// 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());
final Map<String, Object> expectedValues = new LinkedHashMap<>();
expectedValues.put("__tdpInvalid", "0001");
expectedValues.put("0000", "David Bowie");
expectedValues.put("0001", "");
expectedValues.put("0002", "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.api.action.context.ActionContext in project data-prep by Talend.
the class PipelineTest method testCompileAction.
@Test
public void testCompileAction() throws Exception {
// Given
final RunnableAction mockAction = new RunnableAction() {
@Override
public DataSetRowAction getRowAction() {
return new DataSetRowAction() {
@Override
public void compile(ActionContext actionContext) {
actionContext.get("ExecutedCompile", p -> true);
}
@Override
public DataSetRow apply(DataSetRow dataSetRow, ActionContext context) {
return dataSetRow;
}
};
}
};
final ActionContext actionContext = new ActionContext(new TransformationContext());
final Node node = NodeBuilder.source().to(new CompileNode(mockAction, actionContext)).to(output).build();
final RowMetadata rowMetadata = new RowMetadata();
final DataSetRow row = new DataSetRow(rowMetadata);
// when
assertFalse(actionContext.has("ExecutedCompile"));
node.exec().receive(row, rowMetadata);
// then
assertTrue(actionContext.has("ExecutedCompile"));
assertTrue(actionContext.get("ExecutedCompile"));
}
use of org.talend.dataprep.transformation.api.action.context.ActionContext in project data-prep by Talend.
the class PipelineTest method testAction.
@Test
public void testAction() throws Exception {
// Given
final RunnableAction mockAction = new RunnableAction() {
@Override
public DataSetRowAction getRowAction() {
return (r, context) -> {
context.get("ExecutedApply", p -> true);
return r;
};
}
};
final ActionContext actionContext = new ActionContext(new TransformationContext());
final Node node = NodeBuilder.source().to(new ActionNode(mockAction, actionContext)).to(output).build();
final RowMetadata rowMetadata = new RowMetadata();
final DataSetRow row = new DataSetRow(rowMetadata);
// when
assertFalse(actionContext.has("ExecutedApply"));
node.exec().receive(row, rowMetadata);
// then
assertTrue(actionContext.has("ExecutedApply"));
assertTrue(actionContext.get("ExecutedApply"));
}
Aggregations