/** * 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(); }
@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()); } }
.put(COL_INTERFACE, new NodeInterfacePair(nodeName, iface.getName())); for (String property : propertySpecifier.getMatchingProperties()) { PropertyDescriptor<Interface> propertyDescriptor = InterfacePropertySpecifier.JAVA_MAP.get(property);