@Test public void testGetLocationSpecifier_defaultFactory() { LocationSpecifier locationSpecifier = new SpecifiersQuestion(QueryType.LOCATION).getLocationSpecifier(); assertThat(locationSpecifier, equalTo(AllInterfacesLocationSpecifier.INSTANCE)); }
@VisibleForTesting static TableAnswerElement resolveLocation(SpecifiersQuestion question, SpecifierContext context) { List<ColumnMetadata> columns = ImmutableList.of(new ColumnMetadata(COL_LOCATION, Schema.STRING, "Location", false, false)); TableAnswerElement table = new TableAnswerElement(new TableMetadata(columns)); Map<String, ColumnMetadata> columnMap = table.getMetadata().toColumnMap(); Set<Location> locations = question.getLocationSpecifier().resolve(context); for (Location location : locations) { table.addRow(Row.of(columnMap, COL_LOCATION, location.toString())); } return table; }
@VisibleForTesting static TableAnswerElement resolveIpSpace(SpecifiersQuestion question, SpecifierContext context) { List<ColumnMetadata> columns = ImmutableList.of(new ColumnMetadata(COL_IP_SPACE, Schema.STRING, "IP space", false, false)); TableAnswerElement table = new TableAnswerElement(new TableMetadata(columns)); Map<String, ColumnMetadata> columnMap = table.getMetadata().toColumnMap(); // this will yield all default locations for the factory Set<Location> locations = question.getLocationSpecifier().resolve(context); IpSpaceAssignment ipSpaceAssignment = question.getIpSpaceSpecifier().resolve(locations, context); for (IpSpaceAssignment.Entry entry : ipSpaceAssignment.getEntries()) { table.addRow(Row.of(columnMap, COL_IP_SPACE, Objects.toString(entry.getIpSpace()))); } return table; }
@VisibleForTesting static TableAnswerElement resolveIpSpaceOfLocation( SpecifiersQuestion question, SpecifierContext context) { List<ColumnMetadata> columns = ImmutableList.of( new ColumnMetadata(COL_LOCATIONS, Schema.STRING, "Resolution", false, false), new ColumnMetadata(COL_IP_SPACE, Schema.STRING, "IP space", false, false)); TableAnswerElement table = new TableAnswerElement(new TableMetadata(columns)); Map<String, ColumnMetadata> columnMap = table.getMetadata().toColumnMap(); Set<Location> locations = question.getLocationSpecifier().resolve(context); IpSpaceAssignment ipSpaceAssignment = question.getIpSpaceSpecifier().resolve(locations, context); for (IpSpaceAssignment.Entry entry : ipSpaceAssignment.getEntries()) { table.addRow( Row.of( columnMap, COL_LOCATIONS, entry.getLocations().toString(), COL_IP_SPACE, Objects.toString(entry.getIpSpace()))); } return table; }
@Test public void testGetLocationSpecifier_inputWithoutFactory() { exception.expect(NullPointerException.class); SpecifiersQuestion question = new SpecifiersQuestion(QueryType.LOCATION); question.setLocationSpecifierFactory(null); question.setLocationSpecifierInput("foo"); question.getLocationSpecifier(); } }