From e9cb7eb287f88938b0a2f6d2cd0743e6ac2867f8 Mon Sep 17 00:00:00 2001 From: Francis Toth Date: Wed, 24 Jun 2020 09:28:06 -0400 Subject: Cleaned up ArtifactValidatorExecuter and IArtifactValidatorExecutor This commit intends to clean the tests related to ArtifactValidatorExecuter and IArtifactValidatorExecutor by introducing the concept of test contract. Some renaming have to be done to fix the typo in Executer (it should be named Executor), hence the number of changes. Signed-off-by: Francis Toth Change-Id: I5cd4512c425ae01f4f1118c9d61e6fce3df94f1d Issue-ID: SDC-2499 --- .../asdctool/impl/validator/ArtifactToolBL.java | 10 +- .../asdctool/impl/validator/ValidationToolBL.java | 2 +- .../config/ValidationToolConfiguration.java | 10 +- .../executers/ArtifactValidatorExecuter.java | 164 --------------------- .../executers/ArtifactValidatorExecutor.java | 160 ++++++++++++++++++++ .../executers/IArtifactValidatorExecuter.java | 28 ---- .../executers/IArtifactValidatorExecutor.java | 29 ++++ .../NodeToscaArtifactsValidatorExecuter.java | 64 -------- .../NodeToscaArtifactsValidatorExecutor.java | 52 +++++++ .../ServiceToscaArtifactsValidatorExecutor.java | 16 +- .../VFToscaArtifactValidatorExecutor.java | 18 +-- .../validator/executers/VfValidatorExecuter.java | 2 +- .../sdc/asdctool/main/ValidationTool.java | 2 +- .../impl/validator/ArtifactToolBLTest.java | 4 +- .../impl/validator/ValidationToolBLTest.java | 4 +- .../config/ValidationToolConfigurationTest.java | 4 +- .../executers/ArtifactValidatorExecuterTest.java | 95 ------------ .../ArtifactValidatorExecutorContract.java | 75 ++++++++++ .../IArtifactValidatorExecutorContract.java | 50 +++++++ .../NodeToscaArtifactsValidatorExecuterTest.java | 64 -------- .../NodeToscaArtifactsValidatorExecutorTest.java | 36 +++++ ...ServiceToscaArtifactsValidatorExecutorTest.java | 44 +----- .../VFToscaArtifactValidatorExecutorTest.java | 50 +------ 23 files changed, 443 insertions(+), 540 deletions(-) delete mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecuter.java create mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecutor.java delete mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/IArtifactValidatorExecuter.java create mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/IArtifactValidatorExecutor.java delete mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/NodeToscaArtifactsValidatorExecuter.java create mode 100644 asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/NodeToscaArtifactsValidatorExecutor.java delete mode 100644 asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecuterTest.java create mode 100644 asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecutorContract.java create mode 100644 asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/IArtifactValidatorExecutorContract.java delete mode 100644 asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/NodeToscaArtifactsValidatorExecuterTest.java create mode 100644 asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/NodeToscaArtifactsValidatorExecutorTest.java (limited to 'asdctool/src') diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/ArtifactToolBL.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/ArtifactToolBL.java index ebd548202b..75fde3de1e 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/ArtifactToolBL.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/ArtifactToolBL.java @@ -20,7 +20,7 @@ package org.openecomp.sdc.asdctool.impl.validator; -import org.openecomp.sdc.asdctool.impl.validator.executers.IArtifactValidatorExecuter; +import org.openecomp.sdc.asdctool.impl.validator.executers.IArtifactValidatorExecutor; import org.openecomp.sdc.common.log.wrappers.Logger; import org.springframework.beans.factory.annotation.Autowired; @@ -28,20 +28,20 @@ import java.util.List; public class ArtifactToolBL { - private static Logger log = Logger.getLogger(ValidationToolBL.class.getName()); + private static final Logger log = Logger.getLogger(ValidationToolBL.class.getName()); - protected List validators; + protected List validators; private boolean allValid = true; @Autowired public ArtifactToolBL( - List validators) { + List validators) { this.validators = validators; } public boolean validateAll(String outputFilePath) { - for (IArtifactValidatorExecuter validatorExec : validators) { + for (IArtifactValidatorExecutor validatorExec : validators) { log.debug("ValidatorExecuter " + validatorExec.getName() + " started"); if (!validatorExec.executeValidations(outputFilePath)) { allValid = false; 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 6659f6e82c..2fac030188 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 @@ -44,7 +44,7 @@ public class ValidationToolBL { this.validators = validators; } - public boolean validateAll(Report report, ReportFile.TXTFile textFile, String outputFilePath) { + public boolean validateAll(Report report, ReportFile.TXTFile textFile) { for (ValidatorExecuter validatorExec: validators) { log.debug("ValidatorExecuter "+validatorExec.getName()+" started"); if (!validatorExec.executeValidations(report, textFile)) { diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfiguration.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfiguration.java index b13009fecc..81051a62b9 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfiguration.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfiguration.java @@ -23,8 +23,8 @@ package org.openecomp.sdc.asdctool.impl.validator.config; import org.openecomp.sdc.asdctool.impl.VrfObjectFixHandler; import org.openecomp.sdc.asdctool.impl.validator.ArtifactToolBL; import org.openecomp.sdc.asdctool.impl.validator.ValidationToolBL; -import org.openecomp.sdc.asdctool.impl.validator.executers.IArtifactValidatorExecuter; -import org.openecomp.sdc.asdctool.impl.validator.executers.NodeToscaArtifactsValidatorExecuter; +import org.openecomp.sdc.asdctool.impl.validator.executers.IArtifactValidatorExecutor; +import org.openecomp.sdc.asdctool.impl.validator.executers.NodeToscaArtifactsValidatorExecutor; import org.openecomp.sdc.asdctool.impl.validator.executers.ServiceToscaArtifactsValidatorExecutor; import org.openecomp.sdc.asdctool.impl.validator.executers.ServiceValidatorExecuter; import org.openecomp.sdc.asdctool.impl.validator.executers.VFToscaArtifactValidatorExecutor; @@ -83,9 +83,9 @@ public class ValidationToolConfiguration { } @Bean - public NodeToscaArtifactsValidatorExecuter NodeToscaArtifactsValidatorValidator(JanusGraphDao janusGraphDao, + public NodeToscaArtifactsValidatorExecutor NodeToscaArtifactsValidatorValidator(JanusGraphDao janusGraphDao, ToscaOperationFacade toscaOperationFacade) { - return new NodeToscaArtifactsValidatorExecuter(janusGraphDao, toscaOperationFacade); + return new NodeToscaArtifactsValidatorExecutor(janusGraphDao, toscaOperationFacade); } @Bean @@ -121,7 +121,7 @@ public class ValidationToolConfiguration { } @Bean - public ArtifactToolBL artifactToolBL(List validators) { + public ArtifactToolBL artifactToolBL(List validators) { return new ArtifactToolBL(validators); } diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecuter.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecuter.java deleted file mode 100644 index 9007d8ce05..0000000000 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecuter.java +++ /dev/null @@ -1,164 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2019 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.executers; - -import fj.data.Either; -import org.openecomp.sdc.asdctool.impl.validator.config.ValidationConfigManager; -import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; -import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; -import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; -import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum; -import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; -import org.openecomp.sdc.be.model.ArtifactDefinition; -import org.openecomp.sdc.be.model.Component; -import org.openecomp.sdc.be.model.ComponentParametersView; -import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade; -import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; -import org.openecomp.sdc.common.log.wrappers.Logger; - -import java.io.BufferedWriter; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.io.Writer; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; - -public class ArtifactValidatorExecuter { - - protected JanusGraphDao janusGraphDao; - protected ToscaOperationFacade toscaOperationFacade; - - public ArtifactValidatorExecuter(JanusGraphDao janusGraphDao, - ToscaOperationFacade toscaOperationFacade) { - this.janusGraphDao = janusGraphDao; - this.toscaOperationFacade = toscaOperationFacade; - } - - private static Logger log = Logger.getLogger(ArtifactValidatorExecuter.class.getName()); - - protected String name; - - public void setName(String name) { - this.name = name; - } - - public String getName() { - return name; - } - - - public Map> getVerticesToValidate(VertexTypeEnum type, - Map hasProps) { - Map> result = new HashMap<>(); - Either, JanusGraphOperationStatus> resultsEither = janusGraphDao - .getByCriteria(type, hasProps); - if (resultsEither.isRight()) { - log.error("getVerticesToValidate failed " + resultsEither.right().value()); - return result; - } - System.out.println("getVerticesToValidate: " + resultsEither.left().value().size() + " vertices to scan"); - List componentsList = resultsEither.left().value(); - componentsList.forEach(vertex -> { - String ivariantUuid = (String) vertex.getMetadataProperty(GraphPropertyEnum.INVARIANT_UUID); - if (!result.containsKey(ivariantUuid)) { - List compList = new ArrayList(); - result.put(ivariantUuid, compList); - } - List compList = result.get(ivariantUuid); - - ComponentParametersView filter = new ComponentParametersView(true); - filter.setIgnoreArtifacts(false); - - Either toscaElement = toscaOperationFacade - .getToscaElement(vertex.getUniqueId(), filter); - if (toscaElement.isRight()) { - log.error( - "getVerticesToValidate: failed to find element" + vertex.getUniqueId() + " staus is" + toscaElement - .right().value()); - } else { - compList.add(toscaElement.left().value()); - } - - }); - - return result; - } - - public boolean validate(Map> vertices, String outputFilePath) { - boolean result = true; - long time = System.currentTimeMillis(); - String fileName = outputFilePath + this.getName() + "_" + time + ".csv"; - try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "utf-8"))) { - writer.write("name, UUID, invariantUUID, state, version\n"); - Collection> collection = vertices.values(); - for (List compList : collection) { - Set artifactEsId = new HashSet<>(); - for (Component component : compList) { - Map toscaArtifacts = component.getToscaArtifacts(); - Optional op = toscaArtifacts.values(). - stream().filter(a -> artifactEsId.contains(a.getEsId())).findAny(); - if (op.isPresent()) { - result = false; - writeModuleResultToFile(writer, compList); - writer.flush(); - break; - } else { - artifactEsId.addAll(toscaArtifacts.values().stream().map(ArtifactDefinition::getEsId) - .collect(Collectors.toList())); - } - } - - } - - } catch (Exception e) { - log.error("Failed to fetch vf resources ", e); - return false; - } finally { - janusGraphDao.commit(); - } - return result; - } - - private void writeModuleResultToFile(Writer writer, List components) { - try { - // "service name, service id, state, version - for (Component component : components) { - StringBuffer sb = new StringBuffer(component.getName()); - sb.append(",").append(component.getUniqueId()).append(",").append(component.getInvariantUUID()) - .append(",").append(component.getLifecycleState()).append(",").append(component.getVersion()); - - sb.append("\n"); - writer.write(sb.toString()); - } - } catch (IOException e) { - log.error("Failed to write module result to file ", e); - } - } - -} diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecutor.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecutor.java new file mode 100644 index 0000000000..1a19f5d882 --- /dev/null +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecutor.java @@ -0,0 +1,160 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2019 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.executers; + +import static java.nio.charset.StandardCharsets.UTF_8; + +import fj.data.Either; +import java.io.BufferedWriter; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.Writer; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; +import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus; +import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; +import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; +import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum; +import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; +import org.openecomp.sdc.be.model.ArtifactDefinition; +import org.openecomp.sdc.be.model.Component; +import org.openecomp.sdc.be.model.ComponentParametersView; +import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade; +import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; +import org.openecomp.sdc.common.log.wrappers.Logger; + +public abstract class ArtifactValidatorExecutor { + + private static final Logger log = Logger.getLogger(ArtifactValidatorExecutor.class); + + private final JanusGraphDao janusGraphDao; + private final ToscaOperationFacade toscaOperationFacade; + private final String name; + + public ArtifactValidatorExecutor( + JanusGraphDao janusGraphDao, + ToscaOperationFacade toscaOperationFacade, + String name + ) { + this.janusGraphDao = janusGraphDao; + this.toscaOperationFacade = toscaOperationFacade; + this.name = name; + } + + public String getName() { + return name; + } + + public Map> getVerticesToValidate(VertexTypeEnum type, + Map hasProps) { + Map> result = new HashMap<>(); + Either, JanusGraphOperationStatus> resultsEither = janusGraphDao + .getByCriteria(type, hasProps); + if (resultsEither.isRight()) { + log.error("getVerticesToValidate failed " + resultsEither.right().value()); + return result; + } + System.out.println("getVerticesToValidate: " + resultsEither.left().value().size() + " vertices to scan"); + List componentsList = resultsEither.left().value(); + componentsList.forEach(vertex -> { + String ivariantUuid = (String) vertex.getMetadataProperty(GraphPropertyEnum.INVARIANT_UUID); + if (!result.containsKey(ivariantUuid)) { + List compList = new ArrayList<>(); + result.put(ivariantUuid, compList); + } + List compList = result.get(ivariantUuid); + + ComponentParametersView filter = new ComponentParametersView(true); + filter.setIgnoreArtifacts(false); + + Either toscaElement = toscaOperationFacade + .getToscaElement(vertex.getUniqueId(), filter); + if (toscaElement.isRight()) { + log.error( + "getVerticesToValidate: failed to find element" + vertex.getUniqueId() + " staus is" + toscaElement + .right().value()); + } else { + compList.add(toscaElement.left().value()); + } + + }); + + return result; + } + + public boolean validate(Map> vertices, String outputFilePath) { + boolean result = true; + long time = System.currentTimeMillis(); + String fileName = outputFilePath + this.getName() + "_" + time + ".csv"; + try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), UTF_8))) { + writer.write("name, UUID, invariantUUID, state, version\n"); + Collection> collection = vertices.values(); + for (List compList : collection) { + Set artifactEsId = new HashSet<>(); + for (Component component : compList) { + Map toscaArtifacts = component.getToscaArtifacts(); + Optional op = toscaArtifacts.values(). + stream().filter(a -> artifactEsId.contains(a.getEsId())).findAny(); + if (op.isPresent()) { + result = false; + writeModuleResultToFile(writer, compList); + writer.flush(); + break; + } else { + artifactEsId.addAll(toscaArtifacts.values().stream().map(ArtifactDefinition::getEsId) + .collect(Collectors.toList())); + } + } + + } + + } catch (Exception e) { + log.error("Failed to fetch vf resources ", e); + return false; + } finally { + janusGraphDao.commit(); + } + return result; + } + + private void writeModuleResultToFile(Writer writer, List components) { + try { + // "service name, service id, state, version + for (Component component : components) { + String sb = component.getName() + "," + component.getUniqueId() + "," + component.getInvariantUUID() + + "," + component.getLifecycleState() + "," + component.getVersion() + + "\n"; + writer.write(sb); + } + } catch (IOException e) { + log.error("Failed to write module result to file ", e); + } + } + +} diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/IArtifactValidatorExecuter.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/IArtifactValidatorExecuter.java deleted file mode 100644 index 1b3c0375e7..0000000000 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/IArtifactValidatorExecuter.java +++ /dev/null @@ -1,28 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2019 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.executers; - -public interface IArtifactValidatorExecuter { - - boolean executeValidations(String outputFilePath); - - String getName(); -} diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/IArtifactValidatorExecutor.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/IArtifactValidatorExecutor.java new file mode 100644 index 0000000000..19f7bf88c5 --- /dev/null +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/IArtifactValidatorExecutor.java @@ -0,0 +1,29 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2019 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.executers; + +// TODO: Merge this interface with ArtifactValidatorExecutor +public interface IArtifactValidatorExecutor { + + boolean executeValidations(String outputFilePath); + + String getName(); +} diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/NodeToscaArtifactsValidatorExecuter.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/NodeToscaArtifactsValidatorExecuter.java deleted file mode 100644 index 6a52e07dd2..0000000000 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/NodeToscaArtifactsValidatorExecuter.java +++ /dev/null @@ -1,64 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2019 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.executers; - -import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; -import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum; -import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; -import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; -import org.openecomp.sdc.be.model.Component; -import org.openecomp.sdc.be.model.LifecycleStateEnum; -import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class NodeToscaArtifactsValidatorExecuter extends ArtifactValidatorExecuter implements - IArtifactValidatorExecuter { - - protected String name; - - public NodeToscaArtifactsValidatorExecuter(JanusGraphDao janusGraphDao, - ToscaOperationFacade toscaOperationFacade) { - super(janusGraphDao, toscaOperationFacade); - setName("RESOURCE_TOSCA_ARTIFACTS"); - } - - @Override - public boolean executeValidations(String outputFilePath) { - Map hasProps = new HashMap<>(); - hasProps.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name()); - hasProps.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name()); - - Map> vertices = getVerticesToValidate(VertexTypeEnum.NODE_TYPE, hasProps); - return validate(vertices, outputFilePath); - } - - @Override - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } -} diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/NodeToscaArtifactsValidatorExecutor.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/NodeToscaArtifactsValidatorExecutor.java new file mode 100644 index 0000000000..41f2c5516b --- /dev/null +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/NodeToscaArtifactsValidatorExecutor.java @@ -0,0 +1,52 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2019 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.executers; + +import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; +import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum; +import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; +import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; +import org.openecomp.sdc.be.model.Component; +import org.openecomp.sdc.be.model.LifecycleStateEnum; +import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class NodeToscaArtifactsValidatorExecutor + extends ArtifactValidatorExecutor implements IArtifactValidatorExecutor { + + public NodeToscaArtifactsValidatorExecutor(JanusGraphDao janusGraphDao, + ToscaOperationFacade toscaOperationFacade) { + super(janusGraphDao, toscaOperationFacade, "RESOURCE_TOSCA_ARTIFACTS"); + } + + @Override + public boolean executeValidations(String outputFilePath) { + Map hasProps = new HashMap<>(); + hasProps.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name()); + hasProps.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name()); + + Map> vertices = getVerticesToValidate(VertexTypeEnum.NODE_TYPE, hasProps); + return validate(vertices, outputFilePath); + } +} diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceToscaArtifactsValidatorExecutor.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceToscaArtifactsValidatorExecutor.java index 21a8065dff..e633aa0204 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceToscaArtifactsValidatorExecutor.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceToscaArtifactsValidatorExecutor.java @@ -34,14 +34,13 @@ import java.util.List; import java.util.Map; @org.springframework.stereotype.Component -public class ServiceToscaArtifactsValidatorExecutor extends ArtifactValidatorExecuter implements - IArtifactValidatorExecuter { +public class ServiceToscaArtifactsValidatorExecutor + extends ArtifactValidatorExecutor implements IArtifactValidatorExecutor { @Autowired public ServiceToscaArtifactsValidatorExecutor(JanusGraphDao janusGraphDao, ToscaOperationFacade toscaOperationFacade) { - super(janusGraphDao, toscaOperationFacade); - setName("SERVICE_TOSCA_ARTIFACTS"); + super(janusGraphDao, toscaOperationFacade, "SERVICE_TOSCA_ARTIFACTS"); } @Override @@ -53,13 +52,4 @@ public class ServiceToscaArtifactsValidatorExecutor extends ArtifactValidatorExe Map> vertices = getVerticesToValidate(VertexTypeEnum.TOPOLOGY_TEMPLATE, hasProps); return validate(vertices, outputFilePath); } - - @Override - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } } diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/VFToscaArtifactValidatorExecutor.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/VFToscaArtifactValidatorExecutor.java index b5347a2579..ba05994984 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/VFToscaArtifactValidatorExecutor.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/VFToscaArtifactValidatorExecutor.java @@ -33,12 +33,11 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -public class VFToscaArtifactValidatorExecutor extends ArtifactValidatorExecuter implements IArtifactValidatorExecuter { +public class VFToscaArtifactValidatorExecutor + extends ArtifactValidatorExecutor implements IArtifactValidatorExecutor { - public VFToscaArtifactValidatorExecutor(JanusGraphDao janusGraphDao, - ToscaOperationFacade toscaOperationFacade) { - super(janusGraphDao, toscaOperationFacade); - setName("VF_TOSCA_ARTIFACTS"); + public VFToscaArtifactValidatorExecutor(JanusGraphDao janusGraphDao, ToscaOperationFacade toscaOperationFacade) { + super(janusGraphDao, toscaOperationFacade, "VF_TOSCA_ARTIFACTS"); } @Override @@ -52,13 +51,4 @@ public class VFToscaArtifactValidatorExecutor extends ArtifactValidatorExecuter return validate(vertices, outputFilePath); } - - @Override - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } } 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 4786e129d6..40aa601224 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 @@ -32,7 +32,7 @@ import java.util.List; public class VfValidatorExecuter extends TopologyTemplateValidatorExecuter implements ValidatorExecuter { - private List tasks; + private final List tasks; @Autowired(required = false) public VfValidatorExecuter(List tasks, JanusGraphDao janusGraphDao) { 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 22d93b1407..e5cd6f8c14 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 @@ -57,7 +57,7 @@ public class ValidationTool { log.info("Start Validation Tool"); Report report = Report.make(); - boolean result = validationToolBL.validateAll(report, textFile, txtReportFilePath); + boolean result = validationToolBL.validateAll(report, textFile); textFile.reportEndOfToolRun(report); csvFile.printAllResults(report); if (result) { diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ArtifactToolBLTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ArtifactToolBLTest.java index e6ae05f493..47952f8d5c 100644 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ArtifactToolBLTest.java +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ArtifactToolBLTest.java @@ -25,7 +25,7 @@ import static org.mockito.Mockito.mock; import java.util.ArrayList; import java.util.LinkedList; import org.junit.Test; -import org.openecomp.sdc.asdctool.impl.validator.executers.NodeToscaArtifactsValidatorExecuter; +import org.openecomp.sdc.asdctool.impl.validator.executers.NodeToscaArtifactsValidatorExecutor; import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade; @@ -43,7 +43,7 @@ public class ArtifactToolBLTest { ArtifactToolBL testSubject = createTestSubject(); testSubject.validators = new LinkedList<>(); - testSubject.validators.add(new NodeToscaArtifactsValidatorExecuter(janusGraphDaoMock, toscaOperationFacade)); + testSubject.validators.add(new NodeToscaArtifactsValidatorExecutor(janusGraphDaoMock, toscaOperationFacade)); // 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); diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBLTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBLTest.java index 8c2dffcbc2..ddea391ab1 100644 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBLTest.java +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBLTest.java @@ -46,8 +46,6 @@ public class ValidationToolBLTest { 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(report, makeTxtFile(makeConsoleWriter()), null); + testSubject.validateAll(report, makeTxtFile(makeConsoleWriter())); } } diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfigurationTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfigurationTest.java index deadf3250d..1903f0f1e7 100644 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfigurationTest.java +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfigurationTest.java @@ -23,7 +23,7 @@ package org.openecomp.sdc.asdctool.impl.validator.config; import org.junit.Test; import org.openecomp.sdc.asdctool.impl.validator.ArtifactToolBL; import org.openecomp.sdc.asdctool.impl.validator.ValidationToolBL; -import org.openecomp.sdc.asdctool.impl.validator.executers.NodeToscaArtifactsValidatorExecuter; +import org.openecomp.sdc.asdctool.impl.validator.executers.NodeToscaArtifactsValidatorExecutor; import org.openecomp.sdc.asdctool.impl.validator.executers.ServiceToscaArtifactsValidatorExecutor; import org.openecomp.sdc.asdctool.impl.validator.executers.ServiceValidatorExecuter; import org.openecomp.sdc.asdctool.impl.validator.executers.VFToscaArtifactValidatorExecutor; @@ -227,7 +227,7 @@ public class ValidationToolConfigurationTest { @Test public void testNodeToscaArtifactsValidatorValidator() { ValidationToolConfiguration testSubject; - NodeToscaArtifactsValidatorExecuter result; + NodeToscaArtifactsValidatorExecutor result; JanusGraphDao janusGraphDaoMock = mock(JanusGraphDao.class); ToscaOperationFacade toscaOperationFacade = mock(ToscaOperationFacade.class); diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecuterTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecuterTest.java deleted file mode 100644 index 46fae4312d..0000000000 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecuterTest.java +++ /dev/null @@ -1,95 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2019 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.executers; - -import org.junit.Test; -import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; -import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum; -import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; -import org.openecomp.sdc.be.model.Component; -import org.openecomp.sdc.be.model.Resource; -import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade; -import org.testng.Assert; - -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -import static org.mockito.Mockito.mock; - -public class ArtifactValidatorExecuterTest { - - private ArtifactValidatorExecuter createTestSubject() { - JanusGraphDao janusGraphDaoMock = mock(JanusGraphDao.class); - ToscaOperationFacade toscaOperationFacade = mock(ToscaOperationFacade.class); - - return new ArtifactValidatorExecuter(janusGraphDaoMock, toscaOperationFacade); - } - - @Test - public void testGetName() throws Exception { - ArtifactValidatorExecuter testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getName(); - } - - @Test(expected = NullPointerException.class) - public void testGetVerticesToValidate() throws Exception { - ArtifactValidatorExecuter testSubject; - VertexTypeEnum type = null; - Map hasProps = null; - - // default test - testSubject = createTestSubject(); - testSubject.getVerticesToValidate(type, hasProps); - } - - @Test - public void testSetName() throws Exception { - ArtifactValidatorExecuter testSubject; - String name = ""; - - // default test - testSubject = createTestSubject(); - testSubject.setName(name); - } - - @Test - public void testValidate() { - ArtifactValidatorExecuter testSubject; - Map> vertices = new HashMap<>(); - LinkedList linkedList = new LinkedList(); - linkedList.add(new Resource()); - vertices.put("stam", linkedList); - boolean result; - - // default test - 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 - result = testSubject.validate(vertices, null); - Assert.assertFalse(result); - } -} diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecutorContract.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecutorContract.java new file mode 100644 index 0000000000..8564bb8251 --- /dev/null +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecutorContract.java @@ -0,0 +1,75 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2019 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.executers; + +import static org.mockito.Mockito.mock; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; +import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum; +import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; +import org.openecomp.sdc.be.model.Component; +import org.openecomp.sdc.be.model.Resource; +import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade; +import org.testng.Assert; + +public interface ArtifactValidatorExecutorContract { + + ArtifactValidatorExecutor createTestSubject( + JanusGraphDao janusGraphDao, + ToscaOperationFacade toscaOperationFacade + ); + + @Test + default void testGetVerticesToValidate() { + JanusGraphDao janusGraphDaoMock = mock(JanusGraphDao.class); + ToscaOperationFacade toscaOperationFacade = mock(ToscaOperationFacade.class); + final ArtifactValidatorExecutor testSubject = createTestSubject(janusGraphDaoMock, toscaOperationFacade); + + VertexTypeEnum type = null; + Map hasProps = null; + Assertions.assertThrows(NullPointerException.class, () -> + testSubject.getVerticesToValidate(type, hasProps) + ); + } + + @Test + default void testValidate() { + JanusGraphDao janusGraphDaoMock = mock(JanusGraphDao.class); + ToscaOperationFacade toscaOperationFacade = mock(ToscaOperationFacade.class); + final ArtifactValidatorExecutor testSubject = createTestSubject(janusGraphDaoMock, toscaOperationFacade); + + LinkedList linkedList = new LinkedList(); + linkedList.add(new Resource()); + + Map> vertices = new HashMap<>(); + vertices.put("stam", linkedList); + + // 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 + Assert.assertFalse(testSubject.validate(vertices, null)); + } +} diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/IArtifactValidatorExecutorContract.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/IArtifactValidatorExecutorContract.java new file mode 100644 index 0000000000..39a1bbef0c --- /dev/null +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/IArtifactValidatorExecutorContract.java @@ -0,0 +1,50 @@ +/*- + * ============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.executers; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; +import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade; + +import static org.mockito.Mockito.mock; + +public abstract class IArtifactValidatorExecutorContract { + + protected abstract IArtifactValidatorExecutor createTestSubject( + JanusGraphDao janusGraphDao, + ToscaOperationFacade toscaOperationFacade + ); + + private IArtifactValidatorExecutor createTestSubject() { + return createTestSubject(mock(JanusGraphDao.class), mock(ToscaOperationFacade.class)); + } + + @Test + public void testExecuteValidations() { + Assertions.assertThrows(NullPointerException.class, () -> + // 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) + ); + } +} + diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/NodeToscaArtifactsValidatorExecuterTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/NodeToscaArtifactsValidatorExecuterTest.java deleted file mode 100644 index c9c90b2aa4..0000000000 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/NodeToscaArtifactsValidatorExecuterTest.java +++ /dev/null @@ -1,64 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2019 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.executers; - -import org.junit.Test; -import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; -import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade; - -import static org.mockito.Mockito.mock; - -public class NodeToscaArtifactsValidatorExecuterTest { - - private NodeToscaArtifactsValidatorExecuter createTestSubject() { - JanusGraphDao janusGraphDaoMock = mock(JanusGraphDao.class); - ToscaOperationFacade toscaOperationFacade = mock(ToscaOperationFacade.class); - - return new NodeToscaArtifactsValidatorExecuter(janusGraphDaoMock, toscaOperationFacade); - } - - @Test(expected = NullPointerException.class) - public void testExecuteValidations() { - // 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); - } - - @Test - public void testGetName() throws Exception { - NodeToscaArtifactsValidatorExecuter testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getName(); - } - - @Test - public void testSetName() throws Exception { - NodeToscaArtifactsValidatorExecuter testSubject; - String name = ""; - - // default test - testSubject = createTestSubject(); - testSubject.setName(name); - } -} diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/NodeToscaArtifactsValidatorExecutorTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/NodeToscaArtifactsValidatorExecutorTest.java new file mode 100644 index 0000000000..3870a98d78 --- /dev/null +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/NodeToscaArtifactsValidatorExecutorTest.java @@ -0,0 +1,36 @@ +/*- + * ============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.executers; + +import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; +import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade; + +public class NodeToscaArtifactsValidatorExecutorTest + extends IArtifactValidatorExecutorContract implements ArtifactValidatorExecutorContract { + + @Override + public NodeToscaArtifactsValidatorExecutor createTestSubject( + JanusGraphDao janusGraphDao, + ToscaOperationFacade toscaOperationFacade + ) { + return new NodeToscaArtifactsValidatorExecutor(janusGraphDao, toscaOperationFacade); + } +} diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceToscaArtifactsValidatorExecutorTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceToscaArtifactsValidatorExecutorTest.java index 1e24867358..7998c52ea4 100644 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceToscaArtifactsValidatorExecutorTest.java +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceToscaArtifactsValidatorExecutorTest.java @@ -20,45 +20,17 @@ package org.openecomp.sdc.asdctool.impl.validator.executers; -import org.junit.Test; import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade; -import static org.mockito.Mockito.mock; +public class ServiceToscaArtifactsValidatorExecutorTest + extends IArtifactValidatorExecutorContract implements ArtifactValidatorExecutorContract { -public class ServiceToscaArtifactsValidatorExecutorTest { - - private ServiceToscaArtifactsValidatorExecutor createTestSubject() { - JanusGraphDao janusGraphDaoMock = mock(JanusGraphDao.class); - ToscaOperationFacade toscaOperationFacade = mock(ToscaOperationFacade.class); - - return new ServiceToscaArtifactsValidatorExecutor(janusGraphDaoMock, toscaOperationFacade); - } - - @Test(expected = NullPointerException.class) - public void testExecuteValidations() { - // 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); - } - - @Test - public void testGetName() throws Exception { - ServiceToscaArtifactsValidatorExecutor testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getName(); - } - - @Test - public void testSetName() throws Exception { - ServiceToscaArtifactsValidatorExecutor testSubject; - String name = ""; - - // default test - testSubject = createTestSubject(); - testSubject.setName(name); + @Override + public ServiceToscaArtifactsValidatorExecutor createTestSubject( + JanusGraphDao janusGraphDao, + ToscaOperationFacade toscaOperationFacade + ) { + return new ServiceToscaArtifactsValidatorExecutor(janusGraphDao, toscaOperationFacade); } } diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/VFToscaArtifactValidatorExecutorTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/VFToscaArtifactValidatorExecutorTest.java index 783b888dec..ae6dcc1623 100644 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/VFToscaArtifactValidatorExecutorTest.java +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/VFToscaArtifactValidatorExecutorTest.java @@ -20,51 +20,17 @@ package org.openecomp.sdc.asdctool.impl.validator.executers; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade; -import static org.mockito.Mockito.mock; +public class VFToscaArtifactValidatorExecutorTest + extends IArtifactValidatorExecutorContract implements ArtifactValidatorExecutorContract { -public class VFToscaArtifactValidatorExecutorTest { - - private VFToscaArtifactValidatorExecutor createTestSubject() { - JanusGraphDao janusGraphDaoMock = mock(JanusGraphDao.class); - ToscaOperationFacade toscaOperationFacade = mock(ToscaOperationFacade.class); - - return new VFToscaArtifactValidatorExecutor(janusGraphDaoMock, toscaOperationFacade); - } - - @Test - public void testExecuteValidations() { - VFToscaArtifactValidatorExecutor testSubject; - boolean result; - - // default test - 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 - Assertions.assertThrows(NullPointerException.class, () -> testSubject.executeValidations(null)); - } - - @Test - public void testGetName() throws Exception { - VFToscaArtifactValidatorExecutor testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getName(); - } - - @Test - public void testSetName() throws Exception { - VFToscaArtifactValidatorExecutor testSubject; - String name = ""; - - // default test - testSubject = createTestSubject(); - testSubject.setName(name); + @Override + public VFToscaArtifactValidatorExecutor createTestSubject( + JanusGraphDao janusGraphDao, + ToscaOperationFacade toscaOperationFacade + ) { + return new VFToscaArtifactValidatorExecutor(janusGraphDao, toscaOperationFacade); } } -- cgit 1.2.3-korg