Search in sources :

Example 51 with DataSetRow

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

the class ChangeNumberFormatTest method test_TDP_1108_invalid_pattern.

@Test
public void test_TDP_1108_invalid_pattern() throws Exception {
    // given
    final DataSetRow row = getRow("toto", "012.50", "tata");
    parameters.put(TARGET_PATTERN, "custom");
    parameters.put(TARGET_PATTERN + "_" + CUSTOM, "# ##0,#");
    // when
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
    // then
    final DataSetRow expectedRow = getRow("toto", "012.50", "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 52 with DataSetRow

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

the class ChangeNumberFormatTest method should_process_row_SCIENTIFIC.

@Test
public void should_process_row_SCIENTIFIC() throws Exception {
    // given
    final DataSetRow row = getRow("toto", "1.23E+3", "tata");
    // when
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
    // then
    final DataSetRow expectedRow = getRow("toto", "1,230", "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 53 with DataSetRow

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

the class ChangeNumberFormatTest method should_do_nothing_from_wrong_pattern.

@Test
public void should_do_nothing_from_wrong_pattern() throws Exception {
    // given
    final DataSetRow row = getRow("toto", "1'012.50", "tata");
    parameters.put(TARGET_PATTERN, "wrong_pattern");
    // when --> IllegalArgumentException
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
    // then
    final DataSetRow expectedRow = getRow("toto", "1'012.50", "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 54 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_custom.

@Test
public void should_process_row_alt_pattern_alt_seps_empty_custom() 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, CUSTOM);
    parameters.put(TARGET + GROUPING + SEPARATOR + "_" + CUSTOM, "");
    // 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)

Example 55 with DataSetRow

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

the class ChangeNumberFormatTest method test_apply_in_newcolumn_with_empty_value.

@Test
public void test_apply_in_newcolumn_with_empty_value() throws Exception {
    // given
    final DataSetRow row = getRow("toto", "", "tata");
    parameters.put(ActionsUtils.CREATE_NEW_COLUMN, "true");
    // when
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
    // then
    final DataSetRow expectedRow = getRow("toto", "", "tata", "");
    assertEquals(expectedRow.values(), row.values());
    ColumnMetadata expected = ColumnMetadata.Builder.column().id(3).name("0001_formatted").type(Type.STRING).build();
    ColumnMetadata actual = row.getRowMetadata().getById("0003");
    assertEquals(expected, actual);
}
Also used : ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) 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