Search in sources :

Example 96 with RowMetadata

use of org.talend.dataprep.api.dataset.RowMetadata in project data-prep by Talend.

the class FillWithDateIfInvalidTest method should_fill_non_valid_datetime.

@Test
public void should_fill_non_valid_datetime() throws Exception {
    // given
    final Map<String, String> values = new HashMap<>();
    values.put("0000", "David Bowie");
    values.put("0001", "N");
    values.put("0002", "Something");
    final Statistics statistics = getStatistics(this.getClass().getResourceAsStream("fillInvalidDateTimeAction_statistics.json"));
    final DataSetRow row = new DataSetRow(values);
    row.setInvalid("0001");
    final RowMetadata rowMetadata = row.getRowMetadata();
    rowMetadata.getById("0001").setType(Type.DATE.getName());
    rowMetadata.getById("0001").setStatistics(statistics);
    Map<String, String> parameters = ActionMetadataTestUtils.parseParameters(this.getClass().getResourceAsStream("fillInvalidDateTimeAction.json"));
    // when
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
    // then
    assertEquals("09/07/2015 13:31:36", row.get("0001"));
}
Also used : HashMap(java.util.HashMap) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) Statistics(org.talend.dataprep.api.dataset.statistics.Statistics) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) ChangeDatePatternTest(org.talend.dataprep.transformation.actions.date.ChangeDatePatternTest) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest) Test(org.junit.Test)

Example 97 with RowMetadata

use of org.talend.dataprep.api.dataset.RowMetadata 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 98 with RowMetadata

use of org.talend.dataprep.api.dataset.RowMetadata 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 99 with RowMetadata

use of org.talend.dataprep.api.dataset.RowMetadata 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)

Example 100 with RowMetadata

use of org.talend.dataprep.api.dataset.RowMetadata in project data-prep by Talend.

the class DeleteColumnTest method init.

@Before
public void init() {
    List<ColumnMetadata> columns = new ArrayList<>();
    ColumnMetadata columnMetadata = // 
    ColumnMetadata.Builder.column().type(// 
    Type.INTEGER).computedId(// 
    "0001").domain(// 
    "ID").domainFrequency(// 
    1).domainLabel(// 
    "Identifier").build();
    columns.add(columnMetadata);
    columnMetadata = // 
    ColumnMetadata.Builder.column().type(// 
    Type.STRING).computedId(// 
    "0002").domain(// 
    "ANL").domainFrequency(// 
    1).domainLabel(// 
    "Animal").build();
    columns.add(columnMetadata);
    rowMetadata = new RowMetadata();
    rowMetadata.setColumns(columns);
    parameters = new HashMap<>();
    parameters.put(ImplicitParameters.SCOPE.getKey().toLowerCase(), "column");
}
Also used : ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) Before(org.junit.Before)

Aggregations

RowMetadata (org.talend.dataprep.api.dataset.RowMetadata)199 Test (org.junit.Test)130 DataSetRow (org.talend.dataprep.api.dataset.row.DataSetRow)112 ColumnMetadata (org.talend.dataprep.api.dataset.ColumnMetadata)87 AbstractMetadataBaseTest (org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)68 HashMap (java.util.HashMap)48 ActionContext (org.talend.dataprep.transformation.api.action.context.ActionContext)21 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)20 RunnableAction (org.talend.dataprep.transformation.actions.common.RunnableAction)19 TransformationContext (org.talend.dataprep.transformation.api.action.context.TransformationContext)18 ArrayList (java.util.ArrayList)16 DataSet (org.talend.dataprep.api.dataset.DataSet)11 List (java.util.List)9 Statistics (org.talend.dataprep.api.dataset.statistics.Statistics)9 Before (org.junit.Before)7 SemanticDomain (org.talend.dataprep.api.dataset.statistics.SemanticDomain)6 Preparation (org.talend.dataprep.api.preparation.Preparation)6 Response (com.jayway.restassured.response.Response)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 Logger (org.slf4j.Logger)5