@Test public void resolve() { Configuration node1 = new Configuration("node1", ConfigurationFormat.CISCO_IOS); Configuration node2 = new Configuration("node2", ConfigurationFormat.CISCO_IOS); Zone zone1node1 = new Zone("zone1"); Zone zone2node1 = new Zone("zone2"); Zone zone1node2 = new Zone("zone1"); Interface iface11 = Interface.builder().setName("iface11").setOwner(node1).build(); Interface iface12 = Interface.builder().setName("iface12").setOwner(node1).build(); @SuppressWarnings("unused") Interface iface13 = Interface.builder().setName("iface13").setOwner(node1).build(); Interface iface2 = Interface.builder().setName("iface2").setOwner(node2).build(); node1.setZones(ImmutableSortedMap.of("zone1", zone1node1, "zone2", zone2node1)); zone1node1.setInterfaces(ImmutableSortedSet.of("iface11", "iface12")); zone2node1.setInterfaces(ImmutableSortedSet.of("iface13")); node2.setZones(ImmutableSortedMap.of("zone1", zone1node2)); zone1node2.setInterfaces(ImmutableSortedSet.of("iface2")); MockSpecifierContext ctxt = MockSpecifierContext.builder() .setConfigs(ImmutableMap.of("node1", node1, "node2", node2)) .build(); assertThat( new ZoneNameRegexInterfaceSpecifier(Pattern.compile("zone1")) .resolve(ImmutableSet.of("node1"), ctxt), equalTo(ImmutableSet.of(NodeInterfacePair.of(iface11), NodeInterfacePair.of(iface12)))); assertThat( new ZoneNameRegexInterfaceSpecifier(Pattern.compile("zone1")) .resolve(ImmutableSet.of("node1", "node2"), ctxt), equalTo( ImmutableSet.of( NodeInterfacePair.of(iface11), NodeInterfacePair.of(iface12), NodeInterfacePair.of(iface2)))); assertThat( new ZoneNameRegexInterfaceSpecifier(Pattern.compile("no-zone")) .resolve(ImmutableSet.of("node1"), ctxt), equalTo(ImmutableSet.of())); }
@Override public Set<NodeInterfacePair> resolve(Set<String> nodes, SpecifierContext ctxt) { return nodes.stream() .map(n -> resolve(n, ctxt)) .flatMap(Collection::stream) .collect(ImmutableSet.toImmutableSet()); }
ZoneNameRegexInterfaceSpecifier implements InterfaceSpecifier { @Override public Set<NodeInterfacePair> resolve(Set<String> nodes, SpecifierContext ctxt) { return nodes.stream() .map(n -> resolve(n, ctxt)) .flatMap(Collection::stream) .collect(ImmutableSet.toImmutableSet()); } }
ZoneNameRegexInterfaceSpecifier implements InterfaceSpecifier { @Override public Set<NodeInterfacePair> resolve(Set<String> nodes, SpecifierContext ctxt) { return nodes.stream() .map(n -> resolve(n, ctxt)) .flatMap(Collection::stream) .collect(ImmutableSet.toImmutableSet()); } ZoneNameRegexInterfaceSpecifier(Pattern pattern); }
ZoneNameRegexInterfaceSpecifier implements InterfaceSpecifier { @Override public Set<NodeInterfacePair> resolve(Set<String> nodes, SpecifierContext ctxt) { return nodes.stream() .map(n -> resolve(n, ctxt)) .flatMap(Collection::stream) .collect(ImmutableSet.toImmutableSet()); } ZoneNameRegexInterfaceSpecifier(Pattern pattern); @Override boolean equals(Object o); @Override int hashCode(); @Override Set<NodeInterfacePair> resolve(Set<String> nodes, SpecifierContext ctxt); }
ZoneNameRegexInterfaceSpecifier implements InterfaceSpecifier { @Override public Set<NodeInterfacePair> resolve(Set<String> nodes, SpecifierContext ctxt) { return nodes.stream() .map(n -> resolve(n, ctxt)) .flatMap(Collection::stream) .collect(ImmutableSet.toImmutableSet()); } ZoneNameRegexInterfaceSpecifier(Pattern pattern); @Override boolean equals(Object o); @Override int hashCode(); @Override Set<NodeInterfacePair> resolve(Set<String> nodes, SpecifierContext ctxt);  }