Search in sources :

Example 16 with DataSetRow

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

the class ModifyDateTest method should_process_row_other_column_float_number.

@Test
public void should_process_row_other_column_float_number() throws Exception {
    // given
    final DataSetRow row = // 
    builder().with(// 
    value("toto").type(Type.STRING).name("recipe")).with(// 
    value("04/25/1999").type(Type.DATE).name("recipe").statistics(getDateTestJsonAsStream("statistics_MM_dd_yyyy.json"))).with(// 
    value("5.0").type(Type.STRING).name("last update")).build();
    parameters.put(MODE_PARAMETER, OTHER_COLUMN_MODE);
    parameters.put(SELECTED_COLUMN_PARAMETER, "0002");
    parameters.put(TIME_UNIT_PARAMETER, DAYS.name());
    // when
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
    // then
    final DataSetRow expectedRow = getRow("toto", "04/30/1999", "5.0");
    assertEquals(expectedRow.values(), row.values());
}
Also used : DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test)

Example 17 with DataSetRow

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

the class ModifyDateTest method should_check_new_pattern_parameter_when_dealing_with_row_metadata.

@Test(expected = TalendRuntimeException.class)
public void should_check_new_pattern_parameter_when_dealing_with_row_metadata() {
    // given
    Map<String, String> missingParameters = new HashMap<>();
    missingParameters.put("column_id", "0000");
    missingParameters.put(ModifyDate.NEW_PATTERN, "toto");
    // when
    ActionTestWorkbench.test(new DataSetRow(Collections.emptyMap()), actionRegistry, factory.create(action, missingParameters));
}
Also used : HashMap(java.util.HashMap) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test)

Example 18 with DataSetRow

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

the class TimestampToDateTest method test_apply_inplace.

@Test
public void test_apply_inplace() {
    // given
    final Map<String, String> values = new HashMap<>();
    values.put("0000", "lorem bacon");
    values.put("0001", "0");
    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", "01-01-1970");
    expectedValues.put("0002", "01/01/2015");
    parameters.put(ActionsUtils.CREATE_NEW_COLUMN, "false");
    // 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)

Example 19 with DataSetRow

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

the class TimestampToDateTest method test_TDP_925.

/**
 * Behavior of this case, originally defined TDP-925, has been changed with TDP-1108.
 */
@Test
public void test_TDP_925() {
    // given
    final Map<String, String> values = new HashMap<>();
    values.put("0000", "lorem bacon");
    values.put("0001", "1441815638");
    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", "1441815638");
    expectedValues.put("0002", "01/01/2015");
    parameters.put("new_pattern", "custom");
    parameters.put("custom_date_pattern", "not a valid date pattern");
    // 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)

Example 20 with DataSetRow

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

the class DeleteAllEmptyTest method should_not_delete_with_keep.

@Test
public void should_not_delete_with_keep() {
    // given
    // row 1
    final DataSetRow row1 = getRow("David", "Bowie");
    // row 2
    final DataSetRow row2 = getRow("David", "Bowie");
    // row 3
    final DataSetRow row3 = getRow(" ", "    ");
    // row4
    final DataSetRow row4 = getRow("", "");
    // row 5
    final DataSetRow row5 = getRow("", "\n\t");
    parameters.put(DeleteAllEmpty.ACTION_PARAMETER, DeleteAllEmpty.KEEP);
    // when
    ActionTestWorkbench.test(Arrays.asList(row1, row2, row3, row4, row5), actionRegistry, factory.create(action, parameters));
    // then
    assertThat(row1.isDeleted(), is(false));
    assertThat(row2.isDeleted(), is(false));
    assertThat(row3.isDeleted(), is(false));
    assertThat(row4.isDeleted(), is(true));
    assertThat(row5.isDeleted(), is(false));
}
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