private static Row toRow(BidirectionalTrace trace) { return Row.of( COL_FORWARD_FLOW, trace.getForwardFlow(), COL_FORWARD_TRACE, trace.getForwardTrace(), COL_REVERSE_FLOW, trace.getReverseFlow(), COL_REVERSE_TRACE, trace.getReverseTrace()); } }
@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; }
@Test public void testApplyRowIssuesConfigurationNonIssue() { String col = "col"; Row oldRow = Row.of(col, "foo"); Set<String> issueColumns = ImmutableSet.of(); Map<String, MajorIssueConfig> issueConfigs = ImmutableMap.of(); assertThat( _manager.applyRowIssuesConfiguration(oldRow, issueColumns, issueConfigs), equalTo(oldRow)); }
@Test public void testGetRowWithoutHost() { Row expected = Row.of(COL_FILENAME, "nohost", COL_PARSE_STATUS, "FAILED", COL_NODES, ImmutableList.of()); Row row = FileParseStatusAnswerer.getRow("nohost", ParseStatus.FAILED, null); assertThat(row, equalTo(expected)); }
@Test public void testColumnComparatorBoolean() { String col = "col1"; ColumnMetadata columnMetadata = new ColumnMetadata(col, Schema.BOOLEAN, "colDesc"); Comparator<Row> comparator = _manager.columnComparator(columnMetadata); Row r1 = Row.of(col, false); Row r2 = Row.of(col, true); assertThat(comparator.compare(r1, r2), lessThan(0)); }
@Test public void testColumnComparatorInteger() { String col = "col1"; ColumnMetadata columnMetadata = new ColumnMetadata(col, Schema.INTEGER, "colDesc"); Comparator<Row> comparator = _manager.columnComparator(columnMetadata); Row r1 = Row.of(col, 0); Row r2 = Row.of(col, 1); assertThat(comparator.compare(r1, r2), lessThan(0)); }
@Test public void testColumnComparatorString() { String col = "col1"; ColumnMetadata columnMetadata = new ColumnMetadata(col, Schema.STRING, "colDesc"); Comparator<Row> comparator = _manager.columnComparator(columnMetadata); Row r1 = Row.of(col, "a"); Row r2 = Row.of(col, "b"); assertThat(comparator.compare(r1, r2), lessThan(0)); }
@Test public void testColumnComparatorIp() { String col = "col1"; ColumnMetadata columnMetadata = new ColumnMetadata(col, Schema.IP, "colDesc"); Comparator<Row> comparator = _manager.columnComparator(columnMetadata); Row r1 = Row.of(col, Ip.ZERO); Row r2 = Row.of(col, Ip.MAX); assertThat(comparator.compare(r1, r2), lessThan(0)); }
@Test public void testColumnComparatorLong() { String col = "col1"; ColumnMetadata columnMetadata = new ColumnMetadata(col, Schema.LONG, "colDesc"); Comparator<Row> comparator = _manager.columnComparator(columnMetadata); Row r1 = Row.of(col, 0L); Row r2 = Row.of(col, 1L); Row r3 = Row.of(col, Long.MAX_VALUE); assertThat(comparator.compare(r1, r2), lessThan(0)); assertThat(comparator.compare(r1, r3), lessThan(0)); assertThat(comparator.compare(r2, r3), lessThan(0)); }
@Test public void ofTyped() { assertThat( Row.of(ImmutableMap.of("a", new ColumnMetadata("a", Schema.INTEGER, "desc")), "a", 5), equalTo(Row.builder().put("a", 5).build())); _thrown.expect(IllegalArgumentException.class); _thrown.expectMessage("Column 'b' is not present"); Row.of(ImmutableMap.of("a", new ColumnMetadata("a", Schema.INTEGER, "desc")), "b", 5); } }
@Test public void ofUntyped() { assertThat(Row.of("a", 5), equalTo(Row.builder().put("a", 5).build())); }
@Test public void testColumnComparatorInterface() { String col = "col1"; ColumnMetadata columnMetadata = new ColumnMetadata(col, Schema.INTERFACE, "colDesc"); Comparator<Row> comparator = _manager.columnComparator(columnMetadata); Row r1 = Row.of(col, new NodeInterfacePair("a", "a")); Row r2 = Row.of(col, new NodeInterfacePair("a", "b")); Row r3 = Row.of(col, new NodeInterfacePair("b", "a")); assertThat(comparator.compare(r1, r2), lessThan(0)); assertThat(comparator.compare(r1, r3), lessThan(0)); assertThat(comparator.compare(r2, r3), lessThan(0)); }
@Test public void testColumnComparatorSelfDescribingObject() { String col = "col1"; ColumnMetadata columnMetadata = new ColumnMetadata(col, Schema.SELF_DESCRIBING, "colDesc"); Comparator<Row> comparator = _manager.columnComparator(columnMetadata); Row r1 = Row.of(col, new SelfDescribingObject(Schema.STRING, "a")); Row r2 = Row.of(col, new SelfDescribingObject(Schema.STRING, "b")); assertThat(comparator.compare(r1, r2), lessThan(0)); }
@Test public void testColumnComparatorNode() { String col = "col1"; ColumnMetadata columnMetadata = new ColumnMetadata(col, Schema.NODE, "colDesc"); Comparator<Row> comparator = _manager.columnComparator(columnMetadata); Row r1 = Row.of(col, new Node("a")); Row r2 = Row.of(col, new Node("b")); assertThat(comparator.compare(r1, r2), lessThan(0)); }
@Test public void testColumnComparatorAclTrace() { String col = "col1"; ColumnMetadata columnMetadata = new ColumnMetadata(col, Schema.ACL_TRACE, "colDesc"); Comparator<Row> comparator = _manager.columnComparator(columnMetadata); Row r1 = Row.of(col, new AclTrace(ImmutableList.of(new DefaultDeniedByIpAccessList("a", "a", "a")))); Row r2 = Row.of(col, new AclTrace(ImmutableList.of(new DefaultDeniedByIpAccessList("b", "b", "b")))); assertThat(comparator.compare(r1, r2), lessThan(0)); }
@Test public void testComputeMajorIssueTypesNoColumn() { String columnName = "col"; String value = "foo"; TableAnswerElement table = new TableAnswerElement( new TableMetadata( ImmutableList.of(new ColumnMetadata(columnName, Schema.STRING, "foobar")), new DisplayHints().getTextDesc())) .addRow(Row.of(columnName, value)); assertThat(AnswerMetadataUtil.computeMajorIssueConfigs(table), equalTo(ImmutableMap.of())); }
@Test public void testColumnComparatorFlow() { String col = "col1"; ColumnMetadata columnMetadata = new ColumnMetadata(col, Schema.FLOW, "colDesc"); Comparator<Row> comparator = _manager.columnComparator(columnMetadata); Row r1 = Row.of(col, Flow.builder().setDstIp(Ip.ZERO).setIngressNode("a").setTag("a").build()); Row r2 = Row.of(col, Flow.builder().setDstIp(Ip.MAX).setIngressNode("a").setTag("a").build()); assertThat(comparator.compare(r1, r2), lessThan(0)); }
@Test public void testComputeColumnMaxNullInteger() { String columnName = "col"; TableAnswerElement table = new TableAnswerElement( new TableMetadata( ImmutableList.of(new ColumnMetadata(columnName, Schema.INTEGER, "foobar")), new DisplayHints().getTextDesc())) .addRow(Row.of(columnName, null)); assertThat(AnswerMetadataUtil.computeColumnMax(table, columnName, _logger), nullValue()); }
@Test public void testComputeColumnMaxInvalidSchema() { String columnName = "col"; String value = "hello"; TableAnswerElement table = new TableAnswerElement( new TableMetadata( ImmutableList.of(new ColumnMetadata(columnName, Schema.STRING, "foobar")), new DisplayHints().getTextDesc())) .addRow(Row.of(columnName, value)); assertThat(AnswerMetadataUtil.computeColumnMax(table, columnName, _logger), nullValue()); }
@Test public void testComputeColumnMaxOneRowInteger() { String columnName = "col"; int value = 5; TableAnswerElement table = new TableAnswerElement( new TableMetadata( ImmutableList.of(new ColumnMetadata(columnName, Schema.INTEGER, "foobar")), new DisplayHints().getTextDesc())) .addRow(Row.of(columnName, value)); assertThat(AnswerMetadataUtil.computeColumnMax(table, columnName, _logger), equalTo(value)); }