From 4f81700f5d8826d59164c4976a26631c2113e38f Mon Sep 17 00:00:00 2001 From: "k.kedron" Date: Mon, 9 Mar 2020 17:08:53 +0100 Subject: Added new unit tests Added new unit tests to GraphMLDataAnalyzer class. Fixed the Sonar issue. Issue-ID: SDC-2327 Signed-off-by: Krystian Kedron Change-Id: I9a61dff2e9b0be1733de00b06c255abb8a3d5a8f --- .../sdc/asdctool/impl/GraphMLDataAnalyzer.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'asdctool/src/main/java/org') diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/GraphMLDataAnalyzer.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/GraphMLDataAnalyzer.java index 21e22be10c..312d862747 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/GraphMLDataAnalyzer.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/GraphMLDataAnalyzer.java @@ -26,6 +26,7 @@ import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.jdom2.Document; import org.jdom2.Element; +import org.jdom2.JDOMException; import org.jdom2.filter.ElementFilter; import org.jdom2.input.SAXBuilder; import org.jdom2.util.IteratorIterable; @@ -34,6 +35,7 @@ import org.slf4j.LoggerFactory; import java.io.File; import java.io.FileOutputStream; +import java.io.IOException; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -48,34 +50,37 @@ public class GraphMLDataAnalyzer { private static final String[] COMPONENT_INSTANCES_SHEET_HEADER = {"uniqueId", "name", "originUid", "originType", "containerUid"}; + public static final String GRAPH_ML_EXTENSION = ".graphml"; + public static final String EXCEL_EXTENSION = ".xls"; + public String analyzeGraphMLData(String[] args) { - String result = null; + String result; try { String mlFileLocation = args[0]; result = analyzeGraphMLData(mlFileLocation); - log.info("Analyzed ML file=" + mlFileLocation + ", XLS result=" + result); + log.info("Analyzed ML file={}, XLS result={}", mlFileLocation, result); } catch (Exception e) { - log.error("analyze GraphML Data failed - {}", e); + log.error("Analyze GraphML Data failed!", e); return null; } return result; } - private String analyzeGraphMLData(String mlFileLocation) throws Exception { + private String analyzeGraphMLData(String mlFileLocation) throws JDOMException, IOException { // Parse ML file SAXBuilder builder = new SAXBuilder(); File xmlFile = new File(mlFileLocation); Document document = builder.build(xmlFile); // XLS data file name - String outputFile = mlFileLocation.replace(".graphml", ".xls"); + String outputFile = mlFileLocation.replace(GRAPH_ML_EXTENSION, EXCEL_EXTENSION); try (Workbook wb = new HSSFWorkbook(); FileOutputStream fileOut = new FileOutputStream(outputFile)) { writeComponents(wb, document); writeComponentInstances(wb, document); wb.write(fileOut); } catch (Exception e) { - log.error("analyze GraphML Data failed - {}", e); + log.error("Analyze GraphML Data failed!", e); } return outputFile; } -- cgit 1.2.3-korg