Search in sources :

Example 31 with RowMetadata

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

the class FillWithBooleanIfInvalidTest method should_fill_non_valid_boolean.

@Test
public void should_fill_non_valid_boolean() throws Exception {
    // given
    final Map<String, String> values = new HashMap<>();
    values.put("0000", "David Bowie");
    values.put("0001", "N");
    // invalid boolean
    values.put("0002", "100");
    final DataSetRow row = new DataSetRow(values);
    row.setInvalid("0002");
    final RowMetadata rowMetadata = row.getRowMetadata();
    rowMetadata.getById("0002").setType(Type.BOOLEAN.getName());
    Map<String, String> parameters = ActionMetadataTestUtils.parseParameters(this.getClass().getResourceAsStream("fillInvalidBooleanAction.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("True", 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 32 with RowMetadata

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

the class FillWithStringIfInvalidTest method should_fill_empty_string_other_column.

@Test
public void should_fill_empty_string_other_column() throws Exception {
    // given
    final Map<String, String> values = new HashMap<>();
    values.put("0000", "David Bowie");
    values.put("0001", "DC");
    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());
    rowMetadata.getById("0002").setType(Type.STRING.getName());
    Map<String, String> parameters = // 
    ActionMetadataTestUtils.parseParameters(this.getClass().getResourceAsStream("fillInvalidStringAction.json"));
    // when
    parameters.put(FillIfEmpty.MODE_PARAMETER, FillIfEmpty.OTHER_COLUMN_MODE);
    parameters.put(FillIfEmpty.SELECTED_COLUMN_PARAMETER, "0002");
    final RunnableAction runnableAction = factory.create(action, parameters);
    final ActionContext context = new ActionContext(new TransformationContext(), rowMetadata);
    context.setParameters(parameters);
    runnableAction.getRowAction().apply(row, context);
    // then
    Assert.assertEquals("Something", row.get("0001"));
    Assert.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 33 with RowMetadata

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

the class FillWithStringIfInvalidTest method should_fill_non_valid_string.

@Test
public void should_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", "100");
    final DataSetRow row = new DataSetRow(values);
    row.setInvalid("0002");
    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("beer", 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 34 with RowMetadata

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

the class FillWithDateIfEmptyTest method should_fill_empty_string_other_column_not_date.

@Test
public void should_fill_empty_string_other_column_not_date() throws Exception {
    // given
    final Map<String, String> values = new HashMap<>();
    values.put("0000", "David Bowie");
    values.put("0001", "");
    values.put("0002", "tagada");
    final DataSetRow row = new DataSetRow(values);
    final RowMetadata rowMetadata = row.getRowMetadata();
    rowMetadata.getById("0001").setType(Type.DATE.getName());
    rowMetadata.getById("0002").setType(Type.DATE.getName());
    setStatistics(row, "0001", ChangeDatePatternTest.class.getResourceAsStream("statistics_yyyy-MM-dd.json"));
    Map<String, String> parameters = // 
    ActionMetadataTestUtils.parseParameters(this.getClass().getResourceAsStream("fillEmptyIntegerAction.json"));
    // when
    parameters.put(FillIfEmpty.MODE_PARAMETER, FillIfEmpty.OTHER_COLUMN_MODE);
    parameters.put(FillIfEmpty.SELECTED_COLUMN_PARAMETER, "0002");
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
    // then
    assertEquals("tagada", row.get("0002"));
    assertEquals("tagada", row.get("0001"));
    assertEquals("David Bowie", row.get("0000"));
}
Also used : HashMap(java.util.HashMap) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) ChangeDatePatternTest(org.talend.dataprep.transformation.actions.date.ChangeDatePatternTest) Test(org.junit.Test) ChangeDatePatternTest(org.talend.dataprep.transformation.actions.date.ChangeDatePatternTest) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)

Example 35 with RowMetadata

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

the class FillWithDateIfEmptyTest method should_not_fill_empty_date.

@Test
public void should_not_fill_empty_date() throws Exception {
    // given
    final Map<String, String> values = new HashMap<>();
    values.put("0000", "David Bowie");
    values.put("0001", "not empty");
    values.put("0002", "100");
    final DataSetRow row = new DataSetRow(values);
    final RowMetadata rowMetadata = row.getRowMetadata();
    rowMetadata.getById("0001").setType(Type.DATE.getName());
    Map<String, String> parameters = // 
    ActionMetadataTestUtils.parseParameters(this.getClass().getResourceAsStream("fillEmptyDateAction.json"));
    // when
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
    // then
    assertEquals("not empty", row.get("0001"));
    assertEquals("David Bowie", row.get("0000"));
}
Also used : HashMap(java.util.HashMap) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test) ChangeDatePatternTest(org.talend.dataprep.transformation.actions.date.ChangeDatePatternTest) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)

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