Search in sources :

Example 86 with DataSetRow

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

the class ReplaceOnValueTest method test_apply_in_newcolumn.

@Test
public void test_apply_in_newcolumn() {
    // given
    final String columnId = "0000";
    final Map<String, String> values = new HashMap<>();
    values.put(columnId, "James Hetfield");
    final DataSetRow row = new DataSetRow(values);
    final Map<String, String> parameters = new HashMap<>();
    parameters.put(CELL_VALUE_PARAMETER, generateJson("James", ReplaceOnValueHelper.STARTS_WITH_MODE));
    parameters.put(REPLACE_VALUE_PARAMETER, "Jimmy");
    parameters.put(REPLACE_ENTIRE_CELL_PARAMETER, "true");
    parameters.put(ImplicitParameters.SCOPE.getKey().toLowerCase(), "column");
    parameters.put(ImplicitParameters.COLUMN_ID.getKey().toLowerCase(), columnId);
    parameters.put(ActionsUtils.CREATE_NEW_COLUMN, "true");
    // when
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
    // then
    assertThat(row.get(columnId), is("James Hetfield"));
    assertThat(row.get("0001"), is("Jimmy"));
    ColumnMetadata expected = ColumnMetadata.Builder.column().id(1).name("0000_replace").type(Type.STRING).build();
    ColumnMetadata actual = row.getRowMetadata().getById("0001");
    assertEquals(expected, actual);
}
Also used : ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) HashMap(java.util.HashMap) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest) Test(org.junit.Test)

Example 87 with DataSetRow

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

the class SplitTest method test_apply_in_newcolumn.

@Test
public void test_apply_in_newcolumn() {
    // given
    final DataSetRow row = getRow("lorem bacon", "Bacon ipsum dolor amet swine leberkas pork belly", "01/01/2015");
    final Map<String, String> expectedValues = new HashMap<>();
    expectedValues.put("0000", "lorem bacon");
    expectedValues.put("0001", "Bacon ipsum dolor amet swine leberkas pork belly");
    expectedValues.put("0003", "Bacon");
    expectedValues.put("0004", "ipsum dolor amet swine leberkas pork belly");
    expectedValues.put("0002", "01/01/2015");
    // when
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
    // then
    assertEquals(expectedValues, row.values());
}
Also used : HashMap(java.util.HashMap) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest) Test(org.junit.Test)

Example 88 with DataSetRow

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

the class SplitTest method test_TDP_786_empty_pattern.

@Test
public void test_TDP_786_empty_pattern() {
    // given
    final Map<String, String> values = new HashMap<>();
    values.put("0000", "lorem bacon");
    values.put("0001", "Je vais bien (tout va bien)");
    values.put("0002", "01/01/2015");
    final DataSetRow row = new DataSetRow(values);
    parameters.put(Split.SEPARATOR_PARAMETER, Split.OTHER_STRING);
    parameters.put(Split.MANUAL_SEPARATOR_PARAMETER_STRING, "");
    // when
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
    // then
    assertEquals(values, row.values());
}
Also used : HashMap(java.util.HashMap) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest) Test(org.junit.Test)

Example 89 with DataSetRow

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

the class SplitTest method should_split_row_twice.

@Test
public void should_split_row_twice() {
    // given
    final DataSetRow row = getRow("lorem bacon", "Bacon ipsum dolor amet swine leberkas pork belly", "01/01/2015");
    final Map<String, String> expectedValues = new HashMap<>();
    expectedValues.put("0000", "lorem bacon");
    expectedValues.put("0001", "Bacon ipsum dolor amet swine leberkas pork belly");
    expectedValues.put("0005", "Bacon");
    expectedValues.put("0006", "ipsum dolor amet swine leberkas pork belly");
    expectedValues.put("0003", "Bacon");
    expectedValues.put("0004", "ipsum dolor amet swine leberkas pork belly");
    expectedValues.put("0002", "01/01/2015");
    // when
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters), factory.create(action, parameters));
    // then
    assertEquals(expectedValues, row.values());
}
Also used : HashMap(java.util.HashMap) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest) Test(org.junit.Test)

Example 90 with DataSetRow

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

the class SplitTest method should_not_split_because_null_separator.

@Test
public void should_not_split_because_null_separator() throws IOException {
    // given
    final Map<String, String> values = new HashMap<>();
    values.put("0000", "lorem bacon");
    values.put("0001", "Bacon ipsum dolor amet swine leberkas pork belly");
    values.put("0002", "01/01/2015");
    final DataSetRow row = new DataSetRow(values);
    parameters.put(Split.SEPARATOR_PARAMETER, "");
    // when
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
    // then
    assertEquals(values, row.values());
}
Also used : HashMap(java.util.HashMap) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest) Test(org.junit.Test)

Aggregations

DataSetRow (org.talend.dataprep.api.dataset.row.DataSetRow)729 Test (org.junit.Test)688 AbstractMetadataBaseTest (org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)518 HashMap (java.util.HashMap)235 RowMetadata (org.talend.dataprep.api.dataset.RowMetadata)111 ColumnMetadata (org.talend.dataprep.api.dataset.ColumnMetadata)81 LinkedHashMap (java.util.LinkedHashMap)45 RunnableAction (org.talend.dataprep.transformation.actions.common.RunnableAction)21 ActionContext (org.talend.dataprep.transformation.api.action.context.ActionContext)16 TransformationContext (org.talend.dataprep.transformation.api.action.context.TransformationContext)16 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)14 ArrayList (java.util.ArrayList)13 ChangeDatePatternTest (org.talend.dataprep.transformation.actions.date.ChangeDatePatternTest)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)12 AbstractTransformerWriterTest (org.talend.dataprep.transformation.api.transformer.AbstractTransformerWriterTest)12 List (java.util.List)11 PatternFrequency (org.talend.dataprep.api.dataset.statistics.PatternFrequency)11 DataSet (org.talend.dataprep.api.dataset.DataSet)10 Stream (java.util.stream.Stream)6 TDPException (org.talend.dataprep.exception.TDPException)6