aboutsummaryrefslogtreecommitdiffstats
path: root/asdctool/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'asdctool/src/test/java')
-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
6 files changed, 73 insertions, 16 deletions
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) {