/** * Prepares for calling the full auto complete function: {@link * NodesSpecifier#autoComplete(String, Set, NodeRolesData)} by extracting the set of nodes and * node roles from batfish pointer. * * @param query The query to auto complete * @param batfish The pointer to batfish * @return A list of {@link AutocompleteSuggestion} objects */ public static List<AutocompleteSuggestion> autoComplete(String query, IBatfish batfish) { return autoComplete(query, batfish.loadConfigurations().keySet(), batfish.getNodeRolesData()); }
@Test public void autoCompleteNothing() { Set<String> nodes = new HashSet<>(); nodes.add("node1"); String query = "matchNothing"; List<AutocompleteSuggestion> suggestions = NodesSpecifier.autoComplete(query, nodes, null); // autocomplete should yield nothing assertThat(suggestions, hasSize(0)); }
@Test public void autoCompleteEmptyString() { Set<String> nodes = new HashSet<>(); nodes.add("node1"); String query = ""; List<AutocompleteSuggestion> suggestions = NodesSpecifier.autoComplete(query, nodes, null); // autocomplete should yield four entries: NAME:, ROLE:, .*, node1 assertThat(suggestions, hasSize(4)); }
@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:")); }
@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:")); }
"Snapshot name should be supplied for 'NODE' autoCompletion"); suggestions = NodesSpecifier.autoComplete( query, getNodes(network, snapshot), getNetworkNodeRoles(network)); break;