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