Search in sources :

Example 46 with DataSetRow

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

the class ChangeNumberFormatTest method TDP_1361.

/**
 * Format number does not work if there is a null or an invalid in the column.
 * Values after a null or an invalid value (which is not a number) were not formatted by the transformation.
 * Have look at https://jira.talendforge.org/browse/TDP-1361
 */
@Test
public void TDP_1361() throws Exception {
    // given
    final DataSetRow row1 = getRow("toto", "1.5E-11", "tata");
    final DataSetRow row2 = getRow("titi", "azerty", "tata");
    final DataSetRow row3 = getRow("tutu", "010", "tata");
    Collection<DataSetRow> rows = Arrays.asList(row1, row2, row3);
    parameters.put(FROM_SEPARATORS, US_SEPARATORS);
    parameters.put(TARGET_PATTERN, SCIENTIFIC);
    // when
    ActionTestWorkbench.test(rows, actionRegistry, factory.create(action, parameters));
    // then (values should now be compliant with scientific notation)
    final DataSetRow expectedRow1 = getRow("toto", "1.5E-11", "tata");
    final DataSetRow expectedRow2 = getRow("titi", "azerty", "tata");
    final DataSetRow expectedRow3 = getRow("tutu", "1E1", "tata");
    assertEquals(expectedRow1.values(), row1.values());
    assertEquals(expectedRow2.values(), row2.values());
    assertEquals(expectedRow3.values(), row3.values());
}
Also used : DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)

Example 47 with DataSetRow

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

the class ChangeNumberFormatTest method should_process_row_to_CH.

@Test
public void should_process_row_to_CH() throws Exception {
    // given
    final DataSetRow row = getRow("toto", "1.012,50", "tata");
    parameters.put(FROM_SEPARATORS, EU_SEPARATORS);
    parameters.put(TARGET_PATTERN, CH_PATTERN);
    // when
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
    // then
    final DataSetRow expectedRow = getRow("toto", "1'012.5", "tata");
    assertEquals(expectedRow.values(), row.values());
}
Also used : DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)

Example 48 with DataSetRow

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

the class ChangeNumberFormatTest method test_TDP_2354.

@Test
public void test_TDP_2354() throws Exception {
    // given
    final DataSetRow row = getRow("toto", "993,886", "tata");
    parameters.put(FROM_SEPARATORS, US_SEPARATORS);
    parameters.put(TARGET_PATTERN, EU_PATTERN);
    // when
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
    // then
    final DataSetRow expectedRow = getRow("toto", "993 886", "tata");
    assertEquals(expectedRow.values(), row.values());
}
Also used : DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)

Example 49 with DataSetRow

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

the class ChangeNumberFormatTest method should_process_row_alt_pattern_percentage.

@Test
public void should_process_row_alt_pattern_percentage() throws Exception {
    // given
    final DataSetRow row = getRow("toto", "0.12", "tata");
    parameters.put(TARGET_PATTERN, CUSTOM);
    parameters.put(TARGET_PATTERN + "_" + CUSTOM, "#%");
    // when
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
    // then
    final DataSetRow expectedRow = getRow("toto", "12%", "tata");
    assertEquals(expectedRow.values(), row.values());
}
Also used : DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)

Example 50 with DataSetRow

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

the class ChangeNumberFormatTest method should_process_row_alt_pattern_alt_seps_empty.

@Test
public void should_process_row_alt_pattern_alt_seps_empty() throws Exception {
    // given
    final DataSetRow row = getRow("toto", "1012.45", "tata");
    parameters.put(TARGET_PATTERN, CUSTOM);
    parameters.put(TARGET_PATTERN + "_" + CUSTOM, "#,##0.000");
    parameters.put(TARGET + DECIMAL + SEPARATOR, "/");
    parameters.put(TARGET + GROUPING + SEPARATOR, "");
    // when
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
    // then
    final DataSetRow expectedRow = getRow("toto", "1012/450", "tata");
    assertEquals(expectedRow.values(), row.values());
}
Also used : DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)

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