@Test public void getMatchingProperties() { // match everything assertThat( new InterfacePropertySpecifier(".*").getMatchingProperties().size(), equalTo(InterfacePropertySpecifier.JAVA_MAP.size())); // match the description assertThat(new InterfacePropertySpecifier("desc.*").getMatchingProperties().size(), equalTo(1)); // match nothing: ntp assertTrue(new InterfacePropertySpecifier("ntp").getMatchingProperties().isEmpty()); }
@Test public void testMatchingPropertiesSet() { Iterator<String> i = InterfacePropertySpecifier.JAVA_MAP.keySet().iterator(); String prop1 = i.next(); String prop2 = i.next(); Collection<String> firstTwoProperties = ImmutableList.of(prop1, prop2); // should match the two properties passed to constructor assertThat( new InterfacePropertySpecifier(firstTwoProperties).getMatchingProperties(), hasSize(2)); Collection<String> longer = ImmutableList.of(prop1 + prop1); // should not match longer assertThat(new InterfacePropertySpecifier(longer).getMatchingProperties(), emptyIterable()); Collection<String> shorter = ImmutableList.of(prop1.substring(0, 1)); // should not match shorter assertThat(new InterfacePropertySpecifier(shorter).getMatchingProperties(), emptyIterable()); } }
private @Nonnull Multiset<Row> getRows(String property) { InterfacePropertySpecifier propertySpecifier = new InterfacePropertySpecifier(property); return InterfacePropertiesAnswerer.getProperties( propertySpecifier, ImmutableMap.of(HOSTNAME, _c), ImmutableSet.of(HOSTNAME), new InterfacesSpecifier(INTERFACE_NAME), new TableMetadata( InterfacePropertiesAnswerer.createColumnMetadata(propertySpecifier), (String) null) .toColumnMap()); }
String.format("A Batfish %s must be a JSON string", expectedType.getName())); new InterfacePropertySpecifier(value.textValue()); break; case INTERFACES_SPEC:
@Test public void getPropertiesExcludeShutInterfaces() { Configuration conf = new Configuration("node", ConfigurationFormat.CISCO_IOS); Interface active = Interface.builder().setName("active").setOwner(conf).setActive(true).build(); Interface shut = Interface.builder().setName("shut").setOwner(conf).setActive(false).build(); conf.getAllInterfaces().putAll(ImmutableMap.of("active", active, "shut", shut)); String property = InterfacePropertySpecifier.DESCRIPTION; InterfacePropertySpecifier propertySpecifier = new InterfacePropertySpecifier(property); Multiset<Row> propertyRows = InterfacePropertiesAnswerer.getProperties( propertySpecifier, ImmutableMap.of("node", conf), ImmutableSet.of("node"), InterfacesSpecifier.ALL, true, new TableMetadata( InterfacePropertiesAnswerer.createColumnMetadata(propertySpecifier), (String) null) .toColumnMap()); // we should have exactly one row; iface1 should have been filtered out assertThat(propertyRows, hasSize(1)); assertThat( propertyRows.iterator().next(), hasColumn( InterfacePropertiesAnswerer.COL_INTERFACE, equalTo(new NodeInterfacePair("node", "active")), Schema.INTERFACE)); }
String property2 = InterfacePropertySpecifier.ACTIVE; InterfacePropertySpecifier propertySpecifier = new InterfacePropertySpecifier(property1 + "|" + property2);