Search in sources :

Example 96 with DataSetRow

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

the class SplitTest method should_split_row_with_separator_at_the_end.

@Test
public void should_split_row_with_separator_at_the_end() {
    // given
    final DataSetRow row = getRow("lorem bacon", "Bacon ", "01/01/2015");
    final Map<String, String> expectedValues = new HashMap<>();
    expectedValues.put("0000", "lorem bacon");
    expectedValues.put("0001", "Bacon ");
    expectedValues.put("0003", "Bacon");
    expectedValues.put("0004", "");
    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 97 with DataSetRow

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

the class SubstringTest method should_substring_to_the_beginning_when_end_index_is_negative.

@Test
public void should_substring_to_the_beginning_when_end_index_is_negative() {
    // given
    parameters.put(TO_INDEX_PARAMETER, "-1");
    final Map<String, String> values = new HashMap<>();
    values.put("0000", "lorem bacon");
    values.put("0001", "Bac");
    values.put("0002", "01/01/2015");
    final DataSetRow row = new DataSetRow(values);
    final Map<String, String> expectedValues = new HashMap<>();
    expectedValues.put("0000", "lorem bacon");
    expectedValues.put("0001", "Bac");
    expectedValues.put("0003", "");
    expectedValues.put("0002", "01/01/2015");
    // when
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
    // then
    assertEquals(expectedValues, row.values());
}
Also used : DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)

Example 98 with DataSetRow

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

the class SubstringTest method should_substring_n_before_end_3.

@Test
public void should_substring_n_before_end_3() throws IOException {
    // given
    parameters.put(FROM_MODE_PARAMETER, Substring.FROM_INDEX_PARAMETER);
    parameters.put(FROM_INDEX_PARAMETER, "6");
    parameters.put(TO_MODE_PARAMETER, Substring.TO_N_BEFORE_END_PARAMETER);
    parameters.put(TO_N_BEFORE_END_PARAMETER, "1");
    final Map<String, String> values = new HashMap<>();
    values.put("0000", "lorem bacon");
    values.put("0001", "Bacon ipsum");
    values.put("0002", "01/01/2015");
    final DataSetRow row = new DataSetRow(values);
    final Map<String, String> expectedValues = new HashMap<>();
    expectedValues.put("0000", "lorem bacon");
    expectedValues.put("0001", "Bacon ipsum");
    expectedValues.put("0003", "ipsu");
    expectedValues.put("0002", "01/01/2015");
    // when
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
    // then
    assertEquals(expectedValues, row.values());
}
Also used : DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)

Example 99 with DataSetRow

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

the class SubstringTest method should_substring_to_the_end_when_end_index_is_too_big_and_out_of_bound.

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

Example 100 with DataSetRow

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

the class SubstringTest method should_substring_to_the_beginning_when_n_before_end_is_too_big.

@Test
public void should_substring_to_the_beginning_when_n_before_end_is_too_big() throws IOException {
    // given
    parameters.put(FROM_INDEX_PARAMETER, "1");
    parameters.put(TO_MODE_PARAMETER, Substring.TO_N_BEFORE_END_PARAMETER);
    parameters.put(TO_N_BEFORE_END_PARAMETER, "15");
    final Map<String, String> values = new HashMap<>();
    values.put("0000", "lorem bacon");
    values.put("0001", "Bacon");
    values.put("0002", "01/01/2015");
    final DataSetRow row = new DataSetRow(values);
    final Map<String, String> expectedValues = new HashMap<>();
    expectedValues.put("0000", "lorem bacon");
    expectedValues.put("0001", "Bacon");
    expectedValues.put("0003", "");
    expectedValues.put("0002", "01/01/2015");
    // when
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
    // then
    assertEquals(expectedValues, 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