aboutsummaryrefslogtreecommitdiffstats
path: root/asdctool
diff options
context:
space:
mode:
authorFrancis Toth <francis.toth@yoppworks.com>2020-06-18 15:46:31 -0400
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-06-23 11:28:53 +0000
commit8c6ad373281722ce410a1108c67de5f1adf350ea (patch)
tree27bf3bccc1b868b3317806d0e864c4f6a19efb1c /asdctool
parent2879d63dbeecdd485394f9f35df0578040b8cf2c (diff)
Decouple TXT Report file writing and formatting logic (5/6)
This commit aims to move the reportEndOfToolRun function from ReportManager (deprecated) to ReportFile. Signed-off-by: Francis Toth <francis.toth@yoppworks.com> Change-Id: I17731864c34ed9a70b1b1e91b89bad835dc72449 Issue-ID: SDC-2499
Diffstat (limited to 'asdctool')
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/report/ReportFile.java15
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManager.java12
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/main/ValidationTool.java2
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/report/ReportFileNioHelper.java15
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactValidationUtilsTest.java36
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManagerTest.java16
6 files changed, 60 insertions, 36 deletions
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/report/ReportFile.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/report/ReportFile.java
index b22edb6cee..b483964a6e 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/report/ReportFile.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/report/ReportFile.java
@@ -95,6 +95,21 @@ public class ReportFile {
writer.writeln("");
writer.write(sb.toString());
}
+
+ public void reportEndOfToolRun(Report report) {
+ StrBuilder sb = new StrBuilder();
+ sb.appendln("-----------------------------------Validator Tool Summary-----------------------------------");
+ report.forEachFailure((taskName, failedVertices) -> {
+ sb.append("Task: ")
+ .append(taskName)
+ .appendNewLine()
+ .append("FailedVertices: ")
+ .append(String.valueOf(failedVertices))
+ .appendNewLine();
+ });
+ writer.writeln("");
+ writer.write(sb.toString());
+ }
}
/**
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManager.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManager.java
index a733eec38b..9b09e67c39 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManager.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManager.java
@@ -68,16 +68,4 @@ public class ReportManager {
log.info("write to file failed - {}", e.getClass().getSimpleName(), e);
}
}
-
- public static void reportEndOfToolRun(Report report, String outputFilePath) {
- StrBuilder sb = new StrBuilder();
- sb.appendln("-----------------------------------Validator Tool Summary-----------------------------------");
- report.forEachFailure((taskName, failedVertices) -> {
- sb.append("Task: " + taskName);
- sb.appendNewLine();
- sb.append("FailedVertices: " + failedVertices);
- sb.appendNewLine();
- });
- writeReportLineToFile(sb.toString(), outputFilePath);
- }
}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/ValidationTool.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/ValidationTool.java
index d84f0a5d69..3bffa0b5e2 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/ValidationTool.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/main/ValidationTool.java
@@ -59,7 +59,7 @@ public class ValidationTool {
log.info("Start Validation Tool");
Report report = Report.make();
boolean result = validationToolBL.validateAll(report, textFile, txtReportFilePath);
- ReportManager.reportEndOfToolRun(report, txtReportFilePath);
+ textFile.reportEndOfToolRun(report);
csvFile.printAllResults(report);
if (result) {
log.info("Validation finished successfully");
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/report/ReportFileNioHelper.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/report/ReportFileNioHelper.java
index d6d03a9c30..cd35f4ba2e 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/report/ReportFileNioHelper.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/report/ReportFileNioHelper.java
@@ -27,8 +27,10 @@ import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
+import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
+import org.openecomp.sdc.asdctool.impl.validator.report.ReportFile.TXTFile;
/**
* Provides facilities to for writing report files when testing
@@ -55,6 +57,19 @@ public class ReportFileNioHelper {
}
}
+ /**
+ * Provides a transactional context for TXT report file writing
+ *
+ * @param txtReportFilePath The resulting file path
+ * @param f The function consuming the TXT file
+ */
+ public static void withTxtFile(String txtReportFilePath, Consumer<TXTFile> f) {
+ withTxtFile(txtReportFilePath, file -> {
+ f.accept(file);
+ return null;
+ });
+ }
+
/**
* Provides a transactional context for TXT report file writing
*
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactValidationUtilsTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactValidationUtilsTest.java
index 7b35373768..763c69f61e 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactValidationUtilsTest.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactValidationUtilsTest.java
@@ -27,6 +27,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;
+import static org.openecomp.sdc.asdctool.impl.validator.report.ReportFileNioHelper.readFileAsList;
+import static org.openecomp.sdc.asdctool.impl.validator.report.ReportFileNioHelper.withTxtFile;
import fj.data.Either;
import java.io.File;
@@ -137,22 +139,24 @@ public class ArtifactValidationUtilsTest {
artifacts.add(artifactDataDefinitionNotInCassandra);
// when
- ArtifactsVertexResult result =
- testSubject.validateArtifactsAreInCassandra(report, vertex, TASK_NAME, artifacts, txtReportFilePath);
- ReportManager.reportEndOfToolRun(report, txtReportFilePath);
-
- List<String> reportOutputFile = ReportManagerHelper.getReportOutputFileAsList(txtReportFilePath);
-
- // then
- assertFalse(result.getStatus());
- assertEquals(1, result.notFoundArtifacts.size());
- assertEquals(UNIQUE_ID, result.notFoundArtifacts.iterator().next());
-
- assertEquals("Artifact " + ES_ID + " is in Cassandra", reportOutputFile.get(2));
- assertEquals("Artifact " + ES_ID_NOT_IN_CASS + " doesn't exist in Cassandra",
- reportOutputFile.get(3));
- assertEquals("Task: " + TASK_NAME, reportOutputFile.get(5));
- assertEquals("FailedVertices: [" + UNIQUE_ID_VERTEX + "]", reportOutputFile.get(6));
+ withTxtFile(txtReportFilePath, file -> {
+ ArtifactsVertexResult result =
+ testSubject.validateArtifactsAreInCassandra(report, vertex, TASK_NAME, artifacts, txtReportFilePath);
+ file.reportEndOfToolRun(report);
+
+ List<String> reportOutputFile = readFileAsList(txtReportFilePath);
+
+ // then
+ assertFalse(result.getStatus());
+ assertEquals(1, result.notFoundArtifacts.size());
+ assertEquals(UNIQUE_ID, result.notFoundArtifacts.iterator().next());
+
+ assertEquals("Artifact " + ES_ID + " is in Cassandra", reportOutputFile.get(2));
+ assertEquals("Artifact " + ES_ID_NOT_IN_CASS + " doesn't exist in Cassandra",
+ reportOutputFile.get(3));
+ assertEquals("Task: " + TASK_NAME, reportOutputFile.get(5));
+ assertEquals("FailedVertices: [" + UNIQUE_ID_VERTEX + "]", reportOutputFile.get(6));
+ });
}
@Test
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManagerTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManagerTest.java
index e78ab31763..d2276fdd5a 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManagerTest.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManagerTest.java
@@ -110,15 +110,17 @@ public class ReportManagerTest {
Report report = Report.make();
report.addFailure(TASK_1_NAME, VERTEX_1_ID);
- ReportManager.reportEndOfToolRun(report, txtReportFilePath);
- List<String> reportOutputFile = ReportManagerHelper.getReportOutputFileAsList(txtReportFilePath);
+ List<String> reportTxtFile = ReportFileNioHelper.withTxtFile(txtReportFilePath, file -> {
+ file.reportEndOfToolRun(report);
+ return ReportFileNioHelper.readFileAsList(txtReportFilePath);
+ });
// then
- assertNotNull(reportOutputFile);
- assertEquals(EXPECTED_OUTPUT_FILE_HEADER, reportOutputFile.get(0));
- assertEquals(EXPECTED_OUTPUT_FILE_SUMMARY, reportOutputFile.get(2));
- assertEquals("Task: " + TASK_1_NAME, reportOutputFile.get(3));
- assertEquals("FailedVertices: [" + VERTEX_1_ID + "]", reportOutputFile.get(4));
+ assertNotNull(reportTxtFile);
+ assertEquals(EXPECTED_OUTPUT_FILE_HEADER, reportTxtFile.get(0));
+ assertEquals(EXPECTED_OUTPUT_FILE_SUMMARY, reportTxtFile.get(2));
+ assertEquals("Task: " + TASK_1_NAME, reportTxtFile.get(3));
+ assertEquals("FailedVertices: [" + VERTEX_1_ID + "]", reportTxtFile.get(4));
}
@Test