Search in sources :

Example 26 with DataSetRow

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

the class DeleteEmptyTest method should_not_delete_because_value_set_of_float.

@Test
public void should_not_delete_because_value_set_of_float() {
    // given
    final Map<String, String> values = new HashMap<>();
    values.put("0000", "David Bowie");
    values.put("0001", "0.001");
    final DataSetRow row = new DataSetRow(values);
    // when
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
    // then
    assertFalse(row.isDeleted());
}
Also used : HashMap(java.util.HashMap) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)

Example 27 with DataSetRow

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

the class DeleteEmptyTest method should_delete_because_empty.

@Test
public void should_delete_because_empty() {
    // given
    final Map<String, String> values = new HashMap<>();
    values.put("0000", "David Bowie");
    values.put("0001", "");
    final DataSetRow row = new DataSetRow(values);
    // when
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
    // then
    assertTrue(row.isDeleted());
}
Also used : HashMap(java.util.HashMap) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)

Example 28 with DataSetRow

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

the class DeleteEmptyTest method should_not_delete_because_value_set_of_negative_boolean.

@Test
public void should_not_delete_because_value_set_of_negative_boolean() {
    // given
    final Map<String, String> values = new HashMap<>();
    values.put("0000", "David Bowie");
    values.put("0001", "-12");
    final DataSetRow row = new DataSetRow(values);
    // when
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
    // then
    assertFalse(row.isDeleted());
}
Also used : HashMap(java.util.HashMap) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)

Example 29 with DataSetRow

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

the class MakeLineHeaderTest method should_use_mask_on_empty_cell.

@Test
public void should_use_mask_on_empty_cell() {
    // given
    long rowId = 120;
    // row 1
    Map<String, String> rowContent = new HashMap<>();
    rowContent.put("0000", "David");
    rowContent.put("0001", "Bowie");
    final DataSetRow row1 = new DataSetRow(rowContent);
    row1.setTdpId(rowId++);
    // row 2
    rowContent = new HashMap<>();
    rowContent.put("0000", "John");
    rowContent.put("0001", "");
    final DataSetRow row2 = new DataSetRow(rowContent);
    row2.setTdpId(rowId++);
    // row 3
    rowContent = new HashMap<>();
    rowContent.put("0000", "John");
    rowContent.put("0001", "Lennon");
    final DataSetRow row3 = new DataSetRow(rowContent);
    row3.setTdpId(rowId++);
    final Map<String, String> parameters = new HashMap<>();
    parameters.put(ImplicitParameters.SCOPE.getKey().toLowerCase(), "line");
    parameters.put("row_id", row2.getTdpId().toString());
    assertFalse(row1.isDeleted());
    assertFalse(row2.isDeleted());
    assertFalse(row3.isDeleted());
    // when
    ActionTestWorkbench.test(Arrays.asList(row1, row2, row3), actionRegistry, factory.create(action, parameters));
    // then
    assertTrue(row1.isDeleted());
    assertTrue(row2.isDeleted());
    assertFalse(row3.isDeleted());
    assertEquals("John", row2.getRowMetadata().getById("0000").getName());
    assertEquals("Col 2", row2.getRowMetadata().getById("0001").getName());
}
Also used : HashMap(java.util.HashMap) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)

Example 30 with DataSetRow

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

the class MakeLineHeaderTest method should_keep_header_after_modifications.

@Test
public void should_keep_header_after_modifications() {
    // given
    Long rowId = 0L;
    // row 1
    Map<String, String> rowContent = new HashMap<>();
    rowContent.put("0000", "David");
    rowContent.put("0001", "Bowie");
    final DataSetRow row1 = new DataSetRow(rowContent);
    row1.setTdpId(rowId++);
    // row 2
    rowContent = new HashMap<>();
    rowContent.put("0000", "John");
    rowContent.put("0001", "Lennon");
    final DataSetRow row2 = new DataSetRow(rowContent);
    row2.setTdpId(rowId++);
    // row 3
    rowContent = new HashMap<>();
    rowContent.put("0000", "Johnny");
    rowContent.put("0001", "Lennon");
    final DataSetRow row3 = new DataSetRow(rowContent);
    row3.setTdpId(rowId++);
    // when
    final Map<String, String> makeHeaderParameters = new HashMap<>();
    makeHeaderParameters.put(ImplicitParameters.SCOPE.getKey().toLowerCase(), "line");
    makeHeaderParameters.put("row_id", row2.getTdpId().toString());
    final RunnableAction makeHeader = factory.create(action, makeHeaderParameters);
    final Map<String, String> upperCaseParameters = new HashMap<>();
    upperCaseParameters.put(ImplicitParameters.SCOPE.getKey().toLowerCase(), "column");
    upperCaseParameters.put(ImplicitParameters.COLUMN_ID.getKey().toLowerCase(), "0000");
    final RunnableAction upperCase = factory.create(new UpperCase(), upperCaseParameters);
    ActionTestWorkbench.test(Arrays.asList(row1, row2, row3), actionRegistry, makeHeader, upperCase);
    // then
    assertEquals("John", row1.getRowMetadata().getById("0000").getName());
    assertEquals("Lennon", row1.getRowMetadata().getById("0001").getName());
    assertEquals("John", row2.getRowMetadata().getById("0000").getName());
    assertEquals("Lennon", row2.getRowMetadata().getById("0001").getName());
    assertEquals("John", row3.getRowMetadata().getById("0000").getName());
    assertEquals("Lennon", row3.getRowMetadata().getById("0001").getName());
}
Also used : UpperCase(org.talend.dataprep.transformation.actions.text.UpperCase) HashMap(java.util.HashMap) RunnableAction(org.talend.dataprep.transformation.actions.common.RunnableAction) 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