summaryrefslogtreecommitdiffstats
path: root/openecomp-be/backend
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/backend')
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/pom.xml6
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ManifestBuilder.java166
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidator.java50
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ManifestBuilderTest.java157
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidatorTest.java588
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ValidatorFactoryTest.java10
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ValidatorUtil.java23
7 files changed, 823 insertions, 177 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/pom.xml b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/pom.xml
index a259124d25..fd1b32c1d5 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/pom.xml
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/pom.xml
@@ -213,6 +213,12 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ <version>${hamcrest-all.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<properties>
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ManifestBuilder.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ManifestBuilder.java
new file mode 100644
index 0000000000..c7fd225c76
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ManifestBuilder.java
@@ -0,0 +1,166 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.TreeMap;
+import org.openecomp.sdc.tosca.csar.CSARConstants;
+
+/**
+ * Builds SOL0004 manifest file as a String.
+ */
+public class ManifestBuilder {
+
+ private final Map<String, Map<String, String>> sourceWithPropertiesMap = new TreeMap<>();
+ private final Map<String, List<String>> nonManoArtifactMap = new TreeMap<>();
+ private final Map<String, String> metadataMap = new TreeMap<>();
+ private static final String PROPERTY_FORMAT = "%s: %s%n";
+ private static final String SECTION_FORMAT = "%s:%n";
+
+ /**
+ * Adds a metadata property.
+ *
+ * @param metadataProperty the property name
+ * @param value the property value
+ * @return
+ * a reference to this object.
+ */
+ public ManifestBuilder withMetaData(final String metadataProperty, final String value) {
+ metadataMap.put(metadataProperty, value);
+ return this;
+ }
+
+ /**
+ * Adds a manifest source path.
+ *
+ * @param sourcePath The source path
+ * @return
+ * a reference to this object.
+ */
+ public ManifestBuilder withSource(final String sourcePath) {
+ sourceWithPropertiesMap.put(sourcePath, null);
+ return this;
+ }
+
+ /**
+ * Adds a manifest source path with the source sign.
+ *
+ * @param sourcePath The source path
+ * @param hashAlgorithm The hash algorithm
+ * @param hash The hash representing the sign
+ * @return
+ * a reference to this object.
+ */
+ public ManifestBuilder withSignedSource(final String sourcePath, final String hashAlgorithm, final String hash) {
+ TreeMap<String, String> sourcePropertiesMap = new TreeMap<>();
+ sourcePropertiesMap.put(CSARConstants.ALGORITHM_MF_ATTRIBUTE, hashAlgorithm);
+ sourcePropertiesMap.put(CSARConstants.HASH_MF_ATTRIBUTE, hash);
+ sourceWithPropertiesMap.put(sourcePath, sourcePropertiesMap);
+ return this;
+ }
+
+ /**
+ * Adds a non mano artifact.
+ *
+ * @param artifactType the artifact type
+ * @param sourcePath the artifact source path
+ * @return
+ * a reference to this object.
+ */
+ public ManifestBuilder withNonManoArtifact(final String artifactType, final String sourcePath) {
+ nonManoArtifactMap.putIfAbsent(artifactType, new ArrayList<>());
+ nonManoArtifactMap.get(artifactType).add(sourcePath);
+ return this;
+ }
+
+
+ /**
+ * Builds the String representing the manifest file.
+ * @return
+ * The manifest file as String
+ */
+ public String build() {
+ final StringBuilder stringBuilder = new StringBuilder();
+
+ if (!metadataMap.isEmpty()) {
+ stringBuilder.append(buildMetadata());
+ }
+
+ if (!sourceWithPropertiesMap.isEmpty()) {
+ stringBuilder.append(buildSource());
+ }
+
+ if (!nonManoArtifactMap.isEmpty()) {
+ stringBuilder.append(buildNonManoArtifact());
+ }
+
+ return stringBuilder.toString();
+ }
+
+ private String buildMetadata() {
+ final StringBuilder stringBuilder = new StringBuilder();
+ stringBuilder.append(String.format(SECTION_FORMAT, CSARConstants.METADATA_MF_ATTRIBUTE));
+ for (Entry<String, String> metadataAndValue : metadataMap.entrySet()) {
+ stringBuilder.append("\t");
+ stringBuilder.append(String.format(PROPERTY_FORMAT, metadataAndValue.getKey(), metadataAndValue.getValue()));
+ }
+ stringBuilder.append("\n");
+ return stringBuilder.toString();
+ }
+
+ private String buildSource() {
+ final StringBuilder stringBuilder = new StringBuilder();
+ for (final Entry<String, Map<String, String>> signedSourceMap : sourceWithPropertiesMap.entrySet()) {
+ stringBuilder.append(String.format(PROPERTY_FORMAT, CSARConstants.SOURCE_MF_ATTRIBUTE, signedSourceMap.getKey()));
+ final Map<String, String> propertiesMap = signedSourceMap.getValue();
+ if (propertiesMap != null && !propertiesMap.isEmpty()) {
+ final String algorithm = propertiesMap.get(CSARConstants.ALGORITHM_MF_ATTRIBUTE);
+ if (algorithm != null) {
+ stringBuilder.append(String.format(PROPERTY_FORMAT, CSARConstants.ALGORITHM_MF_ATTRIBUTE, algorithm));
+ }
+
+ final String hash = propertiesMap.get(CSARConstants.HASH_MF_ATTRIBUTE);
+ if (hash != null) {
+ stringBuilder.append(String.format(PROPERTY_FORMAT, CSARConstants.HASH_MF_ATTRIBUTE, hash));
+ }
+ }
+ }
+ stringBuilder.append("\n");
+ return stringBuilder.toString();
+ }
+
+ private String buildNonManoArtifact() {
+ final StringBuilder stringBuilder = new StringBuilder();
+ stringBuilder.append(String.format(SECTION_FORMAT, CSARConstants.NON_MANO_MF_ATTRIBUTE));
+ for (Entry<String, List<String>> artifactTypeAndSourcesEntry : nonManoArtifactMap.entrySet()) {
+ stringBuilder.append("\t");
+ stringBuilder.append(String.format(SECTION_FORMAT, artifactTypeAndSourcesEntry.getKey()));
+ for (String source : artifactTypeAndSourcesEntry.getValue()) {
+ stringBuilder.append("\t\t");
+ stringBuilder.append(String.format(PROPERTY_FORMAT, CSARConstants.SOURCE_MF_ATTRIBUTE, source));
+ }
+ }
+ return stringBuilder.toString();
+ }
+
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidator.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidator.java
index 893fb7032d..d41d39cf66 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidator.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidator.java
@@ -20,6 +20,7 @@
package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation;
+import java.util.Collection;
import org.openecomp.core.converter.ServiceTemplateReaderService;
import org.openecomp.core.impl.services.ServiceTemplateReaderServiceImpl;
import org.openecomp.core.utilities.file.FileContentHandler;
@@ -282,8 +283,8 @@ class SOL004MetaDirectoryValidator implements Validator{
}
private void validateManifestFile(FileContentHandler contentHandler, String filePath){
- final Set<String> exitingFiles = contentHandler.getFileList();
- if(verifyFileExists(exitingFiles, filePath)) {
+ final Set<String> existingFiles = contentHandler.getFileList();
+ if(verifyFileExists(existingFiles, filePath)) {
Manifest onboardingManifest = new SOL004ManifestOnboarding();
onboardingManifest.parse(contentHandler.getFileContent(filePath));
if(onboardingManifest.isValid()){
@@ -293,7 +294,7 @@ class SOL004MetaDirectoryValidator implements Validator{
reportError(ErrorLevel.ERROR, e.getMessage());
LOGGER.error(e.getMessage(), e);
}
- verifySourcesExists(exitingFiles, onboardingManifest);
+ verifyManifestSources(existingFiles, onboardingManifest);
}else{
List<String> manifestErrors = onboardingManifest.getErrors();
for(String error: manifestErrors){
@@ -345,13 +346,42 @@ class SOL004MetaDirectoryValidator implements Validator{
}
}
- private void verifySourcesExists(Set<String> exitingFiles, Manifest onboardingManifest) {
- List<String> sources = filterSources(onboardingManifest.getSources());
- Map<String, List<String>> nonManoArtifacts = onboardingManifest.getNonManoSources();
- verifyFilesExist(exitingFiles, sources, MANIFEST_SOURCE);
- for (Map.Entry entry : nonManoArtifacts.entrySet()) {
- verifyFilesExist(exitingFiles, filterSources((List)entry.getValue()), MANIFEST_NON_MANO_SOURCE);
- }
+ /**
+ * Checks if all manifest sources exists within the package and if all package files are being referred.
+ *
+ * @param packageFiles The package file path list
+ * @param onboardingManifest The manifest
+ */
+ private void verifyManifestSources(final Set<String> packageFiles, final Manifest onboardingManifest) {
+ final List<String> sources = filterSources(onboardingManifest.getSources());
+ verifyFilesExist(packageFiles, sources, MANIFEST_SOURCE);
+
+ final Map<String, List<String>> nonManoArtifacts = onboardingManifest.getNonManoSources();
+ final List<String> nonManoFiles = nonManoArtifacts.values().stream()
+ .map(this::filterSources)
+ .flatMap(Collection::stream)
+ .collect(Collectors.toList());
+ verifyFilesExist(packageFiles, nonManoFiles, MANIFEST_NON_MANO_SOURCE);
+
+ final Set<String> allReferredFiles = new HashSet<>();
+ allReferredFiles.addAll(sources);
+ allReferredFiles.addAll(nonManoFiles);
+ verifyFilesBeingReferred(allReferredFiles, packageFiles);
+ }
+
+ /**
+ * Checks if all package files are referred in manifest.
+ * Reports missing references.
+ *
+ * @param referredFileSet the list of referred files path
+ * @param packageFileSet the list of package file path
+ */
+ private void verifyFilesBeingReferred(final Set<String> referredFileSet, final Set<String> packageFileSet) {
+ packageFileSet.forEach(filePath -> {
+ if (!referredFileSet.contains(filePath)) {
+ reportError(ErrorLevel.ERROR, String.format(Messages.MISSING_MANIFEST_REFERENCE.getErrorMessage(), filePath));
+ }
+ });
}
private List<String> filterSources(List<String> source){
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ManifestBuilderTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ManifestBuilderTest.java
new file mode 100644
index 0000000000..72f235e287
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ManifestBuilderTest.java
@@ -0,0 +1,157 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.hasItems;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.isEmptyString;
+
+import java.io.ByteArrayInputStream;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+import org.junit.Before;
+import org.junit.Test;
+import org.openecomp.sdc.tosca.csar.CSARConstants;
+import org.openecomp.sdc.tosca.csar.Manifest;
+import org.openecomp.sdc.tosca.csar.SOL004ManifestOnboarding;
+
+public class ManifestBuilderTest {
+
+ private ManifestBuilder manifestBuilder;
+
+ @Before
+ public void setUp() {
+ manifestBuilder = new ManifestBuilder();
+ }
+
+ @Test
+ public void givenNoManifestInformation_whenBuildingManifest_thenEmptyStringShouldBeReturned() {
+ final String manifest = manifestBuilder.build();
+ assertThat("Manifest should be empty", manifest, isEmptyString());
+ }
+
+ @Test
+ public void givenSourceFiles_whenBuildingManifestWithSources_thenManifestSourceListShouldBeTheSame() {
+ final List<String> expectedSourceList = mockSourceList();
+ mockManifestMetadata();
+ expectedSourceList.forEach(source -> manifestBuilder.withSource(source));
+
+ final Manifest onboardingManifest = parseManifest();
+ final List<String> actualSourceList = onboardingManifest.getSources();
+
+ assertThat("Source list should have the same size as expected source items", actualSourceList,
+ hasSize(expectedSourceList.size()));
+ assertThat("Source list should contain all expected source items", actualSourceList,
+ hasItems(expectedSourceList.toArray(new String[0])));
+ assertThat("Source list should contain only expected sources items", expectedSourceList,
+ hasItems(actualSourceList.toArray(new String[expectedSourceList.size()])));
+ }
+
+ @Test
+ public void givenSourceFiles_whenBuildingManifestWithSignedSources_thenManifestSourceListShouldBeTheSame() {
+ final List<String> expectedSourceList = mockSourceList();
+ mockManifestMetadata();
+ expectedSourceList.forEach(sourceArtifact ->
+ manifestBuilder.withSignedSource(sourceArtifact, "anyAlgorithm", "anyHash")
+ );
+
+ final Manifest onboardingManifest = parseManifest();
+ final List<String> sources = onboardingManifest.getSources();
+
+ assertThat("Source list should have the same size as expected source items", sources,
+ hasSize(expectedSourceList.size()));
+ assertThat("Source list should contain all expected source items", sources,
+ hasItems(expectedSourceList.toArray(new String[0])));
+ assertThat("Source list should contain only expected sources items", expectedSourceList,
+ hasItems(sources.toArray(new String[expectedSourceList.size()])));
+ }
+
+ @Test
+ public void givenMetadata_whenBuildingManifestWithMetadata_thenParsedManifestMetadataShouldBeTheSame() {
+ final Map<String, String> expectedMetadataMap = new TreeMap<>();
+ expectedMetadataMap.put(CSARConstants.PNFD_NAME, "myPnf");
+ expectedMetadataMap.put(CSARConstants.PNFD_PROVIDER, "Acme");
+ expectedMetadataMap.put(CSARConstants.PNFD_ARCHIVE_VERSION, "1.0");
+ expectedMetadataMap.put(CSARConstants.PNFD_RELEASE_DATE_TIME, "2019-03-11T11:25:00+00:00");
+
+ expectedMetadataMap.forEach((key, value) -> manifestBuilder.withMetaData(key, value));
+
+ final Manifest onboardingManifest = parseManifest();
+ final Map<String, String> actualMetadataMap = onboardingManifest.getMetadata();
+
+ assertThat("Metadata should be as expected", actualMetadataMap, is(expectedMetadataMap));
+ }
+
+ @Test
+ public void givenNonManoArtifacts_whenBuildingManifestWithArtifacts_thenParsedManifestNonManoArtifactsShouldBeTheSame() {
+ mockManifestMetadata();
+ mockManifestSource();
+
+ final Map<String, List<String>> expectedNonManoArtifactMap = new TreeMap<>();
+ expectedNonManoArtifactMap.put("onap_ves_events", Arrays.asList("Files/Events/MyPnf_Pnf_v1.yaml"));
+ expectedNonManoArtifactMap.put("onap_pm_dictionary", Arrays.asList("Files/Measurements/PM_Dictionary.yaml"));
+ expectedNonManoArtifactMap.put("onap_yang_modules",
+ Arrays.asList("Files/Yang_module/mynetconf.yang", "Files/Yang_module/mynetconf2.yang"));
+ expectedNonManoArtifactMap
+ .put("onap_others", Arrays.asList("Files/Guides/user_guide.txt", "Files/Test/test.txt"));
+
+ expectedNonManoArtifactMap.forEach((key, artifacts) ->
+ artifacts.forEach(s -> manifestBuilder.withNonManoArtifact(key, s))
+ );
+
+ final Manifest onboardingManifest = parseManifest();
+ final Map<String, List<String>> actualNonManoArtifactMap = onboardingManifest.getNonManoSources();
+
+ assertThat("Non Mano Sources should be as expected", actualNonManoArtifactMap, is(expectedNonManoArtifactMap));
+ }
+
+ private Manifest parseManifest() {
+ final Manifest onboardingManifest = new SOL004ManifestOnboarding();
+ onboardingManifest.parse(new ByteArrayInputStream(manifestBuilder.build().getBytes()));
+ return onboardingManifest;
+ }
+
+ private List<String> mockSourceList() {
+ return Arrays.asList("pnf_main_descriptor.mf"
+ , "Definitions/pnf_main_descriptor.yaml"
+ , "Definitions/etsi_nfv_sol001_pnfd_2_5_1_types.yaml"
+ , "Definitions/etsi_nfv_sol001_vnfd_2_5_1_types.yaml"
+ , "Files/ChangeLog.txt"
+ , "Files/Events/MyPnf_Pnf_v1.yaml"
+ , "Files/Guides/user_guide.txt"
+ , "Files/Measurements/PM_Dictionary.yaml"
+ , "Files/Scripts/my_script.sh"
+ , "Files/Yang_module/mynetconf.yang"
+ , "TOSCA-Metadata/TOSCA.meta"
+ );
+ }
+
+ private void mockManifestMetadata() {
+ manifestBuilder.withMetaData(CSARConstants.PNFD_PROVIDER, "test");
+ }
+
+ private void mockManifestSource() {
+ manifestBuilder.withSource("/test.yaml");
+ }
+} \ No newline at end of file
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidatorTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidatorTest.java
index 93c8b23268..17017f5b95 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidatorTest.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidatorTest.java
@@ -1,5 +1,6 @@
package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation;
+import org.apache.commons.collections.CollectionUtils;
import org.junit.Before;
import org.junit.Test;
import org.openecomp.core.utilities.file.FileContentHandler;
@@ -13,8 +14,10 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.SEPERATOR_MF_ATTRIBUTE;
+import static org.junit.Assert.fail;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.SEPARATOR_MF_ATTRIBUTE;
import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ENTRY_DEFINITIONS;
import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ETSI_ENTRY_CERTIFICATE;
import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ETSI_ENTRY_CHANGE_LOG;
@@ -22,6 +25,15 @@ import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ETSI_ENTRY_L
import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ETSI_ENTRY_MANIFEST;
import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ETSI_ENTRY_TESTS;
import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_PATH_FILE_NAME;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.PNFD_NAME;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.PNFD_PROVIDER;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.PNFD_ARCHIVE_VERSION;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.PNFD_RELEASE_DATE_TIME;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.VNF_PRODUCT_NAME;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.VNF_PROVIDER_ID;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.VNF_PACKAGE_VERSION;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.VNF_RELEASE_DATE_TIME;
+
import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.*;
public class SOL004MetaDirectoryValidatorTest {
@@ -31,400 +43,660 @@ public class SOL004MetaDirectoryValidatorTest {
private String metaFile;
@Before
- public void setUp(){
+ public void setUp() {
sol004MetaDirectoryValidator = new SOL004MetaDirectoryValidator();
handler = new FileContentHandler();
metaFile =
"TOSCA-Meta-File-Version: 1.0\n"+
"CSAR-Version: 1.1\n"+
"Created-by: Vendor\n"+
- TOSCA_META_ENTRY_DEFINITIONS + SEPERATOR_MF_ATTRIBUTE + "Definitions/MainServiceTemplate.yaml\n"+
- TOSCA_META_ETSI_ENTRY_MANIFEST + SEPERATOR_MF_ATTRIBUTE + "Definitions/MainServiceTemplate.mf\n"+
- TOSCA_META_ETSI_ENTRY_CHANGE_LOG + SEPERATOR_MF_ATTRIBUTE + "Artifacts/changeLog.text\n";
+ TOSCA_META_ENTRY_DEFINITIONS + SEPARATOR_MF_ATTRIBUTE + "Definitions/MainServiceTemplate.yaml\n"+
+ TOSCA_META_ETSI_ENTRY_MANIFEST + SEPARATOR_MF_ATTRIBUTE + "Definitions/MainServiceTemplate.mf\n"+
+ TOSCA_META_ETSI_ENTRY_CHANGE_LOG + SEPARATOR_MF_ATTRIBUTE + "Artifacts/changeLog.text\n";
}
@Test
- public void testGivenTOSCAMetaFile_whenEntryHasNoValue_thenErrorIsReturned() throws IOException{
-
- String metaFileWithInvalidEntry = "TOSCA-Meta-File-Version: \n" +
+ public void testGivenTOSCAMetaFile_whenEntryHasNoValue_thenErrorIsReturned() {
+ final String metaFileWithInvalidEntry = "TOSCA-Meta-File-Version: \n" +
"Entry-Definitions: Definitions/MainServiceTemplate.yaml";
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileWithInvalidEntry.getBytes(StandardCharsets.UTF_8));
- handler.addFile(TOSCA_DEFINITION_FILEPATH, ValidatorUtil.getFileResource(TestConstants.SAMPLE_DEFINITION_FILE_PATH));
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(TestConstants.SAMPLE_DEFINITION_FILE_PATH));
- Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
- List<ErrorMessage> errorMessages = errors.get(SdcCommon.UPLOAD_FILE);
- assertTrue(errors.size() == 1 && errorMessages.size() == 1);
+ final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
+ assertExpectedErrors("TOSCA Meta file with no entries", errors, 1);
}
@Test
- public void testGivenTOSCAMeta_withAllSupportedEntries_thenNoErrorsReturned() throws IOException{
+ public void testGivenTOSCAMeta_withAllSupportedEntries_thenNoErrorsReturned() {
- String entryTestFilePath = "Files/Tests";
- String entryLicenseFilePath = "Files/Licenses";
+ final String entryTestFilePath = "Files/Tests";
+ final String entryLicenseFilePath = "Files/Licenses";
- List<String> folderList = new ArrayList<>();
+ final List<String> folderList = new ArrayList<>();
folderList.add("Files/Tests/");
folderList.add("Files/Licenses/");
metaFile = metaFile +
- TOSCA_META_ETSI_ENTRY_TESTS + SEPERATOR_MF_ATTRIBUTE + entryTestFilePath + "\n" +
- TOSCA_META_ETSI_ENTRY_LICENSES + SEPERATOR_MF_ATTRIBUTE + entryLicenseFilePath +"\n";
+ TOSCA_META_ETSI_ENTRY_TESTS + SEPARATOR_MF_ATTRIBUTE + entryTestFilePath + "\n" +
+ TOSCA_META_ETSI_ENTRY_LICENSES + SEPARATOR_MF_ATTRIBUTE + entryLicenseFilePath +"\n";
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
- handler.addFile(TOSCA_DEFINITION_FILEPATH, ValidatorUtil.getFileResource(SAMPLE_DEFINITION_FILE_PATH));
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
- handler.addFile(TOSCA_MANIFEST_FILEPATH, ValidatorUtil.getFileResource(SAMPLE_MANIFEST_FILE_PATH));
+
handler.addFile(SAMPLE_SOURCE, "".getBytes());
handler.addFile(SAMPLE_DEFINITION_IMPORT_FILE_PATH, "".getBytes());
handler.addFile(entryTestFilePath, "".getBytes());
handler.addFile(entryLicenseFilePath, "".getBytes());
- Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, folderList);
+ final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder()
+ .withSource(TOSCA_META_PATH_FILE_NAME)
+ .withSource(TOSCA_DEFINITION_FILEPATH)
+ .withSource(TOSCA_CHANGELOG_FILEPATH)
+ .withSource(TOSCA_MANIFEST_FILEPATH).withSource(SAMPLE_SOURCE)
+ .withSource(SAMPLE_DEFINITION_IMPORT_FILE_PATH)
+ .withSource(entryTestFilePath)
+ .withSource(entryLicenseFilePath);
+
+ handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
+
+ final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, folderList);
assertTrue(errors.size() == 0);
}
@Test
- public void testGivenTOSCAMeta_withUnsupportedEntry_thenWarningIsReturned(){
-
+ public void testGivenTOSCAMeta_withUnsupportedEntry_thenWarningIsReturned() {
metaFile = "Entry-Events: Definitions/events.log";
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
- Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
+ final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
List<ErrorMessage> errorMessages = errors.get(SdcCommon.UPLOAD_FILE);
assertTrue(errors.size() == 1 && errorMessages.size() == 1);
assertTrue(errorMessages.get(0).getLevel() == ErrorLevel.ERROR);
-
}
+ /**
+ * Tests if the meta file contains invalid versions in TOSCA-Meta-File-Version and CSAR-Version attributes.
+ */
@Test
- public void testGivenTOSCAMetaFile_withInvalidTOSCAMetaFileVersionAndCSARVersion_thenErrorIsReturned() throws IOException{
-
- String metaFile =
+ public void testGivenTOSCAMetaFile_withInvalidTOSCAMetaFileVersionAndCSARVersion_thenErrorIsReturned() {
+ final String metaFile =
"TOSCA-Meta-File-Version: " + Integer.MAX_VALUE +
"\nCSAR-Version: " + Integer.MAX_VALUE +
"\nCreated-by: Bilal Iqbal\n" +
- TOSCA_META_ENTRY_DEFINITIONS+ SEPERATOR_MF_ATTRIBUTE + "Definitions/MainServiceTemplate.yaml\n" +
- TOSCA_META_ETSI_ENTRY_MANIFEST + SEPERATOR_MF_ATTRIBUTE + "Definitions/MainServiceTemplate.mf\n"+
- TOSCA_META_ETSI_ENTRY_CHANGE_LOG + SEPERATOR_MF_ATTRIBUTE + "Artifacts/changeLog.text";
+ TOSCA_META_ENTRY_DEFINITIONS+ SEPARATOR_MF_ATTRIBUTE + "Definitions/MainServiceTemplate.yaml\n" +
+ TOSCA_META_ETSI_ENTRY_MANIFEST + SEPARATOR_MF_ATTRIBUTE + "Definitions/MainServiceTemplate.mf\n"+
+ TOSCA_META_ETSI_ENTRY_CHANGE_LOG + SEPARATOR_MF_ATTRIBUTE + "Artifacts/changeLog.text";
+
+ final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
- handler.addFile(TOSCA_DEFINITION_FILEPATH, ValidatorUtil.getFileResource(TestConstants.SAMPLE_DEFINITION_FILE_PATH));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(TestConstants.SAMPLE_DEFINITION_FILE_PATH));
+ manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
+
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
- handler.addFile(TOSCA_MANIFEST_FILEPATH, ValidatorUtil.getFileResource(SAMPLE_MANIFEST_FILE_PATH));
+ manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
- Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
- List<ErrorMessage> errorMessages = errors.get(SdcCommon.UPLOAD_FILE);
- assertTrue(errors.size() == 1 && errorMessages.size() == 2);
+ manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
+ handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
+
+ final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
+ assertExpectedErrors("Invalid TOSCA-Meta-File-Version and CSAR-Version attributes", errors, 2);
}
@Test
- public void testGivenTOSCAMetaFile_withNonExistentFileReferenced_thenErrorsReturned(){
-
+ public void testGivenTOSCAMetaFile_withNonExistentFileReferenced_thenErrorsReturned() {
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
- Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
+ final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
List<ErrorMessage> errorMessages = errors.get(SdcCommon.UPLOAD_FILE);
assertTrue(errors.size() == 1 && errorMessages.size() == 3);
}
@Test
- public void testGivenDefinitionFile_whenValidImportStatementExist_thenNoErrorsReturned() throws IOException{
-
- String definitionFileWithValidImports = "/validation.files/definition/definitionFileWithValidImports.yaml";
-
+ public void testGivenDefinitionFile_whenValidImportStatementExist_thenNoErrorsReturned() {
+ final ManifestBuilder manifestBuilder = getPnfManifestSampleBuilder();
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
- handler.addFile(TOSCA_MANIFEST_FILEPATH, ValidatorUtil.getFileResource(SAMPLE_MANIFEST_FILE_PATH));
+ manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
+
handler.addFile(SAMPLE_SOURCE, "".getBytes());
- handler.addFile("Definitions/etsi_nfv_sol001_pnfd_2_5_1_types.yaml", ValidatorUtil.getFileResource(SAMPLE_DEFINITION_FILE_PATH));
- handler.addFile(TOSCA_DEFINITION_FILEPATH, ValidatorUtil.getFileResource(definitionFileWithValidImports));
+ manifestBuilder.withSource(SAMPLE_SOURCE);
- Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
+ handler.addFile("Definitions/etsi_nfv_sol001_pnfd_2_5_1_types.yaml", getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
+ manifestBuilder.withSource("Definitions/etsi_nfv_sol001_pnfd_2_5_1_types.yaml");
+
+ final String definitionFileWithValidImports = "/validation.files/definition/definitionFileWithValidImports.yaml";
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(definitionFileWithValidImports));
+ manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
+
+ manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
+ handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
+
+ final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
assertTrue(errors.size() == 0);
}
@Test
- public void testGivenDefinitionFile_whenMultipleDefinitionsImportStatementExist_thenNoErrorsReturned() throws IOException{
-
- byte [] sampleDefinitionFile1 = ValidatorUtil.getFileResource("/validation.files/definition/sampleDefinitionFile1.yaml");
- byte [] sampleDefinitionFile2 = ValidatorUtil.getFileResource("/validation.files/definition/sampleDefinitionFile2.yaml");
- byte [] sampleDefinitionFile3 = ValidatorUtil.getFileResource("/validation.files/definition/sampleDefinitionFile3.yaml");
+ public void testGivenDefinitionFile_whenMultipleDefinitionsImportStatementExist_thenNoErrorsReturned() {
+ final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
- handler.addFile(TOSCA_MANIFEST_FILEPATH, ValidatorUtil.getFileResource(SAMPLE_MANIFEST_FILE_PATH));
+ manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
+
handler.addFile(SAMPLE_SOURCE, "".getBytes());
+ manifestBuilder.withSource(SAMPLE_SOURCE);
+
+ final byte [] sampleDefinitionFile1 = getResourceBytes("/validation.files/definition/sampleDefinitionFile1.yaml");
handler.addFile(TOSCA_DEFINITION_FILEPATH, sampleDefinitionFile1);
+ manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
+
+ final byte [] sampleDefinitionFile2 = getResourceBytes("/validation.files/definition/sampleDefinitionFile2.yaml");
handler.addFile("Definitions/etsi_nfv_sol001_pnfd_2_5_1_types.yaml", sampleDefinitionFile2);
+ manifestBuilder.withSource("Definitions/etsi_nfv_sol001_pnfd_2_5_1_types.yaml");
+
+ final byte [] sampleDefinitionFile3 = getResourceBytes("/validation.files/definition/sampleDefinitionFile3.yaml");
handler.addFile("Definitions/etsi_nfv_sol001_pnfd_2_5_2_types.yaml", sampleDefinitionFile3);
+ manifestBuilder.withSource("Definitions/etsi_nfv_sol001_pnfd_2_5_2_types.yaml");
+
+ manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
+ handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
- Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
+ final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
assertTrue(errors.size() == 0);
}
@Test
- public void testGivenDefinitionFile_whenInvalidImportStatementExist_thenErrorIsReturned() throws IOException{
-
- String definitionFileWithInvalidImports = "/validation.files/definition/definitionFileWithInvalidImport.yaml";
+ public void testGivenDefinitionFile_whenInvalidImportStatementExist_thenErrorIsReturned() {
+ final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
- handler.addFile(TOSCA_MANIFEST_FILEPATH, ValidatorUtil.getFileResource(SAMPLE_MANIFEST_FILE_PATH));
+ manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
+
handler.addFile(SAMPLE_SOURCE, "".getBytes());
- handler.addFile(TOSCA_DEFINITION_FILEPATH, ValidatorUtil.getFileResource(definitionFileWithInvalidImports));
+ manifestBuilder.withSource(SAMPLE_SOURCE);
- Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
- List<ErrorMessage> errorMessages = errors.get(SdcCommon.UPLOAD_FILE);
- assertTrue(errors.size() == 1 && errorMessages.size() == 1);
+ final String definitionFileWithInvalidImports = "/validation.files/definition/definitionFileWithInvalidImport.yaml";
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(definitionFileWithInvalidImports));
+ manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
+
+ manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
+ String manifest = manifestBuilder.build();
+ handler.addFile(TOSCA_MANIFEST_FILEPATH, manifest.getBytes(StandardCharsets.UTF_8));
+
+ final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
+ assertExpectedErrors("", errors, 1);
}
+ /**
+ * Manifest referenced import file missing
+ */
@Test
- public void testGivenDefinitionFile_whenReferencedImportDoesNotExist_thenErrorIsReturned() throws IOException{
+ public void testGivenDefinitionFile_whenReferencedImportDoesNotExist_thenErrorIsReturned() {
+ final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
- handler.addFile(TOSCA_MANIFEST_FILEPATH, ValidatorUtil.getFileResource(SAMPLE_MANIFEST_FILE_PATH));
+ manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
+
handler.addFile(SAMPLE_SOURCE, "".getBytes());
+ manifestBuilder.withSource(SAMPLE_SOURCE);
+
handler.addFile("Definitions/etsi_nfv_sol001_pnfd_2_5_1_types.yaml", "".getBytes());
- handler.addFile(TOSCA_DEFINITION_FILEPATH, ValidatorUtil.getFileResource("/validation.files/definition/sampleDefinitionFile2.yaml"));
+ manifestBuilder.withSource("Definitions/etsi_nfv_sol001_pnfd_2_5_1_types.yaml");
- Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
- List<ErrorMessage> errorMessages = errors.get(SdcCommon.UPLOAD_FILE);
- assertTrue(errors.size() == 1 && errorMessages.size() == 1);
+ manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes("/validation.files/definition/sampleDefinitionFile2.yaml"));
+
+ manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
+ handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
+ final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
+ assertExpectedErrors("Manifest referenced import file missing", errors, 1);
}
+ /**
+ * Reference with invalid YAML format.
+ */
@Test
- public void testGivenDefinitionFile_withInvalidYAML_thenErrorIsReturned() throws IOException{
-
- String definitionFileWithInvalidYAML = "/validation.files/definition/invalidDefinitionFile.yaml";
+ public void testGivenDefinitionFile_withInvalidYAML_thenErrorIsReturned() {
+ final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
- handler.addFile(TOSCA_MANIFEST_FILEPATH, ValidatorUtil.getFileResource(SAMPLE_MANIFEST_FILE_PATH));
+ manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
+
handler.addFile(SAMPLE_SOURCE, "".getBytes());
+ manifestBuilder.withSource(SAMPLE_SOURCE);
- handler.addFile(TOSCA_DEFINITION_FILEPATH, ValidatorUtil.getFileResource(definitionFileWithInvalidYAML));
+ final String definitionFileWithInvalidYAML = "/validation.files/definition/invalidDefinitionFile.yaml";
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(definitionFileWithInvalidYAML));
+ manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
- Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
- List<ErrorMessage> errorMessages = errors.get(SdcCommon.UPLOAD_FILE);
- assertTrue(errors.size() == 1 && errorMessages.size() == 1);
+ manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
+ handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
+
+ final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
+ assertExpectedErrors("Reference with invalid YAML format", errors, 1);
}
@Test
- public void testGivenManifestFile_withValidSourceAndNonManoSources_thenNoErrorIsReturned() throws IOException{
-
- String nonManoSource = "Artifacts/Deployment/Measurements/PM_Dictionary.yaml";
+ public void testGivenManifestFile_withValidSourceAndNonManoSources_thenNoErrorIsReturned() {
+ final ManifestBuilder manifestBuilder = getPnfManifestSampleBuilder();
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
- handler.addFile(TOSCA_MANIFEST_FILEPATH, ValidatorUtil.getFileResource("/validation.files/manifest/validManifest.mf"));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
- handler.addFile(TOSCA_DEFINITION_FILEPATH, ValidatorUtil.getFileResource(SAMPLE_DEFINITION_FILE_PATH));
+ manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
+
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
+ manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
+
handler.addFile(SAMPLE_SOURCE, "".getBytes());
- handler.addFile(SAMPLE_DEFINITION_IMPORT_FILE_PATH, ValidatorUtil.getFileResource(SAMPLE_DEFINITION_FILE_PATH));
+ manifestBuilder.withSource(SAMPLE_SOURCE);
+
+ handler.addFile(SAMPLE_DEFINITION_IMPORT_FILE_PATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
+ manifestBuilder.withSource(SAMPLE_DEFINITION_IMPORT_FILE_PATH);
+
+ final String nonManoSource = "Artifacts/Deployment/Measurements/PM_Dictionary.yaml";
handler.addFile(nonManoSource, "".getBytes());
+ manifestBuilder.withNonManoArtifact("onap_pm_events", nonManoSource);
+
+ manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
+ handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
- Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
+ final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
assertTrue(errors.size() == 0);
}
+ /**
+ * Manifest with non existent source files should return error.
+ */
@Test
- public void testGivenManifestFile_withNonExistentSourceFile_thenErrorIsReturned() throws IOException{
- String nonManoSource = "Artifacts/Deployment/Measurements/PM_Dictionary.yaml";
+ public void testGivenManifestFile_withNonExistentSourceFile_thenErrorIsReturned() {
+ final ManifestBuilder manifestBuilder = getPnfManifestSampleBuilder();
+ //non existent reference
+ manifestBuilder.withSource("Artifacts/Deployment/Events/RadioNode_pnf_v1.yaml");
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
- handler.addFile(TOSCA_MANIFEST_FILEPATH, ValidatorUtil.getFileResource("/validation.files/manifest/validManifest.mf"));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
- handler.addFile(TOSCA_DEFINITION_FILEPATH, ValidatorUtil.getFileResource(SAMPLE_DEFINITION_FILE_PATH));
+ manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
+
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
+ manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
+
handler.addFile(SAMPLE_DEFINITION_IMPORT_FILE_PATH, "".getBytes());
+ manifestBuilder.withSource(SAMPLE_DEFINITION_IMPORT_FILE_PATH);
+
+ String nonManoSource = "Artifacts/Deployment/Measurements/PM_Dictionary.yaml";
handler.addFile(nonManoSource, "".getBytes());
+ manifestBuilder.withNonManoArtifact("onap_pm_events", nonManoSource);
- Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
- List<ErrorMessage> errorMessages = errors.get(SdcCommon.UPLOAD_FILE);
- assertTrue(errors.size() == 1 && errorMessages.size() == 1);
+ manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
+ handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
+
+ final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
+ assertExpectedErrors("Manifest with non existent source files", errors, 1);
}
+ /**
+ * Tests the validation for a TOSCA Manifest with invalid data.
+ */
@Test
- public void testGivenManifestFile_withInvalidData_thenErrorIsReturned() throws IOException{
-
+ public void testGivenManifestFile_withInvalidData_thenErrorIsReturned() {
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
- handler.addFile(TOSCA_MANIFEST_FILEPATH, ValidatorUtil.getFileResource("/validation.files/manifest/invalidManifest.mf"));
+ handler.addFile(TOSCA_MANIFEST_FILEPATH, getResourceBytes("/validation.files/manifest/invalidManifest.mf"));
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
- handler.addFile(TOSCA_DEFINITION_FILEPATH, ValidatorUtil.getFileResource(SAMPLE_DEFINITION_FILE_PATH));
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
handler.addFile(SAMPLE_DEFINITION_IMPORT_FILE_PATH, "".getBytes());
- Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
- List<ErrorMessage> errorMessages = errors.get(SdcCommon.UPLOAD_FILE);
- assertTrue(errors.size() == 1 && errorMessages.size() == 1);
+ final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
+ assertExpectedErrors("TOSCA manifest with invalid data", errors, 1);
}
@Test
- public void testGivenManifestAndDefinitionFile_withSameNames_thenNoErrorReturned() throws IOException {
+ public void testGivenManifestAndDefinitionFile_withSameNames_thenNoErrorReturned() {
+ final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
- handler.addFile(TOSCA_MANIFEST_FILEPATH, ValidatorUtil.getFileResource("/validation.files/manifest/sampleManifest.mf"));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
- handler.addFile(TOSCA_DEFINITION_FILEPATH, ValidatorUtil.getFileResource(SAMPLE_DEFINITION_FILE_PATH));
+ manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
+
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
+ manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
+
handler.addFile(SAMPLE_DEFINITION_IMPORT_FILE_PATH, "".getBytes());
+ manifestBuilder.withSource(SAMPLE_DEFINITION_IMPORT_FILE_PATH);
- Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
+ manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
+ handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
+
+ final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
assertTrue(errors.size() == 0);
}
+ /**
+ * Main TOSCA definitions file and Manifest file with different name should return error.
+ */
@Test
- public void testGivenManifestAndMainDefinitionFile_withDifferentNames_thenErrorIsReturned() throws IOException {
+ public void testGivenManifestAndMainDefinitionFile_withDifferentNames_thenErrorIsReturned() {
metaFile =
"TOSCA-Meta-File-Version: 1.0\n"+
"CSAR-Version: 1.1\n"+
"Created-by: Vendor\n"+
- TOSCA_META_ENTRY_DEFINITIONS + SEPERATOR_MF_ATTRIBUTE + "Definitions/MainServiceTemplate.yaml\n"+
- TOSCA_META_ETSI_ENTRY_MANIFEST + SEPERATOR_MF_ATTRIBUTE +"Definitions/MainServiceTemplate2.mf\n"+
- TOSCA_META_ETSI_ENTRY_CHANGE_LOG + SEPERATOR_MF_ATTRIBUTE +"Artifacts/changeLog.text\n";
+ TOSCA_META_ENTRY_DEFINITIONS + SEPARATOR_MF_ATTRIBUTE + "Definitions/MainServiceTemplate.yaml\n"+
+ TOSCA_META_ETSI_ENTRY_MANIFEST + SEPARATOR_MF_ATTRIBUTE +"Definitions/MainServiceTemplate2.mf\n"+
+ TOSCA_META_ETSI_ENTRY_CHANGE_LOG + SEPARATOR_MF_ATTRIBUTE +"Artifacts/changeLog.text\n";
+
+ final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
- handler.addFile("Definitions/MainServiceTemplate2.mf", ValidatorUtil.getFileResource("/validation.files/manifest/sampleManifest.mf"));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
- handler.addFile(TOSCA_DEFINITION_FILEPATH, ValidatorUtil.getFileResource(SAMPLE_DEFINITION_FILE_PATH));
+ manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
+
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
+ manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
+
handler.addFile(SAMPLE_DEFINITION_IMPORT_FILE_PATH, "".getBytes());
+ manifestBuilder.withSource(SAMPLE_DEFINITION_IMPORT_FILE_PATH);
+
+ manifestBuilder.withSource("Definitions/MainServiceTemplate2.mf");
+ handler.addFile("Definitions/MainServiceTemplate2.mf", manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
- Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
+ final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
assertExpectedErrors("Main TOSCA definitions file and Manifest file with different name should return error",
errors, 1);
}
@Test
- public void testGivenManifestFile_withDifferentExtension_thenErrorIsReturned() throws IOException {
+ public void testGivenManifestFile_withDifferentExtension_thenErrorIsReturned() {
metaFile =
"TOSCA-Meta-File-Version: 1.0\n"+
"CSAR-Version: 1.1\n"+
"Created-by: Vendor\n"+
"Entry-Definitions: Definitions/MainServiceTemplate.yaml\n"+
- TOSCA_META_ETSI_ENTRY_MANIFEST + SEPERATOR_MF_ATTRIBUTE + "Definitions/MainServiceTemplate.txt\n"+
- TOSCA_META_ETSI_ENTRY_CHANGE_LOG + SEPERATOR_MF_ATTRIBUTE + "Artifacts/changeLog.text\n";
+ TOSCA_META_ETSI_ENTRY_MANIFEST + SEPARATOR_MF_ATTRIBUTE + "Definitions/MainServiceTemplate.txt\n"+
+ TOSCA_META_ETSI_ENTRY_CHANGE_LOG + SEPARATOR_MF_ATTRIBUTE + "Artifacts/changeLog.text\n";
+
+ final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
- handler.addFile("Definitions/MainServiceTemplate.txt", ValidatorUtil.getFileResource("/validation.files/manifest/sampleManifest.mf"));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
- handler.addFile(TOSCA_DEFINITION_FILEPATH, ValidatorUtil.getFileResource(SAMPLE_DEFINITION_FILE_PATH));
+ manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
+
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
+ manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
+
handler.addFile(SAMPLE_DEFINITION_IMPORT_FILE_PATH, "".getBytes());
+ manifestBuilder.withSource(SAMPLE_DEFINITION_IMPORT_FILE_PATH);
- Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
+ manifestBuilder.withSource("Definitions/MainServiceTemplate.txt");
+ handler.addFile("Definitions/MainServiceTemplate.txt", manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
+
+ final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
assertExpectedErrors("Manifest file with different extension than .mf should return error",
errors, 1);
}
@Test
- public void testGivenManifestFile_withValidVnfMetadata_thenNoErrorsReturned() throws IOException{
+ public void testGivenManifestFile_withValidVnfMetadata_thenNoErrorsReturned() {
+ final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
+
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
- handler.addFile(TOSCA_MANIFEST_FILEPATH, ValidatorUtil.getFileResource("/validation.files/manifest/sampleManifest.mf"));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
- handler.addFile(TOSCA_DEFINITION_FILEPATH, ValidatorUtil.getFileResource(SAMPLE_DEFINITION_FILE_PATH));
+ manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
+ manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
+
+ manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
+ handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
- Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
+ final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
assertExpectedErrors("Manifest with valid vnf mandatory values should not return any errors", errors, 0);
}
@Test
- public void testGivenManifestFile_withValidPnfMetadata_thenNoErrorsReturned() throws IOException {
+ public void testGivenManifestFile_withValidPnfMetadata_thenNoErrorsReturned() {
+ final ManifestBuilder manifestBuilder = getPnfManifestSampleBuilder();
+
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
- handler.addFile(TOSCA_MANIFEST_FILEPATH, ValidatorUtil.getFileResource("/validation.files/manifest/sampleManifest2.mf"));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
- handler.addFile(TOSCA_DEFINITION_FILEPATH, ValidatorUtil.getFileResource(SAMPLE_DEFINITION_FILE_PATH));
+ manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
- Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
+ manifestBuilder.withSignedSource(TOSCA_DEFINITION_FILEPATH
+ , "SHA-abc", "09e5a788acb180162c51679ae4c998039fa6644505db2415e35107d1ee213943");
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
+
+ manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
+ handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
+
+ final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
assertExpectedErrors("Manifest with valid pnf mandatory values should not return any errors", errors, 0);
}
+ /**
+ * Manifest with mixed metadata should return error.
+ */
@Test
- public void testGivenManifestFile_withMetadataContainingMixedPnfVnfMetadata_thenErrorIsReturned() throws IOException {
+ public void testGivenManifestFile_withMetadataContainingMixedPnfVnfMetadata_thenErrorIsReturned() {
+ final ManifestBuilder manifestBuilder = new ManifestBuilder()
+ .withMetaData(PNFD_NAME, "RadioNode")
+ .withMetaData(VNF_PROVIDER_ID, "Bilal Iqbal")
+ .withMetaData(PNFD_ARCHIVE_VERSION, "1.0")
+ .withMetaData(VNF_RELEASE_DATE_TIME, "2019-12-14T11:25:00+00:00");
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
- handler.addFile(TOSCA_MANIFEST_FILEPATH, ValidatorUtil.getFileResource("/validation.files/manifest/manifestInvalidMetadata.mf"));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
- handler.addFile(TOSCA_DEFINITION_FILEPATH, ValidatorUtil.getFileResource(SAMPLE_DEFINITION_FILE_PATH));
+ manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
+ manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
- Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
+ manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
+ handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
+
+ final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
assertExpectedErrors("Manifest with mixed metadata should return error", errors, 1);
}
@Test
- public void testGivenManifestFile_withMetadataMissingPnfOrVnfMandatoryEntries_thenErrorIsReturned() throws IOException{
+ public void testGivenManifestFile_withMetadataMissingPnfOrVnfMandatoryEntries_thenErrorIsReturned() {
+ final ManifestBuilder manifestBuilder = new ManifestBuilder()
+ .withMetaData("invalid_product_name", "RadioNode")
+ .withMetaData("invalid_provider_id", "Bilal Iqbal")
+ .withMetaData("invalid_package_version", "1.0")
+ .withMetaData("invalid_release_date_time", "2019-12-14T11:25:00+00:00");
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
- handler.addFile(TOSCA_MANIFEST_FILEPATH, ValidatorUtil.getFileResource("/validation.files/manifest/manifestInvalidMetadata2.mf"));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
- handler.addFile(TOSCA_DEFINITION_FILEPATH, ValidatorUtil.getFileResource(SAMPLE_DEFINITION_FILE_PATH));
+ manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
- Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
+ manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
+
+ manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
+ handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
+
+ final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
assertExpectedErrors("Manifest with missing vnf or pnf mandatory entries should return error", errors, 1);
}
@Test
- public void testGivenManifestFile_withMetadataMissingMandatoryPnfEntries_thenErrorIsReturned() throws IOException{
+ public void testGivenManifestFile_withMetadataMissingMandatoryPnfEntries_thenErrorIsReturned() {
+ final ManifestBuilder manifestBuilder = new ManifestBuilder();
+
+ manifestBuilder.withMetaData(PNFD_NAME, "RadioNode");
+ manifestBuilder.withMetaData(PNFD_RELEASE_DATE_TIME, "2019-12-14T11:25:00+00:00");
+
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
- handler.addFile(TOSCA_MANIFEST_FILEPATH, ValidatorUtil.getFileResource("/validation.files/manifest/manifestInvalidMetadata4.mf"));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
- handler.addFile(TOSCA_DEFINITION_FILEPATH, ValidatorUtil.getFileResource(SAMPLE_DEFINITION_FILE_PATH));
+ manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
+
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
+ manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
+
+ manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
+ handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
- Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
+ final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
assertExpectedErrors("Manifest with metadata missing pnf mandatory entries should return error", errors, 3);
}
@Test
- public void testGivenManifestFile_withMetadataMissingMandatoryVnfEntries_thenErrorIsReturned() throws IOException{
+ public void testGivenManifestFile_withMetadataMissingMandatoryVnfEntries_thenErrorIsReturned() {
+ final ManifestBuilder manifestBuilder = new ManifestBuilder();
+
+ manifestBuilder.withMetaData(VNF_PRODUCT_NAME, "RadioNode");
+
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
- handler.addFile(TOSCA_MANIFEST_FILEPATH, ValidatorUtil.getFileResource("/validation.files/manifest/manifestInvalidMetadata5.mf"));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
- handler.addFile(TOSCA_DEFINITION_FILEPATH, ValidatorUtil.getFileResource(SAMPLE_DEFINITION_FILE_PATH));
+ manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
+
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
+ manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
- Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
+ manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
+ handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
+
+ final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
assertExpectedErrors("Manifest with metadata missing vnf mandatory entries should return error", errors, 4);
}
+ /**
+ * Manifest with more than 4 metadata entries should return error.
+ */
@Test
- public void testGivenManifestFile_withMetadataEntriesExceedingTheLimit_thenErrorIsReturned() throws IOException{
+ public void testGivenManifestFile_withMetadataEntriesExceedingTheLimit_thenErrorIsReturned() {
+ final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder()
+ .withMetaData(PNFD_NAME, "RadioNode")
+ .withMetaData(PNFD_PROVIDER, "Bilal Iqbal")
+ .withMetaData(PNFD_ARCHIVE_VERSION, "1.0")
+ .withMetaData(PNFD_RELEASE_DATE_TIME, "2019-03-11T11:25:00+00:00");
+
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
- handler.addFile(TOSCA_MANIFEST_FILEPATH, ValidatorUtil.getFileResource("/validation.files/manifest/manifestInvalidMetadata3.mf"));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
- handler.addFile(TOSCA_DEFINITION_FILEPATH, ValidatorUtil.getFileResource(SAMPLE_DEFINITION_FILE_PATH));
+ manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
+
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
+ manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
- Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
+ manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
+ handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
+
+ final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
assertExpectedErrors("Manifest with more than 4 metadata entries should return error", errors, 2);
}
@Test
- public void testGivenManifestFile_withPnfMetadataAndVfEntries_thenErrorIsReturned() throws IOException {
-
- List<String> folderList = new ArrayList<>();
- folderList.add("Files/Certificates/");
+ public void testGivenManifestFile_withPnfMetadataAndVfEntries_thenErrorIsReturned() {
+ final ManifestBuilder manifestBuilder = getPnfManifestSampleBuilder();
metaFile = metaFile +
- TOSCA_META_ETSI_ENTRY_TESTS + SEPERATOR_MF_ATTRIBUTE + "Files/Tests\n" +
- TOSCA_META_ETSI_ENTRY_LICENSES + SEPERATOR_MF_ATTRIBUTE + "Files/Licenses\n" +
- TOSCA_META_ETSI_ENTRY_CERTIFICATE + SEPERATOR_MF_ATTRIBUTE + "Files/Certificates";
+ TOSCA_META_ETSI_ENTRY_TESTS + SEPARATOR_MF_ATTRIBUTE + "Files/Tests\n" +
+ TOSCA_META_ETSI_ENTRY_LICENSES + SEPARATOR_MF_ATTRIBUTE + "Files/Licenses\n" +
+ TOSCA_META_ETSI_ENTRY_CERTIFICATE + SEPARATOR_MF_ATTRIBUTE + "Files/Certificates";
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
- handler.addFile(TOSCA_MANIFEST_FILEPATH, ValidatorUtil.getFileResource("/validation.files/manifest/sampleManifest2.mf"));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
- handler.addFile(TOSCA_DEFINITION_FILEPATH, ValidatorUtil.getFileResource(SAMPLE_DEFINITION_FILE_PATH));
+ manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
+
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
+ manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
- Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, folderList);
+ manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
+ handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
+
+ final List<String> folderList = new ArrayList<>();
+ folderList.add("Files/Certificates/");
+ final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, folderList);
assertExpectedErrors("Tosca.meta should not have entries applicable only to VF", errors, 2);
}
- private void assertExpectedErrors( String testCase, Map<String, List<ErrorMessage>> errors, int expectedErrors){
- if(expectedErrors > 0){
- List<ErrorMessage> errorMessages = errors.get(SdcCommon.UPLOAD_FILE);
- assertTrue(testCase, errorMessages.size() == expectedErrors);
- }else{
- assertTrue(testCase,errors.size() == expectedErrors);
+ private void assertExpectedErrors(final String testCase, final Map<String, List<ErrorMessage>> errors, final int expectedErrors){
+ final List<ErrorMessage> errorMessages = errors.get(SdcCommon.UPLOAD_FILE);
+ printErrorMessages(errorMessages);
+ if (expectedErrors > 0) {
+ assertEquals(testCase, errorMessages.size(), expectedErrors);
+ } else {
+ assertEquals(testCase, errors.size(), expectedErrors);
}
}
+
+ private void printErrorMessages(final List<ErrorMessage> errorMessages) {
+ if (CollectionUtils.isNotEmpty(errorMessages)) {
+ errorMessages.forEach(errorMessage -> {
+ System.out.println(String.format("%s: %s", errorMessage.getLevel(), errorMessage.getMessage()));
+ });
+ }
+ }
+
+ private byte[] getResourceBytes(final String resourcePath) {
+ try {
+ return ValidatorUtil.getFileResource(resourcePath);
+ } catch (final IOException e) {
+ fail(String.format("Could not load resource '%s'", resourcePath));
+ e.printStackTrace();
+ }
+
+ return null;
+ }
+
+ private ManifestBuilder getPnfManifestSampleBuilder() {
+ return new ManifestBuilder()
+ .withMetaData(PNFD_NAME, "myPnf")
+ .withMetaData(PNFD_PROVIDER, "ACME")
+ .withMetaData(PNFD_ARCHIVE_VERSION, "1.0")
+ .withMetaData(PNFD_RELEASE_DATE_TIME, "2019-03-11T11:25:00+00:00");
+ }
+
+ private ManifestBuilder getVnfManifestSampleBuilder() {
+ return new ManifestBuilder()
+ .withMetaData(VNF_PRODUCT_NAME, "RadioNode")
+ .withMetaData(VNF_PROVIDER_ID, "ACME")
+ .withMetaData(VNF_PACKAGE_VERSION, "1.0")
+ .withMetaData(VNF_RELEASE_DATE_TIME, "2019-03-11T11:25:00+00:00");
+ }
} \ No newline at end of file
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ValidatorFactoryTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ValidatorFactoryTest.java
index 3f42c5715c..5a43ab5e71 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ValidatorFactoryTest.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ValidatorFactoryTest.java
@@ -7,7 +7,7 @@ import java.io.IOException;
import java.nio.charset.StandardCharsets;
import static org.junit.Assert.assertEquals;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.SEPERATOR_MF_ATTRIBUTE;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.SEPARATOR_MF_ATTRIBUTE;
import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ENTRY_DEFINITIONS;
import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ETSI_ENTRY_CHANGE_LOG;
import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ETSI_ENTRY_MANIFEST;
@@ -54,7 +54,7 @@ public class ValidatorFactoryTest {
@Test
public void testGivenNonSOL004MetaDirectoryCompliantMetaFile_thenONAPCSARValidatorIsReturned() throws IOException{
metaFile = metaFile +
- TOSCA_META_ENTRY_DEFINITIONS + SEPERATOR_MF_ATTRIBUTE + TOSCA_DEFINITION_FILEPATH;
+ TOSCA_META_ENTRY_DEFINITIONS + SEPARATOR_MF_ATTRIBUTE + TOSCA_DEFINITION_FILEPATH;
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
assertEquals(ONAPCsarValidator.class, ValidatorFactory.getValidator(handler).getClass());
@@ -64,9 +64,9 @@ public class ValidatorFactoryTest {
public void testGivenSOL004MetaDirectoryCompliantMetafile_thenONAPCsarValidatorIsReturned() throws IOException{
metaFile = metaFile +
- TOSCA_META_ENTRY_DEFINITIONS + SEPERATOR_MF_ATTRIBUTE + TOSCA_DEFINITION_FILEPATH + "\n"
- + TOSCA_META_ETSI_ENTRY_MANIFEST + SEPERATOR_MF_ATTRIBUTE + TOSCA_MANIFEST_FILEPATH + "\n"
- + TOSCA_META_ETSI_ENTRY_CHANGE_LOG + SEPERATOR_MF_ATTRIBUTE + TOSCA_CHANGELOG_FILEPATH + "\n";
+ TOSCA_META_ENTRY_DEFINITIONS + SEPARATOR_MF_ATTRIBUTE + TOSCA_DEFINITION_FILEPATH + "\n"
+ + TOSCA_META_ETSI_ENTRY_MANIFEST + SEPARATOR_MF_ATTRIBUTE + TOSCA_MANIFEST_FILEPATH + "\n"
+ + TOSCA_META_ETSI_ENTRY_CHANGE_LOG + SEPARATOR_MF_ATTRIBUTE + TOSCA_CHANGELOG_FILEPATH + "\n";
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
assertEquals(SOL004MetaDirectoryValidator.class, ValidatorFactory.getValidator(handler).getClass());
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ValidatorUtil.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ValidatorUtil.java
index 91e3807a79..fdde36c935 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ValidatorUtil.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ValidatorUtil.java
@@ -11,12 +11,27 @@ import java.io.InputStream;
class ValidatorUtil {
- private ValidatorUtil(){
+ private ValidatorUtil() {
}
- public static byte[] getFileResource(String filePath) throws IOException{
- InputStream inputStream = ClassLoader.class.getClass().getResourceAsStream(filePath);
- return IOUtils.toByteArray(inputStream);
+ /**
+ * Reads a file and coverts it to a byte array.
+ *
+ * @param filePath The file path
+ * @return
+ * The file byte array
+ * @throws IOException
+ * When the file was not found or the input stream could not be opened
+ */
+ public static byte[] getFileResource(final String filePath) throws IOException {
+ try(final InputStream inputStream = ClassLoader.class.getResourceAsStream(filePath)) {
+ if (inputStream == null) {
+ throw new IOException(String.format("Could not find the resource on path \"%s\"", filePath));
+ }
+ return IOUtils.toByteArray(inputStream);
+ } catch (final IOException ex) {
+ throw new IOException(String.format("Could not open the input stream for resource on path \"%s\"", filePath), ex);
+ }
}
}