@Test public void testPrefixAutocomplete() throws IOException { String network = "network"; String snapshot = "snapshot"; String suggested = "1.2.3.4/24"; String notSuggested = "1.3.2.4/30"; CompletionMetadata completionMetadata = CompletionMetadata.builder().setPrefixes(ImmutableSet.of(suggested, notSuggested)).build(); storeCompletionMetadata(completionMetadata, network, snapshot); assertThat( _manager.autoComplete(network, snapshot, Type.PREFIX, "1.2", 5).stream() .map(AutocompleteSuggestion::getText) .collect(Collectors.toSet()), equalTo(ImmutableSet.of(suggested))); }
@Test public void testZoneAutocomplete() throws IOException { String network = "network"; String snapshot = "snapshot"; String suggested = "someZone"; String notSuggested = "blah"; CompletionMetadata completionMetadata = CompletionMetadata.builder().setZones(ImmutableSet.of(suggested, notSuggested)).build(); storeCompletionMetadata(completionMetadata, network, snapshot); assertThat( _manager.autoComplete(network, snapshot, Type.ZONE, "z", 5).stream() .map(AutocompleteSuggestion::getText) .collect(Collectors.toSet()), equalTo(ImmutableSet.of(suggested))); }
@Test public void testAddressGroupAutocomplete() throws IOException { String network = "network"; String snapshot = "snapshot"; String suggestion = "group"; String notSuggestion = "addresses"; CompletionMetadata completionMetadata = CompletionMetadata.builder() .setAddressGroups(ImmutableSet.of(suggestion, notSuggestion)) .build(); storeCompletionMetadata(completionMetadata, network, snapshot); assertThat( _manager.autoComplete(network, snapshot, Type.ADDRESS_GROUP, "gr", 5).stream() .map(AutocompleteSuggestion::getText) .collect(Collectors.toSet()), equalTo(ImmutableSet.of(suggestion))); }
@Test public void testIpAutocomplete() throws IOException { String network = "network"; String snapshot = "snapshot"; String suggested = "1.2.3.4"; String notSuggested = "1.3.2.4"; CompletionMetadata completionMetadata = CompletionMetadata.builder().setIps(ImmutableSet.of(suggested, notSuggested)).build(); storeCompletionMetadata(completionMetadata, network, snapshot); assertThat( _manager.autoComplete(network, snapshot, Type.IP, "1.2", 5).stream() .map(AutocompleteSuggestion::getText) .collect(Collectors.toSet()), equalTo(ImmutableSet.of(suggested))); }
@Test public void testVrfAutocomplete() throws IOException { String network = "network"; String snapshot = "snapshot"; String suggested = "someVrf"; String notSuggested = "blah"; CompletionMetadata completionMetadata = CompletionMetadata.builder().setVrfs(ImmutableSet.of(suggested, notSuggested)).build(); storeCompletionMetadata(completionMetadata, network, snapshot); assertThat( _manager.autoComplete(network, snapshot, Type.VRF, "v", 5).stream() .map(AutocompleteSuggestion::getText) .collect(Collectors.toSet()), equalTo(ImmutableSet.of(suggested))); }
@Test public void testAddressBookAutocomplete() throws IOException { String network = "network"; String snapshot = "snapshot"; String suggestion = "book"; String notSuggestion = "addresses"; CompletionMetadata completionMetadata = CompletionMetadata.builder() .setAddressBooks(ImmutableSet.of(notSuggestion, suggestion)) .build(); storeCompletionMetadata(completionMetadata, network, snapshot); assertThat( _manager.autoComplete(network, snapshot, Type.ADDRESS_BOOK, "bo", 5).stream() .map(AutocompleteSuggestion::getText) .collect(Collectors.toSet()), equalTo(ImmutableSet.of(suggestion))); }
@Test public void testFilterAutocomplete() throws IOException { String network = "network"; String snapshot = "snapshot"; String suggestion = "someFilter"; String notSuggestion = "blah"; CompletionMetadata completionMetadata = CompletionMetadata.builder() .setFilterNames(ImmutableSet.of(suggestion, notSuggestion)) .build(); storeCompletionMetadata(completionMetadata, network, snapshot); assertThat( _manager.autoComplete(network, snapshot, Type.FILTER, "fil", 5).stream() .map(AutocompleteSuggestion::getText) .collect(Collectors.toSet()), equalTo(ImmutableSet.of(suggestion))); }
@Test public void testStructureNameAutocomplete() throws IOException { String network = "network"; String snapshot = "snapshot"; String suggested = "someStructure"; String notSuggested = "blah"; CompletionMetadata completionMetadata = CompletionMetadata.builder() .setStructureNames(ImmutableSet.of(suggested, notSuggested)) .build(); storeCompletionMetadata(completionMetadata, network, snapshot); assertThat( _manager.autoComplete(network, snapshot, Type.STRUCTURE_NAME, "str", 5).stream() .map(AutocompleteSuggestion::getText) .collect(Collectors.toSet()), equalTo(ImmutableSet.of(suggested))); }
@Test public void testInterfaceAutocomplete() throws IOException { String network = "network"; String snapshot = "snapshot"; NodeInterfacePair suggested = new NodeInterfacePair("hostname", "interface"); NodeInterfacePair notSuggested = new NodeInterfacePair("blah", "blahhh"); CompletionMetadata completionMetadata = CompletionMetadata.builder() .setInterfaces(ImmutableSet.of(suggested, notSuggested)) .build(); storeCompletionMetadata(completionMetadata, network, snapshot); assertThat( _manager.autoComplete(network, snapshot, Type.INTERFACE, "int", 5).stream() .map(AutocompleteSuggestion::getText) .collect(Collectors.toSet()), equalTo(ImmutableSet.of(suggested.toString()))); }
@Test public void testJsonSerialization() throws IOException { CompletionMetadata completionMetadata = CompletionMetadata.builder() .setAddressBooks(ImmutableSet.of("addressBook")) .setAddressGroups(ImmutableSet.of("addressGroup")) .setFilterNames(ImmutableSet.of("filter")) .setInterfaces(ImmutableSet.of(new NodeInterfacePair("interface", "node"))) .setIps(ImmutableSet.of("ip")) .setPrefixes(ImmutableSet.of("prefix")) .setStructureNames(ImmutableSet.of("structure")) .setVrfs(ImmutableSet.of("vrf")) .setZones(ImmutableSet.of("zone")) .build(); assertThat( BatfishObjectMapper.clone(completionMetadata, CompletionMetadata.class), equalTo(completionMetadata)); }
@Test public void testJavaSerialization() throws IOException { CompletionMetadata completionMetadata = CompletionMetadata.builder() .setAddressBooks(ImmutableSet.of("addressBook")) .setAddressGroups(ImmutableSet.of("addressGroup")) .setFilterNames(ImmutableSet.of("filter")) .setInterfaces(ImmutableSet.of(new NodeInterfacePair("interface", "node"))) .setIps(ImmutableSet.of("ip")) .setPrefixes(ImmutableSet.of("prefix")) .setStructureNames(ImmutableSet.of("structure")) .setVrfs(ImmutableSet.of("vrf")) .setZones(ImmutableSet.of("zone")) .build(); assertThat(SerializationUtils.clone(completionMetadata), equalTo(completionMetadata)); }
@Test public void testEquals() { CompletionMetadata.Builder builder = CompletionMetadata.builder(); CompletionMetadata initial = builder.build(); new EqualsTester() .addEqualityGroup(new Object()) .addEqualityGroup(initial, initial, builder.build(), CompletionMetadata.EMPTY) .addEqualityGroup(builder.setAddressBooks(ImmutableSet.of("addressBook")).build()) .addEqualityGroup(builder.setAddressGroups(ImmutableSet.of("addressGroup")).build()) .addEqualityGroup(builder.setFilterNames(ImmutableSet.of("filter")).build()) .addEqualityGroup( builder .setInterfaces(ImmutableSet.of(new NodeInterfacePair("interface", "node"))) .build()) .addEqualityGroup(builder.setIps(ImmutableSet.of("ip")).build()) .addEqualityGroup(builder.setPrefixes(ImmutableSet.of("prefix")).build()) .addEqualityGroup(builder.setStructureNames(ImmutableSet.of("structure")).build()) .addEqualityGroup(builder.setVrfs(ImmutableSet.of("vrf")).build()) .addEqualityGroup(builder.setZones(ImmutableSet.of("zone")).build()) .testEquals(); } }