aboutsummaryrefslogtreecommitdiffstats
path: root/asdctool
diff options
context:
space:
mode:
Diffstat (limited to 'asdctool')
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBL.java7
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceValidatorExecuter.java10
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/TopologyTemplateValidatorExecuter.java14
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ValidatorExecuter.java3
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/VfValidatorExecuter.java10
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/report/FileType.java2
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/report/ReportFile.java30
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManager.java18
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/main/ValidationTool.java4
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBLTest.java5
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceValidatorExecuterTest.java8
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/VfValidatorExecuterTest.java13
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/report/ReportFileNioHelper.java37
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/report/ReportFileWriterTestFactory.java13
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManagerTest.java13
15 files changed, 138 insertions, 49 deletions
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBL.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBL.java
index 6347e34558..61b3640d7d 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBL.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBL.java
@@ -22,6 +22,7 @@ package org.openecomp.sdc.asdctool.impl.validator;
import org.openecomp.sdc.asdctool.impl.validator.executers.ValidatorExecuter;
import org.openecomp.sdc.asdctool.impl.validator.report.Report;
+import org.openecomp.sdc.asdctool.impl.validator.report.ReportFile;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -31,7 +32,7 @@ import java.util.List;
@Component
public class ValidationToolBL {
- private static Logger log = Logger.getLogger(ValidationToolBL.class.getName());
+ private static final Logger log = Logger.getLogger(ValidationToolBL.class);
protected List<ValidatorExecuter> validators;
@@ -43,10 +44,10 @@ public class ValidationToolBL {
this.validators = validators;
}
- public boolean validateAll(Report report, String outputFilePath) {
+ public boolean validateAll(Report report, ReportFile.TXTFile textFile, String outputFilePath) {
for (ValidatorExecuter validatorExec: validators) {
log.debug("ValidatorExecuter "+validatorExec.getName()+" started");
- if (!validatorExec.executeValidations(report, outputFilePath)) {
+ if (!validatorExec.executeValidations(report, textFile, outputFilePath)) {
allValid = false;
log.debug("ValidatorExecuter "+validatorExec.getName()+" finished with warnings");
}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceValidatorExecuter.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceValidatorExecuter.java
index 4bcdeaf1d7..af9cb3634c 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceValidatorExecuter.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceValidatorExecuter.java
@@ -21,6 +21,7 @@
package org.openecomp.sdc.asdctool.impl.validator.executers;
import org.openecomp.sdc.asdctool.impl.validator.report.Report;
+import org.openecomp.sdc.asdctool.impl.validator.report.ReportFile.TXTFile;
import org.openecomp.sdc.asdctool.impl.validator.tasks.ServiceValidationTask;
import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
@@ -43,13 +44,8 @@ public class ServiceValidatorExecuter extends TopologyTemplateValidatorExecuter
}
@Override
- public boolean executeValidations(Report report, String outputFilePath) {
+ public boolean executeValidations(Report report, TXTFile reportFile, String outputFilePath) {
List<GraphVertex> vertices = getVerticesToValidate(ComponentTypeEnum.SERVICE);
- return validate(report, tasks, vertices, outputFilePath);
- }
-
- @Override
- public String getName() {
- return super.getName();
+ return validate(report, tasks, vertices, reportFile, outputFilePath);
}
}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/TopologyTemplateValidatorExecuter.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/TopologyTemplateValidatorExecuter.java
index 0c1e3bec5a..d6a5d12a25 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/TopologyTemplateValidatorExecuter.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/TopologyTemplateValidatorExecuter.java
@@ -22,6 +22,7 @@ package org.openecomp.sdc.asdctool.impl.validator.executers;
import fj.data.Either;
import org.openecomp.sdc.asdctool.impl.validator.report.Report;
+import org.openecomp.sdc.asdctool.impl.validator.report.ReportFile.TXTFile;
import org.openecomp.sdc.asdctool.impl.validator.tasks.TopologyTemplateValidationTask;
import org.openecomp.sdc.asdctool.impl.validator.utils.ReportManager;
import org.openecomp.sdc.asdctool.impl.validator.utils.VertexResult;
@@ -44,7 +45,7 @@ import java.util.Set;
public class TopologyTemplateValidatorExecuter {
- private static Logger log = Logger.getLogger(VfValidatorExecuter.class.getName());
+ private static final Logger log = Logger.getLogger(VfValidatorExecuter.class);
protected JanusGraphDao janusGraphDao;
@@ -80,8 +81,13 @@ public class TopologyTemplateValidatorExecuter {
return results.left().value();
}
- protected boolean validate(Report report, List<? extends TopologyTemplateValidationTask> tasks, List<GraphVertex> vertices,
- String outputFilePath) {
+ protected boolean validate(
+ Report report,
+ List<? extends TopologyTemplateValidationTask> tasks,
+ List<GraphVertex> vertices,
+ TXTFile reportFile,
+ String outputFilePath
+ ) {
ReportManager.reportStartValidatorRun(getName(), vertices.size(), outputFilePath);
Set<String> failedTasks = new HashSet<>();
Set<String> successTasks = new HashSet<>();
@@ -93,7 +99,7 @@ public class TopologyTemplateValidatorExecuter {
vertexNum++;
boolean successAllTasks = true;
for (TopologyTemplateValidationTask task : tasks) {
- ReportManager.reportStartTaskRun(vertex, task.getTaskName(), outputFilePath);
+ reportFile.reportStartTaskRun(vertex, task.getTaskName());
VertexResult result = task.validate(report, vertex, outputFilePath);
if (!result.getStatus()) {
failedTasks.add(task.getTaskName());
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ValidatorExecuter.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ValidatorExecuter.java
index 7d5314c1c5..88b7c0c64a 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ValidatorExecuter.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ValidatorExecuter.java
@@ -21,9 +21,10 @@
package org.openecomp.sdc.asdctool.impl.validator.executers;
import org.openecomp.sdc.asdctool.impl.validator.report.Report;
+import org.openecomp.sdc.asdctool.impl.validator.report.ReportFile.TXTFile;
public interface ValidatorExecuter {
- boolean executeValidations(Report report, String outputFilePath);
+ boolean executeValidations(Report report, TXTFile textFile, String outputFilePath);
String getName();
}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/VfValidatorExecuter.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/VfValidatorExecuter.java
index 5c42637d52..3484bbf8dc 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/VfValidatorExecuter.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/VfValidatorExecuter.java
@@ -21,6 +21,7 @@
package org.openecomp.sdc.asdctool.impl.validator.executers;
import org.openecomp.sdc.asdctool.impl.validator.report.Report;
+import org.openecomp.sdc.asdctool.impl.validator.report.ReportFile.TXTFile;
import org.openecomp.sdc.asdctool.impl.validator.tasks.VfValidationTask;
import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
@@ -41,13 +42,8 @@ public class VfValidatorExecuter extends TopologyTemplateValidatorExecuter imple
}
@Override
- public boolean executeValidations(Report report, String outputFilePath) {
+ public boolean executeValidations(Report report, TXTFile reportFile, String outputFilePath) {
List<GraphVertex> vertices = getVerticesToValidate(ComponentTypeEnum.RESOURCE);
- return validate(report, tasks, vertices, outputFilePath);
- }
-
- @Override
- public String getName() {
- return super.getName();
+ return validate(report, tasks, vertices, reportFile, outputFilePath);
}
}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/report/FileType.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/report/FileType.java
index 7598ae1bb8..6ce07912dd 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/report/FileType.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/report/FileType.java
@@ -25,5 +25,7 @@ package org.openecomp.sdc.asdctool.impl.validator.report;
* a {@link org.openecomp.sdc.asdctool.impl.validator.report.ReportFileWriter }.
*/
public interface FileType {
+ interface TXT extends FileType { }
+
interface CSV extends FileType { }
}
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 a0703f47e7..8b767662ee 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
@@ -20,11 +20,23 @@
package org.openecomp.sdc.asdctool.impl.validator.report;
+import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
+
/**
* Provides business logic in regards to file writing required by the validation tools
*/
public class ReportFile {
+ // TODO: Delete this function once all the report file business logic has been moved to ReportFile
+ static public TXTFile makeAppendableTxtFile(ReportFileWriter<FileType.TXT> writer) {
+ return new TXTFile(writer);
+ }
+
+ static public TXTFile makeTxtFile(ReportFileWriter<FileType.TXT> writer) {
+ writer.writeln("-----------------------Validation Tool Results:-------------------------");
+ return new TXTFile(writer);
+ }
+
static public CSVFile makeCsvFile(ReportFileWriter<FileType.CSV> writer) {
writer.writeln("Vertex ID,Task Name,Success,Result Details,Result Description");
return new CSVFile(writer);
@@ -33,6 +45,24 @@ public class ReportFile {
/**
* Provides csv writing business logic related to {@link org.openecomp.sdc.asdctool.main.ValidationTool}
*/
+ public static final class TXTFile extends ReportFile {
+
+ private final ReportFileWriter<FileType.TXT> writer;
+
+ private TXTFile(ReportFileWriter<FileType.TXT> writer) {
+ this.writer = writer;
+ }
+
+ public void reportStartTaskRun(GraphVertex vertex, String taskName) {
+ writer.writeln("");
+ writer.writeln("-----------------------Vertex: " + vertex.getUniqueId() +
+ ", Task " + taskName + " Started-----------------------");
+ }
+ }
+
+ /**
+ * Provides csv writing business logic related to {@link org.openecomp.sdc.asdctool.main.ValidationTool}
+ */
public static final class CSVFile extends ReportFile {
private final ReportFileWriter<FileType.CSV> writer;
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 5b78df8c73..6e8e2de64a 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
@@ -23,6 +23,7 @@ package org.openecomp.sdc.asdctool.impl.validator.utils;
import java.io.IOException;
import java.nio.file.Files;
+import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.Set;
@@ -49,9 +50,13 @@ public class ReportManager {
}
private void initReportFile(String txtReportFilePath) throws IOException {
- StrBuilder sb = new StrBuilder();
- sb.appendln("-----------------------Validation Tool Results:-------------------------");
- Files.write(Paths.get(txtReportFilePath), sb.toString().getBytes());
+ Path path = Paths.get(txtReportFilePath);
+ // TODO: Remove this once all the report file business logic has been moved to ReportFile
+ if(Files.notExists(path)) {
+ StrBuilder sb = new StrBuilder();
+ sb.appendln("-----------------------Validation Tool Results:-------------------------");
+ Files.write(path, sb.toString().getBytes());
+ }
}
public static void printValidationTaskStatus(GraphVertex vertexScanned, String taskName, boolean success,
@@ -92,13 +97,6 @@ public class ReportManager {
writeReportLineToFile(sb.toString(), outputFilePath);
}
- public static void reportStartTaskRun(GraphVertex vertex, String taskName, String outputFilePath) {
- StrBuilder sb = new StrBuilder();
- sb.appendln("-----------------------Vertex: " + vertex.getUniqueId() + ", Task " + taskName
- + " Started-----------------------");
- writeReportLineToFile(sb.toString(), outputFilePath);
- }
-
public static void reportEndOfToolRun(Report report, String outputFilePath) {
StrBuilder sb = new StrBuilder();
sb.appendln("-----------------------------------Validator Tool Summary-----------------------------------");
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 754d163e77..d84f0a5d69 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
@@ -29,6 +29,7 @@ import org.openecomp.sdc.asdctool.impl.validator.report.FileType;
import org.openecomp.sdc.asdctool.impl.validator.report.Report;
import org.openecomp.sdc.asdctool.impl.validator.report.ReportFile;
import org.openecomp.sdc.asdctool.impl.validator.report.ReportFile.CSVFile;
+import org.openecomp.sdc.asdctool.impl.validator.report.ReportFile.TXTFile;
import org.openecomp.sdc.asdctool.impl.validator.report.ReportFileWriter;
import org.openecomp.sdc.asdctool.impl.validator.utils.ReportManager;
import org.openecomp.sdc.be.config.ConfigurationManager;
@@ -49,6 +50,7 @@ public class ValidationTool {
String csvReportFilePath = ValidationConfigManager.csvReportFilePath(outputPath, System::currentTimeMillis);
CSVFile csvFile = ReportFile.makeCsvFile(makeNioWriter(Paths.get(csvReportFilePath)));
+ TXTFile textFile = ReportFile.makeTxtFile(makeNioWriter(Paths.get(txtReportFilePath)));
String appConfigDir = args[1];
AnnotationConfigApplicationContext context = initContext(appConfigDir);
@@ -56,7 +58,7 @@ public class ValidationTool {
log.info("Start Validation Tool");
Report report = Report.make();
- boolean result = validationToolBL.validateAll(report, txtReportFilePath);
+ boolean result = validationToolBL.validateAll(report, textFile, txtReportFilePath);
ReportManager.reportEndOfToolRun(report, txtReportFilePath);
csvFile.printAllResults(report);
if (result) {
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBLTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBLTest.java
index 3db011bae5..8c2dffcbc2 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBLTest.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBLTest.java
@@ -25,6 +25,9 @@ import org.openecomp.sdc.asdctool.impl.validator.executers.ServiceValidatorExecu
import org.openecomp.sdc.asdctool.impl.validator.report.Report;
import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
+import static org.openecomp.sdc.asdctool.impl.validator.report.ReportFile.makeTxtFile;
+import static org.openecomp.sdc.asdctool.impl.validator.report.ReportFileWriterTestFactory.makeConsoleWriter;
+
import java.util.ArrayList;
import java.util.LinkedList;
@@ -45,6 +48,6 @@ public class ValidationToolBLTest {
Report report = Report.make();
// Initially no outputFilePath was passed to this function (hence it is set to null)
// TODO: Fix this null and see if the argument is used by this function
- testSubject.validateAll(report, null);
+ testSubject.validateAll(report, makeTxtFile(makeConsoleWriter()), null);
}
}
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceValidatorExecuterTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceValidatorExecuterTest.java
index 98b8b250c3..2f9f11b28f 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceValidatorExecuterTest.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceValidatorExecuterTest.java
@@ -20,12 +20,14 @@
package org.openecomp.sdc.asdctool.impl.validator.executers;
+import static org.mockito.Mockito.mock;
+import static org.openecomp.sdc.asdctool.impl.validator.report.ReportFile.makeTxtFile;
+import static org.openecomp.sdc.asdctool.impl.validator.report.ReportFileWriterTestFactory.makeConsoleWriter;
+
import org.junit.Test;
import org.openecomp.sdc.asdctool.impl.validator.report.Report;
import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
-import static org.mockito.Mockito.mock;
-
public class ServiceValidatorExecuterTest {
private ServiceValidatorExecuter createTestSubject() {
@@ -43,6 +45,6 @@ public class ServiceValidatorExecuterTest {
Report report = Report.make();
// Initially no outputFilePath was passed to this function (hence it is set to null)
// TODO: Fix this null and see if the argument is used by this function
- createTestSubject().executeValidations(report, null);
+ createTestSubject().executeValidations(report, makeTxtFile(makeConsoleWriter()), null);
}
}
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/VfValidatorExecuterTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/VfValidatorExecuterTest.java
index 8ea87b1241..3760a57e33 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/VfValidatorExecuterTest.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/VfValidatorExecuterTest.java
@@ -20,16 +20,17 @@
package org.openecomp.sdc.asdctool.impl.validator.executers;
+import static org.mockito.Mockito.mock;
+import static org.openecomp.sdc.asdctool.impl.validator.report.ReportFile.makeTxtFile;
+import static org.openecomp.sdc.asdctool.impl.validator.report.ReportFileWriterTestFactory.makeConsoleWriter;
+
+import java.util.ArrayList;
+import java.util.List;
import org.junit.Test;
import org.openecomp.sdc.asdctool.impl.validator.report.Report;
import org.openecomp.sdc.asdctool.impl.validator.tasks.VfValidationTask;
import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.mockito.Mockito.mock;
-
public class VfValidatorExecuterTest {
private VfValidatorExecuter createTestSubject() {
@@ -49,6 +50,6 @@ public class VfValidatorExecuterTest {
Report report = Report.make();
// Initially no outputFilePath was passed to this function (hence it is set to null)
// TODO: Fix this null and see if the argument is used by this function
- createTestSubject().executeValidations(report, null);
+ createTestSubject().executeValidations(report, makeTxtFile(makeConsoleWriter()), null);
}
}
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 7a9bb0cf4d..d6d03a9c30 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
@@ -20,10 +20,15 @@
package org.openecomp.sdc.asdctool.impl.validator.report;
+import static org.openecomp.sdc.asdctool.impl.validator.report.ReportFileWriterTestFactory.makeNioWriter;
+
+import java.io.BufferedReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
+import java.util.List;
import java.util.function.Function;
+import java.util.stream.Collectors;
/**
* Provides facilities to for writing report files when testing
@@ -49,4 +54,36 @@ public class ReportFileNioHelper {
throw new RuntimeException(ex);
}
}
+
+ /**
+ * Provides a transactional context for TXT report file writing
+ *
+ * @param txtReportFilePath The resulting file path
+ * @param f The function to write in a TXT file
+ * @param <A> The type returned by the function consuming the file
+ */
+ public static <A> A withTxtFile(String txtReportFilePath, Function<ReportFile.TXTFile, A> f) {
+ // TODO: Switch to makeTxtFile once all the report file business logic has been moved to
+ // ReportFile
+ ReportFile.TXTFile file = ReportFile.makeAppendableTxtFile(makeNioWriter(txtReportFilePath));
+ A result = f.apply(file);
+ try {
+ Files.delete(Paths.get(txtReportFilePath));
+ return result;
+ } catch (IOException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ /**
+ * Reads the content of a file and store each line in a list
+ * @param filePath The path to the file
+ */
+ public static List<String> readFileAsList(String filePath) {
+ try (BufferedReader br = Files.newBufferedReader(Paths.get(filePath))) {
+ return br.lines().collect(Collectors.toList());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
}
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/report/ReportFileWriterTestFactory.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/report/ReportFileWriterTestFactory.java
index 364c08014e..b28cb7a82c 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/report/ReportFileWriterTestFactory.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/report/ReportFileWriterTestFactory.java
@@ -51,4 +51,17 @@ public class ReportFileWriterTestFactory {
public static <A extends FileType> ReportFileWriter<A> makeNioWriter(Path path) {
return ReportFileWriter.makeNioWriter(path, ex -> fail(ex.getMessage()));
}
+
+ /**
+ * Creates a writer rendering the data written in the console
+ * @param <A> a Phantom type used only for type-safety
+ */
+ public static <A extends FileType> ReportFileWriter<A> makeConsoleWriter() {
+ return new ReportFileWriter<A>() {
+ @Override
+ public void write(String line) {
+ System.out.print(line);
+ }
+ };
+ }
}
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 f28ca5dc41..53e56687a8 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
@@ -193,15 +193,16 @@ public class ReportManagerTest {
when(vertexScanned.getUniqueId()).thenReturn(UNIQUE_ID);
// when
- ReportManager.reportStartTaskRun(vertexScanned, TASK_1_NAME, txtReportFilePath);
-
- List<String> reportOutputFile = ReportManagerHelper.getReportOutputFileAsList(txtReportFilePath);
+ List<String> reportTxtFile = ReportFileNioHelper.withTxtFile(txtReportFilePath, file -> {
+ file.reportStartTaskRun(vertexScanned, TASK_1_NAME);
+ 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
- + " Started-----------------------", reportOutputFile.get(2));
+ + " Started-----------------------", reportTxtFile.get(2));
}
private String getCsvExpectedResult(String vertexID, String taskID) {