Decouple TXT Report file writing and formatting logic (3/6) 87/109387/1
authorFrancis Toth <francis.toth@yoppworks.com>
Thu, 18 Jun 2020 19:30:26 +0000 (15:30 -0400)
committerFrancis Toth <francis.toth@yoppworks.com>
Sun, 21 Jun 2020 11:34:43 +0000 (07:34 -0400)
This commit aims to move the printValidationTaskStatus function's logic from ReportManager (deprecated) to ReportFile.

Signed-off-by: Francis Toth <francis.toth@yoppworks.com>
Change-Id: Ic33a519f4c70276d404a83bf7de8a27f0007b285
Issue-ID: SDC-2499

asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/TopologyTemplateValidatorExecuter.java
asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/report/ReportFile.java
asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManager.java
asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManagerTest.java

index 967a6c6..497e589 100644 (file)
@@ -108,7 +108,7 @@ public class TopologyTemplateValidatorExecuter {
                 } else if (successAllTasks && vertexNum == verticesSize) {
                     successTasks.add(task.getTaskName());
                 }
-                ReportManager.printValidationTaskStatus(vertex, task.getTaskName(), result.getStatus(), outputFilePath);
+                reportFile.printValidationTaskStatus(vertex, task.getTaskName(), result.getStatus());
                 report.addSuccess(vertex.getUniqueId(), task.getTaskName(), result);
             }
             String componentScanStatus = successAllTasks ? "success" : "failed";
index 936ec4b..f1f084e 100644 (file)
@@ -65,6 +65,20 @@ public class ReportFile {
                 validatorName + " Validation Started, on " +
                 componentsNum + " components---------");
         }
+
+        public void printValidationTaskStatus(
+            GraphVertex vertexScanned,
+            String taskName,
+            boolean success
+        ) {
+            String successStatus = success ? "success" : "failed";
+            writer.writeln("");
+            writer.writeln("-----------------------Vertex: " +
+                vertexScanned.getUniqueId() + ", Task " +
+                taskName + " " + successStatus +
+                "-----------------------"
+            );
+        }
     }
 
     /**
index 63e7ebe..3149d04 100644 (file)
@@ -59,17 +59,6 @@ public class ReportManager {
         }
     }
 
-    public static void printValidationTaskStatus(GraphVertex vertexScanned, String taskName, boolean success,
-        String outputFilePath) {
-        String successStatus = success ? "success" : "failed";
-        String line =
-            "-----------------------Vertex: " + vertexScanned.getUniqueId() + ", Task " + taskName + " " + successStatus
-                + "-----------------------";
-        StrBuilder sb = new StrBuilder();
-        sb.appendln(line);
-        writeReportLineToFile(line, outputFilePath);
-    }
-
     public static void writeReportLineToFile(String message, String outputFilePath) {
         try {
             Files.write(Paths.get(outputFilePath), new StrBuilder().appendNewLine().toString().getBytes(),
index 479421e..9a237af 100644 (file)
@@ -72,7 +72,7 @@ public class ReportManagerTest {
         .csvReportFilePath(resourcePath, System::currentTimeMillis);
     private final static String txtReportFilePath = ValidationConfigManager.txtReportFilePath(resourcePath);
 
-    private GraphVertex vertexScanned = Mockito.mock(GraphVertex.class);
+    private final GraphVertex vertexScanned = Mockito.mock(GraphVertex.class);
 
     @BeforeEach
     public void setup() {
@@ -127,16 +127,16 @@ public class ReportManagerTest {
         when(vertexScanned.getUniqueId()).thenReturn(UNIQUE_ID);
 
         // when
-        ReportManager.printValidationTaskStatus(vertexScanned, TASK_1_NAME, false, txtReportFilePath);
-
-        List<String> reportOutputFile = ReportManagerHelper.getReportOutputFileAsList(txtReportFilePath);
+        List<String> reportTxtFile = ReportFileNioHelper.withTxtFile(txtReportFilePath, file -> {
+            file.printValidationTaskStatus(vertexScanned, TASK_1_NAME, false);
+            return ReportFileNioHelper.readFileAsList(txtReportFilePath);
+        });
 
         // then
-        assertNotNull(reportOutputFile);
-
-        assertEquals(EXPECTED_OUTPUT_FILE_HEADER, reportOutputFile.get(0));
+        assertNotNull(reportTxtFile);
+        assertEquals(EXPECTED_OUTPUT_FILE_HEADER, reportTxtFile.get(0));
         assertEquals("-----------------------Vertex: " + UNIQUE_ID + ", Task " + TASK_1_NAME
-            + " failed-----------------------", reportOutputFile.get(2));
+             + " failed-----------------------", reportTxtFile.get(2));
     }
 
     @Test