@Test public void testResolve() { Configuration node1 = new Configuration("node1", ConfigurationFormat.CISCO_IOS); Configuration node2 = new Configuration("node2", ConfigurationFormat.CISCO_IOS); RoutingPolicy routingPolicy1node1 = RoutingPolicy.builder().setName("routingPolicy1").setOwner(node1).build(); RoutingPolicy routingPolicy2node1 = RoutingPolicy.builder().setName("routingPolicy2").setOwner(node1).build(); RoutingPolicy routingPolicy1node2 = RoutingPolicy.builder().setName("routingPolicy1").setOwner(node2).build(); node1.setRoutingPolicies( ImmutableSortedMap.of( routingPolicy1node1.getName(), routingPolicy1node1, routingPolicy2node1.getName(), routingPolicy2node1)); node2.setRoutingPolicies( ImmutableSortedMap.of(routingPolicy1node2.getName(), routingPolicy1node2)); MockSpecifierContext ctxt = MockSpecifierContext.builder() .setConfigs(ImmutableMap.of(node1.getHostname(), node1, node2.getHostname(), node2)) .build(); assertThat( new NameRegexRoutingPolicySpecifier(Pattern.compile("routingPolicy1")) .resolve("node1", ctxt), equalTo(ImmutableSet.of(routingPolicy1node1))); assertThat( new NameRegexRoutingPolicySpecifier(Pattern.compile("routingPolicy")) .resolve("node1", ctxt), equalTo(ImmutableSet.of(routingPolicy1node1, routingPolicy2node1))); assertThat( new NameRegexRoutingPolicySpecifier(Pattern.compile("routingPolicy1")) .resolve("node", ctxt), equalTo(ImmutableSet.of())); assertThat( new NameRegexRoutingPolicySpecifier(Pattern.compile("routingPolicy3")) .resolve("node1", ctxt), equalTo(ImmutableSet.of())); }
@Override public Set<RoutingPolicy> resolve(String node, SpecifierContext ctxt) { return ctxt.getConfigs().values().stream() .filter(c -> c.getHostname().equalsIgnoreCase(node)) .map(c -> c.getRoutingPolicies().values()) .flatMap(Collection::stream) .filter(f -> _pattern.matcher(f.getName()).find()) .collect(ImmutableSet.toImmutableSet()); }
NameRegexRoutingPolicySpecifier implements RoutingPolicySpecifier { @Override public Set<RoutingPolicy> resolve(String node, SpecifierContext ctxt) { return ctxt.getConfigs().values().stream() .filter(c -> c.getHostname().equalsIgnoreCase(node)) .map(c -> c.getRoutingPolicies().values()) .flatMap(Collection::stream) .filter(f -> _pattern.matcher(f.getName()).find()) .collect(ImmutableSet.toImmutableSet()); } }
NameRegexRoutingPolicySpecifier implements RoutingPolicySpecifier { @Override public Set<RoutingPolicy> resolve(String node, SpecifierContext ctxt) { return ctxt.getConfigs().values().stream() .filter(c -> c.getHostname().equalsIgnoreCase(node)) .map(c -> c.getRoutingPolicies().values()) .flatMap(Collection::stream) .filter(f -> _pattern.matcher(f.getName()).find()) .collect(ImmutableSet.toImmutableSet()); } NameRegexRoutingPolicySpecifier(Pattern pattern); }
NameRegexRoutingPolicySpecifier implements RoutingPolicySpecifier { @Override public Set<RoutingPolicy> resolve(String node, SpecifierContext ctxt) { return ctxt.getConfigs().values().stream() .filter(c -> c.getHostname().equalsIgnoreCase(node)) .map(c -> c.getRoutingPolicies().values()) .flatMap(Collection::stream) .filter(f -> _pattern.matcher(f.getName()).find()) .collect(ImmutableSet.toImmutableSet()); } NameRegexRoutingPolicySpecifier(Pattern pattern); @Override boolean equals(@Nullable Object o); @Override int hashCode(); @Override Set<RoutingPolicy> resolve(String node, SpecifierContext ctxt); }
NameRegexRoutingPolicySpecifier implements RoutingPolicySpecifier { @Override public Set<RoutingPolicy> resolve(String node, SpecifierContext ctxt) { return ctxt.getConfigs().values().stream() .filter(c -> c.getHostname().equalsIgnoreCase(node)) .map(c -> c.getRoutingPolicies().values()) .flatMap(Collection::stream) .filter(f -> _pattern.matcher(f.getName()).find()) .collect(ImmutableSet.toImmutableSet()); } NameRegexRoutingPolicySpecifier(Pattern pattern); @Override boolean equals(@Nullable Object o); @Override int hashCode(); @Override Set<RoutingPolicy> resolve(String node, SpecifierContext ctxt); static final NameRegexRoutingPolicySpecifier ALL_ROUTING_POLICIES; }