Search in sources :

Example 16 with ActionContext

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());
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) RunnableAction(org.talend.dataprep.transformation.actions.common.RunnableAction) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) ActionContext(org.talend.dataprep.transformation.api.action.context.ActionContext) TransformationContext(org.talend.dataprep.transformation.api.action.context.TransformationContext) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)

Example 17 with ActionContext

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"));
}
Also used : HashMap(java.util.HashMap) RunnableAction(org.talend.dataprep.transformation.actions.common.RunnableAction) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) ActionContext(org.talend.dataprep.transformation.api.action.context.ActionContext) TransformationContext(org.talend.dataprep.transformation.api.action.context.TransformationContext) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)

Example 18 with ActionContext

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());
}
Also used : RunnableAction(org.talend.dataprep.transformation.actions.common.RunnableAction) ActionContext(org.talend.dataprep.transformation.api.action.context.ActionContext) TransformationContext(org.talend.dataprep.transformation.api.action.context.TransformationContext) Test(org.junit.Test)

Example 19 with ActionContext

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());
}
Also used : DataSetRowAction(org.talend.dataprep.transformation.api.action.DataSetRowAction) ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RunnableAction(org.talend.dataprep.transformation.actions.common.RunnableAction) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) ActionContext(org.talend.dataprep.transformation.api.action.context.ActionContext) TransformationContext(org.talend.dataprep.transformation.api.action.context.TransformationContext) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test)

Example 20 with ActionContext

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"));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) CoreMatchers(org.hamcrest.CoreMatchers) BasicLink(org.talend.dataprep.transformation.pipeline.link.BasicLink) HashMap(java.util.HashMap) Test(org.junit.Test) TransformationContext(org.talend.dataprep.transformation.api.action.context.TransformationContext) ActionContext(org.talend.dataprep.transformation.api.action.context.ActionContext) ArrayList(java.util.ArrayList) List(java.util.List) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) org.talend.dataprep.transformation.pipeline.node(org.talend.dataprep.transformation.pipeline.node) END_OF_STREAM(org.talend.dataprep.transformation.pipeline.Signal.END_OF_STREAM) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) CloneLink(org.talend.dataprep.transformation.pipeline.link.CloneLink) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) DataSetRowAction(org.talend.dataprep.transformation.api.action.DataSetRowAction) Assert(org.junit.Assert) DataSet(org.talend.dataprep.api.dataset.DataSet) NodeBuilder(org.talend.dataprep.transformation.pipeline.builder.NodeBuilder) Before(org.junit.Before) ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) RunnableAction(org.talend.dataprep.transformation.actions.common.RunnableAction) RunnableAction(org.talend.dataprep.transformation.actions.common.RunnableAction) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) ActionContext(org.talend.dataprep.transformation.api.action.context.ActionContext) TransformationContext(org.talend.dataprep.transformation.api.action.context.TransformationContext) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test)

Aggregations

ActionContext (org.talend.dataprep.transformation.api.action.context.ActionContext)29 TransformationContext (org.talend.dataprep.transformation.api.action.context.TransformationContext)26 Test (org.junit.Test)23 RunnableAction (org.talend.dataprep.transformation.actions.common.RunnableAction)21 RowMetadata (org.talend.dataprep.api.dataset.RowMetadata)18 DataSetRow (org.talend.dataprep.api.dataset.row.DataSetRow)16 HashMap (java.util.HashMap)14 AbstractMetadataBaseTest (org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)14 DataSetRowAction (org.talend.dataprep.transformation.api.action.DataSetRowAction)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 ColumnMetadata (org.talend.dataprep.api.dataset.ColumnMetadata)4 LinkedHashMap (java.util.LinkedHashMap)3 Before (org.junit.Before)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 CoreMatchers (org.hamcrest.CoreMatchers)2 CoreMatchers.is (org.hamcrest.CoreMatchers.is)2 Assert (org.junit.Assert)2 DataSet (org.talend.dataprep.api.dataset.DataSet)2 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)2