aboutsummaryrefslogtreecommitdiffstats
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/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/AsdValidator.java122
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/EtsiSol004Version251Validator.java15
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ManifestBuilder.java159
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidator.java12
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ValidatorFactory.java24
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessCsarHandler.java21
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/AsdCsarValidatorTest.java247
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ManifestBuilderTest.java1
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidatorTest.java1
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004Version3MetaDirectoryValidatorTest.java1
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004Version4MetaDirectoryValidatorTest.java1
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ValidatorFactoryTest.java47
12 files changed, 461 insertions, 190 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/AsdValidator.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/AsdValidator.java
new file mode 100644
index 0000000000..71254552a8
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/AsdValidator.java
@@ -0,0 +1,122 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 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 com.google.common.collect.ImmutableSet;
+import lombok.NoArgsConstructor;
+import org.openecomp.sdc.common.errors.Messages;
+import org.openecomp.sdc.datatypes.error.ErrorLevel;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
+import org.openecomp.sdc.tosca.csar.AbstractOnboardingManifest;
+import org.openecomp.sdc.tosca.csar.AsdManifestOnboarding;
+import org.openecomp.sdc.tosca.csar.ToscaMetaEntryAsd;
+
+import java.util.Map;
+
+import static org.openecomp.sdc.tosca.csar.CSARConstants.ASD_DEFINITION_TYPE;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.MANIFEST_ASD_METADATA;
+import static org.openecomp.sdc.tosca.csar.ManifestTokenType.ENTRY_DEFINITION_TYPE;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntryVersion251.ENTRY_MANIFEST;
+
+/**
+ * Validates the contents of the package to ensure it complies with the ASD specifications
+ */
+@NoArgsConstructor
+public class AsdValidator extends SOL004MetaDirectoryValidator {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(AsdValidator.class);
+
+ protected <T extends AbstractOnboardingManifest> T getOnboardingManifest() {
+ return (T) new AsdManifestOnboarding();
+ }
+
+ @Override
+ protected void handleEntry(final Map.Entry<String, String> entry) {
+ final String key = entry.getKey();
+ final var toscaMetaEntry = ToscaMetaEntryAsd.parse(entry.getKey()).orElse(null);
+ // allows any other unknown entry
+ if (toscaMetaEntry == null) {
+ return;
+ }
+ final String value = entry.getValue();
+ switch (toscaMetaEntry) {
+ case TOSCA_META_FILE_VERSION_ENTRY:
+ case CSAR_VERSION_ENTRY:
+ case CREATED_BY_ENTRY:
+ verifyMetadataEntryVersions(key, value);
+ break;
+ case ENTRY_DEFINITIONS:
+ validateDefinitionFile(value);
+ break;
+ case ETSI_ENTRY_MANIFEST:
+ validateManifestFile(value);
+ break;
+ case ETSI_ENTRY_CHANGE_LOG:
+ validateChangeLog(value);
+ break;
+ case ETSI_ENTRY_TESTS:
+ case ETSI_ENTRY_LICENSES:
+ validateOtherEntries(entry);
+ break;
+ case ETSI_ENTRY_CERTIFICATE:
+ validateCertificate(value);
+ break;
+ default:
+ handleOtherEntry(entry);
+ break;
+ }
+ }
+
+ @Override
+ protected String getManifestFilePath() {
+ return getToscaMetadata().getMetaEntries().get(ENTRY_MANIFEST.getName());
+ }
+
+
+ protected boolean isValidEntryDefinitionType(final String key, final String value) {
+ if (!ASD_DEFINITION_TYPE.equalsIgnoreCase(value)) {
+ reportMetadataInvalidValue(key, value);
+ return false;
+ }
+ return true;
+ }
+
+ private void reportMetadataInvalidValue(final String key, final String value) {
+ reportError(ErrorLevel.ERROR, String.format(Messages.MANIFEST_INVALID_LINE.getErrorMessage(), key, value));
+ LOGGER.error("{}: key {} - value {} ", Messages.MANIFEST_INVALID_LINE.getErrorMessage(), key, value);
+ }
+
+ @Override
+ protected ImmutableSet<String> getManifestMetadata(final Map<String, String> metadata) {
+ return MANIFEST_ASD_METADATA;
+ }
+
+ @Override
+ protected void handleMetadataEntries(final Map<String, String> metadata) {
+ getManifestMetadata(metadata).stream().filter(requiredEntry -> !metadata.containsKey(requiredEntry) ||
+ (ENTRY_DEFINITION_TYPE.getToken().equalsIgnoreCase(requiredEntry)
+ && !isValidEntryDefinitionType(requiredEntry, metadata.get(requiredEntry)))).forEach(
+ requiredEntry -> reportError(ErrorLevel.ERROR,
+ String.format(Messages.MANIFEST_METADATA_MISSING_ENTRY.getErrorMessage(), requiredEntry)));
+ }
+
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/EtsiSol004Version251Validator.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/EtsiSol004Version251Validator.java
index 3e4edd6e87..5eae5eb33e 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/EtsiSol004Version251Validator.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/EtsiSol004Version251Validator.java
@@ -20,18 +20,19 @@
*/
package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_MANIFEST_FILE_EXT;
-import static org.openecomp.sdc.tosca.csar.ToscaMetaEntryVersion251.ENTRY_CERTIFICATE;
-import static org.openecomp.sdc.tosca.csar.ToscaMetaEntryVersion251.ENTRY_DEFINITIONS;
-import static org.openecomp.sdc.tosca.csar.ToscaMetaEntryVersion251.ENTRY_MANIFEST;
-
-import java.util.Map;
-import java.util.Optional;
import lombok.NoArgsConstructor;
import org.openecomp.sdc.common.errors.Messages;
import org.openecomp.sdc.datatypes.error.ErrorLevel;
import org.openecomp.sdc.tosca.csar.ToscaMetaEntryVersion251;
+import java.util.Map;
+import java.util.Optional;
+
+import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_MANIFEST_FILE_EXT;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntryVersion251.ENTRY_CERTIFICATE;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntryVersion251.ENTRY_DEFINITIONS;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntryVersion251.ENTRY_MANIFEST;
+
/**
* Validates the contents of the package to ensure it complies with the "CSAR with TOSCA-Metadata directory" structure as defined in ETSI GS NFV-SOL
* 004 v2.5.1.
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
deleted file mode 100644
index ee708b4176..0000000000
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ManifestBuilder.java
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * ============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.openecomp.sdc.tosca.csar.ManifestTokenType.ALGORITHM;
-import static org.openecomp.sdc.tosca.csar.ManifestTokenType.HASH;
-import static org.openecomp.sdc.tosca.csar.ManifestTokenType.METADATA;
-import static org.openecomp.sdc.tosca.csar.ManifestTokenType.NON_MANO_ARTIFACT_SETS;
-import static org.openecomp.sdc.tosca.csar.ManifestTokenType.SOURCE;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.TreeMap;
-
-/**
- * Builds SOL0004 manifest file as a String.
- */
-public class ManifestBuilder {
-
- private static final String PROPERTY_FORMAT = "%s: %s%n";
- private static final String SECTION_FORMAT = "%s:%n";
- 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<>();
-
- /**
- * 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(ALGORITHM.getToken(), hashAlgorithm);
- sourcePropertiesMap.put(HASH.getToken(), 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, METADATA.getToken()));
- 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, SOURCE.getToken(), signedSourceMap.getKey()));
- final Map<String, String> propertiesMap = signedSourceMap.getValue();
- if (propertiesMap != null && !propertiesMap.isEmpty()) {
- final String algorithm = propertiesMap.get(ALGORITHM.getToken());
- if (algorithm != null) {
- stringBuilder.append(String.format(PROPERTY_FORMAT, ALGORITHM.getToken(), algorithm));
- }
- final String hash = propertiesMap.get(HASH.getToken());
- if (hash != null) {
- stringBuilder.append(String.format(PROPERTY_FORMAT, HASH.getToken(), hash));
- }
- }
- }
- stringBuilder.append("\n");
- return stringBuilder.toString();
- }
-
- private String buildNonManoArtifact() {
- final StringBuilder stringBuilder = new StringBuilder();
- stringBuilder.append(String.format(SECTION_FORMAT, NON_MANO_ARTIFACT_SETS.getToken()));
- 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, SOURCE.getToken(), 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 fde0565a3e..b992d22ea6 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
@@ -69,6 +69,7 @@ import org.openecomp.sdc.datatypes.error.ErrorLevel;
import org.openecomp.sdc.datatypes.error.ErrorMessage;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
+import org.openecomp.sdc.tosca.csar.AbstractOnboardingManifest;
import org.openecomp.sdc.tosca.csar.Manifest;
import org.openecomp.sdc.tosca.csar.OnboardingToscaMetadata;
import org.openecomp.sdc.tosca.csar.SOL004ManifestOnboarding;
@@ -230,6 +231,10 @@ public class SOL004MetaDirectoryValidator implements Validator {
toscaMetadata.getMetaEntries().entrySet().parallelStream().forEach(this::handleEntry);
}
+ protected <T extends AbstractOnboardingManifest> T getOnboardingManifest() {
+ return (T) new SOL004ManifestOnboarding();
+ }
+
protected void handleEntry(final Map.Entry<String, String> entry) {
final String key = entry.getKey();
final var toscaMetaEntry = ToscaMetaEntryVersion261.parse(entry.getKey()).orElse(null);
@@ -321,7 +326,7 @@ public class SOL004MetaDirectoryValidator implements Validator {
protected void validateManifestFile(final String filePath) {
final Set<String> existingFiles = contentHandler.getFileList();
if (verifyFileExists(existingFiles, filePath)) {
- final Manifest onboardingManifest = new SOL004ManifestOnboarding();
+ final Manifest onboardingManifest = getOnboardingManifest();
onboardingManifest.parse(contentHandler.getFileContentAsStream(filePath));
if (onboardingManifest.isValid()) {
try {
@@ -356,9 +361,10 @@ public class SOL004MetaDirectoryValidator implements Validator {
return TOSCA_TYPE_PNF.equals(expectedMetadataType);
}
- private void handleMetadataEntries(final Map<String, String> metadata) {
+ protected void handleMetadataEntries(final Map<String, String> metadata) {
getManifestMetadata(metadata).stream().filter(requiredEntry -> !metadata.containsKey(requiredEntry)).forEach(
- requiredEntry -> reportError(ErrorLevel.ERROR, String.format(Messages.MANIFEST_METADATA_MISSING_ENTRY.getErrorMessage(), requiredEntry)));
+ requiredEntry -> reportError(ErrorLevel.ERROR,
+ String.format(Messages.MANIFEST_METADATA_MISSING_ENTRY.getErrorMessage(), requiredEntry)));
}
/**
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ValidatorFactory.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ValidatorFactory.java
index d3ac455a56..6f5cdeeb5a 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ValidatorFactory.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ValidatorFactory.java
@@ -19,7 +19,11 @@
*/
package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.ETSI_VERSION_2_7_1;
+import org.openecomp.core.utilities.file.FileContentHandler;
+import org.openecomp.sdc.tosca.csar.AsdPackageHelper;
+import org.openecomp.sdc.tosca.csar.ManifestUtils;
+import org.openecomp.sdc.vendorsoftwareproduct.services.impl.etsi.ETSIService;
+import org.openecomp.sdc.vendorsoftwareproduct.services.impl.etsi.ETSIServiceImpl;
import java.io.IOException;
import java.util.Comparator;
@@ -27,16 +31,17 @@ import java.util.List;
import java.util.ServiceLoader;
import java.util.ServiceLoader.Provider;
import java.util.stream.Collectors;
-import org.openecomp.core.utilities.file.FileContentHandler;
-import org.openecomp.sdc.vendorsoftwareproduct.services.impl.etsi.ETSIService;
-import org.openecomp.sdc.vendorsoftwareproduct.services.impl.etsi.ETSIServiceImpl;
+
+import static org.openecomp.sdc.tosca.csar.CSARConstants.ETSI_VERSION_2_7_1;
public class ValidatorFactory {
private final ServiceLoader<Validator> validatorLoader;
+ private final AsdPackageHelper asdPackageHelper;
public ValidatorFactory() {
this.validatorLoader = ServiceLoader.load(Validator.class);
+ this.asdPackageHelper = new AsdPackageHelper(new ManifestUtils());
}
/**
@@ -47,9 +52,16 @@ public class ValidatorFactory {
* @throws IOException when metafile is invalid
*/
public Validator getValidator(final FileContentHandler fileContentHandler) throws IOException {
- final ETSIService etsiService = new ETSIServiceImpl(null);
+ final ETSIService etsiService = new ETSIServiceImpl(null, new ManifestUtils());
+ if (asdPackageHelper.isAsdPackage(fileContentHandler)) {
+ return new AsdValidator();
+ }
if (!etsiService.hasEtsiSol261Metadata(fileContentHandler)) {
- return etsiService.isEtsiPackage(fileContentHandler) ? new EtsiSol004Version251Validator() : new ONAPCsarValidator();
+ if (etsiService.isEtsiPackage(fileContentHandler)) {
+
+ return new EtsiSol004Version251Validator();
+ }
+ return new ONAPCsarValidator();
}
if (!etsiService.getHighestCompatibleSpecificationVersion(fileContentHandler).isLowerThan(ETSI_VERSION_2_7_1)) {
if (etsiService.hasCnfEnhancements(fileContentHandler)) {
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessCsarHandler.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessCsarHandler.java
index 08b4b26846..817d212fc7 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessCsarHandler.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessCsarHandler.java
@@ -15,13 +15,6 @@
*/
package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.process;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.openecomp.core.impl.AbstractToscaSolConverter;
@@ -43,6 +36,8 @@ import org.openecomp.sdc.heat.datatypes.structure.ValidationStructureList;
import org.openecomp.sdc.heat.services.tree.ToscaTreeManager;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
+import org.openecomp.sdc.tosca.csar.AsdPackageHelper;
+import org.openecomp.sdc.tosca.csar.ManifestUtils;
import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
@@ -54,6 +49,14 @@ import org.openecomp.sdc.vendorsoftwareproduct.services.impl.etsi.ETSIServiceImp
import org.openecomp.sdc.vendorsoftwareproduct.types.OrchestrationTemplateActionResponse;
import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
public class OrchestrationTemplateProcessCsarHandler implements OrchestrationTemplateProcessHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(OrchestrationTemplateProcessCsarHandler.class);
@@ -62,9 +65,11 @@ public class OrchestrationTemplateProcessCsarHandler implements OrchestrationTem
private final CandidateService candidateService = CandidateServiceFactory.getInstance().createInterface();
private final ToscaTreeManager toscaTreeManager = new ToscaTreeManager();
private final ETSIService etsiService;
+ private final AsdPackageHelper asdPackageHelper;
public OrchestrationTemplateProcessCsarHandler() {
etsiService = new ETSIServiceImpl();
+ this.asdPackageHelper = new AsdPackageHelper(new ManifestUtils());
}
@Override
@@ -124,7 +129,7 @@ public class OrchestrationTemplateProcessCsarHandler implements OrchestrationTem
if (CollectionUtils.isNotEmpty(modelList)) {
return handleToscaModelConversion(modelList, fileContentHandler, candidateData);
}
- if (etsiService.isEtsiPackage(fileContentHandler)) {
+ if (etsiService.isEtsiPackage(fileContentHandler) || asdPackageHelper.isAsdPackage(fileContentHandler)) {
return getToscaServiceModelSol004(fileContentHandler, candidateData);
}
return new ToscaConverterImpl().convert(fileContentHandler);
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/AsdCsarValidatorTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/AsdCsarValidatorTest.java
new file mode 100644
index 0000000000..5cd871ae45
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/AsdCsarValidatorTest.java
@@ -0,0 +1,247 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 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 org.apache.commons.collections.CollectionUtils;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.openecomp.sdc.datatypes.error.ErrorMessage;
+import org.openecomp.sdc.tosca.csar.ManifestBuilder;
+import org.openecomp.sdc.tosca.csar.ManifestTokenType;
+import org.openecomp.sdc.vendorsoftwareproduct.impl.onboarding.OnboardingPackageContentHandler;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.openecomp.sdc.be.test.util.TestResourcesHandler.getResourceBytesOrFail;
+import static org.openecomp.sdc.tosca.csar.ManifestTokenType.APPLICATION_NAME;
+import static org.openecomp.sdc.tosca.csar.ManifestTokenType.APPLICATION_PROVIDER;
+import static org.openecomp.sdc.tosca.csar.ManifestTokenType.ATTRIBUTE_VALUE_SEPARATOR;
+import static org.openecomp.sdc.tosca.csar.ManifestTokenType.ENTRY_DEFINITION_TYPE;
+import static org.openecomp.sdc.tosca.csar.ManifestTokenType.RELEASE_DATE_TIME;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntryVersion261.CREATED_BY_ENTRY;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntryVersion261.CSAR_VERSION_ENTRY;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntryVersion261.ENTRY_DEFINITIONS;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntryVersion261.ETSI_ENTRY_CHANGE_LOG;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntryVersion261.ETSI_ENTRY_LICENSES;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntryVersion261.ETSI_ENTRY_MANIFEST;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntryVersion261.ETSI_ENTRY_TESTS;
+import static org.openecomp.sdc.tosca.csar.ToscaMetaEntryVersion261.TOSCA_META_FILE_VERSION_ENTRY;
+import static org.openecomp.sdc.tosca.csar.ToscaMetadataFileInfo.TOSCA_META_PATH_FILE_NAME;
+import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.SAMPLE_DEFINITION_FILE_PATH;
+import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.SAMPLE_DEFINITION_IMPORT_FILE_PATH;
+import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.SAMPLE_SOURCE;
+import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.TOSCA_CHANGELOG_FILEPATH;
+import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.TOSCA_DEFINITION_FILEPATH;
+import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.TOSCA_MANIFEST_FILEPATH;
+
+
+class AsdCsarValidatorTest {
+
+ private AsdValidator asdValidator;
+ protected OnboardingPackageContentHandler handler;
+ protected StringBuilder metaFileBuilder;
+ private ValidatorFactory validatorFactory;
+
+ @BeforeEach
+ void setUp() {
+ validatorFactory = new ValidatorFactory();
+ asdValidator = new AsdValidator();
+ handler = new OnboardingPackageContentHandler();
+ metaFileBuilder = getMetaFileBuilder();
+ }
+
+ protected StringBuilder getMetaFileBuilder() {
+ return new StringBuilder()
+ .append(ENTRY_DEFINITION_TYPE.getToken())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" asd").append("\n")
+ .append(APPLICATION_PROVIDER.getToken())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" Ericsson").append("\n")
+ .append(APPLICATION_NAME.getToken())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" vCU").append("\n")
+ .append(RELEASE_DATE_TIME.getToken())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" 2022-02-07T11:30:00+05:00").append("\n")
+ .append(TOSCA_META_FILE_VERSION_ENTRY.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" 1.0").append("\n")
+ .append(CSAR_VERSION_ENTRY.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" 1.1").append("\n")
+ .append(CREATED_BY_ENTRY.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" Vendor").append("\n")
+ .append(ENTRY_DEFINITIONS.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" ").append(TOSCA_DEFINITION_FILEPATH).append("\n")
+ .append(ETSI_ENTRY_MANIFEST.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" ").append(TOSCA_MANIFEST_FILEPATH).append("\n")
+ .append(ETSI_ENTRY_CHANGE_LOG.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" ").append(TOSCA_CHANGELOG_FILEPATH).append("\n");
+ }
+
+ @Test
+ void testGivenASDTOSCAMeta_withAllSupportedEntries_thenNoErrorsReturned() {
+
+ final String entryTestFilePath = "Files/Tests";
+ final String entryLicenseFilePath = "Files/Licenses";
+
+ handler.addFolder("Files/Tests/");
+ handler.addFolder("Files/Licenses/");
+ metaFileBuilder
+ .append(ETSI_ENTRY_TESTS.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(entryTestFilePath).append("\n")
+ .append(ETSI_ENTRY_LICENSES.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(entryLicenseFilePath).append("\n");
+
+ handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytesOrFail(SAMPLE_DEFINITION_FILE_PATH));
+ handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
+
+ handler.addFile(SAMPLE_SOURCE, "".getBytes());
+ handler.addFile(SAMPLE_DEFINITION_IMPORT_FILE_PATH, "".getBytes());
+ handler.addFile(entryTestFilePath, "".getBytes());
+ handler.addFile(entryLicenseFilePath, "".getBytes());
+
+ final ManifestBuilder manifestBuilder = getAsdManifestSampleBuilder()
+ .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 ValidationResult validationResult = asdValidator.validate(handler);
+
+ assertTrue(validationResult.getErrors().isEmpty());
+ }
+
+ @Test
+ void testGivenASDTOSCAMetaFile_withInvalidOranEntryDefinitionType_thenErrorIsReturned() {
+ final StringBuilder metaFileBuilder = new StringBuilder()
+ .append(TOSCA_META_FILE_VERSION_ENTRY.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" 1.0").append("\n")
+ .append(CSAR_VERSION_ENTRY.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" 1.1").append("\n")
+ .append(CREATED_BY_ENTRY.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" Vendor").append("\n")
+ .append(ENTRY_DEFINITIONS.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" ").append(TOSCA_DEFINITION_FILEPATH).append("\n")
+ .append(ETSI_ENTRY_MANIFEST.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" ").append(TOSCA_MANIFEST_FILEPATH).append("\n")
+ .append(ETSI_ENTRY_CHANGE_LOG.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" ").append(TOSCA_CHANGELOG_FILEPATH);
+ final ManifestBuilder manifestBuilder = getWrongAsdManifestSampleBuilder();
+
+ handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytesOrFail(SAMPLE_DEFINITION_FILE_PATH));
+ manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
+
+ handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
+ manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
+
+ manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
+ handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
+
+ final ValidationResult validationResult = asdValidator.validate(handler);
+ assertExpectedErrors("Invalid value invalid in TOSCA.meta file", validationResult.getErrors(), 2);
+ }
+
+ @Test
+ void testGivenASDTOSCAMetaFile_withNoReleaseDateTime_thenNoAsdValidatorIsReturned() throws IOException {
+ final StringBuilder metaFileBuilder = new StringBuilder()
+ .append(ENTRY_DEFINITION_TYPE.getToken())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" asd").append("\n")
+ .append(TOSCA_META_FILE_VERSION_ENTRY.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" 1.0").append("\n")
+ .append(CSAR_VERSION_ENTRY.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" 1.1").append("\n")
+ .append(CREATED_BY_ENTRY.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" Vendor").append("\n")
+ .append(ENTRY_DEFINITIONS.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" ").append(TOSCA_DEFINITION_FILEPATH).append("\n")
+ .append(ETSI_ENTRY_MANIFEST.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" ").append(TOSCA_MANIFEST_FILEPATH).append("\n")
+ .append(ETSI_ENTRY_CHANGE_LOG.getName())
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" ").append(TOSCA_CHANGELOG_FILEPATH);
+ final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
+
+ handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytesOrFail(SAMPLE_DEFINITION_FILE_PATH));
+ manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
+
+ handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
+ manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
+
+ manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
+ handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
+
+ assertNotEquals(AsdValidator.class, validatorFactory.getValidator(handler).getClass());
+ }
+
+ protected ManifestBuilder getAsdManifestSampleBuilder() {
+ return new ManifestBuilder()
+ .withMetaData(APPLICATION_NAME.getToken(), "RadioNode")
+ .withMetaData(APPLICATION_PROVIDER.getToken(), "Ericsson")
+ .withMetaData(ENTRY_DEFINITION_TYPE.getToken(), "asd")
+ .withMetaData(RELEASE_DATE_TIME.getToken(), "2022-02-01T11:25:00+00:00");
+ }
+
+ protected ManifestBuilder getWrongAsdManifestSampleBuilder() {
+ return new ManifestBuilder()
+ .withMetaData(APPLICATION_NAME.getToken(), "RadioNode")
+ .withMetaData(APPLICATION_PROVIDER.getToken(), "Ericsson")
+ .withMetaData(ENTRY_DEFINITION_TYPE.getToken(), " Invalid")
+ .withMetaData(RELEASE_DATE_TIME.getToken(), "2022-02-01T11:25:00+00:00");
+ }
+
+ protected ManifestBuilder getVnfManifestSampleBuilder() {
+ return new ManifestBuilder()
+ .withMetaData(ManifestTokenType.VNF_PRODUCT_NAME.getToken(), "RadioNode")
+ .withMetaData(ManifestTokenType.VNF_PROVIDER_ID.getToken(), "ACME")
+ .withMetaData(ManifestTokenType.VNF_PACKAGE_VERSION.getToken(), "1.0")
+ .withMetaData(ManifestTokenType.VNF_RELEASE_DATE_TIME.getToken(), "2019-03-11T11:25:00+00:00");
+ }
+
+ protected void assertExpectedErrors(final String testCase, final List<ErrorMessage> errorMessages, final int expectedErrors){
+ printErrorMessages(errorMessages);
+ if (expectedErrors > 0) {
+ assertEquals(expectedErrors, errorMessages.size(), testCase);
+ } else {
+ assertTrue(errorMessages.isEmpty(), testCase);
+ }
+ }
+
+ private void printErrorMessages(final List<ErrorMessage> errorMessages) {
+ if (CollectionUtils.isNotEmpty(errorMessages)) {
+ errorMessages.forEach(errorMessage ->
+ System.out.printf("%s: %s%n", errorMessage.getLevel(), errorMessage.getMessage())
+ );
+ }
+ }
+}
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
index e966a12b65..5672e065dd 100644
--- 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
@@ -39,6 +39,7 @@ import java.util.TreeMap;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openecomp.sdc.tosca.csar.Manifest;
+import org.openecomp.sdc.tosca.csar.ManifestBuilder;
import org.openecomp.sdc.tosca.csar.SOL004ManifestOnboarding;
public class ManifestBuilderTest {
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 d45031f789..ed1955577a 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
@@ -77,6 +77,7 @@ import org.openecomp.sdc.common.errors.Messages;
import org.openecomp.sdc.common.utils.SdcCommon;
import org.openecomp.sdc.datatypes.error.ErrorLevel;
import org.openecomp.sdc.datatypes.error.ErrorMessage;
+import org.openecomp.sdc.tosca.csar.ManifestBuilder;
import org.openecomp.sdc.tosca.csar.ManifestTokenType;
import org.openecomp.sdc.vendorsoftwareproduct.impl.onboarding.OnboardingPackageContentHandler;
import org.openecomp.sdc.vendorsoftwareproduct.security.SecurityManager;
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004Version3MetaDirectoryValidatorTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004Version3MetaDirectoryValidatorTest.java
index 9235f363eb..470c9cad27 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004Version3MetaDirectoryValidatorTest.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004Version3MetaDirectoryValidatorTest.java
@@ -22,6 +22,7 @@ import static org.openecomp.sdc.tosca.csar.ManifestTokenType.ATTRIBUTE_VALUE_SEP
import static org.openecomp.sdc.tosca.csar.ToscaMetaEntryVersion261.OTHER_DEFINITIONS;
import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.TOSCA_DEFINITION_FILEPATH;
+import org.openecomp.sdc.tosca.csar.ManifestBuilder;
import org.openecomp.sdc.tosca.csar.ManifestTokenType;
import org.openecomp.sdc.vendorsoftwareproduct.security.SecurityManager;
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004Version4MetaDirectoryValidatorTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004Version4MetaDirectoryValidatorTest.java
index fade5d18ad..bfea275d58 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004Version4MetaDirectoryValidatorTest.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004Version4MetaDirectoryValidatorTest.java
@@ -36,6 +36,7 @@ import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.va
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import org.junit.jupiter.api.Test;
+import org.openecomp.sdc.tosca.csar.ManifestBuilder;
import org.openecomp.sdc.tosca.csar.ManifestTokenType;
import org.openecomp.sdc.vendorsoftwareproduct.security.SecurityManager;
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 c603b7fa6d..1eefb2e211 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
@@ -20,6 +20,16 @@
package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.openecomp.core.utilities.file.FileContentHandler;
+import org.openecomp.sdc.tosca.csar.ManifestBuilder;
+import org.openecomp.sdc.tosca.csar.ManifestTokenType;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -33,17 +43,12 @@ import static org.openecomp.sdc.tosca.csar.ToscaMetaEntryVersion261.ETSI_ENTRY_C
import static org.openecomp.sdc.tosca.csar.ToscaMetaEntryVersion261.ETSI_ENTRY_MANIFEST;
import static org.openecomp.sdc.tosca.csar.ToscaMetaEntryVersion261.TOSCA_META_FILE_VERSION_ENTRY;
import static org.openecomp.sdc.tosca.csar.ToscaMetadataFileInfo.TOSCA_META_PATH_FILE_NAME;
+import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.SAMPLE_DEFINITION_IMPORT_FILE_PATH;
+import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.SAMPLE_SOURCE;
import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.TOSCA_CHANGELOG_FILEPATH;
import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.TOSCA_DEFINITION_FILEPATH;
import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.TOSCA_MANIFEST_FILEPATH;
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.util.List;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.openecomp.core.utilities.file.FileContentHandler;
-
class ValidatorFactoryTest {
private String metaFile;
@@ -106,6 +111,26 @@ class ValidatorFactoryTest {
}
@Test
+ void testGivenAsdCompliantMetafile_thenAsdCsarValidatorIsReturned() throws IOException {
+ metaFile = metaFile
+ + ENTRY_DEFINITIONS.getName() + ATTRIBUTE_VALUE_SEPARATOR.getToken() + TOSCA_DEFINITION_FILEPATH + "\n"
+ + ETSI_ENTRY_MANIFEST.getName() + ATTRIBUTE_VALUE_SEPARATOR.getToken() + TOSCA_MANIFEST_FILEPATH + "\n"
+ + ETSI_ENTRY_CHANGE_LOG.getName() + ATTRIBUTE_VALUE_SEPARATOR.getToken() + TOSCA_CHANGELOG_FILEPATH + "\n";
+ handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
+
+ final ManifestBuilder manifestBuilder = getAsdManifestSampleBuilder()
+ .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);
+
+ handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
+
+ assertEquals(AsdValidator.class, validatorFactory.getValidator(handler).getClass());
+ }
+
+ @Test
void testGivenMultiBlockMetadataWithSOL00CompliantMetaFile_thenSOL004MetaDirectoryValidatorReturned()
throws IOException {
handler.addFile(TOSCA_META_PATH_FILE_NAME,
@@ -130,4 +155,12 @@ class ValidatorFactoryTest {
assertTrue(validatorList1.isEmpty());
}
+ protected ManifestBuilder getAsdManifestSampleBuilder() {
+ return new ManifestBuilder()
+ .withMetaData(ManifestTokenType.APPLICATION_NAME.getToken(), "RadioNode")
+ .withMetaData(ManifestTokenType.APPLICATION_PROVIDER.getToken(), "Ericsson")
+ .withMetaData(ManifestTokenType.ENTRY_DEFINITION_TYPE.getToken(), "asd")
+ .withMetaData(ManifestTokenType.RELEASE_DATE_TIME.getToken(), "2022-02-01T11:25:00+00:00");
+ }
+
}