Search in sources :

Example 46 with RowMetadata

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

the class ReorderColumnTest method should_reorder_meta_with_5_columns_and_0004_to_0002.

@Test
public void should_reorder_meta_with_5_columns_and_0004_to_0002() {
    // given
    DataSetRow row = createDataSetRow(5);
    parameters.put(ImplicitParameters.COLUMN_ID.getKey(), "0004");
    parameters.put(OtherColumnParameters.SELECTED_COLUMN_PARAMETER, "0002");
    // when
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
    // then
    final RowMetadata rowMetadata = row.getRowMetadata();
    Assertions.assertThat(rowMetadata.getColumns()).isNotEmpty().hasSize(5);
    Assertions.assertThat(rowMetadata.getColumns().get(0).getId()).isEqualTo("0000");
    Assertions.assertThat(rowMetadata.getColumns().get(1).getId()).isEqualTo("0001");
    Assertions.assertThat(rowMetadata.getColumns().get(2).getId()).isEqualTo("0004");
    Assertions.assertThat(rowMetadata.getColumns().get(3).getId()).isEqualTo("0002");
    Assertions.assertThat(rowMetadata.getColumns().get(4).getId()).isEqualTo("0003");
    assertValuesNotTouched(5, row);
}
Also used : RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)

Example 47 with RowMetadata

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

the class ReorderColumnTest method should_reorder_meta_with_4_columns_and_0003_to_0000.

@Test
public void should_reorder_meta_with_4_columns_and_0003_to_0000() {
    // given
    DataSetRow row = createDataSetRow(4);
    parameters.put(ImplicitParameters.COLUMN_ID.getKey(), "0003");
    parameters.put(OtherColumnParameters.SELECTED_COLUMN_PARAMETER, "0000");
    // when
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
    // then
    final RowMetadata actual = row.getRowMetadata();
    Assertions.assertThat(actual.getColumns()).isNotEmpty().hasSize(4);
    Assertions.assertThat(actual.getColumns().get(0).getId()).isEqualTo("0003");
    Assertions.assertThat(actual.getColumns().get(1).getId()).isEqualTo("0000");
    Assertions.assertThat(actual.getColumns().get(2).getId()).isEqualTo("0001");
    Assertions.assertThat(actual.getColumns().get(3).getId()).isEqualTo("0002");
    assertValuesNotTouched(4, row);
}
Also used : RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)

Example 48 with RowMetadata

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

the class ReorderColumnTest method should_reorder_meta_only_2_columns.

@Test
public void should_reorder_meta_only_2_columns() {
    // given
    DataSetRow row = createDataSetRow(2);
    // when
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
    // then
    final RowMetadata rowMetadata = row.getRowMetadata();
    Assertions.assertThat(rowMetadata.getColumns()).isNotEmpty().hasSize(2);
    Assertions.assertThat(rowMetadata.getColumns().get(0).getName()).isEqualTo("1 col");
    Assertions.assertThat(rowMetadata.getColumns().get(0).getId()).isEqualTo("0001");
    Assertions.assertThat(rowMetadata.getColumns().get(1).getName()).isEqualTo("0 col");
    Assertions.assertThat(rowMetadata.getColumns().get(1).getId()).isEqualTo("0000");
    assertValuesNotTouched(2, row);
}
Also used : RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)

Example 49 with RowMetadata

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

the class ClearInvalidTest method should_not_clear_because_valid.

@Test
public void should_not_clear_because_valid() {
    // given
    final Map<String, String> values = new HashMap<>();
    values.put("0000", "David Bowie");
    values.put("0001", "N");
    values.put("0002", "Something");
    final DataSetRow row = new DataSetRow(values);
    final RowMetadata rowMetadata = row.getRowMetadata();
    rowMetadata.getById("0001").setType(Type.STRING.getName());
    final Map<String, Object> expectedValues = new HashMap<>();
    expectedValues.put("0000", "David Bowie");
    expectedValues.put("0001", "N");
    expectedValues.put("0002", "Something");
    // when
    final RunnableAction runnableAction = factory.create(action, parameters);
    final ActionContext context = new ActionContext(new TransformationContext(), rowMetadata);
    context.setParameters(parameters);
    runnableAction.getRowAction().apply(row, context);
    // then
    assertEquals(expectedValues, row.values());
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) RunnableAction(org.talend.dataprep.transformation.actions.common.RunnableAction) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) ActionContext(org.talend.dataprep.transformation.api.action.context.ActionContext) TransformationContext(org.talend.dataprep.transformation.api.action.context.TransformationContext) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)

Example 50 with RowMetadata

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

the class ClearInvalidTest method test_apply_inplace.

@Test
public void test_apply_inplace() {
    // given
    final Map<String, String> values = new HashMap<>();
    values.put("0000", "David Bowie");
    values.put("0001", "N");
    values.put("0002", "Something");
    final DataSetRow row = new DataSetRow(values);
    row.setInvalid("0001");
    final RowMetadata rowMetadata = row.getRowMetadata();
    rowMetadata.getById("0001").setType(Type.STRING.getName());
    final Map<String, Object> expectedValues = new LinkedHashMap<>();
    expectedValues.put("__tdpInvalid", "0001");
    expectedValues.put("0000", "David Bowie");
    expectedValues.put("0001", "");
    expectedValues.put("0002", "Something");
    // when
    final RunnableAction runnableAction = factory.create(action, parameters);
    final ActionContext context = new ActionContext(new TransformationContext(), rowMetadata);
    context.setParameters(parameters);
    runnableAction.getRowAction().apply(row, context);
    // then
    assertEquals(expectedValues, row.values());
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) RunnableAction(org.talend.dataprep.transformation.actions.common.RunnableAction) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) ActionContext(org.talend.dataprep.transformation.api.action.context.ActionContext) TransformationContext(org.talend.dataprep.transformation.api.action.context.TransformationContext) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)

Aggregations

RowMetadata (org.talend.dataprep.api.dataset.RowMetadata)199 Test (org.junit.Test)130 DataSetRow (org.talend.dataprep.api.dataset.row.DataSetRow)112 ColumnMetadata (org.talend.dataprep.api.dataset.ColumnMetadata)87 AbstractMetadataBaseTest (org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)68 HashMap (java.util.HashMap)48 ActionContext (org.talend.dataprep.transformation.api.action.context.ActionContext)21 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)20 RunnableAction (org.talend.dataprep.transformation.actions.common.RunnableAction)19 TransformationContext (org.talend.dataprep.transformation.api.action.context.TransformationContext)18 ArrayList (java.util.ArrayList)16 DataSet (org.talend.dataprep.api.dataset.DataSet)11 List (java.util.List)9 Statistics (org.talend.dataprep.api.dataset.statistics.Statistics)9 Before (org.junit.Before)7 SemanticDomain (org.talend.dataprep.api.dataset.statistics.SemanticDomain)6 Preparation (org.talend.dataprep.api.preparation.Preparation)6 Response (com.jayway.restassured.response.Response)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 Logger (org.slf4j.Logger)5