/** Computes the summary of this table, given the assertion */ public AnswerSummary computeSummary(Assertion assertion) { String notes = "Found " + _rows.size() + " results"; return computeSummary(assertion, notes); }
/** * Given an initial set of rows produced by an {@link org.batfish.common.Answerer}, this procedure * processes exclusions, assertions, and summary to update this object. * * @param question The question that generated the initial set of rows * @param initialSet The initial set of rows */ public void postProcessAnswer(Question question, Iterable<Row> initialSet) { initialSet.forEach( initialRow -> { // exclude or not? Exclusion exclusion = Exclusion.covered(initialRow, question.getExclusions()); if (exclusion != null) { addExcludedRow(initialRow, exclusion.getName()); } else { addRow(initialRow); } }); setSummary(computeSummary(question.getAssertion())); }
@Override public TableAnswerElement answer() { AaaAuthenticationLoginQuestion question = (AaaAuthenticationLoginQuestion) _question; TableAnswerElement answerElement = create(question); Set<String> specifiedNodes = question.getNodes().getMatchingNodes(_batfish); SortedMap<String, Configuration> configs = _batfish.loadConfigurations(); configs.forEach( (configName, config) -> { if (specifiedNodes.contains(configName)) { Row row = null; if (config.getVendorFamily().getCisco() != null) { row = getRow(configName, config.getVendorFamily().getCisco().getLines().values()); } else if (config.getVendorFamily().getJuniper() != null) { row = getRow(configName, config.getVendorFamily().getJuniper().getLines().values()); } if (row != null) { answerElement.addRow(row); } } }); answerElement.setSummary(answerElement.computeSummary(question.getAssertion())); return answerElement; }
/** Does computerSummary compute the correct summary? */ @Test public void testComputeSummary() { // generate an answer with two rows TableAnswerElement answer = new TableAnswerElement( new TableMetadata( ImmutableList.of(new ColumnMetadata("col", Schema.STRING, "desc")), "no desc")); answer.addRow(Row.builder().put("col", "val").build()); answer.addRow(Row.builder().put("col", "val").build()); Assertion assertion = new Assertion(AssertionType.countequals, new IntNode(1)); // wrong count AnswerSummary summary = answer.computeSummary(assertion); assertThat(summary.getNumResults(), equalTo(2)); assertThat(summary.getNumFailed(), equalTo(1)); assertThat(summary.getNumPassed(), equalTo(0)); }
answer.setSummary(answer.computeSummary(question.getAssertion()));