aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrancis Toth <francis.toth@yoppworks.com>2020-04-20 19:16:47 -0400
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-06-18 05:40:40 +0000
commit841d054f6bf5231c96abf1e91e1715c02809046a (patch)
tree66b681561778e6aa72470ee049927f5e1db05430
parentbc9783d71b65e0ab70dcd5bd6fcb8ff0e09eaf4b (diff)
Decouple CSV Report file writing and formatting logic
Signed-off-by: Francis Toth <francis.toth@yoppworks.com> Change-Id: I6168b71bb54192a806ff6aa437788bedad933c76 Issue-ID: SDC-2499
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/report/FileType.java29
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/report/Report.java2
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/report/ReportFile.java51
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/report/ReportFileWriter.java69
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManager.java32
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/main/ValidationTool.java17
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/report/ReportFileNioHelper.java52
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/report/ReportFileWriterTestFactory.java54
-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/ReportManagerHelper.java9
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManagerTest.java14
11 files changed, 303 insertions, 62 deletions
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
new file mode 100644
index 0000000000..7598ae1bb8
--- /dev/null
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/report/FileType.java
@@ -0,0 +1,29 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 Bell Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.asdctool.impl.validator.report;
+
+/**
+ * This interface provides some marker interfaces to prevent any type information lose when instantiating
+ * a {@link org.openecomp.sdc.asdctool.impl.validator.report.ReportFileWriter }.
+ */
+public interface FileType {
+ interface CSV extends FileType { }
+}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/report/Report.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/report/Report.java
index 68d7210e81..cf6fb0e8b1 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/report/Report.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/report/Report.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* SDC
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020 Bell Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
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
new file mode 100644
index 0000000000..a0703f47e7
--- /dev/null
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/report/ReportFile.java
@@ -0,0 +1,51 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 Bell Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.asdctool.impl.validator.report;
+
+/**
+ * Provides business logic in regards to file writing required by the validation tools
+ */
+public class ReportFile {
+
+ static public CSVFile makeCsvFile(ReportFileWriter<FileType.CSV> writer) {
+ writer.writeln("Vertex ID,Task Name,Success,Result Details,Result Description");
+ return new CSVFile(writer);
+ }
+
+ /**
+ * 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;
+
+ private CSVFile(ReportFileWriter<FileType.CSV> writer) {
+ this.writer = writer;
+ }
+
+ public void printAllResults(Report report) {
+ report.forEachSuccess((vertex, task, result) -> {
+ String resultLine = vertex + "," + task + "," + result.getStatus() + "," + result.getResult();
+ writer.writeln(resultLine);
+ });
+ }
+ }
+}
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/report/ReportFileWriter.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/report/ReportFileWriter.java
new file mode 100644
index 0000000000..e1a0090cb9
--- /dev/null
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/report/ReportFileWriter.java
@@ -0,0 +1,69 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) Bell Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+
+package org.openecomp.sdc.asdctool.impl.validator.report;
+
+import static java.nio.file.StandardOpenOption.APPEND;
+import static java.nio.file.StandardOpenOption.CREATE;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardOpenOption;
+import java.util.function.Consumer;
+
+/**
+ * Describes a writer for report's data
+ * @param <A> phantom type which is only used for type-safety to prevent mixing writers for TXT Report files
+ * and CSV Report files
+ */
+@SuppressWarnings("unused")
+public abstract class ReportFileWriter<A extends FileType> {
+
+ abstract public void write(String s);
+
+ public void writeln(String s) {
+ write(s + "\n");
+ }
+
+ /**
+ *
+ * @param filePath The resulting file path
+ * @param onError error handling callback
+ * @param <A> phantom type which is only used for type-safety
+ */
+ public static <A extends FileType> ReportFileWriter<A> makeNioWriter(
+ Path filePath, Consumer<IOException> onError
+ ) {
+ return new ReportFileWriter<A>() {
+ @Override
+ public void write(String line) {
+ try {
+ StandardOpenOption soo = Files.exists(filePath) ? APPEND : CREATE;
+ Files.write(filePath, line.getBytes(), soo);
+ } catch (IOException ex) {
+ onError.accept(ex);
+ }
+ }
+ };
+ }
+}
+
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 a1300cb70c..5b78df8c73 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
@@ -36,13 +36,12 @@ public class ReportManager {
private static final Logger log = LoggerFactory.getLogger(ReportManager.class);
- public static ReportManager make(String csvReportFilePath, String txtReportFilePath) {
- return new ReportManager(csvReportFilePath, txtReportFilePath);
+ public static ReportManager make(String txtReportFilePath) {
+ return new ReportManager(txtReportFilePath);
}
- private ReportManager(String csvReportFilePath, String txtReportFilePath) {
+ private ReportManager(String txtReportFilePath) {
try {
- initCsvFile(csvReportFilePath);
initReportFile(txtReportFilePath);
} catch (IOException e) {
log.info("Init file failed - {}", e.getClass().getSimpleName(), e);
@@ -55,13 +54,6 @@ public class ReportManager {
Files.write(Paths.get(txtReportFilePath), sb.toString().getBytes());
}
- private void initCsvFile(String csvReportFilePath) throws IOException {
- StrBuilder sb = new StrBuilder();
- sb.append("Vertex ID,Task Name,Success,Result Details,Result Description");
- sb.appendNewLine();
- Files.write(Paths.get(csvReportFilePath), sb.toString().getBytes());
- }
-
public static void printValidationTaskStatus(GraphVertex vertexScanned, String taskName, boolean success,
String outputFilePath) {
String successStatus = success ? "success" : "failed";
@@ -107,7 +99,7 @@ public class ReportManager {
writeReportLineToFile(sb.toString(), outputFilePath);
}
- public static void reportEndOfToolRun(Report report, String csvReportFilePath, String outputFilePath) {
+ public static void reportEndOfToolRun(Report report, String outputFilePath) {
StrBuilder sb = new StrBuilder();
sb.appendln("-----------------------------------Validator Tool Summary-----------------------------------");
report.forEachFailure((taskName, failedVertices) -> {
@@ -117,21 +109,5 @@ public class ReportManager {
sb.appendNewLine();
});
writeReportLineToFile(sb.toString(), outputFilePath);
- printAllResults(report, csvReportFilePath);
- }
-
- public static void printAllResults(Report report, String csvReportFilePath) {
- report.forEachSuccess((vertex, task, result) -> {
- try {
- String resultLine = vertex + "," + task + "," + result.getStatus() + "," + result.getResult();
- Files.write(Paths.get(csvReportFilePath), resultLine.getBytes(),
- StandardOpenOption.APPEND);
- Files.write(Paths.get(csvReportFilePath),
- new StrBuilder().appendNewLine().toString().getBytes(),
- StandardOpenOption.APPEND);
- } catch (IOException e) {
- log.info("write to file failed - {}", e.getClass().getSimpleName(), e);
- }
- });
}
}
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 f37a82d09b..754d163e77 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
@@ -20,10 +20,16 @@
package org.openecomp.sdc.asdctool.main;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import org.openecomp.sdc.asdctool.impl.validator.ValidationToolBL;
import org.openecomp.sdc.asdctool.impl.validator.config.ValidationConfigManager;
import org.openecomp.sdc.asdctool.impl.validator.config.ValidationToolConfiguration;
+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.ReportFileWriter;
import org.openecomp.sdc.asdctool.impl.validator.utils.ReportManager;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.common.api.ConfigurationSource;
@@ -42,6 +48,8 @@ public class ValidationTool {
String txtReportFilePath = ValidationConfigManager.txtReportFilePath(outputPath);
String csvReportFilePath = ValidationConfigManager.csvReportFilePath(outputPath, System::currentTimeMillis);
+ CSVFile csvFile = ReportFile.makeCsvFile(makeNioWriter(Paths.get(csvReportFilePath)));
+
String appConfigDir = args[1];
AnnotationConfigApplicationContext context = initContext(appConfigDir);
ValidationToolBL validationToolBL = context.getBean(ValidationToolBL.class);
@@ -49,7 +57,8 @@ public class ValidationTool {
log.info("Start Validation Tool");
Report report = Report.make();
boolean result = validationToolBL.validateAll(report, txtReportFilePath);
- ReportManager.reportEndOfToolRun(report, csvReportFilePath, txtReportFilePath);
+ ReportManager.reportEndOfToolRun(report, txtReportFilePath);
+ csvFile.printAllResults(report);
if (result) {
log.info("Validation finished successfully");
System.exit(0);
@@ -59,6 +68,12 @@ public class ValidationTool {
}
}
+ private static <A extends FileType> ReportFileWriter<A> makeNioWriter(Path path) {
+ return ReportFileWriter.makeNioWriter(path, ex ->
+ log.info("write to file failed - {}", ex.getClass().getSimpleName(), ex)
+ );
+ }
+
private static AnnotationConfigApplicationContext initContext(String appConfigDir) {
ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
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
new file mode 100644
index 0000000000..7a9bb0cf4d
--- /dev/null
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/report/ReportFileNioHelper.java
@@ -0,0 +1,52 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 Bell. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.asdctool.impl.validator.report;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.function.Function;
+
+/**
+ * Provides facilities to for writing report files when testing
+ */
+public class ReportFileNioHelper {
+ private ReportFileNioHelper() {
+ }
+
+ /**
+ * Provides a transactional context for CSV report file writing
+ *
+ * @param csvReportFilePath The resulting file path
+ * @param f The function to write in a CSV file
+ * @param <A> A Phantom type only required for type-safety
+ */
+ public static <A> A withCsvFile(String csvReportFilePath, Function<ReportFile.CSVFile, A> f) {
+ ReportFile.CSVFile file = ReportFile.makeCsvFile(ReportFileWriterTestFactory.makeNioWriter(csvReportFilePath));
+ A result = f.apply(file);
+ try {
+ Files.delete(Paths.get(csvReportFilePath));
+ return result;
+ } catch (IOException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+}
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
new file mode 100644
index 0000000000..364c08014e
--- /dev/null
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/report/ReportFileWriterTestFactory.java
@@ -0,0 +1,54 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 Bell Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.asdctool.impl.validator.report;
+
+import static org.junit.Assert.fail;
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+/**
+ * Provides facilities to for creating report file writers when testing
+ */
+public class ReportFileWriterTestFactory {
+ private ReportFileWriterTestFactory() {
+ }
+
+ /**
+ * Alias for {@link org.openecomp.sdc.asdctool.impl.validator.report.ReportFileWriterTestFactory#makeNioWriter(Path)}
+ *
+ * @param path The resulting file path
+ * @param <A> a Phantom type used only for type-safety
+ */
+ public static <A extends FileType> ReportFileWriter<A> makeNioWriter(String path) {
+ Path p = Paths.get(path);
+ return makeNioWriter(p);
+ }
+
+ /**
+ * Creates a NIO writer storing the data written into a file on disk
+ * @param path The resulting file path
+ * @param <A> a Phantom type used only for type-safety
+ */
+ public static <A extends FileType> ReportFileWriter<A> makeNioWriter(Path path) {
+ return ReportFileWriter.makeNioWriter(path, ex -> fail(ex.getMessage()));
+ }
+}
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 354714b0c2..7b35373768 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
@@ -21,11 +21,24 @@
package org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+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 fj.data.Either;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.IntStream;
import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.Assertions;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@@ -42,20 +55,6 @@ import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.TopologyTemplate;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.TopologyTemplateOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-import java.io.File;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.IntStream;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-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;
-
public class ArtifactValidationUtilsTest {
@Mock
@@ -85,7 +84,6 @@ public class ArtifactValidationUtilsTest {
private static final String UNIQUE_ID_VERTEX = "321";
private final static String resourcePath = new File("src/test/resources").getAbsolutePath();
- private final static String csvReportFilePath = ValidationConfigManager.DEFAULT_CSV_PATH;
private final static String txtReportFilePath = ValidationConfigManager.txtReportFilePath(resourcePath);
ArtifactValidationUtilsTest () {
@@ -103,12 +101,12 @@ public class ArtifactValidationUtilsTest {
@BeforeEach
public void setup() {
- ReportManager.make(csvReportFilePath, txtReportFilePath);
+ ReportManager.make(txtReportFilePath);
}
@AfterEach
public void clean() {
- ReportManagerHelper.cleanReports(csvReportFilePath, txtReportFilePath);
+ ReportManagerHelper.cleanReports(txtReportFilePath);
}
@Test
@@ -141,7 +139,7 @@ public class ArtifactValidationUtilsTest {
// when
ArtifactsVertexResult result =
testSubject.validateArtifactsAreInCassandra(report, vertex, TASK_NAME, artifacts, txtReportFilePath);
- ReportManager.reportEndOfToolRun(report, csvReportFilePath, txtReportFilePath);
+ ReportManager.reportEndOfToolRun(report, txtReportFilePath);
List<String> reportOutputFile = ReportManagerHelper.getReportOutputFileAsList(txtReportFilePath);
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManagerHelper.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManagerHelper.java
index 938b2c2202..5a8a36a88a 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManagerHelper.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManagerHelper.java
@@ -36,16 +36,11 @@ public class ReportManagerHelper {
return readFileAsList(txtReportFilePath);
}
- public static List<String> getReportCsvFileAsList(String csvReportFilePath) {
- return readFileAsList(csvReportFilePath);
- }
-
- public static void cleanReports(String csvReportFilePath, String txtReportFilePath) {
- cleanFile(csvReportFilePath);
+ public static void cleanReports(String txtReportFilePath) {
cleanFile(txtReportFilePath);
}
- private static List<String> readFileAsList(String filePath) {
+ public static List<String> readFileAsList(String filePath) {
try (BufferedReader br = Files.newBufferedReader(Paths.get(filePath))) {
return br.lines().collect(Collectors.toList());
} catch (IOException e) {
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 c231ca3677..f28ca5dc41 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
@@ -27,6 +27,7 @@ import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.openecomp.sdc.asdctool.impl.validator.config.ValidationConfigManager;
import org.openecomp.sdc.asdctool.impl.validator.report.Report;
+import org.openecomp.sdc.asdctool.impl.validator.report.ReportFileNioHelper;
import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
import java.io.File;
@@ -75,13 +76,13 @@ public class ReportManagerTest {
@BeforeEach
public void setup() {
- ReportManager.make(csvReportFilePath, txtReportFilePath);
+ ReportManager.make(txtReportFilePath);
successResult.setStatus(true);
}
@AfterEach
public void clean() {
- ReportManagerHelper.cleanReports(csvReportFilePath, txtReportFilePath);
+ ReportManagerHelper.cleanReports(txtReportFilePath);
}
@Test
@@ -90,9 +91,11 @@ public class ReportManagerTest {
Report report = Report.make();
report.addSuccess(VERTEX_1_ID, TASK_1_NAME, successResult);
report.addSuccess(VERTEX_2_ID, TASK_2_NAME, successResult);
- ReportManager.printAllResults(report, csvReportFilePath);
- List<String> reportCsvFile = ReportManagerHelper.getReportCsvFileAsList(csvReportFilePath);
+ List<String> reportCsvFile = ReportFileNioHelper.withCsvFile(csvReportFilePath, file -> {
+ file.printAllResults(report);
+ return ReportManagerHelper.readFileAsList(csvReportFilePath);
+ });
// then
assertNotNull(reportCsvFile);
@@ -106,13 +109,12 @@ public class ReportManagerTest {
// when
Report report = Report.make();
report.addFailure(TASK_1_NAME, VERTEX_1_ID);
- ReportManager.reportEndOfToolRun(report, csvReportFilePath, txtReportFilePath);
+ ReportManager.reportEndOfToolRun(report, txtReportFilePath);
List<String> reportOutputFile = ReportManagerHelper.getReportOutputFileAsList(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));