This commit aims to encapsulate the static fields failedVerticesPerTask and resultsPerVertex in their own class (called Report). In the short terms, any state needing to be passed around will be stored there. Unfortunately, this commit required many minor changes in functions signature (to pass the Report instance).
Signed-off-by: Francis Toth <francis.toth@yoppworks.com>
Change-Id: I3756d9a939cbd0f2856be72aa2bd24a3980dde49
Issue-ID: SDC-2499
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.common.log.wrappers.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
-/**
- * Created by chaya on 7/3/2017.
- */
@Component
public class ValidationToolBL {
this.validators = validators;
}
- public boolean validateAll(String outputFilePath) {
+ public boolean validateAll(Report report, String outputFilePath) {
for (ValidatorExecuter validatorExec: validators) {
log.debug("ValidatorExecuter "+validatorExec.getName()+" started");
- if (!validatorExec.executeValidations(outputFilePath)) {
+ if (!validatorExec.executeValidations(report, outputFilePath)) {
allValid = false;
log.debug("ValidatorExecuter "+validatorExec.getName()+" finished with warnings");
}
package org.openecomp.sdc.asdctool.impl.validator.executers;
+import org.openecomp.sdc.asdctool.impl.validator.report.Report;
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;
import java.util.ArrayList;
import java.util.List;
-/**
- * Created by chaya on 7/4/2017.
- */
@Component
public class ServiceValidatorExecuter extends TopologyTemplateValidatorExecuter implements ValidatorExecuter {
}
@Override
- public boolean executeValidations(String outputFilePath) {
+ public boolean executeValidations(Report report, String outputFilePath) {
List<GraphVertex> vertices = getVerticesToValidate(ComponentTypeEnum.SERVICE);
- return validate(tasks, vertices, outputFilePath);
+ return validate(report, tasks, vertices, outputFilePath);
}
@Override
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.tasks.TopologyTemplateValidationTask;
import org.openecomp.sdc.asdctool.impl.validator.utils.ReportManager;
import org.openecomp.sdc.asdctool.impl.validator.utils.VertexResult;
import java.util.Map;
import java.util.Set;
-/**
- * Created by chaya on 7/3/2017.
- */
public class TopologyTemplateValidatorExecuter {
private static Logger log = Logger.getLogger(VfValidatorExecuter.class.getName());
return results.left().value();
}
- protected boolean validate(List<? extends TopologyTemplateValidationTask> tasks, List<GraphVertex> vertices,
+ protected boolean validate(Report report, List<? extends TopologyTemplateValidationTask> tasks, List<GraphVertex> vertices,
String outputFilePath) {
ReportManager.reportStartValidatorRun(getName(), vertices.size(), outputFilePath);
Set<String> failedTasks = new HashSet<>();
boolean successAllTasks = true;
for (TopologyTemplateValidationTask task : tasks) {
ReportManager.reportStartTaskRun(vertex, task.getTaskName(), outputFilePath);
- VertexResult result = task.validate(vertex, outputFilePath);
+ VertexResult result = task.validate(report, vertex, outputFilePath);
if (!result.getStatus()) {
failedTasks.add(task.getTaskName());
successAllVertices = false;
successTasks.add(task.getTaskName());
}
ReportManager.printValidationTaskStatus(vertex, task.getTaskName(), result.getStatus(), outputFilePath);
- ReportManager.reportTaskEnd(vertex.getUniqueId(), task.getTaskName(), result);
+ report.addSuccess(vertex.getUniqueId(), task.getTaskName(), result);
}
String componentScanStatus = successAllTasks ? "success" : "failed";
log.info("Topology Template " + vertex.getUniqueId() + " Validation finished with " + componentScanStatus);
package org.openecomp.sdc.asdctool.impl.validator.executers;
-/**
- * Created by chaya on 7/3/2017.
- */
+import org.openecomp.sdc.asdctool.impl.validator.report.Report;
+
public interface ValidatorExecuter {
- boolean executeValidations(String outputFilePath);
+ boolean executeValidations(Report report, String outputFilePath);
String getName();
}
package org.openecomp.sdc.asdctool.impl.validator.executers;
+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.GraphVertex;
import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
import java.util.List;
-/**
- * Created by chaya on 7/3/2017.
- */
public class VfValidatorExecuter extends TopologyTemplateValidatorExecuter implements ValidatorExecuter {
private List<VfValidationTask> tasks;
}
@Override
- public boolean executeValidations(String outputFilePath) {
+ public boolean executeValidations(Report report, String outputFilePath) {
List<GraphVertex> vertices = getVerticesToValidate(ComponentTypeEnum.RESOURCE);
- return validate(tasks, vertices, outputFilePath);
+ return validate(report, tasks, vertices, outputFilePath);
}
@Override
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T 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 java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.function.BiFunction;
+import java.util.function.Function;
+import java.util.function.Supplier;
+import org.openecomp.sdc.asdctool.impl.validator.utils.VertexResult;
+
+public final class Report {
+
+ private final Map<String, Set<String>> failedVerticesPerTask = new HashMap<>();
+ private final Map<String, Map<String, VertexResult>> resultsPerVertex = new HashMap<>();
+
+ public static Report make() {
+ return new Report();
+ }
+
+ private Report() {
+ }
+
+ public void addFailure(String taskName, String vertexId) {
+ Set<String> failedVertices =
+ get(failedVerticesPerTask, HashSet::new).apply(taskName);
+
+ put(failedVerticesPerTask).apply(taskName,
+ add(failedVertices).apply(vertexId));
+ }
+
+ public void addSuccess(String vertexId, String taskName, VertexResult result) {
+ Map<String, VertexResult> vertexTasksResults =
+ get(resultsPerVertex, HashMap::new).apply(vertexId);
+
+ put(resultsPerVertex).apply(vertexId,
+ put(vertexTasksResults).apply(taskName, result));
+ }
+
+ public void forEachFailure(FailureConsumer c) {
+ failedVerticesPerTask.forEach(c::traverse);
+ }
+
+ @FunctionalInterface
+ public interface FailureConsumer {
+
+ void traverse(String taskName, Set<String> failedVertices);
+ }
+
+ public void forEachSuccess(SuccessConsumer p) {
+ resultsPerVertex.forEach((vertex, tasksResults) ->
+ tasksResults.forEach((task, result) ->
+ p.traverse(vertex, task, result)));
+ }
+
+ @FunctionalInterface
+ public interface SuccessConsumer {
+
+ void traverse(String vertex, String task, VertexResult result);
+ }
+
+ <K, V> Function<K, V> get(Map<K, V> kvs, Supplier<V> fallback) {
+ return k -> Optional.ofNullable(kvs.get(k)).orElseGet(fallback);
+ }
+
+ <V> Function<V, Set<V>> add(Set<V> vs) {
+ return v -> {
+ vs.add(v);
+ return vs;
+ };
+ }
+
+ <K, V> BiFunction<K, V, Map<K, V>> put(Map<K, V> kvs) {
+ return (k, v) -> {
+ kvs.put(k, v);
+ return kvs;
+ };
+ }
+}
package org.openecomp.sdc.asdctool.impl.validator.tasks;
+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;
-/**
- * Created by chaya on 7/5/2017.
- */
public interface TopologyTemplateValidationTask {
- VertexResult validate(GraphVertex vertex, String outputFilePath);
+ VertexResult validate(Report report, GraphVertex vertex, String outputFilePath);
String getTaskName();
String getTaskResultStatus();
void setTaskResultStatus(String status);
package org.openecomp.sdc.asdctool.impl.validator.tasks;
-/**
- * Created by chaya on 7/5/2017.
- */
public abstract class VfValidationTask implements TopologyTemplateValidationTask {
protected String taskStatus = "NOT_STARTED";
protected String name = "";
package org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts;
import fj.data.Either;
+import org.openecomp.sdc.asdctool.impl.validator.report.Report;
import org.openecomp.sdc.asdctool.impl.validator.utils.ReportManager;
import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao;
import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus;
this.topologyTemplateOperation = topologyTemplateOperation;
}
- public ArtifactsVertexResult validateArtifactsAreInCassandra(GraphVertex vertex, String taskName,
+ public ArtifactsVertexResult validateArtifactsAreInCassandra(Report report, GraphVertex vertex, String taskName,
List<ArtifactDataDefinition> artifacts, String outputFilePath) {
ArtifactsVertexResult result = new ArtifactsVertexResult(true);
for (ArtifactDataDefinition artifact : artifacts) {
"Artifact " + artifact.getEsId() + " doesn't exist in Cassandra";
ReportManager.writeReportLineToFile(status, outputFilePath);
if (!isArtifactExist) {
- ReportManager.addFailedVertex(taskName, vertex.getUniqueId());
+ report.addFailure(taskName, vertex.getUniqueId());
result.setStatus(false);
result.addNotFoundArtifact(artifact.getUniqueId());
}
return artifacts;
}
- public ArtifactsVertexResult validateTopologyTemplateArtifacts(GraphVertex vertex, String taskName,
+ public ArtifactsVertexResult validateTopologyTemplateArtifacts(Report report, GraphVertex vertex, String taskName,
String outputFilePath) {
ArtifactsVertexResult result = new ArtifactsVertexResult();
ComponentParametersView paramView = new ComponentParametersView();
allArtifacts.addAll(addRelevantArtifacts(artifactMap.getMapToscaDataDefinition())));
}
- return validateArtifactsAreInCassandra(vertex, taskName, allArtifacts, outputFilePath);
+ return validateArtifactsAreInCassandra(report, vertex, taskName, allArtifacts, outputFilePath);
}
}
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.tasks.ServiceValidationTask;
import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
import org.springframework.beans.factory.annotation.Autowired;
-/**
- * Created by chaya on 7/6/2017.
- */
public class ServiceArtifactValidationTask extends ServiceValidationTask {
private ArtifactValidationUtils artifactValidationUtils;
}
@Override
- public ArtifactsVertexResult validate(GraphVertex vertex, String outputFilePath) {
- return artifactValidationUtils.validateTopologyTemplateArtifacts(vertex, getTaskName(), outputFilePath);
+ public ArtifactsVertexResult validate(Report report, GraphVertex vertex, String outputFilePath) {
+ return artifactValidationUtils.validateTopologyTemplateArtifacts(report, vertex, getTaskName(), outputFilePath);
}
}
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.tasks.VfValidationTask;
import org.openecomp.sdc.asdctool.impl.validator.utils.VertexResult;
import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
}
@Override
- public VertexResult validate(GraphVertex vertex, String outputFilePath) {
- return artifactValidationUtils.validateTopologyTemplateArtifacts(vertex, getTaskName(), outputFilePath);
+ public VertexResult validate(Report report, GraphVertex vertex, String outputFilePath) {
+ return artifactValidationUtils.validateTopologyTemplateArtifacts(report, vertex, getTaskName(), outputFilePath);
}
}
package org.openecomp.sdc.asdctool.impl.validator.tasks.moduleJson;
import fj.data.Either;
+import org.openecomp.sdc.asdctool.impl.validator.report.Report;
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 java.util.Optional;
import java.util.stream.Collectors;
-/**
- * Created by chaya on 7/18/2017.
- */
public class ModuleJsonTask extends ServiceValidationTask {
private TopologyTemplateOperation topologyTemplateOperation;
}
@Override
- public VertexResult validate(GraphVertex vertex, String outputFilePath) {
+ public VertexResult validate(Report report, GraphVertex vertex, String outputFilePath) {
if (!isAfterSubmitForTesting(vertex)) {
return new VertexResult(true);
}
.orElse(Collections.emptyMap()).entrySet()) {
MapGroupsDataDefinition groups = pair.getValue();
if (groups != null && !groups.getMapToscaDataDefinition().isEmpty()) {
- return new VertexResult(findCoordinateModuleJson(pair, instDeploymentArtifacts, vertex, outputFilePath));
+ return new VertexResult(
+ findCoordinateModuleJson(report, pair, instDeploymentArtifacts, vertex, outputFilePath));
}
return new VertexResult(true);
}
return new VertexResult(true);
}
- private boolean findCoordinateModuleJson(Map.Entry<String, MapGroupsDataDefinition> pair,
- Map<String, MapArtifactDataDefinition> instDeploymentArtifacts, GraphVertex vertex, String outputFilePath) {
+ private boolean findCoordinateModuleJson(
+ Report report,
+ Map.Entry<String, MapGroupsDataDefinition> pair,
+ Map<String, MapArtifactDataDefinition> instDeploymentArtifacts,
+ GraphVertex vertex, String outputFilePath
+ ) {
String groupKey = pair.getKey();
String[] split = groupKey.split("\\.");
String instanceName = split[split.length - 1];
}
String status = "Instance " + instanceName + " doesn't have a corresponding modules.json file";
ReportManager.writeReportLineToFile(status, outputFilePath);
- ReportManager.addFailedVertex(getTaskName(), vertex.getUniqueId());
+ report.addFailure(getTaskName(), vertex.getUniqueId());
return false;
}
private boolean isAfterSubmitForTesting(GraphVertex vertex) {
- List allowedStates = new ArrayList<>(Arrays.asList(LifecycleStateEnum.CERTIFIED.name()));
+ List<String> allowedStates = new ArrayList<>(Arrays.asList(LifecycleStateEnum.CERTIFIED.name()));
return allowedStates.contains(vertex.getMetadataProperty(GraphPropertyEnum.STATE));
}
}
package org.openecomp.sdc.asdctool.impl.validator.utils;
-import org.apache.commons.lang.text.StrBuilder;
-import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Optional;
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 Logger log = LoggerFactory.getLogger(ReportManager.class);
-
- private static final Map<String, Set<String>> failedVerticesPerTask = new HashMap<>();
- private static final Map<String, Map<String, VertexResult>> resultsPerVertex = new HashMap<>();
+ private static final Logger log = LoggerFactory.getLogger(ReportManager.class);
public static ReportManager make(String csvReportFilePath, String txtReportFilePath) {
return new ReportManager(csvReportFilePath, txtReportFilePath);
Files.write(Paths.get(csvReportFilePath), sb.toString().getBytes());
}
- public static void reportTaskEnd(String vertexId, String taskName, VertexResult result) {
- Map<String, VertexResult> vertexTasksResults =
- Optional.ofNullable(resultsPerVertex.get(vertexId)).orElse(new HashMap<>());
- vertexTasksResults.put(taskName, result);
- resultsPerVertex.put(vertexId, vertexTasksResults);
- }
-
- public static void addFailedVertex(String taskName, String vertexId) {
- Set<String> failedVertices = failedVerticesPerTask.get(taskName);
- if (failedVertices == null) {
- failedVertices = new HashSet<>();
- }
- failedVertices.add(vertexId);
- failedVerticesPerTask.put(taskName, failedVertices);
- }
-
public static void printValidationTaskStatus(GraphVertex vertexScanned, String taskName, boolean success,
String outputFilePath) {
String successStatus = success ? "success" : "failed";
writeReportLineToFile(sb.toString(), outputFilePath);
}
- public static void reportEndOfToolRun(String csvReportFilePath, String outputFilePath) {
+ public static void reportEndOfToolRun(Report report, String csvReportFilePath, String outputFilePath) {
StrBuilder sb = new StrBuilder();
sb.appendln("-----------------------------------Validator Tool Summary-----------------------------------");
- failedVerticesPerTask.forEach((taskName, failedVertices) -> {
+ report.forEachFailure((taskName, failedVertices) -> {
sb.append("Task: " + taskName);
sb.appendNewLine();
sb.append("FailedVertices: " + failedVertices);
sb.appendNewLine();
});
writeReportLineToFile(sb.toString(), outputFilePath);
- printAllResults(csvReportFilePath);
+ printAllResults(report, csvReportFilePath);
}
- public static void printAllResults(String csvReportFilePath) {
- resultsPerVertex.forEach((vertex, tasksResults) -> tasksResults.forEach((task, result) -> {
+ 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(),
} catch (IOException e) {
log.info("write to file failed - {}", e.getClass().getSimpleName(), e);
}
- }));
+ });
}
}
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.Report;
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.log.wrappers.Logger;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
-/**
- * Created by chaya on 7/3/2017.
- */
public class ValidationTool {
- private static Logger log = Logger.getLogger(ValidationTool.class.getName());
+ private static final Logger log = Logger.getLogger(ValidationTool.class.getName());
public static void main(String[] args) {
ValidationToolBL validationToolBL = context.getBean(ValidationToolBL.class);
log.info("Start Validation Tool");
- boolean result = validationToolBL.validateAll(txtReportFilePath);
- ReportManager.reportEndOfToolRun(csvReportFilePath, txtReportFilePath);
+ Report report = Report.make();
+ boolean result = validationToolBL.validateAll(report, txtReportFilePath);
+ ReportManager.reportEndOfToolRun(report, csvReportFilePath, txtReportFilePath);
if (result) {
log.info("Validation finished successfully");
System.exit(0);
private static AnnotationConfigApplicationContext initContext(String appConfigDir) {
ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
- AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ValidationToolConfiguration.class);
- return context;
+ return new AnnotationConfigApplicationContext(ValidationToolConfiguration.class);
}
}
import org.junit.Test;
import org.openecomp.sdc.asdctool.impl.validator.executers.ServiceValidatorExecuter;
+import org.openecomp.sdc.asdctool.impl.validator.report.Report;
import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
import java.util.ArrayList;
ValidationToolBL testSubject = createTestSubject();
testSubject.validators = new LinkedList<>();
testSubject.validators.add(new ServiceValidatorExecuter(janusGraphDaoMock));
+ 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(null);
+ testSubject.validateAll(report, null);
}
}
package org.openecomp.sdc.asdctool.impl.validator.executers;
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;
@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(null);
+ createTestSubject().executeValidations(report, null);
}
}
package org.openecomp.sdc.asdctool.impl.validator.executers;
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;
@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(null);
+ createTestSubject().executeValidations(report, null);
}
}
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;
@Test
public void testValidateArtifactsAreInCassandra() {
// given
+ Report report = Report.make();
List<ArtifactDataDefinition> artifacts = new ArrayList<>();
artifacts.add(artifactDataDefinition);
// when
ArtifactsVertexResult result =
- testSubject.validateArtifactsAreInCassandra(vertex, TASK_NAME, artifacts, txtReportFilePath);
+ testSubject.validateArtifactsAreInCassandra(report, vertex, TASK_NAME, artifacts, txtReportFilePath);
List<String> reportOutputFile = ReportManagerHelper.getReportOutputFileAsList(txtReportFilePath);
@Test
public void testValidateArtifactsNotInCassandra() {
// given
+ Report report = Report.make();
List<ArtifactDataDefinition> artifacts = new ArrayList<>();
artifacts.add(artifactDataDefinition);
artifacts.add(artifactDataDefinitionNotInCassandra);
// when
ArtifactsVertexResult result =
- testSubject.validateArtifactsAreInCassandra(vertex, TASK_NAME, artifacts, txtReportFilePath);
- ReportManager.reportEndOfToolRun(csvReportFilePath, txtReportFilePath);
+ testSubject.validateArtifactsAreInCassandra(report, vertex, TASK_NAME, artifacts, txtReportFilePath);
+ ReportManager.reportEndOfToolRun(report, csvReportFilePath, txtReportFilePath);
List<String> reportOutputFile = ReportManagerHelper.getReportOutputFileAsList(txtReportFilePath);
@Test
public void testValidateTopologyTemplateArtifacts() {
// given
+ Report report = Report.make();
Map<String, ArtifactDataDefinition> artifacts = new HashMap<>();
artifacts.put(ES_ID, artifactDataDefinition);
// when
ArtifactsVertexResult result =
- testSubject.validateTopologyTemplateArtifacts(vertex, TASK_NAME, txtReportFilePath);
+ testSubject.validateTopologyTemplateArtifacts(report, vertex, TASK_NAME, txtReportFilePath);
List<String> reportOutputFile = ReportManagerHelper.getReportOutputFileAsList(txtReportFilePath);
@Test
public void testValidateTopologyTemplateArtifactsNotFoundToscaElement() {
// given
+ Report report = Report.make();
when(topologyTemplateOperation.getToscaElement(eq(vertex.getUniqueId()), any()))
.thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
// when
ArtifactsVertexResult result =
- testSubject.validateTopologyTemplateArtifacts(vertex, TASK_NAME, txtReportFilePath);
+ testSubject.validateTopologyTemplateArtifacts(report, vertex, TASK_NAME, txtReportFilePath);
// then
assertFalse(result.getStatus());
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;
@Test
public void testValidate() {
+ 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(vertex, null);
+ VertexResult actual = testSubject.validate(report, vertex, null);
assertThat(actual, is(nullValue()));
}
}
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;
@Test
public void testValidate() {
+ 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(vertex, null);
+ VertexResult actual = testSubject.validate(report, vertex, null);
assertThat(actual, is(nullValue()));
}
}
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
+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 org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
// 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
try {
- VertexResult actual = test.validate(vertex, null);
+ Report report = Report.make();
+ VertexResult actual = test.validate(report, vertex, null);
assertThat(actual.getStatus(), is(true));
} catch (Exception e) {
// TODO: Fix this test, as currently, any exception is ignored
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.be.dao.jsongraph.GraphVertex;
import java.io.File;
private final SortedSet<String> successTasksNames =
new TreeSet<>(Arrays.asList(TASK_1_NAME, TASK_2_NAME));
- private VertexResult successResult = new VertexResult();
+ private final VertexResult successResult = new VertexResult();
private final static String resourcePath = new File("src/test/resources").getAbsolutePath();
private final static String csvReportFilePath = ValidationConfigManager
@Test
public void testReportTaskEnd() {
// when
- ReportManager.reportTaskEnd(VERTEX_1_ID, TASK_1_NAME, successResult);
- ReportManager.reportTaskEnd(VERTEX_2_ID, TASK_2_NAME, successResult);
- ReportManager.printAllResults(csvReportFilePath);
+ 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);
@Test
public void testAddFailedVertex() {
// when
- ReportManager.addFailedVertex(TASK_1_NAME, VERTEX_1_ID);
- ReportManager.reportEndOfToolRun(csvReportFilePath, txtReportFilePath);
+ Report report = Report.make();
+ report.addFailure(TASK_1_NAME, VERTEX_1_ID);
+ ReportManager.reportEndOfToolRun(report, csvReportFilePath, txtReportFilePath);
- List reportOutputFile = ReportManagerHelper.getReportOutputFileAsList(txtReportFilePath);
+ List<String> reportOutputFile = ReportManagerHelper.getReportOutputFileAsList(txtReportFilePath);
// then
assertNotNull(reportOutputFile);