use of org.talend.dataprep.transformation.api.action.context.ActionContext 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.api.action.context.ActionContext 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"));
}
use of org.talend.dataprep.transformation.api.action.context.ActionContext in project data-prep by Talend.
the class PipelineTest method testCompileNode.
@Test
public void testCompileNode() throws Exception {
final ActionContext actionContext = new ActionContext(new TransformationContext());
final RunnableAction mockAction = new RunnableAction();
CompileNode compileNode = new CompileNode(mockAction, actionContext);
assertEquals(actionContext, compileNode.getActionContext());
assertEquals(mockAction, compileNode.getAction());
}
use of org.talend.dataprep.transformation.api.action.context.ActionContext in project data-prep by Talend.
the class PipelineTest method testRecompileAction.
@Test
public void testRecompileAction() throws Exception {
// Given
AtomicInteger compileCount = new AtomicInteger();
final RunnableAction mockAction = new RunnableAction() {
@Override
public DataSetRowAction getRowAction() {
return new DataSetRowAction() {
@Override
public void compile(ActionContext actionContext) {
compileCount.incrementAndGet();
actionContext.setActionStatus(ActionContext.ActionStatus.OK);
}
@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
assertEquals(0, compileCount.get());
node.exec().receive(row, rowMetadata);
// Change row metadata in middle of the transformation (to trigger
rowMetadata.addColumn(new ColumnMetadata());
// new compile).
node.exec().receive(row, rowMetadata);
// then
assertEquals(2, compileCount.get());
}
use of org.talend.dataprep.transformation.api.action.context.ActionContext in project data-prep by Talend.
the class PipelineTest method testCanceledAction.
@Test
public void testCanceledAction() throws Exception {
// Given
final RunnableAction mockAction = new RunnableAction() {
@Override
public DataSetRowAction getRowAction() {
return (r, context) -> {
context.get("Executed", p -> true);
return r;
};
}
};
final ActionContext actionContext = new ActionContext(new TransformationContext());
actionContext.setActionStatus(ActionContext.ActionStatus.CANCELED);
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
node.exec().receive(row, rowMetadata);
// then
assertFalse(actionContext.has("Executed"));
}
Aggregations