@Test public void testAnswererParseErrorNoContext() { String file = "configs/nodeError.cfg"; String message = "Exception message"; ParseVendorConfigurationAnswerElement pvcae = new ParseVendorConfigurationAnswerElement(); pvcae.setWarnings(ImmutableSortedMap.of(file, new Warnings())); pvcae.getErrorDetails().put(file, new ErrorDetails(message)); TestBatfishBase batfish = new TestBatfishBase(pvcae, null); InitIssuesAnswerer answerer = new InitIssuesAnswerer(new InitIssuesQuestion(), batfish); TableAnswerElement answer = answerer.answer(batfish.getSnapshot()); assertThat( answer.getRows(), equalTo( new Rows() .add( Row.of( COL_NODES, null, COL_FILELINES, ImmutableList.of(new FileLines(file, ImmutableSortedSet.of())), COL_TYPE, IssueType.ParseError.toString(), COL_DETAILS, message, COL_LINE_TEXT, null, COL_PARSER_CONTEXT, null)))); }
@Override public TableAnswerElement answer(NetworkSnapshot snapshot) { ConvertConfigurationAnswerElement ccae = _batfish.loadConvertConfigurationAnswerElementOrReparse(snapshot); ParseVendorConfigurationAnswerElement pvcae = _batfish.loadParseVendorConfigurationAnswerElement(snapshot); Rows rows = new Rows(); Map<String, Warnings> convertWarnings = ccae.getWarnings(); aggregateDuplicateWarnings(convertWarnings, Warnings::getRedFlagWarnings) .forEach( (warning, nodes) -> rows.add(getRow(nodes, null, IssueType.ConvertWarningRedFlag, warning.getText()))); aggregateDuplicateWarnings(convertWarnings, Warnings::getUnimplementedWarnings) .forEach( (warning, nodes) -> rows.add( getRow(nodes, null, IssueType.ConvertWarningUnimplemented, warning.getText()))); Map<String, Warnings> fileWarnings = pvcae.getWarnings(); aggregateDuplicateParseWarnings(fileWarnings) .forEach( (triplet, fileLines) -> rows.add( getRow( null, fileLines.asMap().entrySet().stream() .map( e -> new FileLines( e.getKey(), ImmutableSortedSet.copyOf(e.getValue()))) .collect(ImmutableList.toImmutableList()), IssueType.ParseWarning, firstNonNull(triplet._comment, "(details not provided)"), triplet._text, triplet._parserContext))); aggregateDuplicateWarnings(fileWarnings, Warnings::getRedFlagWarnings) .forEach( (warning, filenames) -> rows.add( getRow( null, filenamesToFileLines(filenames), IssueType.ParseWarningRedFlag, warning.getText()))); aggregateDuplicateWarnings(fileWarnings, Warnings::getUnimplementedWarnings) .forEach( (warning, filenames) -> rows.add( getRow( null, filenamesToFileLines(filenames), IssueType.ParseWarningUnimplemented, warning.getText()))); for (Entry<ParseStatus, Set<String>> entry : aggregateParseStatuses(pvcae.getParseStatus()).entrySet()) { ParseStatus status = entry.getKey(); switch (status) { case PASSED: case IGNORED: continue; case FAILED: case PARTIALLY_UNRECOGNIZED: continue; case WILL_NOT_COMMIT: default: rows.add( getRow( null, filenamesToFileLines(entry.getValue()), IssueType.ParseStatus, ParseStatus.explanation(status))); } } aggregateDuplicateErrors(ccae.getErrorDetails()) .forEach( (errorDetails, nodeNames) -> rows.add(getRow(nodeNames, null, IssueType.ConvertError, errorDetails._message))); aggregateDuplicateErrors(pvcae.getErrorDetails()) .forEach( (errorDetails, fileNames) -> rows.add( getRow( null, fileNames.stream() .map( name -> { ImmutableSortedSet<Integer> lines = ImmutableSortedSet.of(); ErrorDetails details = pvcae.getErrorDetails().get(name); if (details != null) { ParseExceptionContext context = details.getParseExceptionContext(); if (context != null && context.getLineNumber() != null) { lines = ImmutableSortedSet.of(context.getLineNumber()); } } return new FileLines(name, lines); }) .collect(ImmutableList.toImmutableList()), IssueType.ParseError, errorDetails._message, errorDetails._lineContent, errorDetails._parserContext))); TableAnswerElement answerElement = new TableAnswerElement(TABLE_METADATA); answerElement.postProcessAnswer(_question, rows.getData()); return answerElement; }
InitIssuesAnswerer extends Answerer { @Override public TableAnswerElement answer(NetworkSnapshot snapshot) { ConvertConfigurationAnswerElement ccae = _batfish.loadConvertConfigurationAnswerElementOrReparse(snapshot); ParseVendorConfigurationAnswerElement pvcae = _batfish.loadParseVendorConfigurationAnswerElement(snapshot); Rows rows = new Rows(); Map<String, Warnings> convertWarnings = ccae.getWarnings(); aggregateDuplicateWarnings(convertWarnings, Warnings::getRedFlagWarnings) .forEach( (warning, nodes) -> rows.add(getRow(nodes, null, IssueType.ConvertWarningRedFlag, warning.getText()))); aggregateDuplicateWarnings(convertWarnings, Warnings::getUnimplementedWarnings) .forEach( (warning, nodes) -> rows.add( getRow(nodes, null, IssueType.ConvertWarningUnimplemented, warning.getText()))); Map<String, Warnings> fileWarnings = pvcae.getWarnings(); aggregateDuplicateParseWarnings(fileWarnings) .forEach( (triplet, fileLines) -> rows.add( getRow( null, fileLines.asMap().entrySet().stream() .map( e -> new FileLines( e.getKey(), ImmutableSortedSet.copyOf(e.getValue()))) .collect(ImmutableList.toImmutableList()), IssueType.ParseWarning, firstNonNull(triplet._comment, "(details not provided)"), triplet._text, triplet._parserContext))); aggregateDuplicateWarnings(fileWarnings, Warnings::getRedFlagWarnings) .forEach( (warning, filenames) -> rows.add( getRow( null, filenamesToFileLines(filenames), IssueType.ParseWarningRedFlag, warning.getText()))); aggregateDuplicateWarnings(fileWarnings, Warnings::getUnimplementedWarnings) .forEach( (warning, filenames) -> rows.add( getRow( null, filenamesToFileLines(filenames), IssueType.ParseWarningUnimplemented, warning.getText()))); for (Entry<ParseStatus, Set<String>> entry : aggregateParseStatuses(pvcae.getParseStatus()).entrySet()) { ParseStatus status = entry.getKey(); switch (status) { case PASSED: case IGNORED: continue; case FAILED: case PARTIALLY_UNRECOGNIZED: continue; case WILL_NOT_COMMIT: default: rows.add( getRow( null, filenamesToFileLines(entry.getValue()), IssueType.ParseStatus, ParseStatus.explanation(status))); } } aggregateDuplicateErrors(ccae.getErrorDetails()) .forEach( (errorDetails, nodeNames) -> rows.add(getRow(nodeNames, null, IssueType.ConvertError, errorDetails._message))); aggregateDuplicateErrors(pvcae.getErrorDetails()) .forEach( (errorDetails, fileNames) -> rows.add( getRow( null, fileNames.stream() .map( name -> { ImmutableSortedSet<Integer> lines = ImmutableSortedSet.of(); ErrorDetails details = pvcae.getErrorDetails().get(name); if (details != null) { ParseExceptionContext context = details.getParseExceptionContext(); if (context != null && context.getLineNumber() != null) { lines = ImmutableSortedSet.of(context.getLineNumber()); } } return new FileLines(name, lines); }) .collect(ImmutableList.toImmutableList()), IssueType.ParseError, errorDetails._message, errorDetails._lineContent, errorDetails._parserContext))); TableAnswerElement answerElement = new TableAnswerElement(TABLE_METADATA); answerElement.postProcessAnswer(_question, rows.getData()); return answerElement; } }
InitIssuesAnswerer extends Answerer { @Override public TableAnswerElement answer(NetworkSnapshot snapshot) { ConvertConfigurationAnswerElement ccae = _batfish.loadConvertConfigurationAnswerElementOrReparse(snapshot); ParseVendorConfigurationAnswerElement pvcae = _batfish.loadParseVendorConfigurationAnswerElement(snapshot); Rows rows = new Rows(); Map<String, Warnings> convertWarnings = ccae.getWarnings(); aggregateDuplicateWarnings(convertWarnings, Warnings::getRedFlagWarnings) .forEach( (warning, nodes) -> rows.add(getRow(nodes, null, IssueType.ConvertWarningRedFlag, warning.getText()))); aggregateDuplicateWarnings(convertWarnings, Warnings::getUnimplementedWarnings) .forEach( (warning, nodes) -> rows.add( getRow(nodes, null, IssueType.ConvertWarningUnimplemented, warning.getText()))); Map<String, Warnings> fileWarnings = pvcae.getWarnings(); aggregateDuplicateParseWarnings(fileWarnings) .forEach( (triplet, fileLines) -> rows.add( getRow( null, fileLines.asMap().entrySet().stream() .map( e -> new FileLines( e.getKey(), ImmutableSortedSet.copyOf(e.getValue()))) .collect(ImmutableList.toImmutableList()), IssueType.ParseWarning, firstNonNull(triplet._comment, "(details not provided)"), triplet._text, triplet._parserContext))); aggregateDuplicateWarnings(fileWarnings, Warnings::getRedFlagWarnings) .forEach( (warning, filenames) -> rows.add( getRow( null, filenamesToFileLines(filenames), IssueType.ParseWarningRedFlag, warning.getText()))); aggregateDuplicateWarnings(fileWarnings, Warnings::getUnimplementedWarnings) .forEach( (warning, filenames) -> rows.add( getRow( null, filenamesToFileLines(filenames), IssueType.ParseWarningUnimplemented, warning.getText()))); for (Entry<ParseStatus, Set<String>> entry : aggregateParseStatuses(pvcae.getParseStatus()).entrySet()) { ParseStatus status = entry.getKey(); switch (status) { case PASSED: case IGNORED: continue; case FAILED: case PARTIALLY_UNRECOGNIZED: continue; case WILL_NOT_COMMIT: default: rows.add( getRow( null, filenamesToFileLines(entry.getValue()), IssueType.ParseStatus, ParseStatus.explanation(status))); } } aggregateDuplicateErrors(ccae.getErrorDetails()) .forEach( (errorDetails, nodeNames) -> rows.add(getRow(nodeNames, null, IssueType.ConvertError, errorDetails._message))); aggregateDuplicateErrors(pvcae.getErrorDetails()) .forEach( (errorDetails, fileNames) -> rows.add( getRow( null, fileNames.stream() .map( name -> { ImmutableSortedSet<Integer> lines = ImmutableSortedSet.of(); ErrorDetails details = pvcae.getErrorDetails().get(name); if (details != null) { ParseExceptionContext context = details.getParseExceptionContext(); if (context != null && context.getLineNumber() != null) { lines = ImmutableSortedSet.of(context.getLineNumber()); } } return new FileLines(name, lines); }) .collect(ImmutableList.toImmutableList()), IssueType.ParseError, errorDetails._message, errorDetails._lineContent, errorDetails._parserContext))); TableAnswerElement answerElement = new TableAnswerElement(TABLE_METADATA); answerElement.postProcessAnswer(_question, rows.getData()); return answerElement; } InitIssuesAnswerer(InitIssuesQuestion question, IBatfish batfish); }
InitIssuesAnswerer extends Answerer { @Override public TableAnswerElement answer(NetworkSnapshot snapshot) { ConvertConfigurationAnswerElement ccae = _batfish.loadConvertConfigurationAnswerElementOrReparse(snapshot); ParseVendorConfigurationAnswerElement pvcae = _batfish.loadParseVendorConfigurationAnswerElement(snapshot); Rows rows = new Rows(); Map<String, Warnings> convertWarnings = ccae.getWarnings(); aggregateDuplicateWarnings(convertWarnings, Warnings::getRedFlagWarnings) .forEach( (warning, nodes) -> rows.add(getRow(nodes, null, IssueType.ConvertWarningRedFlag, warning.getText()))); aggregateDuplicateWarnings(convertWarnings, Warnings::getUnimplementedWarnings) .forEach( (warning, nodes) -> rows.add( getRow(nodes, null, IssueType.ConvertWarningUnimplemented, warning.getText()))); Map<String, Warnings> fileWarnings = pvcae.getWarnings(); aggregateDuplicateParseWarnings(fileWarnings) .forEach( (triplet, fileLines) -> rows.add( getRow( null, fileLines.asMap().entrySet().stream() .map( e -> new FileLines( e.getKey(), ImmutableSortedSet.copyOf(e.getValue()))) .collect(ImmutableList.toImmutableList()), IssueType.ParseWarning, firstNonNull(triplet._comment, "(details not provided)"), triplet._text, triplet._parserContext))); aggregateDuplicateWarnings(fileWarnings, Warnings::getRedFlagWarnings) .forEach( (warning, filenames) -> rows.add( getRow( null, filenamesToFileLines(filenames), IssueType.ParseWarningRedFlag, warning.getText()))); aggregateDuplicateWarnings(fileWarnings, Warnings::getUnimplementedWarnings) .forEach( (warning, filenames) -> rows.add( getRow( null, filenamesToFileLines(filenames), IssueType.ParseWarningUnimplemented, warning.getText()))); for (Entry<ParseStatus, Set<String>> entry : aggregateParseStatuses(pvcae.getParseStatus()).entrySet()) { ParseStatus status = entry.getKey(); switch (status) { case PASSED: case IGNORED: continue; case FAILED: case PARTIALLY_UNRECOGNIZED: continue; case WILL_NOT_COMMIT: default: rows.add( getRow( null, filenamesToFileLines(entry.getValue()), IssueType.ParseStatus, ParseStatus.explanation(status))); } } aggregateDuplicateErrors(ccae.getErrorDetails()) .forEach( (errorDetails, nodeNames) -> rows.add(getRow(nodeNames, null, IssueType.ConvertError, errorDetails._message))); aggregateDuplicateErrors(pvcae.getErrorDetails()) .forEach( (errorDetails, fileNames) -> rows.add( getRow( null, fileNames.stream() .map( name -> { ImmutableSortedSet<Integer> lines = ImmutableSortedSet.of(); ErrorDetails details = pvcae.getErrorDetails().get(name); if (details != null) { ParseExceptionContext context = details.getParseExceptionContext(); if (context != null && context.getLineNumber() != null) { lines = ImmutableSortedSet.of(context.getLineNumber()); } } return new FileLines(name, lines); }) .collect(ImmutableList.toImmutableList()), IssueType.ParseError, errorDetails._message, errorDetails._lineContent, errorDetails._parserContext))); TableAnswerElement answerElement = new TableAnswerElement(TABLE_METADATA); answerElement.postProcessAnswer(_question, rows.getData()); return answerElement; } InitIssuesAnswerer(InitIssuesQuestion question, IBatfish batfish); @Override TableAnswerElement answer(NetworkSnapshot snapshot); }
InitIssuesAnswerer extends Answerer { @Override public TableAnswerElement answer(NetworkSnapshot snapshot) { ConvertConfigurationAnswerElement ccae = _batfish.loadConvertConfigurationAnswerElementOrReparse(snapshot); ParseVendorConfigurationAnswerElement pvcae = _batfish.loadParseVendorConfigurationAnswerElement(snapshot); Rows rows = new Rows(); Map<String, Warnings> convertWarnings = ccae.getWarnings(); aggregateDuplicateWarnings(convertWarnings, Warnings::getRedFlagWarnings) .forEach( (warning, nodes) -> rows.add(getRow(nodes, null, IssueType.ConvertWarningRedFlag, warning.getText()))); aggregateDuplicateWarnings(convertWarnings, Warnings::getUnimplementedWarnings) .forEach( (warning, nodes) -> rows.add( getRow(nodes, null, IssueType.ConvertWarningUnimplemented, warning.getText()))); Map<String, Warnings> fileWarnings = pvcae.getWarnings(); aggregateDuplicateParseWarnings(fileWarnings) .forEach( (triplet, fileLines) -> rows.add( getRow( null, fileLines.asMap().entrySet().stream() .map( e -> new FileLines( e.getKey(), ImmutableSortedSet.copyOf(e.getValue()))) .collect(ImmutableList.toImmutableList()), IssueType.ParseWarning, firstNonNull(triplet._comment, "(details not provided)"), triplet._text, triplet._parserContext))); aggregateDuplicateWarnings(fileWarnings, Warnings::getRedFlagWarnings) .forEach( (warning, filenames) -> rows.add( getRow( null, filenamesToFileLines(filenames), IssueType.ParseWarningRedFlag, warning.getText()))); aggregateDuplicateWarnings(fileWarnings, Warnings::getUnimplementedWarnings) .forEach( (warning, filenames) -> rows.add( getRow( null, filenamesToFileLines(filenames), IssueType.ParseWarningUnimplemented, warning.getText()))); for (Entry<ParseStatus, Set<String>> entry : aggregateParseStatuses(pvcae.getParseStatus()).entrySet()) { ParseStatus status = entry.getKey(); switch (status) { case PASSED: case IGNORED: continue; case FAILED: case PARTIALLY_UNRECOGNIZED: continue; case WILL_NOT_COMMIT: default: rows.add( getRow( null, filenamesToFileLines(entry.getValue()), IssueType.ParseStatus, ParseStatus.explanation(status))); } } aggregateDuplicateErrors(ccae.getErrorDetails()) .forEach( (errorDetails, nodeNames) -> rows.add(getRow(nodeNames, null, IssueType.ConvertError, errorDetails._message))); aggregateDuplicateErrors(pvcae.getErrorDetails()) .forEach( (errorDetails, fileNames) -> rows.add( getRow( null, fileNames.stream() .map( name -> { ImmutableSortedSet<Integer> lines = ImmutableSortedSet.of(); ErrorDetails details = pvcae.getErrorDetails().get(name); if (details != null) { ParseExceptionContext context = details.getParseExceptionContext(); if (context != null && context.getLineNumber() != null) { lines = ImmutableSortedSet.of(context.getLineNumber()); } } return new FileLines(name, lines); }) .collect(ImmutableList.toImmutableList()), IssueType.ParseError, errorDetails._message, errorDetails._lineContent, errorDetails._parserContext))); TableAnswerElement answerElement = new TableAnswerElement(TABLE_METADATA); answerElement.postProcessAnswer(_question, rows.getData()); return answerElement; } InitIssuesAnswerer(InitIssuesQuestion question, IBatfish batfish); @Override TableAnswerElement answer(NetworkSnapshot snapshot);  }