Search in sources :

Example 11 with ActionContext

use of org.talend.dataprep.transformation.api.action.context.ActionContext in project data-prep by Talend.

the class PipelineTest method testCleanUp.

@Test
public void testCleanUp() throws Exception {
    // Given
    final TransformationContext transformationContext = new TransformationContext();
    final ActionContext actionContext = transformationContext.create((r, ac) -> r, new RowMetadata());
    final AtomicInteger wasDestroyed = new AtomicInteger(0);
    Destroyable destroyable = new Destroyable() {

        @Override
        public void destroy() {
            wasDestroyed.incrementAndGet();
        }
    };
    actionContext.get("test1", p -> destroyable);
    actionContext.get("test2", p -> destroyable);
    final Node node = // 
    NodeBuilder.source().to(// 
    new BasicNode()).to(// 
    new CleanUpNode(transformationContext)).to(// 
    output).build();
    // when
    node.exec().signal(END_OF_STREAM);
    // then
    assertEquals(2, wasDestroyed.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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) Test(org.junit.Test)

Example 12 with ActionContext

use of org.talend.dataprep.transformation.api.action.context.ActionContext in project data-prep by Talend.

the class UpdatedStepVisitorTest method setUp.

@Before
public void setUp() throws Exception {
    actionContext = new ActionContext(new TransformationContext());
    entryNode = new ActionNode(new RunnableAction((row, context) -> row), actionContext);
}
Also used : RunnableAction(org.talend.dataprep.transformation.actions.common.RunnableAction) ActionNode(org.talend.dataprep.transformation.pipeline.node.ActionNode) ActionContext(org.talend.dataprep.transformation.api.action.context.ActionContext) TransformationContext(org.talend.dataprep.transformation.api.action.context.TransformationContext) Before(org.junit.Before)

Example 13 with ActionContext

use of org.talend.dataprep.transformation.api.action.context.ActionContext in project data-prep by Talend.

the class FillWithNumericIfInvalidTest method should_not_fill_non_valid_integer.

@Test
public void should_not_fill_non_valid_integer() throws Exception {
    // given
    final Map<String, String> values = new HashMap<>();
    values.put("0000", "David Bowie");
    values.put("0001", "30");
    values.put("0002", "Something");
    final DataSetRow row = new DataSetRow(values);
    final RowMetadata rowMetadata = row.getRowMetadata();
    rowMetadata.getById("0001").setType(Type.INTEGER.getName());
    Map<String, String> parameters = ActionMetadataTestUtils.parseParameters(this.getClass().getResourceAsStream("fillInvalidIntegerAction.json"));
    // 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("30", row.get("0001"));
    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 14 with ActionContext

use of org.talend.dataprep.transformation.api.action.context.ActionContext in project data-prep by Talend.

the class FillWithNumericIfInvalidTest method should_fill_non_valid_integer.

@Test
public void should_fill_non_valid_integer() throws Exception {
    // 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.INTEGER.getName());
    Map<String, String> parameters = ActionMetadataTestUtils.parseParameters(this.getClass().getResourceAsStream("fillInvalidIntegerAction.json"));
    // 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("25", row.get("0001"));
    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 15 with ActionContext

use of org.talend.dataprep.transformation.api.action.context.ActionContext in project data-prep by Talend.

the class FillWithStringIfInvalidTest method should_not_fill_non_valid_string.

@Test
public void should_not_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", "wine");
    final DataSetRow row = new DataSetRow(values);
    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("wine", row.get("0002"));
    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)

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