@Test public void testApplyTo() { String filename = "file.cfg"; VendorConfiguration config = new CiscoConfiguration(); config.setHostname("hostname"); ParseTreeSentences parseTree = new ParseTreeSentences(); parseTree.setSentences(ImmutableList.of("test")); Warnings warnings = new Warnings(); warnings.getParseWarnings().add(new ParseWarning(1, "text", "context", null)); ParseVendorConfigurationResult result = new ParseVendorConfigurationResult( 0, new BatfishLoggerHistory(), filename, config, warnings, parseTree, ParseStatus.PASSED, HashMultimap.create()); SortedMap<String, VendorConfiguration> configs = new TreeMap<>(); ParseVendorConfigurationAnswerElement answerElement = new ParseVendorConfigurationAnswerElement(); result.applyTo(configs, new BatfishLogger("debug", false), answerElement); SortedMap<String, ParseTreeSentences> answerParseTrees = answerElement.getParseTrees(); SortedMap<String, Warnings> answerWarnings = answerElement.getWarnings(); assertThat(answerParseTrees, hasEntry(filename, parseTree)); assertThat(answerWarnings, hasEntry(filename, warnings)); }
@Override public void applyTo( Map<String, VendorConfiguration> vendorConfigurations, BatfishLogger logger, ParseVendorConfigurationAnswerElement answerElement) { appendHistory(logger); answerElement.getParseStatus().put(_filename, _status); if (_vc != null) { String hostname = _vc.getHostname(); if (vendorConfigurations.containsKey(hostname)) { VendorConfiguration oldVc = vendorConfigurations.get(hostname); String modifiedOldName = getModifiedName(hostname, oldVc.getFilename()); oldVc.setHostname(modifiedOldName); vendorConfigurations.remove(hostname); vendorConfigurations.put(modifiedOldName, oldVc); _duplicateHostnames.put(hostname, modifiedOldName); } if (_duplicateHostnames.containsKey(hostname)) { String modifiedNewName = getModifiedName(hostname, _vc.getFilename()); _warnings.redFlag( String.format("Duplicate hostname %s. Changed to %s", hostname, modifiedNewName)); _vc.setHostname(modifiedNewName); _duplicateHostnames.put(hostname, modifiedNewName); hostname = modifiedNewName; } vendorConfigurations.put(hostname, _vc); answerElement.getFileMap().put(hostname, _filename); if (!_warnings.isEmpty()) { answerElement.getWarnings().put(_filename, _warnings); } if (!_parseTree.isEmpty()) { answerElement.getParseTrees().put(_filename, _parseTree); } } else if (_status == ParseStatus.FAILED) { assert _failureCause != null; answerElement .getErrors() .put(_filename, ((BatfishException) _failureCause).getBatfishStackTrace()); ErrorDetails errorDetails = _warnings.getErrorDetails(); if (errorDetails != null) { answerElement.getErrorDetails().put(_filename, errorDetails); } else { answerElement .getErrorDetails() .put( _filename, new ErrorDetails( Throwables.getStackTraceAsString( firstNonNull(_failureCause.getCause(), _failureCause)))); } } }
ParseVendorConfigurationResult extends BatfishJobResult<
        Map<String, VendorConfiguration>, ParseVendorConfigurationAnswerElement> { @Override public void applyTo( Map<String, VendorConfiguration> vendorConfigurations, BatfishLogger logger, ParseVendorConfigurationAnswerElement answerElement) { appendHistory(logger); answerElement.getParseStatus().put(_filename, _status); if (_vc != null) { String hostname = _vc.getHostname(); if (vendorConfigurations.containsKey(hostname)) { VendorConfiguration oldVc = vendorConfigurations.get(hostname); String modifiedOldName = getModifiedName(hostname, oldVc.getFilename()); oldVc.setHostname(modifiedOldName); vendorConfigurations.remove(hostname); vendorConfigurations.put(modifiedOldName, oldVc); _duplicateHostnames.put(hostname, modifiedOldName); } if (_duplicateHostnames.containsKey(hostname)) { String modifiedNewName = getModifiedName(hostname, _vc.getFilename()); _warnings.redFlag( String.format("Duplicate hostname %s. Changed to %s", hostname, modifiedNewName)); _vc.setHostname(modifiedNewName); _duplicateHostnames.put(hostname, modifiedNewName); hostname = modifiedNewName; } vendorConfigurations.put(hostname, _vc); answerElement.getFileMap().put(hostname, _filename); if (!_warnings.isEmpty()) { answerElement.getWarnings().put(_filename, _warnings); } if (!_parseTree.isEmpty()) { answerElement.getParseTrees().put(_filename, _parseTree); } } else if (_status == ParseStatus.FAILED) { assert _failureCause != null; answerElement .getErrors() .put(_filename, ((BatfishException) _failureCause).getBatfishStackTrace()); ErrorDetails errorDetails = _warnings.getErrorDetails(); if (errorDetails != null) { answerElement.getErrorDetails().put(_filename, errorDetails); } else { answerElement .getErrorDetails() .put( _filename, new ErrorDetails( Throwables.getStackTraceAsString( firstNonNull(_failureCause.getCause(), _failureCause)))); } } } }
ParseVendorConfigurationResult extends BatfishJobResult<
        Map<String, VendorConfiguration>, ParseVendorConfigurationAnswerElement> { @Override public void applyTo( Map<String, VendorConfiguration> vendorConfigurations, BatfishLogger logger, ParseVendorConfigurationAnswerElement answerElement) { appendHistory(logger); answerElement.getParseStatus().put(_filename, _status); if (_vc != null) { String hostname = _vc.getHostname(); if (vendorConfigurations.containsKey(hostname)) { VendorConfiguration oldVc = vendorConfigurations.get(hostname); String modifiedOldName = getModifiedName(hostname, oldVc.getFilename()); oldVc.setHostname(modifiedOldName); vendorConfigurations.remove(hostname); vendorConfigurations.put(modifiedOldName, oldVc); _duplicateHostnames.put(hostname, modifiedOldName); } if (_duplicateHostnames.containsKey(hostname)) { String modifiedNewName = getModifiedName(hostname, _vc.getFilename()); _warnings.redFlag( String.format("Duplicate hostname %s. Changed to %s", hostname, modifiedNewName)); _vc.setHostname(modifiedNewName); _duplicateHostnames.put(hostname, modifiedNewName); hostname = modifiedNewName; } vendorConfigurations.put(hostname, _vc); answerElement.getFileMap().put(hostname, _filename); if (!_warnings.isEmpty()) { answerElement.getWarnings().put(_filename, _warnings); } if (!_parseTree.isEmpty()) { answerElement.getParseTrees().put(_filename, _parseTree); } } else if (_status == ParseStatus.FAILED) { assert _failureCause != null; answerElement .getErrors() .put(_filename, ((BatfishException) _failureCause).getBatfishStackTrace()); ErrorDetails errorDetails = _warnings.getErrorDetails(); if (errorDetails != null) { answerElement.getErrorDetails().put(_filename, errorDetails); } else { answerElement .getErrorDetails() .put( _filename, new ErrorDetails( Throwables.getStackTraceAsString( firstNonNull(_failureCause.getCause(), _failureCause)))); } } } ParseVendorConfigurationResult(
      long elapsedTime,
      BatfishLoggerHistory history,
      String filename,
      @Nonnull Warnings warnings,
      @Nonnull ParseTreeSentences parseTree,
      @Nonnull Throwable failureCause);  ParseVendorConfigurationResult(
      long elapsedTime,
      BatfishLoggerHistory history,
      String filename,
      VendorConfiguration vc,
      @Nonnull Warnings warnings,
      @Nonnull ParseTreeSentences parseTree,
      @Nonnull ParseStatus status,
      @Nonnull Multimap<String, String> duplicateHostnames);  ParseVendorConfigurationResult(
      long elapsedTime,
      BatfishLoggerHistory history,
      String filename,
      @Nonnull Warnings warnings,
      @Nonnull ParseStatus status); }
ParseVendorConfigurationResult extends BatfishJobResult<
        Map<String, VendorConfiguration>, ParseVendorConfigurationAnswerElement> { @Override public void applyTo( Map<String, VendorConfiguration> vendorConfigurations, BatfishLogger logger, ParseVendorConfigurationAnswerElement answerElement) { appendHistory(logger); answerElement.getParseStatus().put(_filename, _status); if (_vc != null) { String hostname = _vc.getHostname(); if (vendorConfigurations.containsKey(hostname)) { VendorConfiguration oldVc = vendorConfigurations.get(hostname); String modifiedOldName = getModifiedName(hostname, oldVc.getFilename()); oldVc.setHostname(modifiedOldName); vendorConfigurations.remove(hostname); vendorConfigurations.put(modifiedOldName, oldVc); _duplicateHostnames.put(hostname, modifiedOldName); } if (_duplicateHostnames.containsKey(hostname)) { String modifiedNewName = getModifiedName(hostname, _vc.getFilename()); _warnings.redFlag( String.format("Duplicate hostname %s. Changed to %s", hostname, modifiedNewName)); _vc.setHostname(modifiedNewName); _duplicateHostnames.put(hostname, modifiedNewName); hostname = modifiedNewName; } vendorConfigurations.put(hostname, _vc); answerElement.getFileMap().put(hostname, _filename); if (!_warnings.isEmpty()) { answerElement.getWarnings().put(_filename, _warnings); } if (!_parseTree.isEmpty()) { answerElement.getParseTrees().put(_filename, _parseTree); } } else if (_status == ParseStatus.FAILED) { assert _failureCause != null; answerElement .getErrors() .put(_filename, ((BatfishException) _failureCause).getBatfishStackTrace()); ErrorDetails errorDetails = _warnings.getErrorDetails(); if (errorDetails != null) { answerElement.getErrorDetails().put(_filename, errorDetails); } else { answerElement .getErrorDetails() .put( _filename, new ErrorDetails( Throwables.getStackTraceAsString( firstNonNull(_failureCause.getCause(), _failureCause)))); } } } ParseVendorConfigurationResult(
      long elapsedTime,
      BatfishLoggerHistory history,
      String filename,
      @Nonnull Warnings warnings,
      @Nonnull ParseTreeSentences parseTree,
      @Nonnull Throwable failureCause);  ParseVendorConfigurationResult(
      long elapsedTime,
      BatfishLoggerHistory history,
      String filename,
      VendorConfiguration vc,
      @Nonnull Warnings warnings,
      @Nonnull ParseTreeSentences parseTree,
      @Nonnull ParseStatus status,
      @Nonnull Multimap<String, String> duplicateHostnames);  ParseVendorConfigurationResult(
      long elapsedTime,
      BatfishLoggerHistory history,
      String filename,
      @Nonnull Warnings warnings,
      @Nonnull ParseStatus status); @Override void appendHistory(BatfishLogger logger); @Override void applyTo(
      Map<String, VendorConfiguration> vendorConfigurations,
      BatfishLogger logger,
      ParseVendorConfigurationAnswerElement answerElement); String getFilename(); @Override BatfishLoggerHistory getHistory(); static String getModifiedNameBase(String baseName, String filename); VendorConfiguration getVendorConfiguration(); @Override String toString(); }
ParseVendorConfigurationResult extends BatfishJobResult<
        Map<String, VendorConfiguration>, ParseVendorConfigurationAnswerElement> { @Override public void applyTo( Map<String, VendorConfiguration> vendorConfigurations, BatfishLogger logger, ParseVendorConfigurationAnswerElement answerElement) { appendHistory(logger); answerElement.getParseStatus().put(_filename, _status); if (_vc != null) { String hostname = _vc.getHostname(); if (vendorConfigurations.containsKey(hostname)) { VendorConfiguration oldVc = vendorConfigurations.get(hostname); String modifiedOldName = getModifiedName(hostname, oldVc.getFilename()); oldVc.setHostname(modifiedOldName); vendorConfigurations.remove(hostname); vendorConfigurations.put(modifiedOldName, oldVc); _duplicateHostnames.put(hostname, modifiedOldName); } if (_duplicateHostnames.containsKey(hostname)) { String modifiedNewName = getModifiedName(hostname, _vc.getFilename()); _warnings.redFlag( String.format("Duplicate hostname %s. Changed to %s", hostname, modifiedNewName)); _vc.setHostname(modifiedNewName); _duplicateHostnames.put(hostname, modifiedNewName); hostname = modifiedNewName; } vendorConfigurations.put(hostname, _vc); answerElement.getFileMap().put(hostname, _filename); if (!_warnings.isEmpty()) { answerElement.getWarnings().put(_filename, _warnings); } if (!_parseTree.isEmpty()) { answerElement.getParseTrees().put(_filename, _parseTree); } } else if (_status == ParseStatus.FAILED) { assert _failureCause != null; answerElement .getErrors() .put(_filename, ((BatfishException) _failureCause).getBatfishStackTrace()); ErrorDetails errorDetails = _warnings.getErrorDetails(); if (errorDetails != null) { answerElement.getErrorDetails().put(_filename, errorDetails); } else { answerElement .getErrorDetails() .put( _filename, new ErrorDetails( Throwables.getStackTraceAsString( firstNonNull(_failureCause.getCause(), _failureCause)))); } } } ParseVendorConfigurationResult(
      long elapsedTime,
      BatfishLoggerHistory history,
      String filename,
      @Nonnull Warnings warnings,
      @Nonnull ParseTreeSentences parseTree,
      @Nonnull Throwable failureCause);  ParseVendorConfigurationResult(
      long elapsedTime,
      BatfishLoggerHistory history,
      String filename,
      VendorConfiguration vc,
      @Nonnull Warnings warnings,
      @Nonnull ParseTreeSentences parseTree,
      @Nonnull ParseStatus status,
      @Nonnull Multimap<String, String> duplicateHostnames);  ParseVendorConfigurationResult(
      long elapsedTime,
      BatfishLoggerHistory history,
      String filename,
      @Nonnull Warnings warnings,
      @Nonnull ParseStatus status); @Override void appendHistory(BatfishLogger logger); @Override void applyTo(
      Map<String, VendorConfiguration> vendorConfigurations,
      BatfishLogger logger,
      ParseVendorConfigurationAnswerElement answerElement); String getFilename(); @Override BatfishLoggerHistory getHistory(); static String getModifiedNameBase(String baseName, String filename); VendorConfiguration getVendorConfiguration(); @Override String toString();  }