@Test public void testResolve() { Configuration node1 = new Configuration("node1", ConfigurationFormat.CISCO_IOS); Configuration node2 = new Configuration("node2", ConfigurationFormat.CISCO_IOS); Interface iface1node1 = Interface.builder().setName("iface1").setOwner(node1).build(); Interface iface2node1 = Interface.builder().setName("iface2").setOwner(node1).build(); Interface iface1node2 = Interface.builder().setName("iface1").setOwner(node2).build(); node1.setInterfaces( ImmutableSortedMap.of( iface1node1.getName(), iface1node1, iface2node1.getName(), iface2node1)); node2.setInterfaces(ImmutableSortedMap.of(iface1node2.getName(), iface1node2)); MockSpecifierContext ctxt = MockSpecifierContext.builder() .setConfigs(ImmutableMap.of(node1.getHostname(), node1, node2.getHostname(), node2)) .build(); assertThat( new NameInterfaceSpecifier("iface1").resolve(ImmutableSet.of("node1"), ctxt), contains(NodeInterfacePair.of(iface1node1))); assertThat( new NameInterfaceSpecifier("iface1").resolve(ImmutableSet.of("node1", "node2"), ctxt), containsInAnyOrder(NodeInterfacePair.of(iface1node1), NodeInterfacePair.of(iface1node2))); assertThat( new NameInterfaceSpecifier("iface").resolve(ImmutableSet.of("node1"), ctxt), empty()); assertThat( new NameInterfaceSpecifier("IfACe1").resolve(ImmutableSet.of("node1"), ctxt), contains(NodeInterfacePair.of(iface1node1))); }
@Override public Set<NodeInterfacePair> resolve(Set<String> nodes, SpecifierContext ctxt) { return ctxt.getConfigs().values().stream() .filter(c -> nodes.contains(c.getHostname())) .map(c -> c.getAllInterfaces().values()) .flatMap(Collection::stream) .filter(iface -> iface.getName().equalsIgnoreCase(_name)) .map(NodeInterfacePair::of) .collect(ImmutableSet.toImmutableSet()); }
NameInterfaceSpecifier implements InterfaceSpecifier { @Override public Set<NodeInterfacePair> resolve(Set<String> nodes, SpecifierContext ctxt) { return ctxt.getConfigs().values().stream() .filter(c -> nodes.contains(c.getHostname())) .map(c -> c.getAllInterfaces().values()) .flatMap(Collection::stream) .filter(iface -> iface.getName().equalsIgnoreCase(_name)) .map(NodeInterfacePair::of) .collect(ImmutableSet.toImmutableSet()); } }
NameInterfaceSpecifier implements InterfaceSpecifier { @Override public Set<NodeInterfacePair> resolve(Set<String> nodes, SpecifierContext ctxt) { return ctxt.getConfigs().values().stream() .filter(c -> nodes.contains(c.getHostname())) .map(c -> c.getAllInterfaces().values()) .flatMap(Collection::stream) .filter(iface -> iface.getName().equalsIgnoreCase(_name)) .map(NodeInterfacePair::of) .collect(ImmutableSet.toImmutableSet()); } NameInterfaceSpecifier(String name); }
NameInterfaceSpecifier implements InterfaceSpecifier { @Override public Set<NodeInterfacePair> resolve(Set<String> nodes, SpecifierContext ctxt) { return ctxt.getConfigs().values().stream() .filter(c -> nodes.contains(c.getHostname())) .map(c -> c.getAllInterfaces().values()) .flatMap(Collection::stream) .filter(iface -> iface.getName().equalsIgnoreCase(_name)) .map(NodeInterfacePair::of) .collect(ImmutableSet.toImmutableSet()); } NameInterfaceSpecifier(String name); @Override boolean equals(@Nullable Object o); @Override int hashCode(); @Override Set<NodeInterfacePair> resolve(Set<String> nodes, SpecifierContext ctxt); }
NameInterfaceSpecifier implements InterfaceSpecifier { @Override public Set<NodeInterfacePair> resolve(Set<String> nodes, SpecifierContext ctxt) { return ctxt.getConfigs().values().stream() .filter(c -> nodes.contains(c.getHostname())) .map(c -> c.getAllInterfaces().values()) .flatMap(Collection::stream) .filter(iface -> iface.getName().equalsIgnoreCase(_name)) .map(NodeInterfacePair::of) .collect(ImmutableSet.toImmutableSet()); } NameInterfaceSpecifier(String name); @Override boolean equals(@Nullable Object o); @Override int hashCode(); @Override Set<NodeInterfacePair> resolve(Set<String> nodes, SpecifierContext ctxt);  }