diff options
author | k.kedron <k.kedron@partner.samsung.com> | 2019-07-02 11:04:56 +0200 |
---|---|---|
committer | Ofir Sonsino <ofir.sonsino@intl.att.com> | 2019-07-22 08:08:46 +0000 |
commit | 2ca6a9f860889c17202d4a518eefc980a1bb139a (patch) | |
tree | 2eba77cb98402d692cb46e0d41abf6edc84c12b0 /asdctool/src/main/java | |
parent | aebdb3efa77f2cbeaf65361be3f46528f089b17a (diff) |
Improved unit tests for ArtifactValidationUtils and Sonar fixes.
Added new tests for ArtifactValidationUtils.
Checkstyle in the ValidationConfigManager and ArtifactValidationUtils.
Added private constructor to ValidationConfigManager.
Added logger for ArtifactValidationUtils and simplified code.
Updated the ValidationConfigManagerTest and ReportManagerTests
to not influence on each other.
Issue-ID: SDC-2327
Signed-off-by: Krystian Kedron <k.kedron@partner.samsung.com>
Change-Id: I9c7c725792737b6cfa6bba20eeeb3b1d4ef1e471
Diffstat (limited to 'asdctool/src/main/java')
2 files changed, 40 insertions, 30 deletions
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationConfigManager.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationConfigManager.java index 5630a2be7f..cc75dfc968 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationConfigManager.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationConfigManager.java @@ -3,13 +3,17 @@ * 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 - * + * + * + * 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. @@ -24,6 +28,7 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Properties; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,37 +43,40 @@ public class ValidationConfigManager { private static String outputFullFilePath; private static String outputFilePath; + private ValidationConfigManager() { + } + public static String getOutputFullFilePath() { return outputFullFilePath; } + public static String getOutputFilePath() { return outputFilePath; } public static void setOutputFullFilePath(String outputPath) { - ValidationConfigManager.outputFilePath = outputPath; - ValidationConfigManager.outputFullFilePath = outputPath+ "/reportOutput.txt"; + ValidationConfigManager.outputFilePath = outputPath; + ValidationConfigManager.outputFullFilePath = outputPath + "/reportOutput.txt"; } - - public static String getCsvReportFilePath() { return csvReportFilePath; } public static void setCsvReportFilePath(String outputPath) { - ValidationConfigManager.csvReportFilePath = outputPath +"/csvSummary_"+System.currentTimeMillis()+".csv"; + ValidationConfigManager.csvReportFilePath = + outputPath + "/csvSummary_" + System.currentTimeMillis() + ".csv"; } private static String csvReportFilePath = "summary.csv"; - public static Properties setValidationConfiguration(String path){ - InputStream input = null; + public static Properties setValidationConfiguration(String path) { + InputStream input; try { input = new FileInputStream(path); prop.load(input); } catch (IOException ex) { - log.info("FileInputStream failed - " , ex); + log.info("FileInputStream failed - {}", ex); } return prop; } 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 025e0b61e1..2e804cc8a2 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 @@ -3,13 +3,14 @@ * 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. @@ -20,7 +21,12 @@ 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.utils.ReportManager; import org.openecomp.sdc.be.dao.cassandra.ArtifactCassandraDao; import org.openecomp.sdc.be.dao.cassandra.CassandraOperationStatus; @@ -32,15 +38,18 @@ import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.TopologyTemplate; import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElement; import org.openecomp.sdc.be.model.jsonjanusgraph.operations.TopologyTemplateOperation; 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.*; +import fj.data.Either; /** * Created by chaya on 7/6/2017. */ public class ArtifactValidationUtils { + private static final Logger logger = Logger.getLogger(ArtifactValidationUtils.class); + private ArtifactCassandraDao artifactCassandraDao; private TopologyTemplateOperation topologyTemplateOperation; @@ -55,10 +64,9 @@ public class ArtifactValidationUtils { public ArtifactsVertexResult validateArtifactsAreInCassandra(GraphVertex vertex, String taskName, List<ArtifactDataDefinition> artifacts) { ArtifactsVertexResult result = new ArtifactsVertexResult(true); for(ArtifactDataDefinition artifact:artifacts) { - boolean isArtifactExist = isArtifcatInCassandra(artifact.getEsId()); + 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); if (!isArtifactExist) { ReportManager.addFailedVertex(taskName, vertex.getUniqueId()); @@ -69,24 +77,20 @@ public class ArtifactValidationUtils { return result; } - public boolean isArtifcatInCassandra(String uniueId) { + public boolean isArtifactInCassandra(String uniqueId) { Either<Long, CassandraOperationStatus> countOfArtifactsEither = - artifactCassandraDao.getCountOfArtifactById(uniueId); + artifactCassandraDao.getCountOfArtifactById(uniqueId); if (countOfArtifactsEither.isRight()) { - // print to console - System.out.print("Failed to retrieve artifact with id: "+uniueId+" from Cassandra" ); + logger.debug("Failed to retrieve artifact with id: {} from Cassandra", uniqueId); return false; } Long count = countOfArtifactsEither.left().value(); - if (count <1) { - return false; - } - return true; + return count >= 1; } public List<ArtifactDataDefinition> addRelevantArtifacts(Map<String, ArtifactDataDefinition> artifactsMap) { List<ArtifactDataDefinition> artifacts = new ArrayList<>(); - Optional.ofNullable(artifactsMap).orElse(Collections.emptyMap()).forEach( (key, dataDef) -> { + Optional.ofNullable(artifactsMap).orElse(Collections.emptyMap()).forEach((key, dataDef) -> { if (dataDef.getEsId() != null && !dataDef.getEsId().isEmpty()) { artifacts.add(dataDef); } @@ -119,15 +123,13 @@ public class ArtifactValidationUtils { allArtifacts.addAll(addRelevantArtifacts(apiArtifacts)); if (instanceArtifacts != null) { - instanceArtifacts.forEach((key, artifactMap) -> { - allArtifacts.addAll(addRelevantArtifacts(artifactMap.getMapToscaDataDefinition())); - }); + instanceArtifacts.forEach((key, artifactMap) -> + allArtifacts.addAll(addRelevantArtifacts(artifactMap.getMapToscaDataDefinition()))); } if (instanceDeploymentArtifacts != null) { - instanceDeploymentArtifacts.forEach((key, artifactMap) -> { - allArtifacts.addAll(addRelevantArtifacts(artifactMap.getMapToscaDataDefinition())); - }); + instanceDeploymentArtifacts.forEach((key, artifactMap) -> + allArtifacts.addAll(addRelevantArtifacts(artifactMap.getMapToscaDataDefinition()))); } return validateArtifactsAreInCassandra(vertex, taskName, allArtifacts); |