Search in sources :

Example 11 with DataSetRow

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

the class ExtractDateTokensTest method test_TDP_1676.

@Test
public void test_TDP_1676() throws Exception {
    // given
    final DataSetRow row = // 
    builder().with(// 
    value("toto").type(Type.STRING)).with(value("Dec-17-2017").type(Type.DATE).statistics(// 
    getDateTestJsonAsStream("statistics_MM_dd_yyyy.json"))).with(// 
    value("tata").type(Type.STRING)).build();
    parameters.put(ExtractDateTokens.DAY_LABEL, "true");
    parameters.put(ExtractDateTokens.MONTH_LABEL, "true");
    final Map<String, String> expectedValues = new HashMap<>();
    expectedValues.put("0000", "toto");
    expectedValues.put("0001", "Dec-17-2017");
    expectedValues.put("0008", "2017");
    expectedValues.put("0007", "12");
    expectedValues.put("0006", "December");
    expectedValues.put("0005", "Sunday");
    expectedValues.put("0004", "0");
    expectedValues.put("0003", "0");
    expectedValues.put("0002", "tata");
    // 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 12 with DataSetRow

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

the class ExtractDateTokensTest method test_TDP_4494.

@Test
public void test_TDP_4494() throws Exception {
    // given
    final DataSetRow row = // 
    builder().with(// 
    value("toto").type(Type.STRING)).with(value("Dec-17-2017").type(Type.DATE).statistics(// 
    getDateTestJsonAsStream("statistics_MM_dd_yyyy.json"))).with(// 
    value("tata").type(Type.STRING)).build();
    parameters.put(ExtractDateTokens.QUARTER, "true");
    final Map<String, String> expectedValues = new HashMap<>();
    expectedValues.put("0000", "toto");
    expectedValues.put("0001", "Dec-17-2017");
    expectedValues.put("0007", "2017");
    expectedValues.put("0006", "4");
    expectedValues.put("0005", "12");
    expectedValues.put("0004", "0");
    expectedValues.put("0003", "0");
    expectedValues.put("0002", "tata");
    // 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 13 with DataSetRow

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

the class ExtractDateTokensTest method test_TDP_2480.

@Test
public void test_TDP_2480() throws Exception {
    // given
    final DataSetRow row = // 
    builder().with(// 
    value("toto").type(Type.STRING)).with(value("Apr-25-1999").type(Type.DATE).statistics(// 
    getDateTestJsonAsStream("statistics_MM_dd_yyyy.json"))).with(// 
    value("tata").type(Type.STRING)).build();
    final Map<String, String> expectedValues = new HashMap<>();
    expectedValues.put("0000", "toto");
    expectedValues.put("0001", "Apr-25-1999");
    expectedValues.put("0006", "1999");
    expectedValues.put("0005", "4");
    expectedValues.put("0004", "0");
    expectedValues.put("0003", "0");
    expectedValues.put("0002", "tata");
    // 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 14 with DataSetRow

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

the class ModifyDateTest method test_apply_in_newcolumn.

@Test
public void test_apply_in_newcolumn() throws Exception {
    // given
    final DataSetRow row1 = // 
    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("tata").type(Type.STRING).name("last update")).build();
    final DataSetRow row2 = // 
    builder().with(// 
    value("tata mouche").type(Type.STRING).name("recipe")).with(// 
    value("  ").type(Type.DATE).name("recipe").statistics(getDateTestJsonAsStream("statistics_MM_dd_yyyy.json"))).with(// 
    value("toto pouche").type(Type.STRING).name("last update")).build();
    final DataSetRow row3 = // 
    builder().with(// 
    value("titi louche").type(Type.STRING).name("recipe")).with(// 
    value("culbutoqué").type(Type.DATE).name("recipe").statistics(getDateTestJsonAsStream("statistics_MM_dd_yyyy.json"))).with(// 
    value("tutu couche").type(Type.STRING).name("last update")).build();
    parameters.put(ActionsUtils.CREATE_NEW_COLUMN, "true");
    // when
    ActionTestWorkbench.test(row1, actionRegistry, factory.create(action, parameters));
    ActionTestWorkbench.test(row2, actionRegistry, factory.create(action, parameters));
    ActionTestWorkbench.test(row3, actionRegistry, factory.create(action, parameters));
    // then
    final DataSetRow expectedRow1 = getRow("toto", "04/25/1999", "tata", "04/25/2000");
    assertEquals(expectedRow1.values(), row1.values());
    ColumnMetadata expected1 = ColumnMetadata.Builder.column().id(3).name("recipe_modified").type(Type.STRING).build();
    ColumnMetadata actual1 = row1.getRowMetadata().getById("0003");
    assertEquals(expected1, actual1);
    final DataSetRow expectedRow2 = getRow("tata mouche", "  ", "toto pouche", "  ");
    assertEquals(expectedRow2.values(), row2.values());
    ColumnMetadata expected2 = ColumnMetadata.Builder.column().id(3).name("recipe_modified").type(Type.STRING).build();
    ColumnMetadata actual2 = row2.getRowMetadata().getById("0003");
    assertEquals(expected2, actual2);
    final DataSetRow expectedRow3 = getRow("titi louche", "culbutoqué", "tutu couche", "culbutoqué");
    assertEquals(expectedRow3.values(), row3.values());
    ColumnMetadata expected3 = ColumnMetadata.Builder.column().id(3).name("recipe_modified").type(Type.STRING).build();
    ColumnMetadata actual3 = row3.getRowMetadata().getById("0003");
    assertEquals(expected3, actual3);
}
Also used : ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test)

Example 15 with DataSetRow

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

the class ModifyDateTest method should_process_row_alternate_amount.

@Test
public void should_process_row_alternate_amount() 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("tata").type(Type.STRING).name("last update")).build();
    parameters.put(CONSTANT_VALUE, "4");
    // when
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
    // then
    final DataSetRow expectedRow = getRow("toto", "04/25/2003", "tata");
    assertEquals(expectedRow.values(), row.values());
}
Also used : DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) 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