/** * Returns a new {@link Row} with the given entries. * * <p>{@code objects} should be an even number of parameters, where the 0th and every even * parameter is a {@link String} representing the name of a column. */ public static Row of(Object... objects) { return builder().rowOf(objects); }
/** * Returns a new {@link Row} with the given entries. * * <p>{@code objects} should be an even number of parameters, where the 0th and every even * parameter is a {@link String} representing the name of a column. The columns names and the * actual objects (in odd parameters) must be compliant with the metadata map in {@code columns}. */ public static Row of(Map<String, ColumnMetadata> columns, Object... objects) { return builder(columns).rowOf(objects); }
@VisibleForTesting static Row getOspfEdgeRow(String node, String iface, String remoteNode, String remoteIface) { RowBuilder row = Row.builder(); row.put(COL_INTERFACE, new NodeInterfacePair(node, iface)) .put(COL_REMOTE_INTERFACE, new NodeInterfacePair(remoteNode, remoteIface)); return row.build(); }
/** Adds {@code nodes} (which are present in only one snapshot) to the {@code table} */ private void addOneSnapshotNodes(SetView<String> nodes, TableAnswerElement table) { for (String node : nodes) { table.addRow(Row.builder(table.getMetadata().toColumnMap()).put(COL_NODE, node).build()); } } }
@Test public void fillPropertyNull() { Configuration configuration = new Configuration("hostname", ConfigurationFormat.CISCO_IOS); String property = NodePropertySpecifier.NTP_SOURCE_INTERFACE; PropertyDescriptor<Configuration> propertyDescriptor = NodePropertySpecifier.JAVA_MAP.get(property); RowBuilder row = Row.builder(); PropertySpecifier.fillProperty(propertyDescriptor, configuration, property, row); // the row should be filled out with null and the schemas shouldn't be assertThat(row.build(), equalTo(Row.builder().put(property, null).build())); } }
@Test public void fillInEmptyColumnsOnBuild() { Row row = Row.builder(ImmutableMap.of("col", new ColumnMetadata("col", Schema.INTEGER, "desc"))) .build(); assertThat(row.getColumnNames(), contains("col")); assertThat(row.hasNonNull("col"), equalTo(false)); } }
@Test public void testGetTypeReference() { String column = "col"; List<String> stringList = ImmutableList.of("a", "b"); Row row = Row.builder().put(column, stringList).build(); List<String> extracted = row.get(column, new TypeReference<List<String>>() {}); assertThat(stringList, equalTo(extracted)); }
@Test public void putNullValue() { TypedRowBuilder builder = Row.builder(ImmutableMap.of("col", new ColumnMetadata("col", Schema.INTEGER, "desc"))); // we should be able to put null Row row = builder.put("col", null).build(); assertThat(row.get("col", Schema.INTEGER), Matchers.is(nullValue())); }
@Test public void putBadColumn() { TypedRowBuilder builder = Row.builder(ImmutableMap.of("col", new ColumnMetadata("col", Schema.INTEGER, "desc"))); // we should not be able to put in a non-existent column _thrown.expect(IllegalArgumentException.class); _thrown.expectMessage("not present"); builder.put("badcol", 2); }
@Test public void rowOfArgumentsWrong() { _thrown.expect(IllegalArgumentException.class); _thrown.expectMessage("argument 2 must be a string, but is: 7"); Row.builder().rowOf("a", 5, 7, "b"); } }
@Test public void testAddRowMissingColumn() { TableAnswerElement table = new TableAnswerElement(twoKeyTableMetadata); Row row = Row.builder().put("key1", null).build(); _thrown.expect(IllegalArgumentException.class); _thrown.expectMessage( String.format( "Row columns %s do not match metadata columns metadata %s", row.getColumnNames(), twoKeyTableMetadata.toColumnMap().keySet())); table.addRow(row); }
@Test public void testComputeMajorIssueTypesNone() { String columnName = "col"; TableMetadata tableMetadata = new TableMetadata( ImmutableList.of(new ColumnMetadata(columnName, Schema.ISSUE, "foobar")), new DisplayHints().getTextDesc()); TableAnswerElement table = new TableAnswerElement(tableMetadata) .addRow(Row.builder(tableMetadata.toColumnMap()).build()); assertThat(AnswerMetadataUtil.computeMajorIssueConfigs(table), equalTo(ImmutableMap.of())); }
static Row isisEdgeToRow(IsisEdge isisEdge) { RowBuilder row = Row.builder(); row.put( COL_INTERFACE, new NodeInterfacePair( isisEdge.getNode1().getNode(), isisEdge.getNode1().getInterfaceName())) .put( COL_REMOTE_INTERFACE, new NodeInterfacePair( isisEdge.getNode2().getNode(), isisEdge.getNode2().getInterfaceName())); return row.build(); }
@Test public void testAddRowExtraColumn() { TableAnswerElement table = new TableAnswerElement(twoKeyTableMetadata); Row row = Row.builder().put("key1", null).put("key2", null).put("key3", null).build(); _thrown.expect(IllegalArgumentException.class); _thrown.expectMessage( String.format( "Row columns %s do not match metadata columns metadata %s", row.getColumnNames(), twoKeyTableMetadata.toColumnMap().keySet())); table.addRow(row); } }
@Test public void fillPropertyFail() { PropertyDescriptor<Configuration> propDescriptor = new PropertyDescriptor<>(null, Schema.list(Schema.STRING)); _thrown.expect(ClassCastException.class); _thrown.expectMessage("Cannot recover object"); PropertySpecifier.fillProperty("col", "stringNotList", Row.builder(), propDescriptor); }
@Test public void testMatches() { String columnName = "column"; String filterText = "bLah"; ColumnFilter filter = new ColumnFilter(columnName, filterText); Row row = Row.builder().put(columnName, "BlaHah").build(); assertTrue(filter.matches(row)); } }
@Test public void testAddValidRow() { TableAnswerElement table = new TableAnswerElement(twoKeyTableMetadata); Row row = Row.builder().put("key1", null).put("key2", null).build(); table.addRow(row); assertThat(table.getRows().getData(), contains(row)); }
@Test public void matchesDifferentTypes() { // throw an exception when objects are different types _thrown.expect(ClassCastException.class); _thrown.expectMessage("cannot be cast"); new Filter("col != true").matches(Row.builder().put("col", 42).build()); }