From bdbfc2e460ccb561c3e174260b2908b974996d4f Mon Sep 17 00:00:00 2001 From: Francis Toth Date: Thu, 18 Jun 2020 16:06:01 -0400 Subject: Decouple TXT Report file writing and formatting logic (6/6) This commit moves the writeReportLineToFile from ReportManager to ReportFile, deletes ReportManager (as it's not longer used), and finalizes the decoupling between the writing and the formatting logic of the TXT Report file. Signed-off-by: Francis Toth Change-Id: Ia5cce71535ea808e6e24807ed62ae9b262eab6ad Issue-ID: SDC-2499 --- .../asdctool/impl/validator/ValidationToolBL.java | 2 +- .../executers/ServiceValidatorExecuter.java | 4 +- .../TopologyTemplateValidatorExecuter.java | 19 +++--- .../validator/executers/ValidatorExecuter.java | 2 +- .../validator/executers/VfValidatorExecuter.java | 4 +- .../asdctool/impl/validator/report/ReportFile.java | 18 +++--- .../tasks/TopologyTemplateValidationTask.java | 3 +- .../tasks/artifacts/ArtifactValidationUtils.java | 41 +++++++------ .../artifacts/ServiceArtifactValidationTask.java | 5 +- .../tasks/artifacts/VfArtifactValidationTask.java | 5 +- .../tasks/module/json/ModuleJsonTask.java | 36 ++++++----- .../impl/validator/utils/ReportManager.java | 71 ---------------------- .../sdc/asdctool/main/ValidationTool.java | 1 - .../executers/ServiceValidatorExecuterTest.java | 4 +- .../executers/VfValidatorExecuterTest.java | 4 +- .../impl/validator/report/ReportFileNioHelper.java | 4 +- .../artifacts/ArtifactValidationUtilsTest.java | 61 ++++++++----------- .../ServiceArtifactValidationTaskTest.java | 19 +++--- .../artifacts/VfArtifactValidationTaskTest.java | 9 ++- .../impl/validator/utils/ReportManagerTest.java | 46 +++++--------- 20 files changed, 136 insertions(+), 222 deletions(-) delete mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManager.java 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 61b3640d7d..6659f6e82c 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 @@ -47,7 +47,7 @@ public class ValidationToolBL { public boolean validateAll(Report report, ReportFile.TXTFile textFile, String outputFilePath) { for (ValidatorExecuter validatorExec: validators) { log.debug("ValidatorExecuter "+validatorExec.getName()+" started"); - if (!validatorExec.executeValidations(report, textFile, outputFilePath)) { + if (!validatorExec.executeValidations(report, textFile)) { 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 af9cb3634c..5d209807b6 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 @@ -44,8 +44,8 @@ public class ServiceValidatorExecuter extends TopologyTemplateValidatorExecuter } @Override - public boolean executeValidations(Report report, TXTFile reportFile, String outputFilePath) { + public boolean executeValidations(Report report, TXTFile reportFile) { List vertices = getVerticesToValidate(ComponentTypeEnum.SERVICE); - return validate(report, tasks, vertices, reportFile, outputFilePath); + return validate(report, tasks, vertices, reportFile); } } 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 52c8cb5f96..ddf9e7bce5 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 @@ -21,10 +21,15 @@ package org.openecomp.sdc.asdctool.impl.validator.executers; import fj.data.Either; +import java.util.ArrayList; +import java.util.EnumMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; 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; import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; @@ -36,13 +41,6 @@ import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; import org.openecomp.sdc.common.log.wrappers.Logger; import org.springframework.beans.factory.annotation.Autowired; -import java.util.ArrayList; -import java.util.EnumMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - public class TopologyTemplateValidatorExecuter { private static final Logger log = Logger.getLogger(VfValidatorExecuter.class); @@ -85,8 +83,7 @@ public class TopologyTemplateValidatorExecuter { Report report, List tasks, List vertices, - TXTFile reportFile, - String outputFilePath + TXTFile reportFile ) { reportFile.reportStartValidatorRun(getName(), vertices.size()); Set failedTasks = new HashSet<>(); @@ -100,7 +97,7 @@ public class TopologyTemplateValidatorExecuter { boolean successAllTasks = true; for (TopologyTemplateValidationTask task : tasks) { reportFile.reportStartTaskRun(vertex, task.getTaskName()); - VertexResult result = task.validate(report, vertex, outputFilePath); + VertexResult result = task.validate(report, vertex, reportFile); if (!result.getStatus()) { failedTasks.add(task.getTaskName()); successAllVertices = false; 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 88b7c0c64a..87449886d8 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 @@ -25,6 +25,6 @@ import org.openecomp.sdc.asdctool.impl.validator.report.ReportFile.TXTFile; public interface ValidatorExecuter { - boolean executeValidations(Report report, TXTFile textFile, String outputFilePath); + boolean executeValidations(Report report, TXTFile textFile); 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 3484bbf8dc..4786e129d6 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 @@ -42,8 +42,8 @@ public class VfValidatorExecuter extends TopologyTemplateValidatorExecuter imple } @Override - public boolean executeValidations(Report report, TXTFile reportFile, String outputFilePath) { + public boolean executeValidations(Report report, TXTFile reportFile) { List vertices = getVerticesToValidate(ComponentTypeEnum.RESOURCE); - return validate(report, tasks, vertices, reportFile, outputFilePath); + return validate(report, tasks, vertices, reportFile); } } 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 b483964a6e..e706d8a8bb 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 @@ -29,11 +29,6 @@ import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; */ public class ReportFile { - // TODO: Delete this function once all the report file business logic has been moved to ReportFile - static public TXTFile makeAppendableTxtFile(ReportFileWriter writer) { - return new TXTFile(writer); - } - static public TXTFile makeTxtFile(ReportFileWriter writer) { writer.writeln("-----------------------Validation Tool Results:-------------------------"); return new TXTFile(writer); @@ -82,7 +77,7 @@ public class ReportFile { ); } - public void reportValidatorTypeSummary( + public void reportValidatorTypeSummary( String validatorName, Set failedTasksNames, Set successTasksNames @@ -99,17 +94,22 @@ public class ReportFile { public void reportEndOfToolRun(Report report) { StrBuilder sb = new StrBuilder(); sb.appendln("-----------------------------------Validator Tool Summary-----------------------------------"); - report.forEachFailure((taskName, failedVertices) -> { + report.forEachFailure((taskName, failedVertices) -> sb.append("Task: ") .append(taskName) .appendNewLine() .append("FailedVertices: ") .append(String.valueOf(failedVertices)) - .appendNewLine(); - }); + .appendNewLine()); + writer.writeln(""); writer.write(sb.toString()); } + + public void writeReportLineToFile(String message) { + writer.writeln(""); + writer.write(message); + } } /** diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/TopologyTemplateValidationTask.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/TopologyTemplateValidationTask.java index f50e552970..99470c6aee 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/TopologyTemplateValidationTask.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/TopologyTemplateValidationTask.java @@ -21,11 +21,12 @@ package org.openecomp.sdc.asdctool.impl.validator.tasks; 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.utils.VertexResult; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; public interface TopologyTemplateValidationTask { - VertexResult validate(Report report, GraphVertex vertex, String outputFilePath); + VertexResult validate(Report report, GraphVertex vertex, ReportFile.TXTFile reportFile); String getTaskName(); String getTaskResultStatus(); void setTaskResultStatus(String status); diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactValidationUtils.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactValidationUtils.java index 428b6606a6..bf3d267ab9 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactValidationUtils.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactValidationUtils.java @@ -22,8 +22,13 @@ package org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts; import fj.data.Either; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Optional; import org.openecomp.sdc.asdctool.impl.validator.report.Report; -import org.openecomp.sdc.asdctool.impl.validator.utils.ReportManager; +import org.openecomp.sdc.asdctool.impl.validator.report.ReportFile; import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao; import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; @@ -37,22 +42,13 @@ import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.common.log.wrappers.Logger; import org.springframework.beans.factory.annotation.Autowired; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Optional; - -/** - * Created by chaya on 7/6/2017. - */ public class ArtifactValidationUtils { private static final Logger logger = Logger.getLogger(ArtifactValidationUtils.class); - private ArtifactCassandraDao artifactCassandraDao; + private final ArtifactCassandraDao artifactCassandraDao; - private TopologyTemplateOperation topologyTemplateOperation; + private final TopologyTemplateOperation topologyTemplateOperation; @Autowired public ArtifactValidationUtils(ArtifactCassandraDao artifactCassandraDao, @@ -61,14 +57,19 @@ public class ArtifactValidationUtils { this.topologyTemplateOperation = topologyTemplateOperation; } - public ArtifactsVertexResult validateArtifactsAreInCassandra(Report report, GraphVertex vertex, String taskName, - List artifacts, String outputFilePath) { + public ArtifactsVertexResult validateArtifactsAreInCassandra( + Report report, + GraphVertex vertex, + String taskName, + List artifacts, + ReportFile.TXTFile reportFile + ) { ArtifactsVertexResult result = new ArtifactsVertexResult(true); for (ArtifactDataDefinition artifact : artifacts) { boolean isArtifactExist = isArtifactInCassandra(artifact.getEsId()); String status = isArtifactExist ? "Artifact " + artifact.getEsId() + " is in Cassandra" : "Artifact " + artifact.getEsId() + " doesn't exist in Cassandra"; - ReportManager.writeReportLineToFile(status, outputFilePath); + reportFile.writeReportLineToFile(status); if (!isArtifactExist) { report.addFailure(taskName, vertex.getUniqueId()); result.setStatus(false); @@ -99,8 +100,12 @@ public class ArtifactValidationUtils { return artifacts; } - public ArtifactsVertexResult validateTopologyTemplateArtifacts(Report report, GraphVertex vertex, String taskName, - String outputFilePath) { + public ArtifactsVertexResult validateTopologyTemplateArtifacts( + Report report, + GraphVertex vertex, + String taskName, + ReportFile.TXTFile reportFile + ) { ArtifactsVertexResult result = new ArtifactsVertexResult(); ComponentParametersView paramView = new ComponentParametersView(); paramView.disableAll(); @@ -135,6 +140,6 @@ public class ArtifactValidationUtils { allArtifacts.addAll(addRelevantArtifacts(artifactMap.getMapToscaDataDefinition()))); } - return validateArtifactsAreInCassandra(report, vertex, taskName, allArtifacts, outputFilePath); + return validateArtifactsAreInCassandra(report, vertex, taskName, allArtifacts, reportFile); } } diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ServiceArtifactValidationTask.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ServiceArtifactValidationTask.java index e3f547485a..a5d518510e 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ServiceArtifactValidationTask.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ServiceArtifactValidationTask.java @@ -21,6 +21,7 @@ package org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts; 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.tasks.ServiceValidationTask; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; import org.springframework.beans.factory.annotation.Autowired; @@ -37,7 +38,7 @@ public class ServiceArtifactValidationTask extends ServiceValidationTask { } @Override - public ArtifactsVertexResult validate(Report report, GraphVertex vertex, String outputFilePath) { - return artifactValidationUtils.validateTopologyTemplateArtifacts(report, vertex, getTaskName(), outputFilePath); + public ArtifactsVertexResult validate(Report report, GraphVertex vertex, ReportFile.TXTFile reportFile) { + return artifactValidationUtils.validateTopologyTemplateArtifacts(report, vertex, getTaskName(), reportFile); } } diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/VfArtifactValidationTask.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/VfArtifactValidationTask.java index f48088304f..26495fa4e3 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/VfArtifactValidationTask.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/VfArtifactValidationTask.java @@ -21,6 +21,7 @@ package org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts; 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.tasks.VfValidationTask; import org.openecomp.sdc.asdctool.impl.validator.utils.VertexResult; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; @@ -41,7 +42,7 @@ public class VfArtifactValidationTask extends VfValidationTask { } @Override - public VertexResult validate(Report report, GraphVertex vertex, String outputFilePath) { - return artifactValidationUtils.validateTopologyTemplateArtifacts(report, vertex, getTaskName(), outputFilePath); + public VertexResult validate(Report report, GraphVertex vertex, ReportFile.TXTFile reportFile) { + return artifactValidationUtils.validateTopologyTemplateArtifacts(report, vertex, getTaskName(), reportFile); } } diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/module/json/ModuleJsonTask.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/module/json/ModuleJsonTask.java index 58c2ef031b..62404e1e43 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/module/json/ModuleJsonTask.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/module/json/ModuleJsonTask.java @@ -29,8 +29,8 @@ import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; 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.tasks.ServiceValidationTask; -import org.openecomp.sdc.asdctool.impl.validator.utils.ReportManager; import org.openecomp.sdc.asdctool.impl.validator.utils.VertexResult; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition; @@ -47,7 +47,7 @@ import org.springframework.beans.factory.annotation.Autowired; public class ModuleJsonTask extends ServiceValidationTask { - private TopologyTemplateOperation topologyTemplateOperation; + private final TopologyTemplateOperation topologyTemplateOperation; @Autowired public ModuleJsonTask(TopologyTemplateOperation topologyTemplateOperation) { @@ -56,7 +56,7 @@ public class ModuleJsonTask extends ServiceValidationTask { } @Override - public VertexResult validate(Report report, GraphVertex vertex, String outputFilePath) { + public VertexResult validate(Report report, GraphVertex vertex, ReportFile.TXTFile reportFile) { if (!isAfterSubmitForTesting(vertex)) { return new VertexResult(true); } @@ -80,35 +80,39 @@ public class ModuleJsonTask extends ServiceValidationTask { MapGroupsDataDefinition groups = pair.getValue(); if (groups != null && !groups.getMapToscaDataDefinition().isEmpty()) { return new VertexResult( - findCoordinateModuleJson(report, pair, instDeploymentArtifacts, vertex, outputFilePath)); + findCoordinateModuleJson(report, pair, instDeploymentArtifacts, vertex, reportFile)); } } return new VertexResult(true); } - private boolean findCoordinateModuleJson(Report report, Map.Entry pair, - Map instDeploymentArtifacts, - GraphVertex vertex, String outputFilePath) { + private boolean findCoordinateModuleJson( + Report report, + Map.Entry pair, + Map instDeploymentArtifacts, + GraphVertex vertex, + ReportFile.TXTFile reportFile + ) { String groupKey = pair.getKey(); String[] split = groupKey.split("\\."); String instanceName = split[split.length - 1]; MapArtifactDataDefinition deploymentsArtifacts = instDeploymentArtifacts.get(groupKey); if (deploymentsArtifacts != null && !deploymentsArtifacts.getMapToscaDataDefinition().isEmpty()) { List moduleJsonArtifacts = deploymentsArtifacts.getMapToscaDataDefinition().values() - .stream().filter(artifact -> { - String artifactName = artifact.getArtifactName(); - return (artifactName.startsWith(instanceName) && artifactName.endsWith("modules.json")); - }).collect(Collectors.toList()); - if (!moduleJsonArtifacts.isEmpty()) { - String status = "Instance " + instanceName + " has a corresponding modules.json file: " - + moduleJsonArtifacts.get(0) + .stream().filter(artifact -> { + String artifactName = artifact.getArtifactName(); + return artifactName.startsWith(instanceName) && artifactName.endsWith("modules.json"); + }).collect(Collectors.toList()); + if (moduleJsonArtifacts.size() > 0) { + String status = + "Instance " + instanceName + " has a corresponding modules.json file: " + moduleJsonArtifacts.get(0) .getArtifactName(); - ReportManager.writeReportLineToFile(status, outputFilePath); + reportFile.writeReportLineToFile(status); return true; } } String status = "Instance " + instanceName + " doesn't have a corresponding modules.json file"; - ReportManager.writeReportLineToFile(status, outputFilePath); + reportFile.writeReportLineToFile(status); report.addFailure(getTaskName(), vertex.getUniqueId()); return false; } 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 deleted file mode 100644 index 9b09e67c39..0000000000 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManager.java +++ /dev/null @@ -1,71 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (c) 2019 Samsung - * ================================================================================ - * 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.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; -import org.apache.commons.lang.text.StrBuilder; -import org.openecomp.sdc.asdctool.impl.validator.report.Report; -import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ReportManager { - - private static final Logger log = LoggerFactory.getLogger(ReportManager.class); - - public static ReportManager make(String txtReportFilePath) { - return new ReportManager(txtReportFilePath); - } - - private ReportManager(String txtReportFilePath) { - try { - initReportFile(txtReportFilePath); - } catch (IOException e) { - log.info("Init file failed - {}", e.getClass().getSimpleName(), e); - } - } - - private void initReportFile(String txtReportFilePath) throws IOException { - 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 writeReportLineToFile(String message, String outputFilePath) { - try { - Files.write(Paths.get(outputFilePath), new StrBuilder().appendNewLine().toString().getBytes(), - StandardOpenOption.APPEND); - Files.write(Paths.get(outputFilePath), message.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 3bffa0b5e2..22d93b1407 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 @@ -31,7 +31,6 @@ 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; import org.openecomp.sdc.common.api.ConfigurationSource; import org.openecomp.sdc.common.impl.ExternalConfiguration; 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 2f9f11b28f..41fb048757 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 @@ -43,8 +43,6 @@ public class ServiceValidatorExecuterTest { @Test(expected = NullPointerException.class) public void testExecuteValidations() { 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, makeTxtFile(makeConsoleWriter()), null); + createTestSubject().executeValidations(report, makeTxtFile(makeConsoleWriter())); } } 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 3760a57e33..aa388f68b7 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 @@ -48,8 +48,6 @@ public class VfValidatorExecuterTest { @Test(expected = NullPointerException.class) public void testExecuteValidations() { 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, makeTxtFile(makeConsoleWriter()), null); + createTestSubject().executeValidations(report, makeTxtFile(makeConsoleWriter())); } } 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 cd35f4ba2e..2ef85fda1f 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 @@ -78,9 +78,7 @@ public class ReportFileNioHelper { * @param The type returned by the function consuming the file */ public static A withTxtFile(String txtReportFilePath, Function f) { - // TODO: Switch to makeTxtFile once all the report file business logic has been moved to - // ReportFile - ReportFile.TXTFile file = ReportFile.makeAppendableTxtFile(makeNioWriter(txtReportFilePath)); + ReportFile.TXTFile file = ReportFile.makeTxtFile(makeNioWriter(txtReportFilePath)); A result = f.apply(file); try { Files.delete(Paths.get(txtReportFilePath)); 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 763c69f61e..26ad7d8e20 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 @@ -37,17 +37,13 @@ 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.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; 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.utils.ReportManager; -import org.openecomp.sdc.asdctool.impl.validator.utils.ReportManagerHelper; import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao; import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; @@ -101,16 +97,6 @@ public class ArtifactValidationUtilsTest { when(vertex.getUniqueId()).thenReturn(UNIQUE_ID_VERTEX); } - @BeforeEach - public void setup() { - ReportManager.make(txtReportFilePath); - } - - @AfterEach - public void clean() { - ReportManagerHelper.cleanReports(txtReportFilePath); - } - @Test public void testValidateArtifactsAreInCassandra() { // given @@ -119,15 +105,17 @@ public class ArtifactValidationUtilsTest { artifacts.add(artifactDataDefinition); // when - ArtifactsVertexResult result = - testSubject.validateArtifactsAreInCassandra(report, vertex, TASK_NAME, artifacts, txtReportFilePath); + withTxtFile(txtReportFilePath, file -> { + ArtifactsVertexResult result = + testSubject.validateArtifactsAreInCassandra(report, vertex, TASK_NAME, artifacts, file); - List reportOutputFile = ReportManagerHelper.getReportOutputFileAsList(txtReportFilePath); + List reportOutputFile = readFileAsList(txtReportFilePath); - // then - assertTrue(result.getStatus()); - assertEquals(0, result.notFoundArtifacts.size()); - assertEquals("Artifact " + ES_ID + " is in Cassandra", reportOutputFile.get(2)); + // then + assertTrue(result.getStatus()); + assertEquals(0, result.notFoundArtifacts.size()); + assertEquals("Artifact " + ES_ID + " is in Cassandra", reportOutputFile.get(2)); + }); } @Test @@ -141,7 +129,7 @@ public class ArtifactValidationUtilsTest { // when withTxtFile(txtReportFilePath, file -> { ArtifactsVertexResult result = - testSubject.validateArtifactsAreInCassandra(report, vertex, TASK_NAME, artifacts, txtReportFilePath); + testSubject.validateArtifactsAreInCassandra(report, vertex, TASK_NAME, artifacts, file); file.reportEndOfToolRun(report); List reportOutputFile = readFileAsList(txtReportFilePath); @@ -219,17 +207,19 @@ public class ArtifactValidationUtilsTest { .thenReturn(Either.left(topologyTemplate)); // when - ArtifactsVertexResult result = - testSubject.validateTopologyTemplateArtifacts(report, vertex, TASK_NAME, txtReportFilePath); + withTxtFile(txtReportFilePath, file -> { + ArtifactsVertexResult result = + testSubject.validateTopologyTemplateArtifacts(report, vertex, TASK_NAME, file); - List reportOutputFile = ReportManagerHelper.getReportOutputFileAsList(txtReportFilePath); + List reportOutputFile = readFileAsList(txtReportFilePath); - // then - assertTrue(result.getStatus()); - assertEquals(0, result.notFoundArtifacts.size()); + // then + assertTrue(result.getStatus()); + assertEquals(0, result.notFoundArtifacts.size()); - IntStream.range(2, reportOutputFile.size()).forEach( - i -> assertEquals("Artifact " + ES_ID + " is in Cassandra", reportOutputFile.get(i))); + IntStream.range(2, reportOutputFile.size()).forEach( + i -> assertEquals("Artifact " + ES_ID + " is in Cassandra", reportOutputFile.get(i))); + }); } @Test @@ -240,10 +230,11 @@ public class ArtifactValidationUtilsTest { .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND)); // when - ArtifactsVertexResult result = - testSubject.validateTopologyTemplateArtifacts(report, vertex, TASK_NAME, txtReportFilePath); - - // then - assertFalse(result.getStatus()); + withTxtFile(txtReportFilePath, file -> { + ArtifactsVertexResult result = + testSubject.validateTopologyTemplateArtifacts(report, vertex, TASK_NAME, file); + // then + assertFalse(result.getStatus()); + }); } } diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ServiceArtifactValidationTaskTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ServiceArtifactValidationTaskTest.java index b45b589752..849c679376 100644 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ServiceArtifactValidationTaskTest.java +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ServiceArtifactValidationTaskTest.java @@ -20,15 +20,17 @@ package org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts; -import org.junit.Test; -import org.openecomp.sdc.asdctool.impl.validator.report.Report; -import org.openecomp.sdc.asdctool.impl.validator.utils.VertexResult; -import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; - import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.nullValue; import static org.junit.Assert.assertThat; import static org.mockito.Mockito.mock; +import static org.openecomp.sdc.asdctool.impl.validator.report.ReportFile.makeTxtFile; + +import org.junit.Test; +import org.openecomp.sdc.asdctool.impl.validator.report.Report; +import org.openecomp.sdc.asdctool.impl.validator.report.ReportFileWriterTestFactory; +import org.openecomp.sdc.asdctool.impl.validator.utils.VertexResult; +import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; public class ServiceArtifactValidationTaskTest { @@ -42,9 +44,10 @@ public class ServiceArtifactValidationTaskTest { Report report = Report.make(); GraphVertex vertex = null; ServiceArtifactValidationTask testSubject = createTestSubject(); - // 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 - VertexResult actual = testSubject.validate(report, vertex, null); + VertexResult actual = testSubject.validate( + report, vertex, + makeTxtFile(ReportFileWriterTestFactory.makeConsoleWriter()) + ); assertThat(actual, is(nullValue())); } } diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/VfArtifactValidationTaskTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/VfArtifactValidationTaskTest.java index 60e41abf4f..a70326b928 100644 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/VfArtifactValidationTaskTest.java +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/VfArtifactValidationTaskTest.java @@ -22,6 +22,7 @@ package org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts; import org.junit.Test; import org.openecomp.sdc.asdctool.impl.validator.report.Report; +import org.openecomp.sdc.asdctool.impl.validator.report.ReportFileWriterTestFactory; import org.openecomp.sdc.asdctool.impl.validator.utils.VertexResult; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; @@ -29,6 +30,7 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.nullValue; import static org.junit.Assert.assertThat; import static org.mockito.Mockito.mock; +import static org.openecomp.sdc.asdctool.impl.validator.report.ReportFile.makeTxtFile; public class VfArtifactValidationTaskTest { @@ -42,9 +44,10 @@ public class VfArtifactValidationTaskTest { Report report = Report.make(); GraphVertex vertex = null; VfArtifactValidationTask testSubject = createTestSubject(); - // 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 - VertexResult actual = testSubject.validate(report, vertex, null); + VertexResult actual = testSubject.validate( + report, vertex, + makeTxtFile(ReportFileWriterTestFactory.makeConsoleWriter()) + ); assertThat(actual, is(nullValue())); } } 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 d2276fdd5a..af056103ff 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 @@ -21,24 +21,21 @@ package org.openecomp.sdc.asdctool.impl.validator.utils; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -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 static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.mockito.Mockito.when; import java.io.File; import java.util.Arrays; import java.util.List; import java.util.SortedSet; import java.util.TreeSet; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.mockito.Mockito.when; +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; public class ReportManagerTest { @@ -74,17 +71,6 @@ public class ReportManagerTest { private final GraphVertex vertexScanned = Mockito.mock(GraphVertex.class); - @BeforeEach - public void setup() { - ReportManager.make(txtReportFilePath); - successResult.setStatus(true); - } - - @AfterEach - public void clean() { - ReportManagerHelper.cleanReports(txtReportFilePath); - } - @Test public void testReportTaskEnd() { // when @@ -144,15 +130,15 @@ public class ReportManagerTest { @Test public void testWriteReportLineToFile() { // when - ReportManager.writeReportLineToFile(DUMMY_MESSAGE, txtReportFilePath); - - List reportOutputFile = ReportManagerHelper.getReportOutputFileAsList(txtReportFilePath); + List reportTxtFile = ReportFileNioHelper.withTxtFile(txtReportFilePath, file -> { + file.writeReportLineToFile(DUMMY_MESSAGE); + return ReportFileNioHelper.readFileAsList(txtReportFilePath); + }); // then - assertNotNull(reportOutputFile); - - assertEquals(EXPECTED_OUTPUT_FILE_HEADER, reportOutputFile.get(0)); - assertEquals(DUMMY_MESSAGE, reportOutputFile.get(2)); + assertNotNull(reportTxtFile); + assertEquals(EXPECTED_OUTPUT_FILE_HEADER, reportTxtFile.get(0)); + assertEquals(DUMMY_MESSAGE, reportTxtFile.get(2)); } @Test -- cgit 1.2.3-korg