From e58e011a89ae5c8ada209a82d9b0f3ad1b0ca58f Mon Sep 17 00:00:00 2001 From: Bogumil Zebek Date: Tue, 26 Mar 2019 14:19:31 +0100 Subject: PNF TC R146092 Change-Id: I27c881a8673957dde346fae393fffa6e946c2cd4 Issue-ID: VNFSDK-388 Signed-off-by: Zebek Bogumil --- .../main/java/org/onap/cvc/csar/CSARArchive.java | 10 +- .../java/org/onap/cvc/csar/PnfCSARArchive.java | 37 ++++-- .../java/org/onap/cvc/csar/PnfManifestParser.java | 93 +++++++++---- .../onap/cvc/csar/cc/VTPValidatePnfCSARBase.java | 1 + .../cvc/csar/cc/sol004/VTPValidateCSARR146092.java | 144 +++++++++++++++++++++ .../cvc/csar/cc/sol004/VTPValidateCSARR293901.java | 18 +-- .../cvc/csar/cc/sol004/VTPValidateCSARR57019.java | 61 +++++++++ .../services/org.onap.cli.fw.cmd.OnapCommand | 3 + .../sol004/vtp-validate-csar-r146092.yaml | 58 +++++++++ .../sol004/vtp-validate-csar-r57019.yaml | 60 +++++++++ .../src/main/resources/vnfreqs.properties | 2 +- .../java/org/onap/cvc/csar/PnfCSARArchiveTest.java | 44 ++++--- .../org/onap/cvc/csar/PnfManifestParserTest.java | 16 ++- .../cvc/csar/cc/sol004/IntegrationTestUtils.java | 78 +++++++++++ .../VTPValidateCSARR146092IntegrationTest.java | 118 +++++++++++++++++ .../VTPValidateCSARR293901IntegrationTest.java | 60 +-------- .../VTPValidateCSARR57019IntegrationTest.java | 78 +++++++++++ .../src/test/resources/pnf/MainServiceTemplate.mf | 4 +- .../pnf/allMandatoryEntriesDefinedInTOSCAMeta.csar | Bin 4117 -> 0 bytes .../src/test/resources/pnf/dummyPnfv2.csar | Bin 4039 -> 4037 bytes .../pnf/noMandatoryEntriesInTOSCAMeta.csar | Bin 3943 -> 0 bytes .../resources/pnf/noTOSCAMetaInTOSCADirectory.csar | Bin 164 -> 0 bytes .../missingFieldsInNonManoArtifactManifest.csar | Bin 0 -> 3965 bytes .../r146092/missingNonManoArtifactInManifest.csar | Bin 0 -> 3950 bytes ...ourceElementInNonManoArtifactEntryManifest.csar | Bin 0 -> 4078 bytes ...hUnknownFileInNonManoArtifactEntryManifest.csar | Bin 0 -> 4086 bytes .../allMandatoryEntriesDefinedInTOSCAMeta.csar | Bin 0 -> 4117 bytes .../pnf/r293901/noMandatoryEntriesInTOSCAMeta.csar | Bin 0 -> 3943 bytes .../pnf/r293901/noTOSCAMetaInTOSCADirectory.csar | Bin 0 -> 164 bytes ...lMandatoryEntriesDefinedInMetadataManifest.csar | Bin 0 -> 4099 bytes .../noMandatoryEntriesInMetadataManifest.csar | Bin 0 -> 4039 bytes 31 files changed, 767 insertions(+), 118 deletions(-) create mode 100644 csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR146092.java create mode 100644 csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR57019.java create mode 100644 csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r146092.yaml create mode 100644 csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r57019.yaml create mode 100644 csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/IntegrationTestUtils.java create mode 100644 csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR146092IntegrationTest.java create mode 100644 csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR57019IntegrationTest.java delete mode 100644 csarvalidation/src/test/resources/pnf/allMandatoryEntriesDefinedInTOSCAMeta.csar delete mode 100644 csarvalidation/src/test/resources/pnf/noMandatoryEntriesInTOSCAMeta.csar delete mode 100644 csarvalidation/src/test/resources/pnf/noTOSCAMetaInTOSCADirectory.csar create mode 100644 csarvalidation/src/test/resources/pnf/r146092/missingFieldsInNonManoArtifactManifest.csar create mode 100644 csarvalidation/src/test/resources/pnf/r146092/missingNonManoArtifactInManifest.csar create mode 100644 csarvalidation/src/test/resources/pnf/r146092/noSourceElementInNonManoArtifactEntryManifest.csar create mode 100644 csarvalidation/src/test/resources/pnf/r146092/sourceElementWithUnknownFileInNonManoArtifactEntryManifest.csar create mode 100644 csarvalidation/src/test/resources/pnf/r293901/allMandatoryEntriesDefinedInTOSCAMeta.csar create mode 100644 csarvalidation/src/test/resources/pnf/r293901/noMandatoryEntriesInTOSCAMeta.csar create mode 100644 csarvalidation/src/test/resources/pnf/r293901/noTOSCAMetaInTOSCADirectory.csar create mode 100644 csarvalidation/src/test/resources/pnf/r57019/allMandatoryEntriesDefinedInMetadataManifest.csar create mode 100644 csarvalidation/src/test/resources/pnf/r57019/noMandatoryEntriesInMetadataManifest.csar diff --git a/csarvalidation/src/main/java/org/onap/cvc/csar/CSARArchive.java b/csarvalidation/src/main/java/org/onap/cvc/csar/CSARArchive.java index 9d80605..bc12e55 100644 --- a/csarvalidation/src/main/java/org/onap/cvc/csar/CSARArchive.java +++ b/csarvalidation/src/main/java/org/onap/cvc/csar/CSARArchive.java @@ -808,7 +808,7 @@ public class CSARArchive implements AutoCloseable { private Definition definition = new Definition(); - private Manifest manifest = new Manifest(); + private Manifest manifest; private File toscaMetaFile; @@ -870,6 +870,14 @@ public class CSARArchive implements AutoCloseable { return errors; } + public CSARArchive(){ + this(new Manifest()); + } + + public CSARArchive(Manifest manifest) { + this.manifest = manifest; + } + private void unzip(String csarPath, Path destination) throws IOException { File csarFile = new File(csarPath); diff --git a/csarvalidation/src/main/java/org/onap/cvc/csar/PnfCSARArchive.java b/csarvalidation/src/main/java/org/onap/cvc/csar/PnfCSARArchive.java index 9dc966b..b51faf8 100644 --- a/csarvalidation/src/main/java/org/onap/cvc/csar/PnfCSARArchive.java +++ b/csarvalidation/src/main/java/org/onap/cvc/csar/PnfCSARArchive.java @@ -1,12 +1,12 @@ /** * Copyright 2019 Nokia - * + *

* 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. @@ -18,11 +18,17 @@ package org.onap.cvc.csar; import org.apache.commons.lang3.tuple.Pair; import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; public class PnfCSARArchive extends CSARArchive { + public PnfCSARArchive(){ + super(new PnfManifest()); + } + @Override void parseManifest() throws IOException { @@ -32,26 +38,41 @@ public class PnfCSARArchive extends CSARArchive { } PnfManifestParser pnfManifestParser = PnfManifestParser.getInstance( - this.getManifestMfFile().getAbsolutePath() + this.getManifestMfFile() ); Pair> metadataData = pnfManifestParser.fetchMetadata(); + Pair, List> sourcesSectionData = pnfManifestParser.fetchSourcesSection(); Pair>>, List> nonManoArtifactsData = pnfManifestParser.fetchNonManoArtifacts(); - Manifest manifest = this.getManifest(); + PnfManifest manifest = (PnfManifest) this.getManifest(); manifest.setMetadata(metadataData.getKey()); + manifest.setSources(sourcesSectionData.getKey()); manifest.setNonMano(nonManoArtifactsData.getKey()); this.getErrors().addAll(metadataData.getValue()); this.getErrors().addAll(nonManoArtifactsData.getValue()); + this.getErrors().addAll(sourcesSectionData.getValue()); } @Override - String getEntryManifestParamName(){ + String getEntryManifestParamName() { return "ETSI-Entry-Manifest"; } @Override - String getEntryChangeLogParamName(){ + String getEntryChangeLogParamName() { return "ETSI-Entry-Change-Log"; } + + public static class PnfManifest extends Manifest { + private List sources = new ArrayList<>(); + + public List getSources() { + return Collections.unmodifiableList(sources); + } + + public void setSources(List sources) { + this.sources.addAll(sources); + } + } } diff --git a/csarvalidation/src/main/java/org/onap/cvc/csar/PnfManifestParser.java b/csarvalidation/src/main/java/org/onap/cvc/csar/PnfManifestParser.java index ea52841..5ef74fd 100644 --- a/csarvalidation/src/main/java/org/onap/cvc/csar/PnfManifestParser.java +++ b/csarvalidation/src/main/java/org/onap/cvc/csar/PnfManifestParser.java @@ -21,6 +21,7 @@ import org.onap.cvc.csar.PnfCSARError.PnfCSARErrorEntryMissing; import org.onap.cvc.csar.PnfCSARError.PnfCSARErrorInvalidEntry; import org.onap.cvc.csar.PnfCSARError.PnfCSARErrorWarning; +import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; @@ -34,8 +35,9 @@ import java.util.stream.Stream; class PnfManifestParser { - private static final String METADATA_SECTION = "metadata"; - private static final String NON_MANO_ARTIFACT_SETS_SECTION = "non_mano_artifact_sets"; + private static final String METADATA_SECTION_TAG_SECTION = "metadata"; + private static final String SOURCE_TAG_SECTION = "source"; + private static final String NON_MANO_ARTIFACT_SETS_TAG_SECTION = "non_mano_artifact_sets"; private static final String PRODUCT_NAME = "pnfd_name"; private static final String PROVIDER_ID = "pnfd_provider"; private static final String VERSION = "pnfd_archive_version"; @@ -49,13 +51,14 @@ class PnfManifestParser { this.fileName = fileName; } - static PnfManifestParser getInstance(String fileName) throws IOException { + static PnfManifestParser getInstance(File pnfManifestFile) throws IOException { + String fileName = pnfManifestFile.getAbsolutePath(); try (Stream stream = Files.lines(Paths.get(fileName))) { List lines = stream .map(String::trim) .collect(Collectors.toList()); - return new PnfManifestParser(lines, fileName); + return new PnfManifestParser(lines, pnfManifestFile.getName()); } } @@ -64,20 +67,16 @@ class PnfManifestParser { List errors = new ArrayList<>(); boolean isMetadataSectionAvailable = false; - int lineNumber = 0; - for (String line : lines) { - lineNumber++; - if (line.trim().isEmpty() || line.trim().startsWith("#")){ - continue; - } else if (line.startsWith(METADATA_SECTION)) { + + for (int lineNumber = 0; lineNumber < lines.size(); lineNumber++) { + String line = lines.get(lineNumber); + Pair data = parseLine(line); + + if(data.getKey().toLowerCase().equals(METADATA_SECTION_TAG_SECTION)) { isMetadataSectionAvailable = true; - }else if (isMetadataSectionAvailable) { - Pair data = parseLine(line); + }else if (isMetadataSectionAvailable && !isLineExcluded(line)) { - if (isNewSection(data)) { - if(!isSectionSupported(data.getKey())) { - errors.add(new PnfCSARErrorWarning(data.getKey(), this.fileName, lineNumber)); - } + if (shouldStopProcessing(data, errors, lineNumber)) { break; } @@ -86,13 +85,39 @@ class PnfManifestParser { } if (!isMetadataSectionAvailable) { - errors.add(new PnfCSARErrorEntryMissing(METADATA_SECTION, this.fileName, -1)); + errors.add(new PnfCSARErrorEntryMissing(METADATA_SECTION_TAG_SECTION, this.fileName, -1)); } return Pair.of(metadata, errors); } + Pair, List> fetchSourcesSection() { + List sources = new ArrayList<>(); + List errors = new ArrayList<>(); + boolean isSpecialTagReached = false; + boolean sourceSectionParsing = false; + for (int lineNumber = 0; lineNumber < lines.size(); lineNumber++) { + String line = lines.get(lineNumber); + if (sourceSectionParsing && (startsWith(line, METADATA_SECTION_TAG_SECTION) || startsWith(line, NON_MANO_ARTIFACT_SETS_TAG_SECTION))) { + isSpecialTagReached = true; + }else if (!isSpecialTagReached && startsWith(line, SOURCE_TAG_SECTION)) { + sourceSectionParsing = true; + Pair data = parseLine(line); + + String value = data.getValue(); + if (value.isEmpty()) { + errors.add(new PnfCSARErrorWarning(data.getKey(), this.fileName, lineNumber)); + break; + } else { + sources.add(value); + } + } + } + + return Pair.of(sources, errors); + } + Pair>>, List> fetchNonManoArtifacts() { Map>> nonManoArtifacts = new HashMap<>(); List errors = new ArrayList<>(); @@ -102,15 +127,14 @@ class PnfManifestParser { for (String line : lines) { - if (line.trim().isEmpty() || line.trim().startsWith("#")) { - continue; - } else if (line.startsWith(NON_MANO_ARTIFACT_SETS_SECTION)) { + if (startsWith(line, NON_MANO_ARTIFACT_SETS_TAG_SECTION)) { isNonManoArtifactsSectionAvailable = true; } else if (isNonManoArtifactsSectionAvailable) { Pair data = parseLine(line); if (isNewSection(data)) { attributeName = data.getKey(); + nonManoArtifacts.put(attributeName, new HashMap<>()); continue; } @@ -119,12 +143,32 @@ class PnfManifestParser { } if (!isNonManoArtifactsSectionAvailable) { - errors.add(new PnfCSARErrorEntryMissing(NON_MANO_ARTIFACT_SETS_SECTION, this.fileName, -1)); + errors.add(new PnfCSARErrorEntryMissing(NON_MANO_ARTIFACT_SETS_TAG_SECTION, this.fileName, -1)); } return Pair.of(nonManoArtifacts, errors); } + private boolean isLineExcluded(String line) { + return line.trim().isEmpty() + || startsWith(line, "#") + || startsWith(line,SOURCE_TAG_SECTION); + } + + private boolean shouldStopProcessing(Pair data, List errors, int lineNumber) { + if (isNewSection(data) || data.getKey().toLowerCase().equals(SOURCE_TAG_SECTION)) { + if(!isSectionSupported(data.getKey())) { + errors.add(new PnfCSARErrorWarning(data.getKey(), this.fileName, lineNumber)); + } + return true; + } + return false; + } + + private boolean startsWith(String line, String word){ + return line.trim().toLowerCase().startsWith(word); + } + private void handleMetadataLine( CSARArchive.Manifest.Metadata metadata, List errors, @@ -172,14 +216,17 @@ class PnfManifestParser { } private boolean isSectionSupported(String key) { - return Lists.newArrayList(METADATA_SECTION, NON_MANO_ARTIFACT_SETS_SECTION).contains(key); + return Lists.newArrayList( + METADATA_SECTION_TAG_SECTION, + SOURCE_TAG_SECTION, + NON_MANO_ARTIFACT_SETS_TAG_SECTION).contains(key.toLowerCase()); } private boolean isNewSection(Pair data) { String key = data.getKey().trim(); String value = data.getValue().trim(); - return key.matches("[a-zA-z_0-9]+") && (value.isEmpty() || value.startsWith("#")); + return key.matches("[a-zA-z_0-9]+") && (value.isEmpty() || startsWith(value,"#")); } diff --git a/csarvalidation/src/main/java/org/onap/cvc/csar/cc/VTPValidatePnfCSARBase.java b/csarvalidation/src/main/java/org/onap/cvc/csar/cc/VTPValidatePnfCSARBase.java index 2effffd..6c7d3a0 100644 --- a/csarvalidation/src/main/java/org/onap/cvc/csar/cc/VTPValidatePnfCSARBase.java +++ b/csarvalidation/src/main/java/org/onap/cvc/csar/cc/VTPValidatePnfCSARBase.java @@ -23,6 +23,7 @@ import org.onap.cvc.csar.PnfCSARArchive; import java.util.List; public abstract class VTPValidatePnfCSARBase extends VTPValidateCSARBase { + @Override protected CSARArchive createArchiveInstance(){ return new PnfCSARArchive(); } diff --git a/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR146092.java b/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR146092.java new file mode 100644 index 0000000..1cdfe7a --- /dev/null +++ b/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR146092.java @@ -0,0 +1,144 @@ +/* + * Copyright 2019 Nokia + *

+ * 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. + * + */ + +package org.onap.cvc.csar.cc.sol004; + + +import org.onap.cli.fw.schema.OnapCommandSchema; +import org.onap.cvc.csar.CSARArchive; +import org.onap.cvc.csar.PnfCSARError; +import org.onap.cvc.csar.PnfCSARError.PnfCSARErrorEntryMissing; +import org.onap.cvc.csar.cc.VTPValidatePnfCSARBase; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +@OnapCommandSchema(schema = "vtp-validate-csar-r146092.yaml") +public class VTPValidateCSARR146092 extends VTPValidatePnfCSARBase { + + private static final int UNKNOWN_LINE_NUMBER = -1; + private static final String SOURCE_ELEMENT_TAG = "source"; + + private static class MissingSourceElementUnderAttributeError extends PnfCSARError { + private MissingSourceElementUnderAttributeError(String attributeName, String fileName) { + super("0x2002", + String.format("Missing. Entry [%s under %s]", SOURCE_ELEMENT_TAG, attributeName), + UNKNOWN_LINE_NUMBER, + fileName); + } + } + + private static class InvalidPathToFileError extends PnfCSARError { + private InvalidPathToFileError(String attributeName, String pathToSourceFile, String fileName) { + super("0x2002", + String.format("Invalid. Entry [%s under %s has invalid '%s' path]", SOURCE_ELEMENT_TAG, attributeName, pathToSourceFile), + UNKNOWN_LINE_NUMBER, + fileName); + } + } + + @Override + protected void validateCSAR(CSARArchive csar) { + ValidateNonManoSection validateNonManoSection = ValidateNonManoSection.getInstance(csar); + List csarErrors = validateNonManoSection.validate(); + + this.errors.addAll(csarErrors); + } + + + private static class ValidateNonManoSection { + private final CSARArchive csar; + private final String fileName; + private final Map>> nonMano; + private final List errors = new ArrayList<>(); + + static ValidateNonManoSection getInstance(CSARArchive csar) { + final String fileName = csar.getManifestMfFile().getName(); + final Map>> nonMano = csar.getManifest().getNonMano(); + return new ValidateNonManoSection(csar, fileName,nonMano); + } + + private ValidateNonManoSection(CSARArchive csar, String fileName, Map>> nonMano) { + this.csar = csar; + this.fileName = fileName; + this.nonMano = nonMano; + } + + public List validate() { + + List attributeNames = Arrays.asList( + "onap_ves_events", + "onap_pm_dictionary", + "onap_yang_module", + "onap_others" + ); + + for (String attributeName : attributeNames) { + validateAttribute(attributeName); + } + + return this.errors; + } + + private void validateAttribute(String attributeName) { + Set nonManoAttributes = this.nonMano.keySet(); + if (!nonManoAttributes.contains(attributeName)) { + this.errors.add(new PnfCSARErrorEntryMissing( + attributeName, + this.fileName, + UNKNOWN_LINE_NUMBER) + ); + } else { + validateSourceElementsUnderAttribute(attributeName); + } + } + + private void validateSourceElementsUnderAttribute(String attributeName) { + + Map> attributeElements = this.nonMano.get(attributeName); + List attributeElementNames = attributeElements.keySet().stream() + .map(String::toLowerCase) + .collect(Collectors.toList()); + + if (!attributeElementNames.contains(SOURCE_ELEMENT_TAG)) { + this.errors.add(new MissingSourceElementUnderAttributeError(attributeName, this.fileName)); + } else { + for (String pathToFile : attributeElements.get(SOURCE_ELEMENT_TAG)) { + File fileFromCsar = this.csar.getFileFromCsar(pathToFile); + if (!fileFromCsar.exists()) { + this.errors.add( + new InvalidPathToFileError(attributeName, + pathToFile, this.fileName) + ); + } + } + } + } + } + + @Override + protected String getVnfReqsNo() { + return "R146092"; + } + + +} diff --git a/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR293901.java b/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR293901.java index 09edc34..b114880 100644 --- a/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR293901.java +++ b/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR293901.java @@ -33,16 +33,16 @@ public class VTPValidateCSARR293901 extends VTPValidatePnfCSARBase { @Override protected void validateCSAR(CSARArchive csar) { final CSARArchive.TOSCAMeta toscaMeta = csar.getToscaMeta(); - if (Objects.isNull(toscaMeta.getEntryManifestMf())) { - this.errors.add(new PnfCSARErrorEntryMissing( - "ETSI-Entry-Manifest", - CSARArchive.TOSCA_Metadata__TOSCA_Meta, - UNKNOWN_LINE_NUMBER) - ); - } - if (Objects.isNull(toscaMeta.getEntryChangeLog())) { + String entryManifestMf = toscaMeta.getEntryManifestMf(); + + validateToscaMetaValue(entryManifestMf, "ETSI-Entry-Manifest"); + validateToscaMetaValue(toscaMeta.getEntryChangeLog(), "ETSI-Entry-Change-Log"); + } + + private void validateToscaMetaValue(String entryManifestMf, String toscaMetaAttributeName) { + if (Objects.isNull(entryManifestMf)) { this.errors.add(new PnfCSARErrorEntryMissing( - "ETSI-Entry-Change-Log", + toscaMetaAttributeName, CSARArchive.TOSCA_Metadata__TOSCA_Meta, UNKNOWN_LINE_NUMBER) ); diff --git a/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR57019.java b/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR57019.java new file mode 100644 index 0000000..8f6118b --- /dev/null +++ b/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR57019.java @@ -0,0 +1,61 @@ +/* + * Copyright 2019 Nokia + *

+ * 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. + * + */ + +package org.onap.cvc.csar.cc.sol004; + + +import org.onap.cli.fw.schema.OnapCommandSchema; +import org.onap.cvc.csar.CSARArchive; +import org.onap.cvc.csar.PnfCSARError.PnfCSARErrorEntryMissing; +import org.onap.cvc.csar.cc.VTPValidatePnfCSARBase; + +import java.util.Objects; + +@OnapCommandSchema(schema = "vtp-validate-csar-r57019.yaml") +public class VTPValidateCSARR57019 extends VTPValidatePnfCSARBase { + + private static final int UNKNOWN_LINE_NUMBER = -1; + + @Override + protected void validateCSAR(CSARArchive csar) { + final CSARArchive.Manifest.Metadata metadata = csar.getManifest().getMetadata(); + final String fileName = csar.getManifestMfFile().getName(); + + validateMetadataValue(fileName, metadata.getProviderId(), "pnfd_provider"); + validateMetadataValue(fileName, metadata.getProductName(), "pnfd_name"); + validateMetadataValue(fileName, metadata.getReleaseDateTime(), "pnfd_release_date_time"); + validateMetadataValue(fileName, metadata.getPackageVersion(), "pnfd_archive_version"); + + } + + private void validateMetadataValue(String fileName, String providerId, String metadataArgumentName) { + if (Objects.isNull(providerId)) { + this.errors.add(new PnfCSARErrorEntryMissing( + metadataArgumentName, + fileName, + UNKNOWN_LINE_NUMBER) + ); + } + } + + @Override + protected String getVnfReqsNo() { + return "R57019"; + } + + +} diff --git a/csarvalidation/src/main/resources/META-INF/services/org.onap.cli.fw.cmd.OnapCommand b/csarvalidation/src/main/resources/META-INF/services/org.onap.cli.fw.cmd.OnapCommand index 800784c..4712548 100644 --- a/csarvalidation/src/main/resources/META-INF/services/org.onap.cli.fw.cmd.OnapCommand +++ b/csarvalidation/src/main/resources/META-INF/services/org.onap.cli.fw.cmd.OnapCommand @@ -44,3 +44,6 @@ org.onap.cvc.csar.cc.sol004.VTPValidateCSARR77707 org.onap.cvc.csar.cc.sol004.VTPValidateCSARR77786 org.onap.cvc.csar.cc.sol004.VTPValidateCSARR87234 org.onap.cvc.csar.cc.sol004.VTPValidateCSARR293901 +org.onap.cvc.csar.cc.sol004.VTPValidateCSARR146092 +org.onap.cvc.csar.cc.sol004.VTPValidateCSARR57019 + diff --git a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r146092.yaml b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r146092.yaml new file mode 100644 index 0000000..5646c98 --- /dev/null +++ b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r146092.yaml @@ -0,0 +1,58 @@ +# Copyright 2019 Nokia +# +# 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. + +open_cli_schema_version: 1.0 + +name: csar-validate-r146092 + +description: | + The VNF/PNF package Manifest file MUST contain: non-mano artifact set with following ONAP public tag + -onap_ves_events + -onap_pm_dictionary + -onap_yang_module + -onap_others + +info: + product: onap-vtp + version: 1.0 + service: validation + author: ONAP VTP Team onap-discuss@lists.onap.org + +parameters: + - name: csar + description: CSAR file path + long_option: csar + short_option: b + type: binary + is_optional: false + +results: + direction: landscape + attributes: + - name: code + description: Error code + scope: short + type: string + - name: message + description: Error message + scope: short + type: string + - name: file + description: File in which error occured + scope: short + type: string + - name: line-no + description: Line no at which error occured + scope: short + type: string diff --git a/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r57019.yaml b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r57019.yaml new file mode 100644 index 0000000..2e4380f --- /dev/null +++ b/csarvalidation/src/main/resources/open-cli-schema/sol004/vtp-validate-csar-r57019.yaml @@ -0,0 +1,60 @@ +# Copyright 2019 Nokia +# +# 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. + +open_cli_schema_version: 1.0 + +name: csar-validate-r57019 + +description: | + The PNF TOSCA CSAR package Manifest file MUST start with the PNF package metadata + in the form of a name-value pairs. Each pair shall appear on a different line. + The name is specified as following: + -pnfd_provider + -pnfd_name + -pnfd_release_date_time + -pnfd_archive_version + +info: + product: onap-vtp + version: 1.0 + service: validation + author: ONAP VTP Team onap-discuss@lists.onap.org + +parameters: + - name: csar + description: CSAR file path + long_option: csar + short_option: b + type: binary + is_optional: false + +results: + direction: landscape + attributes: + - name: code + description: Error code + scope: short + type: string + - name: message + description: Error message + scope: short + type: string + - name: file + description: File in which error occured + scope: short + type: string + - name: line-no + description: Line no at which error occured + scope: short + type: string diff --git a/csarvalidation/src/main/resources/vnfreqs.properties b/csarvalidation/src/main/resources/vnfreqs.properties index f290fb8..b4a0d37 100644 --- a/csarvalidation/src/main/resources/vnfreqs.properties +++ b/csarvalidation/src/main/resources/vnfreqs.properties @@ -1,3 +1,3 @@ -vnfreqs.enabled=r02454,r04298,r07879,r09467,r13390,r23823,r26881,r27310,r35851,r40293,r43958,r66070,r77707,r77786,r87234,r10087,r21322,r26885,r40820,r35854,r65486,r17852,r46527,r15837,r54356,r67895,r95321,r32155,r01123,r51347,r293901 +vnfreqs.enabled=r02454,r04298,r07879,r09467,r13390,r23823,r26881,r27310,r35851,r40293,r43958,r66070,r77707,r77786,r87234,r10087,r21322,r26885,r40820,r35854,r65486,r17852,r46527,r15837,r54356,r67895,r95321,r32155,r01123,r51347,r293901,r146092,r57019 # ignored all chef and ansible related tests errors.ignored=0x1005,0x1006,r07879-0x1000,r13390-0x1000,r27310-0x1000,r40293-0x1000,r77786-0x1000 \ No newline at end of file diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/PnfCSARArchiveTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/PnfCSARArchiveTest.java index b29470c..ca85c7a 100644 --- a/csarvalidation/src/test/java/org/onap/cvc/csar/PnfCSARArchiveTest.java +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/PnfCSARArchiveTest.java @@ -1,12 +1,12 @@ /** * Copyright 2019 Nokia - * + *

* 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. @@ -19,8 +19,6 @@ package org.onap.cvc.csar; import com.google.common.collect.Lists; import org.junit.Test; -import java.io.IOException; -import java.net.URISyntaxException; import java.util.List; import java.util.Map; @@ -35,18 +33,34 @@ public class PnfCSARArchiveTest { .toURI().getPath(); // when - try( PnfCSARArchive pnfCSARArchive = new PnfCSARArchive()) { + try (PnfCSARArchive pnfCSARArchive = new PnfCSARArchive()) { pnfCSARArchive.init(fileName); pnfCSARArchive.parse(); // then - verifyThatMetadataWasSet(pnfCSARArchive); - verifyThatNonManoArtifactsWereSet(pnfCSARArchive); + PnfCSARArchive.PnfManifest manifest = (PnfCSARArchive.PnfManifest) pnfCSARArchive.getManifest(); + verifyThatMetadataWasSet(manifest); + verifyThatSourcesSectionWasSet(manifest); + verifyThatNonManoArtifactsWereSet(manifest); } } - private void verifyThatNonManoArtifactsWereSet(PnfCSARArchive pnfCSARArchive) { - Map>> nonManoArtifacts = pnfCSARArchive.getManifest().getNonMano(); + private void verifyThatMetadataWasSet(PnfCSARArchive.PnfManifest manifest) { + CSARArchive.Manifest.Metadata metadata = manifest.getMetadata(); + assertThat(metadata.getProductName()).isEqualTo("RadioNode"); + assertThat(metadata.getProviderId()).isEqualTo("Ericsson"); + assertThat(metadata.getPackageVersion()).isEqualTo("1.0"); + assertThat(metadata.getReleaseDateTime()).isEqualTo("2019-01-14T11:25:00+00:00"); + } + + private void verifyThatSourcesSectionWasSet(PnfCSARArchive.PnfManifest manifest) { + + List sources = manifest.getSources(); + assertThat(sources).contains("Definitions/MainServiceTemplate.yaml", "Definitions/etsi_nfv_sol001_vnfd_2_5_1_types.yaml"); + } + + private void verifyThatNonManoArtifactsWereSet(PnfCSARArchive.PnfManifest manifest) { + Map>> nonManoArtifacts = manifest.getNonMano(); assertThat(nonManoArtifacts.get("onap_ves_events").get("source")) .isEqualTo(Lists.newArrayList("Artifacts/Events/VES_registration.yml") ); @@ -66,12 +80,4 @@ public class PnfCSARArchiveTest { ); } - private void verifyThatMetadataWasSet(PnfCSARArchive pnfCSARArchive) { - CSARArchive.Manifest.Metadata metadata = pnfCSARArchive.getManifest().getMetadata(); - assertThat(metadata.getProductName()).isEqualTo("RadioNode"); - assertThat(metadata.getProviderId()).isEqualTo("Ericsson"); - assertThat(metadata.getPackageVersion()).isEqualTo("1.0"); - assertThat(metadata.getReleaseDateTime()).isEqualTo("2019-01-14T11:25:00+00:00"); - } - } \ No newline at end of file diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/PnfManifestParserTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/PnfManifestParserTest.java index f680438..2f3a050 100644 --- a/csarvalidation/src/test/java/org/onap/cvc/csar/PnfManifestParserTest.java +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/PnfManifestParserTest.java @@ -20,6 +20,7 @@ import org.apache.commons.lang3.tuple.Pair; import org.junit.Before; import org.junit.Test; +import java.io.File; import java.io.IOException; import java.net.URISyntaxException; import java.util.List; @@ -34,7 +35,7 @@ public class PnfManifestParserTest { @Before public void setUp() throws URISyntaxException, IOException { - pnfManifestParser = PnfManifestParser.getInstance("./src/test/resources/pnf/MainServiceTemplate.mf"); + pnfManifestParser = PnfManifestParser.getInstance(new File("./src/test/resources/pnf/MainServiceTemplate.mf")); } @Test @@ -51,6 +52,19 @@ public class PnfManifestParserTest { } + @Test + public void shouldFetchSourcesSectionFromFile() { + + Pair, List> sourcesPair = pnfManifestParser.fetchSourcesSection(); + List sources = sourcesPair.getKey(); + List errors = sourcesPair.getValue(); + + assertThat(sources).contains("Definitions/MainServiceTemplate.yaml", "Definitions/etsi_nfv_sol001_vnfd_2_5_1_types.yaml"); + assertThat(errors.size()).isEqualTo(0); + } + + + @Test public void shouldFetchNonManoArtifactsFromFile() { Pair>>, List> mapListPair = pnfManifestParser.fetchNonManoArtifacts(); diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/IntegrationTestUtils.java b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/IntegrationTestUtils.java new file mode 100644 index 0000000..32ac187 --- /dev/null +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/IntegrationTestUtils.java @@ -0,0 +1,78 @@ +/* + * Copyright 2019 Nokia + *

+ * 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. + * + */ + +package org.onap.cvc.csar.cc.sol004; + +import com.google.common.collect.Lists; +import org.onap.cli.fw.error.OnapCommandException; +import org.onap.cli.fw.error.OnapCommandInvalidParameterValue; +import org.onap.cli.fw.input.OnapCommandParameter; +import org.onap.cli.fw.output.OnapCommandResult; +import org.onap.cli.fw.output.OnapCommandResultAttribute; +import org.onap.cvc.csar.CSARArchive; +import org.onap.cvc.csar.cc.VTPValidatePnfCSARBase; + +import java.net.URISyntaxException; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +class IntegrationTestUtils { + + private IntegrationTestUtils() { + + } + + private static String absoluteFilePath(String relativeFilePath) throws URISyntaxException { + return VTPValidatePnfCSARBase.class.getClassLoader().getResource(relativeFilePath) + .toURI().getPath(); + } + + static void configureTestCase(VTPValidatePnfCSARBase testCase, String fileName) throws OnapCommandException, URISyntaxException { + configureCommandAttributes(testCase); + + testCase.initializeSchema("vtp-validate-csar-r146092.yaml"); + + configurePathToCsar(testCase, fileName); + } + + private static void configureCommandAttributes(VTPValidatePnfCSARBase testCase) { + OnapCommandResult onapCommandResult = new OnapCommandResult(); + OnapCommandResultAttribute onapCommandResultAttributeCode = new OnapCommandResultAttribute(); + onapCommandResultAttributeCode.setName("code"); + OnapCommandResultAttribute onapCommandResultAttributeMessage = new OnapCommandResultAttribute(); + onapCommandResultAttributeMessage.setName("message"); + OnapCommandResultAttribute onapCommandResultAttributeFile = new OnapCommandResultAttribute(); + onapCommandResultAttributeFile.setName("file"); + OnapCommandResultAttribute onapCommandResultAttributeLineNo = new OnapCommandResultAttribute(); + onapCommandResultAttributeLineNo.setName("line-no"); + List records = Lists.newArrayList(onapCommandResultAttributeCode, onapCommandResultAttributeMessage, onapCommandResultAttributeFile, onapCommandResultAttributeLineNo); + onapCommandResult.setRecords(records); + testCase.setResult(onapCommandResult); + } + + private static void configurePathToCsar(VTPValidatePnfCSARBase testCase, String fileName) throws URISyntaxException, OnapCommandInvalidParameterValue { + String pathToFile = absoluteFilePath(fileName); + Set parameters = testCase.getParameters(); + OnapCommandParameter csar = parameters.stream().filter(op -> op.getName().equals("csar")).findFirst().get(); + csar.setValue(pathToFile); + } + + static List convertToMessagesList(List errors) { + return errors.stream().map(CSARArchive.CSARError::getMessage).collect(Collectors.toList()); + } +} diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR146092IntegrationTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR146092IntegrationTest.java new file mode 100644 index 0000000..d5cb153 --- /dev/null +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR146092IntegrationTest.java @@ -0,0 +1,118 @@ +/* + * Copyright 2019 Nokia + *

+ * 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. + * + */ + +package org.onap.cvc.csar.cc.sol004; + +import org.junit.Before; +import org.junit.Test; +import org.onap.cvc.csar.CSARArchive; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.onap.cvc.csar.cc.sol004.IntegrationTestUtils.configureTestCase; +import static org.onap.cvc.csar.cc.sol004.IntegrationTestUtils.convertToMessagesList; + + +public class VTPValidateCSARR146092IntegrationTest { + + private VTPValidateCSARR146092 testCase; + + @Before + public void setUp() { + testCase = new VTPValidateCSARR146092(); + } + + @Test + public void shouldReturnProperRequestNumber() { + assertThat(testCase.getVnfReqsNo()).isEqualTo("R146092"); + } + + @Test + public void shouldReportThatMandatoryNonManoArtifactsAreNotAvailable() throws Exception { + // given + configureTestCase(testCase, "pnf/r146092/missingNonManoArtifactInManifest.csar"); + + // when + testCase.execute(); + + // then + List errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(5); + assertThat(convertToMessagesList(errors)).contains( + "Missing. Entry [non_mano_artifact_sets]", + "Missing. Entry [onap_ves_events]", + "Missing. Entry [onap_pm_dictionary]", + "Missing. Entry [onap_yang_module]", + "Missing. Entry [onap_others]" + ); + } + + @Test + public void shouldReportThatMandatoryNonManoArtifactSetEntryHasNotAllFields() throws Exception { + // given + configureTestCase(testCase, "pnf/r146092/missingFieldsInNonManoArtifactManifest.csar"); + + // when + testCase.execute(); + + // then + List errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(4); + assertThat(convertToMessagesList(errors)).contains( + "Missing. Entry [onap_ves_events]", + "Missing. Entry [onap_pm_dictionary]", + "Missing. Entry [onap_yang_module]", + "Missing. Entry [onap_others]" + ); + } + + + @Test + public void shouldReportThatNonManoArtifactEntryHasAnySource() throws Exception { + // given + configureTestCase(testCase, "pnf/r146092/noSourceElementInNonManoArtifactEntryManifest.csar"); + + // when + testCase.execute(); + + // then + List errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(1); + assertThat(convertToMessagesList(errors)).contains( + "Missing. Entry [source under onap_ves_events]" + ); + } + + + @Test + public void shouldReportThatNonManoArtifactEntryHasSourceWithUnknownFile() throws Exception { + // given + configureTestCase(testCase, "pnf/r146092/sourceElementWithUnknownFileInNonManoArtifactEntryManifest.csar"); + + // when + testCase.execute(); + + // then + List errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(1); + assertThat(convertToMessagesList(errors)).contains( + "Invalid. Entry [source under onap_ves_events has invalid 'Artifacts/Deployment/Events/RadioNode.yml' path]" + ); + } + +} \ No newline at end of file diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR293901IntegrationTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR293901IntegrationTest.java index eca3c1a..cd1dc06 100644 --- a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR293901IntegrationTest.java +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR293901IntegrationTest.java @@ -17,22 +17,15 @@ package org.onap.cvc.csar.cc.sol004; -import com.google.common.collect.Lists; import org.junit.Before; import org.junit.Test; -import org.onap.cli.fw.error.OnapCommandException; -import org.onap.cli.fw.error.OnapCommandInvalidParameterValue; -import org.onap.cli.fw.input.OnapCommandParameter; -import org.onap.cli.fw.output.OnapCommandResult; -import org.onap.cli.fw.output.OnapCommandResultAttribute; import org.onap.cvc.csar.CSARArchive; -import java.net.URISyntaxException; import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; import static org.assertj.core.api.Assertions.assertThat; +import static org.onap.cvc.csar.cc.sol004.IntegrationTestUtils.configureTestCase; +import static org.onap.cvc.csar.cc.sol004.IntegrationTestUtils.convertToMessagesList; public class VTPValidateCSARR293901IntegrationTest { @@ -40,7 +33,7 @@ public class VTPValidateCSARR293901IntegrationTest { private VTPValidateCSARR293901 testCase; @Before - public void setUp(){ + public void setUp() { testCase = new VTPValidateCSARR293901(); } @@ -52,7 +45,7 @@ public class VTPValidateCSARR293901IntegrationTest { @Test public void shouldReportThatMandatoryEntriesAreNotAvailable() throws Exception { // given - configureTestCase(testCase, "pnf/noMandatoryEntriesInTOSCAMeta.csar"); + configureTestCase(testCase, "pnf/r293901/noMandatoryEntriesInTOSCAMeta.csar"); // when testCase.execute(); @@ -70,7 +63,7 @@ public class VTPValidateCSARR293901IntegrationTest { @Test public void shouldDoNotReportAnyErrorWhenAllMandatoryEntriesWereDefined() throws Exception { // given - configureTestCase(testCase, "pnf/allMandatoryEntriesDefinedInTOSCAMeta.csar"); + configureTestCase(testCase, "pnf/r293901/allMandatoryEntriesDefinedInTOSCAMeta.csar"); // when testCase.execute(); @@ -83,7 +76,7 @@ public class VTPValidateCSARR293901IntegrationTest { @Test public void shouldReportAnyErrorWhneThereIsNoTOSCAMetaFileInTOSCADirectory() throws Exception { // given - configureTestCase(testCase, "pnf/noTOSCAMetaInTOSCADirectory.csar"); + configureTestCase(testCase, "pnf/r293901/noTOSCAMetaInTOSCADirectory.csar"); // when testCase.execute(); @@ -98,45 +91,4 @@ public class VTPValidateCSARR293901IntegrationTest { "Missing. Entry [ETSI-Entry-Change-Log]" ); } - - private String resolvePathToFile(String s) throws URISyntaxException { - return VTPValidateCSARR293901IntegrationTest.class.getClassLoader().getResource(s) - .toURI().getPath(); - } - - private void configureTestCase(VTPValidateCSARR293901 testCase, String fileName) throws OnapCommandException, URISyntaxException { - configureCommandAttributes(testCase); - - testCase.initializeSchema("vtp-validate-csar-r293901.yaml"); - - configurePathToCsar(testCase, fileName); - } - - private void configureCommandAttributes(VTPValidateCSARR293901 testCase) { - OnapCommandResult onapCommandResult = new OnapCommandResult(); - OnapCommandResultAttribute onapCommandResultAttributeCode = new OnapCommandResultAttribute(); - onapCommandResultAttributeCode.setName("code"); - OnapCommandResultAttribute onapCommandResultAttributeMessage = new OnapCommandResultAttribute(); - onapCommandResultAttributeMessage.setName("message"); - OnapCommandResultAttribute onapCommandResultAttributeFile = new OnapCommandResultAttribute(); - onapCommandResultAttributeFile.setName("file"); - OnapCommandResultAttribute onapCommandResultAttributeLineNo = new OnapCommandResultAttribute(); - onapCommandResultAttributeLineNo.setName("line-no"); - List records = Lists.newArrayList(onapCommandResultAttributeCode, onapCommandResultAttributeMessage, onapCommandResultAttributeFile, onapCommandResultAttributeLineNo); - onapCommandResult.setRecords(records); - testCase.setResult(onapCommandResult); - } - - private void configurePathToCsar(VTPValidateCSARR293901 testCase, String fileName) throws URISyntaxException, OnapCommandInvalidParameterValue { - String pathToFile = resolvePathToFile(fileName); - Set parameters = testCase.getParameters(); - OnapCommandParameter csar = parameters.stream().filter(op -> op.getName().equals("csar")).findFirst().get(); - csar.setValue(pathToFile); - } - - private List convertToMessagesList(List errors) { - return errors.stream().map(CSARArchive.CSARError::getMessage).collect(Collectors.toList()); - } - - } \ No newline at end of file diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR57019IntegrationTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR57019IntegrationTest.java new file mode 100644 index 0000000..8ec88ea --- /dev/null +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR57019IntegrationTest.java @@ -0,0 +1,78 @@ +/* + * Copyright 2019 Nokia + *

+ * 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. + * + */ + +package org.onap.cvc.csar.cc.sol004; + +import org.junit.Before; +import org.junit.Test; +import org.onap.cvc.csar.CSARArchive; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.onap.cvc.csar.cc.sol004.IntegrationTestUtils.configureTestCase; +import static org.onap.cvc.csar.cc.sol004.IntegrationTestUtils.convertToMessagesList; + + +public class VTPValidateCSARR57019IntegrationTest { + + private VTPValidateCSARR57019 testCase; + + @Before + public void setUp() { + testCase = new VTPValidateCSARR57019(); + } + + @Test + public void shouldReturnProperRequestNumber() { + assertThat(testCase.getVnfReqsNo()).isEqualTo("R57019"); + } + + @Test + public void shouldReportThatMandatoryEntriesInMetadataAreNotAvailable() throws Exception { + // given + configureTestCase(testCase, "pnf/r57019/noMandatoryEntriesInMetadataManifest.csar"); + + // when + testCase.execute(); + + // then + List errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(5); + assertThat(convertToMessagesList(errors)).contains( + "Missing. Entry [pnfd_provider]", + "Missing. Entry [pnfd_name]", + "Missing. Entry [pnfd_release_date_time]", + "Missing. Entry [pnfd_archive_version]", + "Invalid. Entry [pnfd_archivee_version]" + ); + } + + @Test + public void shouldDoNotReportAnyErrorWhenAllMandatoryEntriesInMetadataWereDefined() throws Exception { + // given + configureTestCase(testCase, "pnf/r57019/allMandatoryEntriesDefinedInMetadataManifest.csar"); + + // when + testCase.execute(); + + // then + List errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(0); + } + +} \ No newline at end of file diff --git a/csarvalidation/src/test/resources/pnf/MainServiceTemplate.mf b/csarvalidation/src/test/resources/pnf/MainServiceTemplate.mf index c0c0f97..4ffa857 100644 --- a/csarvalidation/src/test/resources/pnf/MainServiceTemplate.mf +++ b/csarvalidation/src/test/resources/pnf/MainServiceTemplate.mf @@ -5,8 +5,8 @@ metadata: pnfd_release_date_time: 2019-01-14T11:25:00+00:00 #The manifest file shall include a list of all files contained in or referenced from the VNF package with their location -#source: Definitions/MainServiceTemplate.yaml -#source: Definitions/etsi_nfv_sol001_vnfd_2_5_1_types.yaml +source: Definitions/MainServiceTemplate.yaml +source: Definitions/etsi_nfv_sol001_vnfd_2_5_1_types.yaml non_mano_artifact_sets: diff --git a/csarvalidation/src/test/resources/pnf/allMandatoryEntriesDefinedInTOSCAMeta.csar b/csarvalidation/src/test/resources/pnf/allMandatoryEntriesDefinedInTOSCAMeta.csar deleted file mode 100644 index f22366a..0000000 Binary files a/csarvalidation/src/test/resources/pnf/allMandatoryEntriesDefinedInTOSCAMeta.csar and /dev/null differ diff --git a/csarvalidation/src/test/resources/pnf/dummyPnfv2.csar b/csarvalidation/src/test/resources/pnf/dummyPnfv2.csar index 778f45c..dd45b66 100644 Binary files a/csarvalidation/src/test/resources/pnf/dummyPnfv2.csar and b/csarvalidation/src/test/resources/pnf/dummyPnfv2.csar differ diff --git a/csarvalidation/src/test/resources/pnf/noMandatoryEntriesInTOSCAMeta.csar b/csarvalidation/src/test/resources/pnf/noMandatoryEntriesInTOSCAMeta.csar deleted file mode 100644 index 9ef56cf..0000000 Binary files a/csarvalidation/src/test/resources/pnf/noMandatoryEntriesInTOSCAMeta.csar and /dev/null differ diff --git a/csarvalidation/src/test/resources/pnf/noTOSCAMetaInTOSCADirectory.csar b/csarvalidation/src/test/resources/pnf/noTOSCAMetaInTOSCADirectory.csar deleted file mode 100644 index 7ab26c3..0000000 Binary files a/csarvalidation/src/test/resources/pnf/noTOSCAMetaInTOSCADirectory.csar and /dev/null differ diff --git a/csarvalidation/src/test/resources/pnf/r146092/missingFieldsInNonManoArtifactManifest.csar b/csarvalidation/src/test/resources/pnf/r146092/missingFieldsInNonManoArtifactManifest.csar new file mode 100644 index 0000000..545dd16 Binary files /dev/null and b/csarvalidation/src/test/resources/pnf/r146092/missingFieldsInNonManoArtifactManifest.csar differ diff --git a/csarvalidation/src/test/resources/pnf/r146092/missingNonManoArtifactInManifest.csar b/csarvalidation/src/test/resources/pnf/r146092/missingNonManoArtifactInManifest.csar new file mode 100644 index 0000000..0bb0e16 Binary files /dev/null and b/csarvalidation/src/test/resources/pnf/r146092/missingNonManoArtifactInManifest.csar differ diff --git a/csarvalidation/src/test/resources/pnf/r146092/noSourceElementInNonManoArtifactEntryManifest.csar b/csarvalidation/src/test/resources/pnf/r146092/noSourceElementInNonManoArtifactEntryManifest.csar new file mode 100644 index 0000000..edeaf9b Binary files /dev/null and b/csarvalidation/src/test/resources/pnf/r146092/noSourceElementInNonManoArtifactEntryManifest.csar differ diff --git a/csarvalidation/src/test/resources/pnf/r146092/sourceElementWithUnknownFileInNonManoArtifactEntryManifest.csar b/csarvalidation/src/test/resources/pnf/r146092/sourceElementWithUnknownFileInNonManoArtifactEntryManifest.csar new file mode 100644 index 0000000..434d614 Binary files /dev/null and b/csarvalidation/src/test/resources/pnf/r146092/sourceElementWithUnknownFileInNonManoArtifactEntryManifest.csar differ diff --git a/csarvalidation/src/test/resources/pnf/r293901/allMandatoryEntriesDefinedInTOSCAMeta.csar b/csarvalidation/src/test/resources/pnf/r293901/allMandatoryEntriesDefinedInTOSCAMeta.csar new file mode 100644 index 0000000..f22366a Binary files /dev/null and b/csarvalidation/src/test/resources/pnf/r293901/allMandatoryEntriesDefinedInTOSCAMeta.csar differ diff --git a/csarvalidation/src/test/resources/pnf/r293901/noMandatoryEntriesInTOSCAMeta.csar b/csarvalidation/src/test/resources/pnf/r293901/noMandatoryEntriesInTOSCAMeta.csar new file mode 100644 index 0000000..9ef56cf Binary files /dev/null and b/csarvalidation/src/test/resources/pnf/r293901/noMandatoryEntriesInTOSCAMeta.csar differ diff --git a/csarvalidation/src/test/resources/pnf/r293901/noTOSCAMetaInTOSCADirectory.csar b/csarvalidation/src/test/resources/pnf/r293901/noTOSCAMetaInTOSCADirectory.csar new file mode 100644 index 0000000..7ab26c3 Binary files /dev/null and b/csarvalidation/src/test/resources/pnf/r293901/noTOSCAMetaInTOSCADirectory.csar differ diff --git a/csarvalidation/src/test/resources/pnf/r57019/allMandatoryEntriesDefinedInMetadataManifest.csar b/csarvalidation/src/test/resources/pnf/r57019/allMandatoryEntriesDefinedInMetadataManifest.csar new file mode 100644 index 0000000..3311713 Binary files /dev/null and b/csarvalidation/src/test/resources/pnf/r57019/allMandatoryEntriesDefinedInMetadataManifest.csar differ diff --git a/csarvalidation/src/test/resources/pnf/r57019/noMandatoryEntriesInMetadataManifest.csar b/csarvalidation/src/test/resources/pnf/r57019/noMandatoryEntriesInMetadataManifest.csar new file mode 100644 index 0000000..6b16ed5 Binary files /dev/null and b/csarvalidation/src/test/resources/pnf/r57019/noMandatoryEntriesInMetadataManifest.csar differ -- cgit 1.2.3-korg