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);
}
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);
}
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);
}
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());
}
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());
}
Aggregations