use of org.talend.dataprep.transformation.actions.common.RunnableAction in project data-prep by Talend.
the class ActionParserTest method should_return_expected_actions.
@Test
public void should_return_expected_actions() throws IOException {
String json = IOUtils.toString(ActionParserTest.class.getResourceAsStream("actions.json"), UTF_8);
// when
List<RunnableAction> actualActions = actionParser.parse(json);
// then
assertTrue(actualActions.size() == 1);
Action actionParsed = actualActions.get(0);
assertEquals("lookup", actionParsed.getName());
}
use of org.talend.dataprep.transformation.actions.common.RunnableAction in project data-prep by Talend.
the class ActionTestWorkbench method test.
public static void test(Collection<DataSetRow> input, AnalyzerService analyzerService, ActionRegistry actionRegistry, RunnableAction... actions) {
final List<RunnableAction> allActions = new ArrayList<>();
Collections.addAll(allActions, actions);
final DataSet dataSet = new DataSet();
final RowMetadata rowMetadata = input.iterator().next().getRowMetadata();
final DataSetMetadata dataSetMetadata = new DataSetMetadata();
dataSetMetadata.setRowMetadata(rowMetadata);
dataSet.setMetadata(dataSetMetadata);
dataSet.setRecords(input.stream());
final TestOutputNode outputNode = new TestOutputNode(input);
Pipeline pipeline = //
Pipeline.Builder.builder().withActionRegistry(actionRegistry).withInitialMetadata(rowMetadata, //
true).withActions(//
allActions).withAnalyzerService(analyzerService).withStatisticsAdapter(//
new StatisticsAdapter(40)).withOutput(//
() -> outputNode).build();
pipeline.execute(dataSet);
// Some tests rely on the metadata changes in the provided metadata so set back modified columns in row metadata
// (although this should be avoided in tests).
// TODO Make this method return the modified metadata iso. setting modified columns.
rowMetadata.setColumns(outputNode.getMetadata().getColumns());
for (DataSetRow dataSetRow : input) {
dataSetRow.setRowMetadata(rowMetadata);
}
}
use of org.talend.dataprep.transformation.actions.common.RunnableAction 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.actions.common.RunnableAction 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.actions.common.RunnableAction 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"));
}
Aggregations