SimpleSuggestionEngine implements SuggestionEngine { @Override public Stream<Suggestion> score(Stream<ActionDefinition> actions, ColumnMetadata column) { return actions.map(actionMetadata -> score(actionMetadata, column)).sorted(SUGGESTION_COMPARATOR); }  void setRules(List<SuggestionEngineRule> rules); @Override Stream<Suggestion> score(Stream<ActionDefinition> actions, ColumnMetadata column); @Override Suggestion score(ActionDefinition actionDef, ColumnMetadata column); @Override List<ActionDefinition> suggest(DataSet dataSet);  }
@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 = suggestionEngine.score(actions.stream(), columnMetadata); int currentScore = Integer.MAX_VALUE; for (Suggestion suggestion : suggestions.collect(Collectors.toList())) { assertTrue(currentScore >= suggestion.getScore()); currentScore = suggestion.getScore(); } }
@Test public void shouldTestSuggestColumnValid() 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); String[] expectedResult = { "clear_invalid", "delete_invalid", "fillinvalidwithdefault", "standardize_value", "delete_empty" }; String[] newActionFormArray = suggestionEngine .score(actionRegistry.findAll(), columnMetadata) .filter(i -> i.getScore() > 0) .limit(5) .map(a -> a.getAction().getName()) .toArray(String[]::new); assertEquals(5, newActionFormArray.length); assertArrayEquals(expectedResult, newActionFormArray); }
@Test public void shouldTestSuggestColumnString() throws IOException { final String json = IOUtils.toString(this.getClass().getResourceAsStream("metadata_gonfleurs_suggestion.json"), UTF_8); ObjectMapper mapper = new ObjectMapper(); final ColumnMetadata columnMetadata = mapper.readValue(json, ColumnMetadata.class); String[] expectedResult = { "lowercase", "propercase", "replace_on_value", "uppercase" }; String[] newActionFormArray = suggestionEngine .score(actionRegistry.findAll(), columnMetadata) .filter(i -> i.getScore() > 0) .limit(5) .map(a -> a.getAction().getName()) .toArray(String[]::new); assertEquals(4, newActionFormArray.length); assertArrayEquals(expectedResult, newActionFormArray); }