Search in sources :

Example 1 with UpperCase

use of org.talend.dataprep.transformation.actions.text.UpperCase 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)

Example 2 with UpperCase

use of org.talend.dataprep.transformation.actions.text.UpperCase in project data-prep by Talend.

the class SimpleSuggestionEngineTest method shouldSuggestionsShouldBeSorted.

@Test
public void shouldSuggestionsShouldBeSorted() throws IOException {
    final String json = IOUtils.toString(this.getClass().getResourceAsStream("sample_column.json"), UTF_8);
    ObjectMapper mapper = new ObjectMapper();
    final ColumnMetadata columnMetadata = mapper.readValue(json, ColumnMetadata.class);
    List<ActionDefinition> actions = new ArrayList<>();
    actions.add(new FillIfEmpty());
    actions.add(new FillInvalid());
    actions.add(new DeleteInvalid());
    actions.add(new DeleteEmpty());
    actions.add(new Absolute());
    actions.add(new UpperCase());
    final Stream<Suggestion> suggestions = engine.score(actions.stream(), columnMetadata);
    int currentScore = Integer.MAX_VALUE;
    for (Suggestion suggestion : suggestions.collect(Collectors.toList())) {
        assertTrue(currentScore >= suggestion.getScore());
        currentScore = suggestion.getScore();
    }
}
Also used : ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) UpperCase(org.talend.dataprep.transformation.actions.text.UpperCase) ArrayList(java.util.ArrayList) Absolute(org.talend.dataprep.transformation.actions.math.Absolute) ActionDefinition(org.talend.dataprep.api.action.ActionDefinition) DeleteInvalid(org.talend.dataprep.transformation.actions.delete.DeleteInvalid) FillIfEmpty(org.talend.dataprep.transformation.actions.fill.FillIfEmpty) DeleteEmpty(org.talend.dataprep.transformation.actions.delete.DeleteEmpty) FillInvalid(org.talend.dataprep.transformation.actions.fill.FillInvalid) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 UpperCase (org.talend.dataprep.transformation.actions.text.UpperCase)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ActionDefinition (org.talend.dataprep.api.action.ActionDefinition)1 ColumnMetadata (org.talend.dataprep.api.dataset.ColumnMetadata)1 DataSetRow (org.talend.dataprep.api.dataset.row.DataSetRow)1 AbstractMetadataBaseTest (org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)1 RunnableAction (org.talend.dataprep.transformation.actions.common.RunnableAction)1 DeleteEmpty (org.talend.dataprep.transformation.actions.delete.DeleteEmpty)1 DeleteInvalid (org.talend.dataprep.transformation.actions.delete.DeleteInvalid)1 FillIfEmpty (org.talend.dataprep.transformation.actions.fill.FillIfEmpty)1 FillInvalid (org.talend.dataprep.transformation.actions.fill.FillInvalid)1 Absolute (org.talend.dataprep.transformation.actions.math.Absolute)1