summaryrefslogtreecommitdiffstats
path: root/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src')
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateCSARHandler.java133
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ONAPCsarValidator.java157
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidator.java360
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/Validator.java41
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ValidatorFactory.java45
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/exceptions/InvalidManifestMetadataException.java28
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ONAPCsarValidatorTest.java73
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidatorTest.java405
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/TestConstants.java25
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ValidatorFactoryTest.java88
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ValidatorUtil.java22
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/definition/definitionFileWithInvalidImport.yaml6
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/definition/definitionFileWithValidImports.yaml15
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/definition/invalidDefinitionFile.yaml49
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/definition/sampleDefinitionFile.yaml4
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/definition/sampleDefinitionFile1.yaml7
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/definition/sampleDefinitionFile2.yaml7
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/definition/sampleDefinitionFile3.yaml6
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/manifest/invalidManifest.mf3
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/manifest/manifestInvalidMetadata.mf7
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/manifest/manifestInvalidMetadata2.mf7
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/manifest/manifestInvalidMetadata3.mf11
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/manifest/manifestInvalidMetadata4.mf5
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/manifest/manifestInvalidMetadata5.mf4
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/manifest/sampleManifest.mf7
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/manifest/sampleManifest2.mf7
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/manifest/validManifest.mf11
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/metafile/metaFileWithMultipleBlocks.meta10
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/metafile/nonSOL004WithMetaDirectoryCompliantMetaFile.meta4
29 files changed, 1422 insertions, 125 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateCSARHandler.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateCSARHandler.java
index a3772d9298..af5512d119 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateCSARHandler.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateCSARHandler.java
@@ -3,6 +3,7 @@
* Copyright (c) 2018 AT&T Intellectual Property.
* Modifications Copyright (c) 2018 Verizon Property.
+ * Modifications 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.
@@ -29,48 +30,36 @@ import org.openecomp.sdc.common.utils.CommonUtil;
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.logging.api.Logger;
-import org.openecomp.sdc.logging.api.LoggerFactory;
-import org.openecomp.sdc.tosca.csar.ToscaMetadata;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
-import org.openecomp.sdc.tosca.csar.Manifest;
-import org.openecomp.sdc.tosca.csar.OnboardingManifest;
-import org.openecomp.sdc.tosca.csar.OnboardingToscaMetadata;
-import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.exceptions.OrchestrationTemplateHandlerException;
+import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.Validator;
+import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.ValidatorFactory;
import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService;
import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
import java.io.IOException;
-import java.io.InputStream;
import java.nio.ByteBuffer;
-import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
-import java.util.stream.Collectors;
import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.ELIGBLE_FOLDERS;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.ELIGIBLE_FILES;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.MAIN_SERVICE_TEMPLATE_MF_FILE_NAME;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.MAIN_SERVICE_TEMPLATE_YAML_FILE_NAME;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ENTRY_DEFINITIONS;
-import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_PATH_FILE_NAME;
public class OrchestrationTemplateCSARHandler extends BaseOrchestrationTemplateHandler
implements OrchestrationTemplateFileHandler {
- private static Logger logger = LoggerFactory.getLogger(OrchestrationTemplateCSARHandler.class);
+
@Override
public Optional<FileContentHandler> getFileContentMap(UploadFileResponse uploadFileResponse,
byte[] uploadedFileData) {
FileContentHandler contentMap = null;
- List<String> folderList = new ArrayList<>();
+ List<String> folderList;
try {
Pair<FileContentHandler, List<String>> fileContentMapFromOrchestrationCandidateZip =
CommonUtil.getFileContentMapFromOrchestrationCandidateZip(uploadedFileData);
contentMap = fileContentMapFromOrchestrationCandidateZip.getKey();
folderList = fileContentMapFromOrchestrationCandidateZip.getRight();
+ Validator validator = ValidatorFactory.getValidator(contentMap);
+ uploadFileResponse.addStructureErrors(validator.validateContent(contentMap, folderList));
} catch (IOException exception) {
logger.error(exception.getMessage(), exception);
uploadFileResponse.addStructureError(
@@ -81,113 +70,8 @@ public class OrchestrationTemplateCSARHandler extends BaseOrchestrationTemplateH
uploadFileResponse.addStructureError(
SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR, coreException.getMessage()));
}
- validateContent(uploadFileResponse, contentMap, folderList);
- return Optional.ofNullable(contentMap);
- }
-
- private void validateContent(UploadFileResponse uploadFileResponse, FileContentHandler contentMap,
- List<String> folderList) {
- validateManifest(uploadFileResponse, contentMap);
- validateMetadata(uploadFileResponse, contentMap);
- validateNoExtraFiles(uploadFileResponse, contentMap);
- validateFolders(uploadFileResponse, folderList);
- }
-
- private void validateMetadata(UploadFileResponse uploadFileResponse,
- FileContentHandler contentMap){
- if (!validateTOSCAYamlFileInRootExist(contentMap, MAIN_SERVICE_TEMPLATE_YAML_FILE_NAME)) {
- try (InputStream metaFileContent = contentMap.getFileContent(TOSCA_META_PATH_FILE_NAME)) {
-
- ToscaMetadata onboardingToscaMetadata = OnboardingToscaMetadata.parseToscaMetadataFile(metaFileContent);
- String entryDefinitionsPath = onboardingToscaMetadata.getMetaEntries().get(TOSCA_META_ENTRY_DEFINITIONS);
- if (entryDefinitionsPath != null) {
- validateFileExist(uploadFileResponse, contentMap, entryDefinitionsPath);
- } else {
- uploadFileResponse.addStructureError(
- SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR,
- Messages.METADATA_NO_ENTRY_DEFINITIONS.getErrorMessage()));
- }
- } catch (IOException exception) {
- logger.error(exception.getMessage(), exception);
- uploadFileResponse.addStructureError(
- SdcCommon.UPLOAD_FILE,
- new ErrorMessage(ErrorLevel.ERROR, Messages.FAILED_TO_VALIDATE_METADATA.getErrorMessage()));
- }
- } else {
- validateFileExist(uploadFileResponse, contentMap, MAIN_SERVICE_TEMPLATE_YAML_FILE_NAME);
- }
- }
-
- private void validateManifest(UploadFileResponse uploadFileResponse,
- FileContentHandler contentMap) {
-
- if (!validateFileExist(uploadFileResponse, contentMap, MAIN_SERVICE_TEMPLATE_MF_FILE_NAME)) {
- return;
- }
-
- try (InputStream fileContent = contentMap.getFileContent(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME)) {
-
- Manifest onboardingManifest = OnboardingManifest.parse(fileContent);
- if (!onboardingManifest.isValid()) {
- onboardingManifest.getErrors().forEach(error -> uploadFileResponse.addStructureError(
- SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR, error)));
- }
-
- } catch (IOException e) {
- // convert to runtime to keep the throws unchanged
- throw new OrchestrationTemplateHandlerException("Failed to validate manifest", e);
- }
- }
-
- private void validateNoExtraFiles(UploadFileResponse uploadFileResponse,
- FileContentHandler contentMap) {
- List<String> unwantedFiles = contentMap.getFileList().stream()
- .filter(this::filterFiles).collect(Collectors.toList());
- if (!unwantedFiles.isEmpty()) {
- unwantedFiles.stream().filter(this::filterFiles).forEach(unwantedFile ->
- uploadFileResponse.addStructureError(
- SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR,
- getErrorWithParameters(Messages.CSAR_FILES_NOT_ALLOWED.getErrorMessage(),
- unwantedFile))));
- }
- }
-
- private void validateFolders(UploadFileResponse uploadFileResponse, List<String> folderList) {
- List<String> filterResult =
- folderList.stream().filter(this::filterFolders).collect(Collectors.toList());
- if (!filterResult.isEmpty()) {
- folderList.stream().filter(this::filterFolders).forEach(unwantedFolder ->
- uploadFileResponse.addStructureError(
- SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR,
- getErrorWithParameters(Messages.CSAR_DIRECTORIES_NOT_ALLOWED.getErrorMessage(),
- unwantedFolder))));
- }
- }
-
- private boolean filterFiles(String inFileName) {
- boolean valid = ELIGIBLE_FILES.stream().anyMatch(fileName -> fileName.equals(inFileName));
- return !valid && filterFolders(inFileName);
- }
-
- private boolean filterFolders(String fileName) {
- return ELIGBLE_FOLDERS.stream().noneMatch(fileName::startsWith);
- }
-
- private boolean validateTOSCAYamlFileInRootExist(FileContentHandler contentMap, String fileName) {
- return contentMap.containsFile(fileName);
- }
-
- private boolean validateFileExist(UploadFileResponse uploadFileResponse,
- FileContentHandler contentMap, String fileName) {
-
- boolean containsFile = contentMap.containsFile(fileName);
- if (!containsFile) {
- uploadFileResponse.addStructureError(
- SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR,
- getErrorWithParameters(Messages.CSAR_FILE_NOT_FOUND.getErrorMessage(), fileName)));
- }
- return containsFile;
+ return Optional.ofNullable(contentMap);
}
@Override
@@ -210,7 +94,6 @@ public class OrchestrationTemplateCSARHandler extends BaseOrchestrationTemplateH
return false;
}
-
@Override
protected OnboardingTypesEnum getHandlerType() {
return OnboardingTypesEnum.CSAR;
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ONAPCsarValidator.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ONAPCsarValidator.java
new file mode 100644
index 0000000000..0f44427edd
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ONAPCsarValidator.java
@@ -0,0 +1,157 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Modification 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 org.openecomp.core.utilities.file.FileContentHandler;
+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.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
+import org.openecomp.sdc.tosca.csar.Manifest;
+import org.openecomp.sdc.tosca.csar.OnboardingManifest;
+import org.openecomp.sdc.tosca.csar.OnboardingToscaMetadata;
+import org.openecomp.sdc.tosca.csar.ToscaMetadata;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.ELIGBLE_FOLDERS;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.ELIGIBLE_FILES;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.MAIN_SERVICE_TEMPLATE_MF_FILE_NAME;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.MAIN_SERVICE_TEMPLATE_YAML_FILE_NAME;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ENTRY_DEFINITIONS;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_PATH_FILE_NAME;
+
+class ONAPCsarValidator implements Validator {
+
+ private static Logger logger = LoggerFactory.getLogger(ONAPCsarValidator.class);
+
+ private List<ErrorMessage> uploadFileErrors = new ArrayList<>();
+
+ @Override
+ public Map<String, List<ErrorMessage>> validateContent(FileContentHandler contentHandler, List<String> folderList) {
+
+ Map<String, List<ErrorMessage>> errors = new HashMap<>();
+ validateManifest(contentHandler);
+ validateMetadata(contentHandler);
+ validateNoExtraFiles(contentHandler);
+ validateFolders(folderList);
+
+ if(uploadFileErrors == null || uploadFileErrors.isEmpty()){
+ return errors;
+ }
+ errors.put(SdcCommon.UPLOAD_FILE, uploadFileErrors);
+ return errors;
+ }
+
+ private void validateMetadata(FileContentHandler contentMap){
+ if (!validateTOSCAYamlFileInRootExist(contentMap, MAIN_SERVICE_TEMPLATE_YAML_FILE_NAME)) {
+ try (InputStream metaFileContent = contentMap.getFileContent(TOSCA_META_PATH_FILE_NAME)) {
+
+ ToscaMetadata onboardingToscaMetadata = OnboardingToscaMetadata.parseToscaMetadataFile(metaFileContent);
+ String entryDefinitionsPath = onboardingToscaMetadata.getMetaEntries().get(TOSCA_META_ENTRY_DEFINITIONS);
+ if (entryDefinitionsPath != null) {
+ validateFileExist(contentMap, entryDefinitionsPath);
+ } else {
+ uploadFileErrors.add(new ErrorMessage(ErrorLevel.ERROR,
+ Messages.METADATA_NO_ENTRY_DEFINITIONS.getErrorMessage()));
+ }
+ } catch (IOException exception) {
+ logger.error(exception.getMessage(), exception);
+ uploadFileErrors.add(new ErrorMessage(ErrorLevel.ERROR,
+ Messages.FAILED_TO_VALIDATE_METADATA.getErrorMessage()));
+ }
+ } else {
+ validateFileExist(contentMap, MAIN_SERVICE_TEMPLATE_YAML_FILE_NAME);
+ }
+ }
+
+ private void validateManifest(FileContentHandler contentMap) {
+
+ if (!validateFileExist(contentMap, MAIN_SERVICE_TEMPLATE_MF_FILE_NAME)) {
+ return;
+ }
+
+ try (InputStream fileContent = contentMap.getFileContent(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME)) {
+
+ Manifest onboardingManifest = OnboardingManifest.parse(fileContent);
+ if (!onboardingManifest.isValid()) {
+ onboardingManifest.getErrors().forEach(error -> uploadFileErrors.add(new ErrorMessage(ErrorLevel.ERROR,
+ error)));
+ }
+
+ } catch (IOException e) {
+ // convert to runtime to keep the throws unchanged
+ throw new RuntimeException("Failed to validateContent manifest", e);
+ }
+ }
+
+ private void validateNoExtraFiles(FileContentHandler contentMap) {
+ List<String> unwantedFiles = contentMap.getFileList().stream()
+ .filter(this::filterFiles).collect(Collectors.toList());
+ if (!unwantedFiles.isEmpty()) {
+ unwantedFiles.stream().filter(this::filterFiles).forEach(unwantedFile ->
+ uploadFileErrors.add(new ErrorMessage(ErrorLevel.ERROR,
+ getErrorWithParameters(Messages.CSAR_FILES_NOT_ALLOWED.getErrorMessage(), unwantedFile))));
+ }
+ }
+
+ private void validateFolders(List<String> folderList) {
+ List<String> filterResult =
+ folderList.stream().filter(this::filterFolders).collect(Collectors.toList());
+ if (!filterResult.isEmpty()) {
+ folderList.stream().filter(this::filterFolders).forEach(unwantedFolder ->
+ uploadFileErrors.add(new ErrorMessage(ErrorLevel.ERROR,
+ getErrorWithParameters(Messages.CSAR_DIRECTORIES_NOT_ALLOWED.getErrorMessage(),
+ unwantedFolder))));
+ }
+ }
+
+ private boolean filterFiles(String inFileName) {
+ boolean valid = ELIGIBLE_FILES.stream().anyMatch(fileName -> fileName.equals(inFileName));
+ return !valid && filterFolders(inFileName);
+ }
+
+ private boolean filterFolders(String fileName) {
+ return ELIGBLE_FOLDERS.stream().noneMatch(fileName::startsWith);
+ }
+
+ private boolean validateTOSCAYamlFileInRootExist(FileContentHandler contentMap, String fileName) {
+ return contentMap.containsFile(fileName);
+ }
+
+ private boolean validateFileExist(FileContentHandler contentMap, String fileName) {
+
+ boolean containsFile = contentMap.containsFile(fileName);
+ if (!containsFile) {
+ uploadFileErrors.add(new ErrorMessage(ErrorLevel.ERROR,
+ getErrorWithParameters(Messages.CSAR_FILE_NOT_FOUND.getErrorMessage(), fileName)));
+ }
+ return containsFile;
+ }
+}
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
new file mode 100644
index 0000000000..570eee3736
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidator.java
@@ -0,0 +1,360 @@
+/*-
+ * ============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 org.openecomp.core.converter.ServiceTemplateReaderService;
+import org.openecomp.core.impl.services.ServiceTemplateReaderServiceImpl;
+import org.openecomp.core.utilities.file.FileContentHandler;
+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.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
+import org.openecomp.sdc.tosca.csar.Manifest;
+import org.openecomp.sdc.tosca.csar.OnboardingManifest;
+import org.openecomp.sdc.tosca.csar.OnboardingToscaMetadata;
+import org.openecomp.sdc.tosca.csar.ToscaMetadata;
+import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.exceptions.InvalidManifestMetadataException;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import static org.openecomp.sdc.tosca.csar.CSARConstants.CSAR_VERSION_1_0;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.CSAR_VERSION_1_1;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.MANIFEST_METADATA_LIMIT;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.MANIFEST_PNF_METADATA;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.MANIFEST_VNF_METADATA;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.NON_FILE_IMPORT_ATTRIBUTES;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_FILE_VERSION_ENTRY;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_CREATED_BY_ENTRY;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_CSAR_VERSION_ENTRY;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ENTRY_CHANGE_LOG;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ENTRY_DEFINITIONS;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ENTRY_LICENSES;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ENTRY_MANIFEST;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ENTRY_TESTS;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_FILE_VERSION;
+import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_PATH_FILE_NAME;
+
+/**
+ * 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.
+ *
+ */
+
+class SOL004MetaDirectoryValidator implements Validator{
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(SOL004MetaDirectoryValidator.class);
+
+ private final List<ErrorMessage> errorsByFile = new ArrayList<>();
+ private final Set<String> verifiedImports = new HashSet<>();
+
+ @Override
+ public Map<String, List<ErrorMessage>> validateContent(FileContentHandler contentHandler, List<String> folderList) {
+ validateMetaFile(contentHandler, folderList);
+ return Collections.unmodifiableMap(getAnyValidationErrors());
+ }
+
+ private void validateMetaFile(FileContentHandler contentHandler, List<String> folderList) {
+ try {
+ ToscaMetadata toscaMetadata = OnboardingToscaMetadata.parseToscaMetadataFile(contentHandler.getFileContent(TOSCA_META_PATH_FILE_NAME));
+ if(toscaMetadata.isValid() && hasETSIMetadata(toscaMetadata)) {
+ verifyManifestNameAndExtension(toscaMetadata);
+ handleMetadataEntries(contentHandler, folderList, toscaMetadata);
+ }else {
+ errorsByFile.addAll(toscaMetadata.getErrors());
+ }
+ }catch (IOException e){
+ reportError(ErrorLevel.ERROR, Messages.METADATA_PARSER_INTERNAL.getErrorMessage());
+ LOGGER.error(Messages.METADATA_PARSER_INTERNAL.getErrorMessage(), e.getMessage(), e);
+ }
+ }
+
+ private void verifyManifestNameAndExtension(ToscaMetadata toscaMetadata) {
+ Map<String, String> entries = toscaMetadata.getMetaEntries();
+ String manifestFileName = getFileName(entries.get(TOSCA_META_ENTRY_MANIFEST));
+ String manifestExtension = getFileExtension(entries.get(TOSCA_META_ENTRY_MANIFEST));
+ String mainDefinitionFileName= getFileName(entries.get(TOSCA_META_ENTRY_DEFINITIONS));
+ if(!("mf").equals(manifestExtension)){
+ reportError(ErrorLevel.ERROR, Messages.MANIFEST_INVALID_EXT.getErrorMessage());
+ }
+ if(!mainDefinitionFileName.equals(manifestFileName)){
+ reportError(ErrorLevel.ERROR, Messages.MANIFEST_INVALID_NAME.getErrorMessage());
+ }
+ }
+
+ public String getFileExtension(String filePath){
+ return filePath.substring(filePath.lastIndexOf(".") + 1);
+ }
+
+ private String getFileName(String filePath){
+ return filePath.substring(filePath.lastIndexOf("/") + 1, filePath.lastIndexOf("."));
+ }
+
+ private boolean hasETSIMetadata(ToscaMetadata toscaMetadata){
+ Map<String, String> entries = toscaMetadata.getMetaEntries();
+ return hasEntry(entries, TOSCA_META_FILE_VERSION_ENTRY)
+ && hasEntry(entries, TOSCA_META_CSAR_VERSION_ENTRY)
+ && hasEntry(entries, TOSCA_META_CREATED_BY_ENTRY);
+ }
+
+ private boolean hasEntry(Map<String, String> entries, String mandatoryEntry) {
+ if (!entries.containsKey(mandatoryEntry)) {
+ reportError(ErrorLevel.ERROR, String.format(Messages.METADATA_MISSING_ENTRY.getErrorMessage(),mandatoryEntry));
+ return false;
+ }
+ return true;
+ }
+
+ private void handleMetadataEntries(FileContentHandler contentHandler, List<String> folderList, ToscaMetadata toscaMetadata) {
+ for(Map.Entry entry: toscaMetadata.getMetaEntries().entrySet()){
+ String key = (String) entry.getKey();
+ String value = (String) entry.getValue();
+ switch (key){
+ case TOSCA_META_FILE_VERSION_ENTRY:
+ case TOSCA_META_CSAR_VERSION_ENTRY:
+ case TOSCA_META_CREATED_BY_ENTRY:
+ verifyMetadataEntryVersions(key, value);
+ break;
+ case TOSCA_META_ENTRY_DEFINITIONS:
+ validateDefinitionFile(contentHandler, value);
+ break;
+ case TOSCA_META_ENTRY_MANIFEST:
+ validateManifestFile(contentHandler, value);
+ break;
+ case TOSCA_META_ENTRY_CHANGE_LOG:
+ validateChangeLog(contentHandler, value);
+ break;
+ case TOSCA_META_ENTRY_TESTS:
+ case TOSCA_META_ENTRY_LICENSES:
+ validateOtherEntries(folderList, value);
+ break;
+ default:
+ errorsByFile.add(new ErrorMessage(ErrorLevel.ERROR, String.format(Messages.METADATA_UNSUPPORTED_ENTRY.getErrorMessage(), entry)));
+ LOGGER.warn(Messages.METADATA_UNSUPPORTED_ENTRY.getErrorMessage(), entry);
+ break;
+ }
+
+ }
+ }
+
+
+ private void verifyMetadataEntryVersions(String key, String version) {
+ if(!(isValidTOSCAVersion(key,version) || isValidCSARVersion(key, version) || TOSCA_META_CREATED_BY_ENTRY.equals(key))) {
+ errorsByFile.add(new ErrorMessage(ErrorLevel.ERROR, Messages.ENTITY_NOT_FOUND.getErrorMessage()));
+ LOGGER.error("{}: key {} - value {} ", Messages.ENTITY_NOT_FOUND.getErrorMessage(), key, version);
+ }
+ }
+
+ private boolean isValidTOSCAVersion(String key, String version){
+ return TOSCA_META_FILE_VERSION_ENTRY.equals(key) && TOSCA_META_FILE_VERSION.equals(version);
+ }
+
+ private boolean isValidCSARVersion(String value, String version){
+ return "CSAR-Version".equals(value) && (CSAR_VERSION_1_1.equals(version)
+ || CSAR_VERSION_1_0.equals(version));
+ }
+
+ private void validateDefinitionFile(FileContentHandler contentHandler, String filePath) {
+ Set<String> existingFiles = contentHandler.getFileList();
+
+ if (verifyFileExists(existingFiles, filePath)) {
+ byte[] definitionFile = getFileContent(filePath, contentHandler);
+ handleImports(contentHandler, filePath, existingFiles, definitionFile);
+ }else{
+ reportError(ErrorLevel.ERROR, String.format(Messages.MISSING_DEFINITION_FILE.getErrorMessage(), filePath));
+ }
+ }
+
+ private void handleImports(FileContentHandler contentHandler, String filePath, Set<String> existingFiles,
+ byte[] definitionFile) {
+ try {
+ ServiceTemplateReaderService readerService = new ServiceTemplateReaderServiceImpl(definitionFile);
+ List<Object> imports = (readerService).getImports();
+ for (Object o : imports) {
+ String rootDir = "/";
+ if (filePath.contains("/")) {
+ rootDir = filePath.substring(0, filePath.lastIndexOf("/"));
+ }
+ String verifiedFile = verifyImport(existingFiles, o, rootDir);
+ if (verifiedFile != null && !verifiedImports.contains(verifiedFile)) {
+ verifiedImports.add(verifiedFile);
+ handleImports(contentHandler, verifiedFile, existingFiles, getFileContent(verifiedFile,
+ contentHandler));
+ }
+ }
+ }
+ catch (Exception e){
+ reportError(ErrorLevel.ERROR, String.format(Messages.INVALID_YAML_FORMAT.getErrorMessage(), e.getMessage()));
+ LOGGER.error("{}", Messages.INVALID_YAML_FORMAT_REASON, e.getMessage(), e);
+ }
+ }
+
+ private String verifyImport(Set<String> existingFiles, Object o, String parentDir) {
+ if(o instanceof String){
+ String filePath = ((String) o);
+ if(!filePath.contains("/")){
+ filePath = parentDir + "/" + filePath;
+ }
+ if(!verifyFileExists(existingFiles, filePath)){
+ reportError(ErrorLevel.ERROR, String.format(Messages.MISSING_IMPORT_FILE.getErrorMessage(), (String) o));
+ return null;
+ }
+ return filePath;
+ } else if(o instanceof Map){
+ Map<String, Object> o1 = (Map)o;
+ for(Map.Entry<String, Object> entry: o1.entrySet()){
+ if(NON_FILE_IMPORT_ATTRIBUTES.stream().noneMatch(attr -> entry.getKey().equals(attr))){
+ verifyImport(existingFiles, entry.getValue(), parentDir);
+ }
+ }
+ }else {
+ reportError(ErrorLevel.ERROR, Messages.INVALID_IMPORT_STATEMENT.getErrorMessage());
+ }
+ return null;
+ }
+
+ private boolean verifyFileExists(Set<String> existingFiles, String filePath){
+ return existingFiles.contains(filePath);
+ }
+
+ private byte[] getFileContent(String filename, FileContentHandler contentHandler){
+ Map<String, byte[]> files = contentHandler.getFiles();
+ return files.get(filename);
+ }
+
+ private void validateManifestFile(FileContentHandler contentHandler, String filePath){
+ final Set<String> exitingFiles = contentHandler.getFileList();
+ if(verifyFileExists(exitingFiles, filePath)) {
+ Manifest onboardingManifest = OnboardingManifest.parse(contentHandler.getFileContent(filePath));
+ if(onboardingManifest.isValid()){
+ try {
+ verifyManifestMetadata(onboardingManifest.getMetadata());
+ }catch (InvalidManifestMetadataException e){
+ reportError(ErrorLevel.ERROR, e.getMessage());
+ LOGGER.error(e.getMessage(), e);
+ }
+ verifySourcesExists(exitingFiles, onboardingManifest);
+ }else{
+ List<String> manifestErrors = onboardingManifest.getErrors();
+ for(String error: manifestErrors){
+ reportError(ErrorLevel.ERROR, error);
+ }
+ }
+ }else {
+ reportError(ErrorLevel.ERROR, String.format(Messages.MANIFEST_NOT_EXIST.getErrorMessage(), filePath));
+ }
+ }
+
+ private void verifyManifestMetadata(Map<String, String> metadata) {
+ if(metadata.size() != MANIFEST_METADATA_LIMIT){
+ reportError(ErrorLevel.ERROR, String.format(Messages.MANIFEST_METADATA_DOES_NOT_MATCH_LIMIT.getErrorMessage(),
+ MANIFEST_METADATA_LIMIT));
+ }
+ if(isPnfMetadata(metadata)){
+ handlePnfMetadataEntries(metadata);
+ }else {
+ handleVnfMetadataEntries(metadata);
+ }
+ }
+
+ private boolean isPnfMetadata(Map<String, String> metadata) {
+ String metadataType = null;
+ for(String key: metadata.keySet()) {
+ if(metadataType == null){
+ metadataType = key.contains("pnf") ? "pnf" : "vnf";
+ }else if(!key.contains(metadataType)){
+ throw new InvalidManifestMetadataException(Messages.MANIFEST_METADATA_INVALID_ENTRY.getErrorMessage());
+ }
+ }
+ return "pnf".equals(metadataType);
+ }
+
+ private void handleVnfMetadataEntries(Map<String, String> metadata) {
+ for (String requiredPnfEntry : MANIFEST_VNF_METADATA) {
+ if (!metadata.containsKey(requiredPnfEntry)) {
+ reportError(ErrorLevel.ERROR, String.format(Messages.MANIFEST_METADATA_MISSING_ENTRY.getErrorMessage(), requiredPnfEntry));
+ }
+ }
+ }
+
+ private void handlePnfMetadataEntries(Map<String, String> metadata) {
+ for (String requiredPnfEntry : MANIFEST_PNF_METADATA) {
+ if (!metadata.containsKey(requiredPnfEntry)) {
+ reportError(ErrorLevel.ERROR, String.format(Messages.MANIFEST_METADATA_MISSING_ENTRY.getErrorMessage(), requiredPnfEntry));
+ }
+ }
+ }
+
+ private void verifySourcesExists(Set<String> exitingFiles, Manifest onboardingManifest) {
+ List<String> sources = onboardingManifest.getSources();
+ Map<String, List<String>> nonManoArtifacts = onboardingManifest.getNonManoSources();
+ verifyFilesExist(exitingFiles, sources);
+ for (Map.Entry entry : nonManoArtifacts.entrySet()) {
+ verifyFilesExist(exitingFiles, (List) entry.getValue());
+ }
+ }
+
+ private void validateOtherEntries(List<String> folderList, String folderPath){
+ if(!verifyFoldersExist(folderList, folderPath))
+ reportError(ErrorLevel.ERROR, String.format(Messages.METADATA_MISSING_OPTIONAL_FOLDERS.getErrorMessage(),
+ folderPath));
+ }
+
+ private boolean verifyFoldersExist(List<String> folderList, String folderPath){
+ return folderList.contains(folderPath + "/");
+ }
+
+ private void verifyFilesExist(Set<String> existingFiles, List<String> sources){
+ for(String file: sources){
+ if(!verifyFileExists(existingFiles, file)){
+ reportError(ErrorLevel.ERROR, String.format(Messages.MISSING_ARTIFACT.getErrorMessage(), file));
+ }
+
+ }
+ }
+
+ private void validateChangeLog(FileContentHandler contentHandler, String filePath){
+ if(!verifyFileExists(contentHandler.getFileList(), filePath)){
+ reportError(ErrorLevel.ERROR, String.format(Messages.MISSING_ARTIFACT.getErrorMessage(), filePath));
+ }
+ }
+
+ private void reportError(ErrorLevel errorLevel, String errorMessage){
+ errorsByFile.add(new ErrorMessage(errorLevel, errorMessage));
+ }
+
+ private Map<String, List<ErrorMessage>> getAnyValidationErrors(){
+
+ if(errorsByFile.isEmpty()){
+ return Collections.emptyMap();
+ }
+ Map<String, List<ErrorMessage>> errors = new HashMap<>();
+ errors.put(SdcCommon.UPLOAD_FILE, errorsByFile);
+ return errors;
+ }
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/Validator.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/Validator.java
new file mode 100644
index 0000000000..927f3c0b69
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/Validator.java
@@ -0,0 +1,41 @@
+/*-
+ * ============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 org.openecomp.core.utilities.file.FileContentHandler;
+import org.openecomp.sdc.datatypes.error.ErrorMessage;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Validates the contents of the CSAR package uploaded in SDC.
+ */
+
+public interface Validator {
+
+ /**
+ *
+ * @param contentHandler contains file and its data
+ * @param folderList folder structure inside the package
+ * @return errors Map of errors that occur
+ */
+ Map<String, List<ErrorMessage>> validateContent(FileContentHandler contentHandler, List<String> folderList);
+}
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
new file mode 100644
index 0000000000..bc44496fef
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ValidatorFactory.java
@@ -0,0 +1,45 @@
+/*-
+ * ============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 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 java.io.IOException;
+
+public class ValidatorFactory {
+
+ private ValidatorFactory(){
+
+ }
+
+ /**
+ * Returns a validator based on the contents of the csar package.
+ *
+ * @param contentMap the csar package
+ * @return Validator based on the contents of the csar package provided
+ * @throws IOException when metafile is invalid
+ */
+ public static Validator getValidator(FileContentHandler contentMap) throws IOException{
+ ETSIService etsiService = new ETSIServiceImpl(null);
+ return etsiService.isSol004WithToscaMetaDirectory(contentMap) ? new SOL004MetaDirectoryValidator() : new ONAPCsarValidator();
+ }
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/exceptions/InvalidManifestMetadataException.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/exceptions/InvalidManifestMetadataException.java
new file mode 100644
index 0000000000..137891c0c9
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/exceptions/InvalidManifestMetadataException.java
@@ -0,0 +1,28 @@
+/*-
+ * ============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.exceptions;
+
+public class InvalidManifestMetadataException extends RuntimeException{
+
+ public InvalidManifestMetadataException(String message){
+ super(message);
+ }
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ONAPCsarValidatorTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ONAPCsarValidatorTest.java
new file mode 100644
index 0000000000..bedf599cf5
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ONAPCsarValidatorTest.java
@@ -0,0 +1,73 @@
+package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openecomp.core.utilities.file.FileContentHandler;
+import org.openecomp.sdc.common.utils.SdcCommon;
+import org.openecomp.sdc.datatypes.error.ErrorMessage;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.Assert.assertTrue;
+
+
+public class ONAPCsarValidatorTest {
+
+ ONAPCsarValidator onapCsarValidator;
+ private FileContentHandler contentHandler;
+ private List<String> folderList;
+
+ @Before
+ public void setUp() throws IOException{
+ onapCsarValidator = new ONAPCsarValidator();
+ contentHandler = new FileContentHandler();
+ folderList = new ArrayList<>();
+
+ contentHandler.addFile("TOSCA-Metadata/TOSCA.meta", ValidatorUtil.getFileResource("/validation.files/metafile/nonSOL004WithMetaDirectoryCompliantMetaFile.meta"));
+ contentHandler.addFile("MainServiceTemplate.mf", ValidatorUtil.getFileResource("/validation.files/manifest/sampleManifest.mf"));
+ contentHandler.addFile(TestConstants.TOSCA_DEFINITION_FILEPATH, ValidatorUtil.getFileResource(TestConstants.SAMPLE_DEFINITION_FILE_PATH));
+ }
+
+ @Test
+ public void testGivenCSARPackage_withValidContent_thenNoErrorsReturned() {
+ assertExpectedErrors("Valid CSAR Package should have 0 errors",
+ onapCsarValidator.validateContent(contentHandler, folderList), 0);
+ }
+
+ @Test
+ public void testGivenCSARPackage_withInvalidManifestFile_thenErrorsReturned() throws IOException{
+ contentHandler = new FileContentHandler();
+ contentHandler.addFile("TOSCA-Metadata/TOSCA.meta", ValidatorUtil.getFileResource("/validation.files/metafile/nonSOL004WithMetaDirectoryCompliantMetaFile.meta"));
+ contentHandler.addFile("MainServiceTemplate.mf", ValidatorUtil.getFileResource("/validation.files/manifest/invalidManifest.mf"));
+ contentHandler.addFile(TestConstants.TOSCA_DEFINITION_FILEPATH, ValidatorUtil.getFileResource(TestConstants.SAMPLE_DEFINITION_FILE_PATH));
+
+ assertExpectedErrors("CSAR package with invalid manifest file should have errors", onapCsarValidator.validateContent(contentHandler, folderList), 1);
+
+ }
+
+ @Test
+ public void testGivenCSARPackage_withUnwantedFolders_thenErrorsReturned(){
+
+ folderList.add("Files/");
+ assertExpectedErrors("CSAR package with unwanted folders should fail with errors", onapCsarValidator.validateContent(contentHandler, folderList), 1);
+ }
+
+ @Test
+ public void testGivenCSARPackage_withUnwantedFiles_thenErrorsReturned(){
+
+ contentHandler.addFile("ExtraFile.text", "".getBytes());
+ assertExpectedErrors("CSAR package with unwanted files should fail with errors",
+ onapCsarValidator.validateContent(contentHandler, folderList), 1);
+ }
+
+ 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);
+ }
+ }
+} \ 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
new file mode 100644
index 0000000000..8584d482b4
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidatorTest.java
@@ -0,0 +1,405 @@
+package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openecomp.core.utilities.file.FileContentHandler;
+import org.openecomp.sdc.common.utils.SdcCommon;
+import org.openecomp.sdc.datatypes.error.ErrorLevel;
+import org.openecomp.sdc.datatypes.error.ErrorMessage;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.Assert.assertTrue;
+import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.*;
+
+public class SOL004MetaDirectoryValidatorTest {
+
+ private SOL004MetaDirectoryValidator sol004MetaDirectoryValidator;
+ private FileContentHandler handler;
+ private String metaFile;
+
+ @Before
+ 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"+
+ "Entry-Definitions: Definitions/MainServiceTemplate.yaml\n"+
+ "Entry-Manifest: Definitions/MainServiceTemplate.mf\n"+
+ "Entry-Change-Log: Artifacts/changeLog.text\n";
+ }
+
+ @Test
+ public void testGivenTOSCAMetaFile_whenEntryHasNoValue_thenErrorIsReturned() throws IOException{
+
+ String metaFileWithInvalidEntry = "TOSCA-Meta-File-Version: \n" +
+ "Entry-Definitions: Definitions/MainServiceTemplate.yaml";
+
+ handler.addFile(TOSCA_METADATA_FILEPATH, metaFileWithInvalidEntry.getBytes(StandardCharsets.UTF_8));
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, ValidatorUtil.getFileResource(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);
+ }
+
+ @Test
+ public void testGivenTOSCAMeta_withAllSupportedEntries_thenNoErrorsReturned() throws IOException{
+
+ String entryTestFilePath = "Files/Tests";
+ String entryLicenseFilePath = "Files/Licenses";
+
+ List<String> folderList = new ArrayList<>();
+ folderList.add("Files/Tests/");
+ folderList.add("Files/Licenses/");
+
+ metaFile = metaFile +
+ "Entry-Tests: "+ entryTestFilePath + "\n" +
+ "Entry-Licenses: "+ entryLicenseFilePath +"\n";
+
+ handler.addFile(TOSCA_METADATA_FILEPATH, metaFile.getBytes(StandardCharsets.UTF_8));
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, ValidatorUtil.getFileResource(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);
+ assertTrue(errors.size() == 0);
+ }
+
+ @Test
+ public void testGivenTOSCAMeta_withUnsupportedEntry_thenWarningIsReturned(){
+
+ metaFile = "Entry-Events: Definitions/events.log";
+
+ handler.addFile(TOSCA_METADATA_FILEPATH, metaFile.getBytes(StandardCharsets.UTF_8));
+ 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);
+
+ }
+
+ @Test
+ public void testGivenTOSCAMetaFile_withInvalidTOSCAMetaFileVersionAndCSARVersion_thenErrorIsReturned() throws IOException{
+
+ String metaFile =
+ "TOSCA-Meta-File-Version: " + Integer.MAX_VALUE +
+ "\nCSAR-Version: " + Integer.MAX_VALUE +
+ "\nCreated-by: Bilal Iqbal" +
+ "\nEntry-Definitions: Definitions/MainServiceTemplate.yaml" +
+ "\nEntry-Manifest: Definitions/MainServiceTemplate.mf"+
+ "\nEntry-Change-Log: Artifacts/changeLog.text";
+
+ handler.addFile(TOSCA_METADATA_FILEPATH, metaFile.getBytes(StandardCharsets.UTF_8));
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, ValidatorUtil.getFileResource(TestConstants.SAMPLE_DEFINITION_FILE_PATH));
+ handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
+ handler.addFile(TOSCA_MANIFEST_FILEPATH, ValidatorUtil.getFileResource(SAMPLE_MANIFEST_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() == 2);
+ }
+
+ @Test
+ public void testGivenTOSCAMetaFile_withNonExistentFileReferenced_thenErrorsReturned(){
+
+ metaFile = metaFile +
+ "Entry-Tests: Files/Tests\n" +
+ "Entry-License: Files/Licenses\n";
+
+ handler.addFile(TOSCA_METADATA_FILEPATH, metaFile.getBytes(StandardCharsets.UTF_8));
+
+ Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
+ List<ErrorMessage> errorMessages = errors.get(SdcCommon.UPLOAD_FILE);
+ assertTrue(errors.size() == 1 && errorMessages.size() == 5);
+ }
+
+
+ @Test
+ public void testGivenDefinitionFile_whenValidImportStatementExist_thenNoErrorsReturned() throws IOException{
+
+ String definitionFileWithValidImports = "/validation.files/definition/definitionFileWithValidImports.yaml";
+
+
+ handler.addFile(TOSCA_METADATA_FILEPATH, metaFile.getBytes(StandardCharsets.UTF_8));
+ 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("Definitions/etsi_nfv_sol001_pnfd_2_5_1_types.yaml", ValidatorUtil.getFileResource(SAMPLE_DEFINITION_FILE_PATH));
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, ValidatorUtil.getFileResource(definitionFileWithValidImports));
+
+ 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");
+
+ handler.addFile(TOSCA_METADATA_FILEPATH, metaFile.getBytes(StandardCharsets.UTF_8));
+ 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(TOSCA_DEFINITION_FILEPATH, sampleDefinitionFile1);
+ handler.addFile("Definitions/etsi_nfv_sol001_pnfd_2_5_1_types.yaml", sampleDefinitionFile2);
+ handler.addFile("Definitions/etsi_nfv_sol001_pnfd_2_5_2_types.yaml", sampleDefinitionFile3);
+
+ 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";
+
+ handler.addFile(TOSCA_METADATA_FILEPATH, metaFile.getBytes(StandardCharsets.UTF_8));
+ 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(TOSCA_DEFINITION_FILEPATH, ValidatorUtil.getFileResource(definitionFileWithInvalidImports));
+
+ 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);
+ }
+
+ @Test
+ public void testGivenDefinitionFile_whenReferencedImportDoesNotExist_thenErrorIsReturned() throws IOException{
+
+ handler.addFile(TOSCA_METADATA_FILEPATH, metaFile.getBytes(StandardCharsets.UTF_8));
+ 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("Definitions/etsi_nfv_sol001_pnfd_2_5_1_types.yaml", "".getBytes());
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, ValidatorUtil.getFileResource("/validation.files/definition/sampleDefinitionFile2.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);
+
+ }
+
+ @Test
+ public void testGivenDefinitionFile_withInvalidYAML_thenErrorIsReturned() throws IOException{
+
+ String definitionFileWithInvalidYAML = "/validation.files/definition/invalidDefinitionFile.yaml";
+
+ handler.addFile(TOSCA_METADATA_FILEPATH, metaFile.getBytes(StandardCharsets.UTF_8));
+ 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(TOSCA_DEFINITION_FILEPATH, ValidatorUtil.getFileResource(definitionFileWithInvalidYAML));
+
+ 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);
+ }
+
+ @Test
+ public void testGivenManifestFile_withValidSourceAndNonManoSources_thenNoErrorIsReturned() throws IOException{
+
+ String nonManoSource = "Artifacts/Deployment/Measurements/PM_Dictionary.yaml";
+
+ handler.addFile(TOSCA_METADATA_FILEPATH, metaFile.getBytes(StandardCharsets.UTF_8));
+ handler.addFile(TOSCA_MANIFEST_FILEPATH, ValidatorUtil.getFileResource("/validation.files/manifest/validManifest.mf"));
+ handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, ValidatorUtil.getFileResource(SAMPLE_DEFINITION_FILE_PATH));
+ handler.addFile(SAMPLE_SOURCE, "".getBytes());
+ handler.addFile(SAMPLE_DEFINITION_IMPORT_FILE_PATH, ValidatorUtil.getFileResource(SAMPLE_DEFINITION_FILE_PATH));
+ handler.addFile(nonManoSource, "".getBytes());
+
+ Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
+ assertTrue(errors.size() == 0);
+ }
+
+ @Test
+ public void testGivenManifestFile_withNonExistentSourceFile_thenErrorIsReturned() throws IOException{
+ String nonManoSource = "Artifacts/Deployment/Measurements/PM_Dictionary.yaml";
+
+ handler.addFile(TOSCA_METADATA_FILEPATH, metaFile.getBytes(StandardCharsets.UTF_8));
+ handler.addFile(TOSCA_MANIFEST_FILEPATH, ValidatorUtil.getFileResource("/validation.files/manifest/validManifest.mf"));
+ handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, ValidatorUtil.getFileResource(SAMPLE_DEFINITION_FILE_PATH));
+ handler.addFile(SAMPLE_DEFINITION_IMPORT_FILE_PATH, "".getBytes());
+ handler.addFile(nonManoSource, "".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);
+ }
+
+ @Test
+ public void testGivenManifestFile_withInvalidData_thenErrorIsReturned() throws IOException{
+
+ handler.addFile(TOSCA_METADATA_FILEPATH, metaFile.getBytes(StandardCharsets.UTF_8));
+ handler.addFile(TOSCA_MANIFEST_FILEPATH, ValidatorUtil.getFileResource("/validation.files/manifest/invalidManifest.mf"));
+ handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, ValidatorUtil.getFileResource(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);
+ }
+
+ @Test
+ public void testGivenManifestAndDefinitionFile_withSameNames_thenNoErrorReturned() throws IOException {
+
+ handler.addFile(TOSCA_METADATA_FILEPATH, metaFile.getBytes(StandardCharsets.UTF_8));
+ handler.addFile(TOSCA_MANIFEST_FILEPATH, ValidatorUtil.getFileResource("/validation.files/manifest/sampleManifest.mf"));
+ handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, ValidatorUtil.getFileResource(SAMPLE_DEFINITION_FILE_PATH));
+ handler.addFile(SAMPLE_DEFINITION_IMPORT_FILE_PATH, "".getBytes());
+
+ Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
+ assertTrue(errors.size() == 0);
+ }
+
+ @Test
+ public void testGivenManifestAndMainDefinitionFile_withDifferentNames_thenErrorIsReturned() throws IOException {
+ metaFile =
+ "TOSCA-Meta-File-Version: 1.0\n"+
+ "CSAR-Version: 1.1\n"+
+ "Created-by: Vendor\n"+
+ "Entry-Definitions: Definitions/MainServiceTemplate.yaml\n"+
+ "Entry-Manifest: Definitions/MainServiceTemplate2.mf\n"+
+ "Entry-Change-Log: Artifacts/changeLog.text\n";
+
+ handler.addFile(TOSCA_METADATA_FILEPATH, metaFile.getBytes(StandardCharsets.UTF_8));
+ handler.addFile("Definitions/MainServiceTemplate2.mf", ValidatorUtil.getFileResource("/validation.files/manifest/sampleManifest.mf"));
+ handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, ValidatorUtil.getFileResource(SAMPLE_DEFINITION_FILE_PATH));
+ handler.addFile(SAMPLE_DEFINITION_IMPORT_FILE_PATH, "".getBytes());
+
+ 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 {
+ metaFile =
+ "TOSCA-Meta-File-Version: 1.0\n"+
+ "CSAR-Version: 1.1\n"+
+ "Created-by: Vendor\n"+
+ "Entry-Definitions: Definitions/MainServiceTemplate.yaml\n"+
+ "Entry-Manifest: Definitions/MainServiceTemplate.txt\n"+
+ "Entry-Change-Log: Artifacts/changeLog.text\n";
+
+ handler.addFile(TOSCA_METADATA_FILEPATH, metaFile.getBytes(StandardCharsets.UTF_8));
+ handler.addFile("Definitions/MainServiceTemplate.txt", ValidatorUtil.getFileResource("/validation.files/manifest/sampleManifest.mf"));
+ handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, ValidatorUtil.getFileResource(SAMPLE_DEFINITION_FILE_PATH));
+ handler.addFile(SAMPLE_DEFINITION_IMPORT_FILE_PATH, "".getBytes());
+
+ 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{
+ handler.addFile(TOSCA_METADATA_FILEPATH, metaFile.getBytes(StandardCharsets.UTF_8));
+ handler.addFile(TOSCA_MANIFEST_FILEPATH, ValidatorUtil.getFileResource("/validation.files/manifest/sampleManifest.mf"));
+ handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, ValidatorUtil.getFileResource(SAMPLE_DEFINITION_FILE_PATH));
+
+ 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 {
+ handler.addFile(TOSCA_METADATA_FILEPATH, metaFile.getBytes(StandardCharsets.UTF_8));
+ handler.addFile(TOSCA_MANIFEST_FILEPATH, ValidatorUtil.getFileResource("/validation.files/manifest/sampleManifest2.mf"));
+ handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, ValidatorUtil.getFileResource(SAMPLE_DEFINITION_FILE_PATH));
+
+ Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
+ assertExpectedErrors("Manifest with valid pnf mandatory values should not return any errors", errors, 0);
+ }
+
+ @Test
+ public void testGivenManifestFile_withMetadataContainingMixedPnfVnfMetadata_thenErrorIsReturned() throws IOException {
+
+ handler.addFile(TOSCA_METADATA_FILEPATH, metaFile.getBytes(StandardCharsets.UTF_8));
+ handler.addFile(TOSCA_MANIFEST_FILEPATH, ValidatorUtil.getFileResource("/validation.files/manifest/manifestInvalidMetadata.mf"));
+ handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, ValidatorUtil.getFileResource(SAMPLE_DEFINITION_FILE_PATH));
+
+ 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{
+
+ handler.addFile(TOSCA_METADATA_FILEPATH, metaFile.getBytes(StandardCharsets.UTF_8));
+ handler.addFile(TOSCA_MANIFEST_FILEPATH, ValidatorUtil.getFileResource("/validation.files/manifest/manifestInvalidMetadata2.mf"));
+ handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, ValidatorUtil.getFileResource(SAMPLE_DEFINITION_FILE_PATH));
+
+ 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{
+ handler.addFile(TOSCA_METADATA_FILEPATH, metaFile.getBytes(StandardCharsets.UTF_8));
+ handler.addFile(TOSCA_MANIFEST_FILEPATH, ValidatorUtil.getFileResource("/validation.files/manifest/manifestInvalidMetadata4.mf"));
+ handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, ValidatorUtil.getFileResource(SAMPLE_DEFINITION_FILE_PATH));
+
+ 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{
+ handler.addFile(TOSCA_METADATA_FILEPATH, metaFile.getBytes(StandardCharsets.UTF_8));
+ handler.addFile(TOSCA_MANIFEST_FILEPATH, ValidatorUtil.getFileResource("/validation.files/manifest/manifestInvalidMetadata5.mf"));
+ handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, ValidatorUtil.getFileResource(SAMPLE_DEFINITION_FILE_PATH));
+
+ Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
+ assertExpectedErrors("Manifest with metadata missing vnf mandatory entries should return error", errors, 4);
+
+ }
+
+ @Test
+ public void testGivenManifestFile_withMetadataEntriesExceedingTheLimit_thenErrorIsReturned() throws IOException{
+ handler.addFile(TOSCA_METADATA_FILEPATH, metaFile.getBytes(StandardCharsets.UTF_8));
+ handler.addFile(TOSCA_MANIFEST_FILEPATH, ValidatorUtil.getFileResource("/validation.files/manifest/manifestInvalidMetadata3.mf"));
+ handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, ValidatorUtil.getFileResource(SAMPLE_DEFINITION_FILE_PATH));
+
+ Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
+ assertExpectedErrors("Manifest with more than 4 metadata entries should return error", 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);
+ }
+ }
+} \ 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/TestConstants.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/TestConstants.java
new file mode 100644
index 0000000000..0a88ebc37d
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/TestConstants.java
@@ -0,0 +1,25 @@
+package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation;
+
+class TestConstants {
+
+
+ public static final String SAMPLE_DEFINITION_IMPORT_FILE_PATH = "Definitions/etsi_nfv_sol001_pnfd_2_5_1_types.yaml";
+ public static final String SAMPLE_SOURCE = "Artifacts/Deployment/Events/RadioNode_pnf_v1.yaml";
+ public static final String SAMPLE_DEFINITION_FILE_PATH = "/validation.files/definition/sampleDefinitionFile.yaml";
+ public static final String SAMPLE_MANIFEST_FILE_PATH = "/validation.files/manifest/sampleManifest.mf";
+
+ public static final String ENTRY_DEFINITIONS = "Entry-Definitions";
+ public static final String ENTRY_MANIFEST = "Entry-Manifest";
+ public static final String ENTRY_CHANGE_LOG = "Entry-Change-Log";
+
+ public static final String ENTRY_SEPARATOR = ":";
+
+ public static final String TOSCA_DEFINITION_FILEPATH = "Definitions/MainServiceTemplate.yaml";
+ public static final String TOSCA_MANIFEST_FILEPATH = "Definitions/MainServiceTemplate.mf";
+ public static final String TOSCA_CHANGELOG_FILEPATH = "Artifacts/changeLog.text";
+ public static final String TOSCA_METADATA_FILEPATH = "TOSCA-Metadata/TOSCA.meta";
+
+ private TestConstants(){
+
+ }
+}
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
new file mode 100644
index 0000000000..287662283c
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ValidatorFactoryTest.java
@@ -0,0 +1,88 @@
+package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openecomp.core.utilities.file.FileContentHandler;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+
+import static org.junit.Assert.assertEquals;
+import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.ENTRY_CHANGE_LOG;
+import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.ENTRY_DEFINITIONS;
+import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.ENTRY_MANIFEST;
+import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.ENTRY_SEPARATOR;
+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 static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.TOSCA_METADATA_FILEPATH;
+
+public class ValidatorFactoryTest {
+
+ private String metaFile;
+ private FileContentHandler handler;
+
+ @Before
+ public void setUp(){
+ handler = new FileContentHandler();
+ metaFile =
+ "TOSCA-Meta-File-Version: 1.0\n" +
+ "CSAR-Version: 1.1\n" +
+ "Created-by: Bilal Iqbal\n";
+ }
+
+ @Test(expected = IOException.class)
+ public void testGivenEmptyMetaFile_thenIOExceptionIsThrown() throws IOException{
+ handler.addFile(TOSCA_METADATA_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, "".getBytes());
+ handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
+ handler.addFile(TOSCA_MANIFEST_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
+
+ ValidatorFactory.getValidator(handler);
+ }
+
+ @Test
+ public void testGivenEmptyBlock0_thenONAPCsarValidatorIsReturned() throws IOException{
+ handler.addFile(TOSCA_METADATA_FILEPATH, " ".getBytes(StandardCharsets.UTF_8));
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, "".getBytes());
+ handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
+ handler.addFile(TOSCA_MANIFEST_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
+
+ assertEquals(ONAPCsarValidator.class, ValidatorFactory.getValidator(handler).getClass());
+ }
+
+
+ @Test
+ public void testGivenNonSOL004MetaDirectoryCompliantMetaFile_thenONAPCSARValidatorIsReturned() throws IOException{
+ metaFile = metaFile +
+ ENTRY_DEFINITIONS + ENTRY_SEPARATOR + TOSCA_DEFINITION_FILEPATH;
+ handler.addFile(TOSCA_METADATA_FILEPATH, metaFile.getBytes(StandardCharsets.UTF_8));
+
+ assertEquals(ONAPCsarValidator.class, ValidatorFactory.getValidator(handler).getClass());
+ }
+
+ @Test
+ public void testGivenSOL004MetaDirectoryCompliantMetafile_thenONAPCsarValidatorIsReturned() throws IOException{
+
+ metaFile = metaFile +
+ ENTRY_DEFINITIONS + ENTRY_SEPARATOR + TOSCA_DEFINITION_FILEPATH + "\n"
+ + ENTRY_MANIFEST + ENTRY_SEPARATOR + TOSCA_MANIFEST_FILEPATH + "\n"
+ + ENTRY_CHANGE_LOG + ENTRY_SEPARATOR + TOSCA_CHANGELOG_FILEPATH + "\n";
+ handler.addFile(TOSCA_METADATA_FILEPATH, metaFile.getBytes(StandardCharsets.UTF_8));
+
+ assertEquals(SOL004MetaDirectoryValidator.class, ValidatorFactory.getValidator(handler).getClass());
+ }
+
+ @Test
+ public void testGivenMultiBlockMetadataWithSOL00CompliantMetaFile_thenSOL004MetaDirectoryValidatorReturned() throws IOException {
+
+ handler.addFile(TOSCA_METADATA_FILEPATH, ValidatorUtil.getFileResource("/validation.files/metafile/metaFileWithMultipleBlocks.meta"));
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, "".getBytes());
+ handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
+ handler.addFile(TOSCA_MANIFEST_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
+
+ assertEquals(SOL004MetaDirectoryValidator.class, ValidatorFactory.getValidator(handler).getClass());
+
+ }
+
+} \ 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/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
new file mode 100644
index 0000000000..91e3807a79
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ValidatorUtil.java
@@ -0,0 +1,22 @@
+package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation;
+
+import org.apache.commons.io.IOUtils;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Provides util methods for Validation Test classes.
+ */
+
+class ValidatorUtil {
+
+ private ValidatorUtil(){
+
+ }
+
+ public static byte[] getFileResource(String filePath) throws IOException{
+ InputStream inputStream = ClassLoader.class.getClass().getResourceAsStream(filePath);
+ return IOUtils.toByteArray(inputStream);
+ }
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/definition/definitionFileWithInvalidImport.yaml b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/definition/definitionFileWithInvalidImport.yaml
new file mode 100644
index 0000000000..432a86a985
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/definition/definitionFileWithInvalidImport.yaml
@@ -0,0 +1,6 @@
+tosca_definitions_version: tosca_simple_yaml_1_2
+
+description: example definition file for testing
+
+imports:
+ - file:
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/definition/definitionFileWithValidImports.yaml b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/definition/definitionFileWithValidImports.yaml
new file mode 100644
index 0000000000..392a568c82
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/definition/definitionFileWithValidImports.yaml
@@ -0,0 +1,15 @@
+tosca_definitions_version: tosca_simple_yaml_1_2
+
+description: example definition file for testing
+
+imports:
+ - etsi_nfv_sol001_pnfd_2_5_1_types.yaml
+ - file: etsi_nfv_sol001_pnfd_2_5_1_types.yaml
+ - repository: <some_repository>
+ - namespace_uri: <some_namespace_uri>
+ - definitionFile3: etsi_nfv_sol001_pnfd_2_5_1_types.yaml
+ - definitionFile4: etsi_nfv_sol001_pnfd_2_5_1_types.yaml
+ - definitionFile5:
+ file: etsi_nfv_sol001_pnfd_2_5_1_types.yaml
+ - definitionFile6:
+ file: etsi_nfv_sol001_pnfd_2_5_1_types.yaml \ No newline at end of file
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/definition/invalidDefinitionFile.yaml b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/definition/invalidDefinitionFile.yaml
new file mode 100644
index 0000000000..6a2df5ec70
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/definition/invalidDefinitionFile.yaml
@@ -0,0 +1,49 @@
+tosca_definitions_version: tosca_simple_profile_yaml_1_1
+description: Sample yaml definition file for validation purpose
+
+node_types:
+ MyCompany.MyVnf.1_0.1_0: # node type of MyVnf
+ derived_from: tosca.nodes.nfv.VNF # this line has invalid tabbing
+ properties:
+ descriptor_id:
+ type: string
+ constraints: [ valid_values: [ b1bb0ce7-ebca-4fa7-95ed-4840d70a1177 ] ]
+ default: b1bb0ce7-ebca-4fa7-95ed-4840d70a1177
+ provider:
+ type: string
+ constraints: [ valid_values: [ MyCompany ] ]
+ default: MyCompany
+ product_name:
+ type: string
+ constraints: [ valid_values: [ MyVnf ] ]
+ default: Myvnf
+ software_version:
+ type: string
+ constraints: [ valid_values: [ '1.0' ] ]
+ default: '1.0'
+ descriptor_version:
+ type: string
+ constraints: [ valid_values: [ '1.0' ] ]
+ default: '1.0'
+ flavour_id:
+ type: string
+ constraints: [ valid_values: [ simple ] ] #only one and only allowed one DF in this example
+ default: simple
+ flavour_description:
+ type: string
+ vnfm_info:
+ type: list
+ interfaces:
+ Nfv:
+ instantiate:
+ inputs:
+ parameter_1:
+ type: string
+ required: false
+ default: value_1
+ parameter_2:
+ type: string
+ required: false
+ default: value_2
+ terminate:
+ implementation: terminate.workbook.mistral.yaml \ No newline at end of file
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/definition/sampleDefinitionFile.yaml b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/definition/sampleDefinitionFile.yaml
new file mode 100644
index 0000000000..cab7950763
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/definition/sampleDefinitionFile.yaml
@@ -0,0 +1,4 @@
+tosca_definitions_version: tosca_simple_yaml_1_2
+
+description: example definition file for testing
+
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/definition/sampleDefinitionFile1.yaml b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/definition/sampleDefinitionFile1.yaml
new file mode 100644
index 0000000000..3187f4f292
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/definition/sampleDefinitionFile1.yaml
@@ -0,0 +1,7 @@
+tosca_definitions_version: tosca_simple_yaml_1_2
+
+description: example definition file for testing
+
+imports:
+ - etsi_nfv_sol001_pnfd_2_5_1_types.yaml
+
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/definition/sampleDefinitionFile2.yaml b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/definition/sampleDefinitionFile2.yaml
new file mode 100644
index 0000000000..0b7f774140
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/definition/sampleDefinitionFile2.yaml
@@ -0,0 +1,7 @@
+tosca_definitions_version: tosca_simple_yaml_1_2
+
+description: example definition file for testing
+
+imports:
+ - etsi_nfv_sol001_pnfd_2_5_2_types.yaml
+
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/definition/sampleDefinitionFile3.yaml b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/definition/sampleDefinitionFile3.yaml
new file mode 100644
index 0000000000..4df199d767
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/definition/sampleDefinitionFile3.yaml
@@ -0,0 +1,6 @@
+tosca_definitions_version: tosca_simple_yaml_1_2
+
+description: example definition file for testing
+
+imports:
+ - etsi_nfv_sol001_pnfd_2_5_1_types.yaml \ No newline at end of file
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/manifest/invalidManifest.mf b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/manifest/invalidManifest.mf
new file mode 100644
index 0000000000..08e211c8d8
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/manifest/invalidManifest.mf
@@ -0,0 +1,3 @@
+Source: #This should start with metadata:
+
+
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/manifest/manifestInvalidMetadata.mf b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/manifest/manifestInvalidMetadata.mf
new file mode 100644
index 0000000000..53395c9f34
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/manifest/manifestInvalidMetadata.mf
@@ -0,0 +1,7 @@
+metadata:
+ pnf_product_name: RadioNode
+ vnf_provider_id: Bilal Iqbal
+ pnf_package_version: 1.0
+ vnf_release_date_time: 2019-12-14T11:25:00+00:00
+
+Source: Definitions/MainServiceTemplate.yaml \ No newline at end of file
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/manifest/manifestInvalidMetadata2.mf b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/manifest/manifestInvalidMetadata2.mf
new file mode 100644
index 0000000000..64fcdc247b
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/manifest/manifestInvalidMetadata2.mf
@@ -0,0 +1,7 @@
+metadata:
+ invalid_product_name: RadioNode
+ invalid_provider_id: Bilal Iqbal
+ invalid_package_version: 1.0
+ invalid_release_date_time: 2019-12-14T11:25:00+00:00
+
+Source: Definitions/MainServiceTemplate.yaml \ No newline at end of file
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/manifest/manifestInvalidMetadata3.mf b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/manifest/manifestInvalidMetadata3.mf
new file mode 100644
index 0000000000..ea92856e43
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/manifest/manifestInvalidMetadata3.mf
@@ -0,0 +1,11 @@
+metadata:
+ pnf_product_name: RadioNode
+ pnf_provider_id: Bilal Iqbal
+ pnf_package_version: 1.0
+ pnf_release_date_time: 2019-12-14T11:25:00+00:00
+ vnf_product_name: RadioNode
+ vnf_provider_id: Bilal Iqbal
+ vnf_package_version: 1.0
+ vnf_release_date_time: 2019-12-14T11:26:00+00:00
+
+Source: Definitions/MainServiceTemplate.yaml \ No newline at end of file
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/manifest/manifestInvalidMetadata4.mf b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/manifest/manifestInvalidMetadata4.mf
new file mode 100644
index 0000000000..bce6beef01
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/manifest/manifestInvalidMetadata4.mf
@@ -0,0 +1,5 @@
+metadata:
+ pnf_product_name: RadioNode
+ pnf_release_date_time: 2019-12-14T11:25:00+00:00
+
+Source: Definitions/MainServiceTemplate.yaml \ No newline at end of file
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/manifest/manifestInvalidMetadata5.mf b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/manifest/manifestInvalidMetadata5.mf
new file mode 100644
index 0000000000..aabbd470f7
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/manifest/manifestInvalidMetadata5.mf
@@ -0,0 +1,4 @@
+metadata:
+ vnf_product_name: RadioNode
+
+Source: Definitions/MainServiceTemplate.yaml \ No newline at end of file
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/manifest/sampleManifest.mf b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/manifest/sampleManifest.mf
new file mode 100644
index 0000000000..a7aebd6cae
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/manifest/sampleManifest.mf
@@ -0,0 +1,7 @@
+metadata:
+ vnf_product_name: RadioNode
+ vnf_provider_id: Bilal Iqbal
+ vnf_package_version: 1.0
+ vnf_release_date_time: 2019-12-14T11:25:00+00:00
+
+Source: Definitions/MainServiceTemplate.yaml \ No newline at end of file
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/manifest/sampleManifest2.mf b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/manifest/sampleManifest2.mf
new file mode 100644
index 0000000000..cfdf539be5
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/manifest/sampleManifest2.mf
@@ -0,0 +1,7 @@
+metadata:
+ pnf_product_name: RadioNode
+ pnf_provider_id: Bilal Iqbal
+ pnf_package_version: 1.0
+ pnf_release_date_time: 2019-12-14T11:25:00+00:00
+
+Source: Definitions/MainServiceTemplate.yaml \ No newline at end of file
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/manifest/validManifest.mf b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/manifest/validManifest.mf
new file mode 100644
index 0000000000..f34feafdf7
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/manifest/validManifest.mf
@@ -0,0 +1,11 @@
+metadata:
+ pnf_product_name: RadioNode
+ pnf_provider_id: Bilal Iqbal
+ pnf_package_version: 1.0
+ pnf_release_date_time: 2019-12-14T11:25:00+00:00
+
+Source: Artifacts/Deployment/Events/RadioNode_pnf_v1.yaml
+
+non_mano_artifact_sets:
+ onap_pm_events:
+ Source: Artifacts/Deployment/Measurements/PM_Dictionary.yaml \ No newline at end of file
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/metafile/metaFileWithMultipleBlocks.meta b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/metafile/metaFileWithMultipleBlocks.meta
new file mode 100644
index 0000000000..38440a2133
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/metafile/metaFileWithMultipleBlocks.meta
@@ -0,0 +1,10 @@
+TOSCA-Meta-File-Version: 1.0
+CSAR-Version: 1.1
+Created-by: Bilal Iqbal
+Entry-Definitions: Definitions/MainServiceTemplate.yml
+Entry-Manifest: Definitions/MainServiceTemplate.mf
+Entry-Change-Log: Definitions/changeLog.text
+
+Entry-Definitions: Definitions/MainServiceTemplate2.yml
+Entry-Manifest: Definitions/MainServiceTemplate2.mf
+Entry-Change-Log: Definitions/changeLog2.text \ No newline at end of file
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/metafile/nonSOL004WithMetaDirectoryCompliantMetaFile.meta b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/metafile/nonSOL004WithMetaDirectoryCompliantMetaFile.meta
new file mode 100644
index 0000000000..eea0795386
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/metafile/nonSOL004WithMetaDirectoryCompliantMetaFile.meta
@@ -0,0 +1,4 @@
+TOSCA-Meta-File-Version: 1.0
+CSAR-Version: 1.1
+Created-by: Bilal Iqbal
+Entry-Definitions: Definitions/MainServiceTemplate.yaml