@Test public void testResolve() { Configuration node1 = new Configuration("node1", ConfigurationFormat.CISCO_IOS); Configuration node2 = new Configuration("node2", ConfigurationFormat.CISCO_IOS); IpAccessList filter1node1 = IpAccessList.builder().setName("filter1").setOwner(node1).build(); IpAccessList filter2node1 = IpAccessList.builder().setName("filter2").setOwner(node1).build(); IpAccessList filter1node2 = IpAccessList.builder().setName("filter1").setOwner(node2).build(); node1.setIpAccessLists( ImmutableSortedMap.of( filter1node1.getName(), filter1node1, filter2node1.getName(), filter2node1)); node2.setIpAccessLists(ImmutableSortedMap.of(filter1node2.getName(), filter1node2)); MockSpecifierContext ctxt = MockSpecifierContext.builder() .setConfigs(ImmutableMap.of(node1.getHostname(), node1, node2.getHostname(), node2)) .build(); assertThat( new NameRegexFilterSpecifier(Pattern.compile("filter1")).resolve("node1", ctxt), equalTo(ImmutableSet.of(filter1node1))); assertThat( new NameRegexFilterSpecifier(Pattern.compile("filter")).resolve("node1", ctxt), equalTo(ImmutableSet.of(filter1node1, filter2node1))); assertThat( new NameRegexFilterSpecifier(Pattern.compile("filter1")).resolve("node", ctxt), equalTo(ImmutableSet.of())); assertThat( new NameRegexFilterSpecifier(Pattern.compile("filter3")).resolve("node1", ctxt), equalTo(ImmutableSet.of())); }
@Override public Set<IpAccessList> resolve(String node, SpecifierContext ctxt) { return ctxt.getConfigs().values().stream() .filter(c -> c.getHostname().equalsIgnoreCase(node)) .map(c -> c.getIpAccessLists().values()) .flatMap(Collection::stream) .filter(f -> _pattern.matcher(f.getName()).find()) .collect(ImmutableSet.toImmutableSet()); }
NameRegexFilterSpecifier implements FilterSpecifier { @Override public Set<IpAccessList> resolve(String node, SpecifierContext ctxt) { return ctxt.getConfigs().values().stream() .filter(c -> c.getHostname().equalsIgnoreCase(node)) .map(c -> c.getIpAccessLists().values()) .flatMap(Collection::stream) .filter(f -> _pattern.matcher(f.getName()).find()) .collect(ImmutableSet.toImmutableSet()); } }
NameRegexFilterSpecifier implements FilterSpecifier { @Override public Set<IpAccessList> resolve(String node, SpecifierContext ctxt) { return ctxt.getConfigs().values().stream() .filter(c -> c.getHostname().equalsIgnoreCase(node)) .map(c -> c.getIpAccessLists().values()) .flatMap(Collection::stream) .filter(f -> _pattern.matcher(f.getName()).find()) .collect(ImmutableSet.toImmutableSet()); } NameRegexFilterSpecifier(Pattern pattern); }
NameRegexFilterSpecifier implements FilterSpecifier { @Override public Set<IpAccessList> resolve(String node, SpecifierContext ctxt) { return ctxt.getConfigs().values().stream() .filter(c -> c.getHostname().equalsIgnoreCase(node)) .map(c -> c.getIpAccessLists().values()) .flatMap(Collection::stream) .filter(f -> _pattern.matcher(f.getName()).find()) .collect(ImmutableSet.toImmutableSet()); } NameRegexFilterSpecifier(Pattern pattern); @Override boolean equals(@Nullable Object o); @Override int hashCode(); @Override Set<IpAccessList> resolve(String node, SpecifierContext ctxt); }
NameRegexFilterSpecifier implements FilterSpecifier { @Override public Set<IpAccessList> resolve(String node, SpecifierContext ctxt) { return ctxt.getConfigs().values().stream() .filter(c -> c.getHostname().equalsIgnoreCase(node)) .map(c -> c.getIpAccessLists().values()) .flatMap(Collection::stream) .filter(f -> _pattern.matcher(f.getName()).find()) .collect(ImmutableSet.toImmutableSet()); } NameRegexFilterSpecifier(Pattern pattern); @Override boolean equals(@Nullable Object o); @Override int hashCode(); @Override Set<IpAccessList> resolve(String node, SpecifierContext ctxt);  }