suggestion -> new AutocompleteSuggestion( createSuggestionText(atoms, startsWith + suggestion.getText()), suggestion.getIsPartial(), suggestion.getDescription(),
@Test public void baseAutoComplete() { Set<String> properties = ImmutableSet.of( "abc", NodePropertySpecifier.NTP_SERVERS, NodePropertySpecifier.NTP_SOURCE_INTERFACE); // null or empty string should yield all options assertThat( PropertySpecifier.baseAutoComplete(null, properties).stream() .map(s -> s.getText()) .collect(Collectors.toList()), equalTo(ImmutableList.builder().addAll(properties).build())); // the capital P shouldn't matter and this should autoComplete to three entries assertThat( new ArrayList<>(PropertySpecifier.baseAutoComplete("ntP", properties)), equalTo( ImmutableList.of( new AutocompleteSuggestion(NodePropertySpecifier.NTP_SERVERS, false), new AutocompleteSuggestion(NodePropertySpecifier.NTP_SOURCE_INTERFACE, false)))); }
@Test public void autoCompleteTypeAndName() { Set<String> nodes = new HashSet<>(); nodes.add("nade1"); // will match nodes.add("node1"); // won't match String queryName = "na"; String queryRole = "ro"; List<AutocompleteSuggestion> suggestionsName = NodesSpecifier.autoComplete(queryName, nodes, null); List<AutocompleteSuggestion> suggestionsRole = NodesSpecifier.autoComplete(queryRole, nodes, null); // suggestionsName should have three elements: NAME:, na.*, and nade1 assertThat(suggestionsName, hasSize(3)); assertThat(suggestionsName.get(0).getText(), equalTo("NAME:")); assertThat(suggestionsName.get(1).getText(), equalTo("na.*")); assertThat(suggestionsName.get(2).getText(), equalTo("nade1")); // suggestionsRole should have one element: ROLE: assertThat(suggestionsRole, hasSize(1)); assertThat(suggestionsRole.get(0).getText(), equalTo("ROLE:")); }
@Test public void autoCompleteRoleAllDimensions() { NodeRolesData nodeRolesData = initNodeRoleData(); String queryAllDimensions = "ROLE:"; List<AutocompleteSuggestion> suggestions = NodesSpecifier.autoComplete(queryAllDimensions, null, nodeRolesData); Set<String> suggestionsText = suggestions.stream().map(suggestion -> suggestion.getText()).collect(Collectors.toSet()); // suggestions should have two elements, one for each dimension assertThat(suggestions, hasSize(2)); assertThat(suggestionsText, hasItem("ROLE:dim10:")); assertThat(suggestionsText, hasItem("ROLE:dim20:")); }
@Test public void autoCompleteRoleDimension() { NodeRolesData nodeRolesData = initNodeRoleData(); String queryDimension = "ROLE:dim10:"; List<AutocompleteSuggestion> suggestions = NodesSpecifier.autoComplete(queryDimension, null, nodeRolesData); Set<String> suggestionsText = suggestions.stream().map(suggestion -> suggestion.getText()).collect(Collectors.toSet()); // suggestions should have three elements, one for each role and one .* assertThat(suggestions, hasSize(3)); assertThat(suggestionsText, hasItem("ROLE:dim10:.*")); assertThat(suggestionsText, hasItem("ROLE:dim10:role1")); assertThat(suggestionsText, hasItem("ROLE:dim10:role2")); }
@Test public void autoCompleteRolePartialDimension() { NodeRolesData nodeRolesData = initNodeRoleData(); String queryDimensionPartial = "ROLE:dim1"; List<AutocompleteSuggestion> suggestions = NodesSpecifier.autoComplete(queryDimensionPartial, null, nodeRolesData); // suggestions should have one element assertThat(suggestions, hasSize(1)); assertThat(suggestions.get(0).getText(), equalTo("ROLE:dim10:")); }