@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()); }
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()); }
/** * Creates {@link ColumnMetadata}s that the answer should have based on the {@code * propertySpecifier}. * * @param propertySpecifier The {@link InterfacePropertySpecifier} that describes the set of * properties * @return The {@link List} of {@link ColumnMetadata}s */ public static List<ColumnMetadata> createColumnMetadata( InterfacePropertySpecifier propertySpecifier) { return ImmutableList.<ColumnMetadata>builder() .add(new ColumnMetadata(COL_INTERFACE, Schema.INTERFACE, "Interface", true, false)) .addAll( propertySpecifier.getMatchingProperties().stream() .map( prop -> new ColumnMetadata( getColumnName(prop), InterfacePropertySpecifier.JAVA_MAP.get(prop).getSchema(), "Property " + prop, false, true)) .collect(Collectors.toList())) .build(); }
suggestions = InterfacePropertySpecifier.autoComplete(query); break;
String.format("A Batfish %s must be a JSON string", expectedType.getName())); new InterfacePropertySpecifier(value.textValue()); break; case INTERFACES_SPEC:
.put(COL_INTERFACE, new NodeInterfacePair(nodeName, iface.getName())); for (String property : propertySpecifier.getMatchingProperties()) { PropertyDescriptor<Interface> propertyDescriptor = InterfacePropertySpecifier.JAVA_MAP.get(property);
@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()); } }
@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);