aboutsummaryrefslogtreecommitdiffstats
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.java8
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/CsarValidationResult.java52
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ONAPCsarValidator.java46
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidator.java47
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ValidationResult.java55
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/Validator.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.java39
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidatorTest.java274
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004Version3MetaDirectoryValidatorTest.java4
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004Version4MetaDirectoryValidatorTest.java31
10 files changed, 358 insertions, 226 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 f1cab482f2..3005a2df2c 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
@@ -22,7 +22,9 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration;
import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters;
import java.io.IOException;
+import java.util.Map;
import java.util.Optional;
+import org.apache.commons.collections4.CollectionUtils;
import org.openecomp.core.utilities.file.FileContentHandler;
import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
import org.openecomp.sdc.be.csar.storage.ArtifactInfo;
@@ -34,6 +36,7 @@ import org.openecomp.sdc.datatypes.error.ErrorMessage;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData;
import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.CsarSecurityValidator;
+import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.ValidationResult;
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.security.SecurityManagerException;
@@ -64,7 +67,10 @@ public class OrchestrationTemplateCSARHandler extends BaseOrchestrationTemplateH
final FileContentHandler fileContentHandler = onboardPackage.getFileContentHandler();
try {
final Validator validator = ValidatorFactory.getValidator(fileContentHandler);
- uploadFileResponse.addStructureErrors(validator.validateContent(fileContentHandler));
+ final ValidationResult validationResult = validator.validate(fileContentHandler);
+ if (CollectionUtils.isNotEmpty(validationResult.getErrors())) {
+ uploadFileResponse.addStructureErrors(Map.of(SdcCommon.UPLOAD_FILE, validationResult.getErrors()));
+ }
} catch (IOException exception) {
logger.error(exception.getMessage(), exception);
uploadFileResponse
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/CsarValidationResult.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/CsarValidationResult.java
new file mode 100644
index 0000000000..ddb42cf873
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/CsarValidationResult.java
@@ -0,0 +1,52 @@
+/*
+ * -
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+import org.openecomp.sdc.datatypes.error.ErrorLevel;
+import org.openecomp.sdc.datatypes.error.ErrorMessage;
+
+public class CsarValidationResult implements ValidationResult {
+
+ private final List<ErrorMessage> errorMessages = new ArrayList<>();
+
+ @Override
+ public boolean isValid() {
+ return errorMessages.stream().noneMatch(errorMessage -> errorMessage.getLevel().equals(ErrorLevel.ERROR));
+ }
+
+ @Override
+ public List<ErrorMessage> getErrors() {
+ return errorMessages;
+ }
+
+ @Override
+ public List<ErrorMessage> getErrors(final ErrorLevel errorLevel) {
+ return errorMessages.stream().filter(errorMessage -> errorMessage.getLevel().equals(errorLevel)).collect(Collectors.toList());
+ }
+
+ public void addError(final ErrorMessage errorMessage) {
+ errorMessages.add(errorMessage);
+ }
+} \ No newline at end of file
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
index 486970451f..12901abde5 100644
--- 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
@@ -30,14 +30,11 @@ import static org.openecomp.sdc.tosca.csar.ToscaMetadataFileInfo.TOSCA_META_PATH
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.Set;
import java.util.stream.Collectors;
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;
@@ -49,22 +46,8 @@ import org.openecomp.sdc.tosca.csar.ToscaMetadata;
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(final FileContentHandler contentHandler) {
- Map<String, List<ErrorMessage>> errors = new HashMap<>();
- validateManifest(contentHandler);
- validateMetadata(contentHandler);
- validateNoExtraFiles(contentHandler);
- validateFolders(contentHandler.getFolderList());
- if (uploadFileErrors == null || uploadFileErrors.isEmpty()) {
- return errors;
- }
- errors.put(SdcCommon.UPLOAD_FILE, uploadFileErrors);
- return errors;
- }
+ private static final Logger LOGGER = LoggerFactory.getLogger(ONAPCsarValidator.class);
+ private final List<ErrorMessage> uploadFileErrors = new ArrayList<>();
private void validateMetadata(FileContentHandler contentMap) {
if (!validateTOSCAYamlFileInRootExist(contentMap, MAIN_SERVICE_TEMPLATE_YAML_FILE_NAME)) {
@@ -77,7 +60,7 @@ class ONAPCsarValidator implements Validator {
uploadFileErrors.add(new ErrorMessage(ErrorLevel.ERROR, Messages.METADATA_NO_ENTRY_DEFINITIONS.getErrorMessage()));
}
} catch (IOException exception) {
- logger.error(exception.getMessage(), exception);
+ LOGGER.error(exception.getMessage(), exception);
uploadFileErrors.add(new ErrorMessage(ErrorLevel.ERROR, Messages.FAILED_TO_VALIDATE_METADATA.getErrorMessage()));
}
} else {
@@ -98,7 +81,7 @@ class ONAPCsarValidator implements Validator {
} catch (final IOException ex) {
final String errorMessage = Messages.MANIFEST_UNEXPECTED_ERROR.formatMessage(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME, ex.getMessage());
uploadFileErrors.add(new ErrorMessage(ErrorLevel.ERROR, errorMessage));
- logger.error(errorMessage, ex);
+ LOGGER.error(errorMessage, ex);
}
}
@@ -139,4 +122,25 @@ class ONAPCsarValidator implements Validator {
}
return containsFile;
}
+
+ @Override
+ public ValidationResult validate(final FileContentHandler csarContent) {
+ validateManifest(csarContent);
+ validateMetadata(csarContent);
+ validateNoExtraFiles(csarContent);
+ validateFolders(csarContent.getFolderList());
+ final var csarValidationResult = new CsarValidationResult();
+ uploadFileErrors.forEach(csarValidationResult::addError);
+ return csarValidationResult;
+ }
+
+ @Override
+ public boolean appliesTo(String model) {
+ return model == null;
+ }
+
+ @Override
+ public int getOrder() {
+ return 0;
+ }
}
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 d99848ddb8..7416339b87 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
@@ -111,19 +111,6 @@ class SOL004MetaDirectoryValidator implements Validator {
this.securityManager = securityManager;
}
- @Override
- public Map<String, List<ErrorMessage>> validateContent(final FileContentHandler fileContentHandler) {
- this.contentHandler = (OnboardingPackageContentHandler) fileContentHandler;
- this.folderList = contentHandler.getFolderList();
- parseToscaMetadata();
- verifyMetadataFile();
- if (packageHasCertificate()) {
- verifySignedFiles();
- }
- validatePmDictionaryContentsAgainstSchema();
- return Collections.unmodifiableMap(getAnyValidationErrors());
- }
-
private boolean packageHasCertificate() {
final String certificatePath = getCertificatePath().orElse(null);
return contentHandler.containsFile(certificatePath);
@@ -499,15 +486,6 @@ class SOL004MetaDirectoryValidator implements Validator {
LOGGER.warn(Messages.METADATA_UNSUPPORTED_ENTRY.getErrorMessage(), entry.getKey());
}
- private Map<String, List<ErrorMessage>> getAnyValidationErrors() {
- if (errorsByFile.isEmpty()) {
- return Collections.emptyMap();
- }
- final Map<String, List<ErrorMessage>> errors = new HashMap<>();
- errors.put(SdcCommon.UPLOAD_FILE, errorsByFile);
- return errors;
- }
-
private void validatePmDictionaryContentsAgainstSchema() {
final Stream<byte[]> pmDictionaryFiles = new FileExtractor(getEtsiEntryManifestPath(), contentHandler).findFiles(ONAP_PM_DICTIONARY);
new PMDictionaryValidator().validate(pmDictionaryFiles, (String message) -> reportError(ErrorLevel.ERROR, message));
@@ -532,4 +510,29 @@ class SOL004MetaDirectoryValidator implements Validator {
reportError(ErrorLevel.ERROR, Messages.UNIQUE_ONAP_CNF_HELM_NON_MANO_ERROR.formatMessage(formattedFileList));
}
}
+
+ @Override
+ public ValidationResult validate(final FileContentHandler csarContent) {
+ this.contentHandler = (OnboardingPackageContentHandler) csarContent;
+ this.folderList = contentHandler.getFolderList();
+ parseToscaMetadata();
+ verifyMetadataFile();
+ if (packageHasCertificate()) {
+ verifySignedFiles();
+ }
+ validatePmDictionaryContentsAgainstSchema();
+ final var csarValidationResult = new CsarValidationResult();
+ errorsByFile.forEach(csarValidationResult::addError);
+ return csarValidationResult;
+ }
+
+ @Override
+ public boolean appliesTo(final String model) {
+ return model == null;
+ }
+
+ @Override
+ public int getOrder() {
+ return 0;
+ }
}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ValidationResult.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ValidationResult.java
new file mode 100644
index 0000000000..df4a91c85e
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ValidationResult.java
@@ -0,0 +1,55 @@
+/*
+ * -
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2021 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation;
+
+import java.util.List;
+import org.openecomp.sdc.datatypes.error.ErrorLevel;
+import org.openecomp.sdc.datatypes.error.ErrorMessage;
+
+/**
+ * Holds the result of a CSAR validation.
+ */
+public interface ValidationResult {
+
+ /**
+ * Check if the CSAR is valid.
+ *
+ * @return {@code true} if there is no messages with error level, {@code false} otherwise.
+ */
+ boolean isValid();
+
+ /**
+ * Gets all the error messages.
+ *
+ * @return the error messages.
+ */
+ List<ErrorMessage> getErrors();
+
+ /**
+ * Gets the error messages based on the given error level.
+ *
+ * @param errorLevel the error level
+ * @return the existing messages for the given error level, or an empty List if no messages are found.
+ */
+ List<ErrorMessage> getErrors(final ErrorLevel errorLevel);
+
+}
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
index e8f88c7eba..bd099779f6 100644
--- 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
@@ -19,10 +19,7 @@
*/
package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation;
-import java.util.List;
-import java.util.Map;
import org.openecomp.core.utilities.file.FileContentHandler;
-import org.openecomp.sdc.datatypes.error.ErrorMessage;
/**
* Validates the contents of the CSAR package uploaded in SDC.
@@ -30,8 +27,27 @@ import org.openecomp.sdc.datatypes.error.ErrorMessage;
public interface Validator {
/**
- * @param contentHandler contains file and its data
- * @return errors Map of errors that occur
+ * Validates the structure and content of a CSAR.
+ *
+ * @param csarContent the CSAR content
+ * @return the result of the validation
*/
- Map<String, List<ErrorMessage>> validateContent(final FileContentHandler contentHandler);
+ ValidationResult validate(final FileContentHandler csarContent);
+
+ /**
+ * Checks if the validator applies to the given model.
+ *
+ * @param model the model to check
+ * @return {@code true} if the validator applies to the given model, {@code false} otherwise
+ */
+ boolean appliesTo(final String model);
+
+ /**
+ * Should return the execution order that the validator is intended to run in relation to other validators that applies to the same model ({@link
+ * #appliesTo(String)}). The lower the value, the higher the priority. If a validator happens to have the same order of others, the system will
+ * randomly decides the execution order.
+ *
+ * @return the execution order of the validator.
+ */
+ int getOrder();
}
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
index c3c220079b..000f88e9e6 100644
--- 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
@@ -20,26 +20,24 @@
package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.openecomp.sdc.be.test.util.TestResourcesHandler.getResourceBytesOrFail;
-import java.io.IOException;
import java.util.List;
-import java.util.Map;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.openecomp.core.utilities.file.FileContentHandler;
-import org.openecomp.sdc.common.utils.SdcCommon;
import org.openecomp.sdc.datatypes.error.ErrorMessage;
-public class ONAPCsarValidatorTest {
+class ONAPCsarValidatorTest {
private ONAPCsarValidator onapCsarValidator;
private FileContentHandler contentHandler;
@BeforeEach
- public void setUp() throws IOException{
+ void setUp() {
onapCsarValidator = new ONAPCsarValidator();
contentHandler = new FileContentHandler();
contentHandler.addFile("TOSCA-Metadata/TOSCA.meta",
@@ -51,13 +49,13 @@ public class ONAPCsarValidatorTest {
}
@Test
- public void testGivenCSARPackage_withValidContent_thenNoErrorsReturned() {
+ void testGivenCSARPackage_withValidContent_thenNoErrorsReturned() {
assertExpectedErrors("Valid CSAR Package should have 0 errors",
- onapCsarValidator.validateContent(contentHandler), 0);
+ onapCsarValidator.validate(contentHandler).getErrors(), 0);
}
@Test
- public void testGivenCSARPackage_withInvalidManifestFile_thenErrorsReturned() throws IOException{
+ void testGivenCSARPackage_withInvalidManifestFile_thenErrorsReturned() {
contentHandler = new FileContentHandler();
contentHandler.addFile("TOSCA-Metadata/TOSCA.meta",
getResourceBytesOrFail("validation.files/metafile/nonSOL004WithMetaDirectoryCompliantMetaFile.meta"));
@@ -66,29 +64,30 @@ public class ONAPCsarValidatorTest {
contentHandler.addFile(TestConstants.TOSCA_DEFINITION_FILEPATH,
getResourceBytesOrFail(TestConstants.SAMPLE_DEFINITION_FILE_PATH));
- assertExpectedErrors("CSAR package with invalid manifest file should have errors", onapCsarValidator.validateContent(contentHandler), 1);
+ assertExpectedErrors("CSAR package with invalid manifest file should have errors",
+ onapCsarValidator.validate(contentHandler).getErrors(), 1);
}
@Test
- public void testGivenCSARPackage_withUnwantedFolders_thenErrorsReturned(){
+ void testGivenCSARPackage_withUnwantedFolders_thenErrorsReturned() {
contentHandler.addFolder("Files/");
- assertExpectedErrors("CSAR package with unwanted folders should fail with errors", onapCsarValidator.validateContent(contentHandler), 1);
+ assertExpectedErrors("CSAR package with unwanted folders should fail with errors",
+ onapCsarValidator.validate(contentHandler).getErrors(), 1);
}
@Test
- public void testGivenCSARPackage_withUnwantedFiles_thenErrorsReturned(){
+ void testGivenCSARPackage_withUnwantedFiles_thenErrorsReturned() {
contentHandler.addFile("ExtraFile.text", "".getBytes());
assertExpectedErrors("CSAR package with unwanted files should fail with errors",
- onapCsarValidator.validateContent(contentHandler), 1);
+ onapCsarValidator.validate(contentHandler).getErrors(), 1);
}
- private void assertExpectedErrors( String testCase, Map<String, List<ErrorMessage>> errors, int expectedErrors){
- if(expectedErrors > 0){
- List<ErrorMessage> errorMessages = errors.get(SdcCommon.UPLOAD_FILE);
- assertEquals(testCase, expectedErrors, errorMessages.size());
- }else{
- assertEquals(testCase, expectedErrors, errors.size());
+ private void assertExpectedErrors(String testCase, List<ErrorMessage> errorMessages, int expectedErrors) {
+ if (expectedErrors > 0) {
+ assertEquals(expectedErrors, errorMessages.size(), testCase);
+ } else {
+ assertTrue(errorMessages.isEmpty(), testCase);
}
}
}
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 33a558ea75..a4fd64626a 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
@@ -23,11 +23,11 @@
package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.anEmptyMap;
+import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -63,7 +63,10 @@ import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.va
import java.io.IOException;
import java.nio.charset.StandardCharsets;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -79,9 +82,7 @@ import org.openecomp.sdc.vendorsoftwareproduct.impl.onboarding.OnboardingPackage
import org.openecomp.sdc.vendorsoftwareproduct.security.SecurityManager;
import org.openecomp.sdc.vendorsoftwareproduct.security.SecurityManagerException;
-public class SOL004MetaDirectoryValidatorTest {
-
- private static int MANIFEST_DEFINITION_ERROR_COUNT = 1;
+class SOL004MetaDirectoryValidatorTest {
protected SOL004MetaDirectoryValidator sol004MetaDirectoryValidator;
protected OnboardingPackageContentHandler handler;
@@ -139,23 +140,23 @@ public class SOL004MetaDirectoryValidatorTest {
* ETSI Version 2.7.1 onwards contains two possible Definition File reference
*/
protected int getManifestDefinitionErrorCount() {
- return MANIFEST_DEFINITION_ERROR_COUNT;
+ return 1;
}
@Test
- public void testGivenTOSCAMetaFile_whenEntryHasNoValue_thenErrorIsReturned() {
+ void testGivenTOSCAMetaFile_whenEntryHasNoValue_thenErrorIsReturned() {
final String metaFileWithInvalidEntry = "TOSCA-Meta-File-Version: \n" +
"Entry-Definitions: " + TOSCA_DEFINITION_FILEPATH;
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileWithInvalidEntry.getBytes(StandardCharsets.UTF_8));
handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytesOrFail(SAMPLE_DEFINITION_FILE_PATH));
- final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler);
- assertExpectedErrors("TOSCA Meta file with no entries", errors, 1);
+ final ValidationResult validationResult = sol004MetaDirectoryValidator.validate(handler);
+ assertExpectedErrors("TOSCA Meta file with no entries", validationResult.getErrors(), 1);
}
@Test
- public void testGivenTOSCAMeta_withAllSupportedEntries_thenNoErrorsReturned() {
+ void testGivenTOSCAMeta_withAllSupportedEntries_thenNoErrorsReturned() {
final String entryTestFilePath = "Files/Tests";
final String entryLicenseFilePath = "Files/Licenses";
@@ -188,13 +189,13 @@ public class SOL004MetaDirectoryValidatorTest {
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
- final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler);
+ final ValidationResult validationResult = sol004MetaDirectoryValidator.validate(handler);
- assertEquals(0, errors.size());
+ assertTrue(validationResult.getErrors().isEmpty());
}
@Test
- public void testGivenTOSCAMeta_withUnsupportedEntry_thenNoErrorIsReturned() {
+ void testGivenTOSCAMeta_withUnsupportedEntry_thenNoErrorIsReturned() {
metaFileBuilder
.append("a-unknown-entry")
.append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" ")
@@ -210,15 +211,15 @@ public class SOL004MetaDirectoryValidatorTest {
.withSource(TOSCA_MANIFEST_FILEPATH);
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
- final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler);
- assertThat("Validation should produce no errors", errors, is(anEmptyMap()));
+ final ValidationResult validationResult = sol004MetaDirectoryValidator.validate(handler);
+ assertThat("Validation should produce no errors", validationResult.getErrors(), is(empty()));
}
/**
* Tests if the meta file contains invalid versions in TOSCA-Meta-File-Version and CSAR-Version attributes.
*/
@Test
- public void testGivenTOSCAMetaFile_withInvalidTOSCAMetaFileVersionAndCSARVersion_thenErrorIsReturned() {
+ void testGivenTOSCAMetaFile_withInvalidTOSCAMetaFileVersionAndCSARVersion_thenErrorIsReturned() {
final StringBuilder metaFileBuilder = new StringBuilder()
.append(TOSCA_META_FILE_VERSION_ENTRY.getName())
.append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(Integer.MAX_VALUE).append("\n")
@@ -246,23 +247,22 @@ public class SOL004MetaDirectoryValidatorTest {
manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
- final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler);
- assertExpectedErrors("Invalid TOSCA-Meta-File-Version and CSAR-Version attributes", errors, 2);
+ final ValidationResult validationResult = sol004MetaDirectoryValidator.validate(handler);
+ assertExpectedErrors("Invalid TOSCA-Meta-File-Version and CSAR-Version attributes", validationResult.getErrors(), 2);
}
@Test
- public void testGivenTOSCAMetaFile_withNonExistentFileReferenced_thenErrorsReturned() {
+ void testGivenTOSCAMetaFile_withNonExistentFileReferenced_thenErrorsReturned() {
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
- final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler);
- assertThat("Total of errors should be as expected", errors.size(), is(1));
- final List<ErrorMessage> errorMessages = errors.get(SdcCommon.UPLOAD_FILE);
- assertThat("Total of errors messages should be as expected", errorMessages.size(), is((2 + getManifestDefinitionErrorCount())));
+ final ValidationResult validationResult = sol004MetaDirectoryValidator.validate(handler);
+ final List<ErrorMessage> errors = validationResult.getErrors();
+ assertThat("Total of errors messages should be as expected", errors.size(), is((2 + getManifestDefinitionErrorCount())));
}
@Test
- public void testGivenDefinitionFile_whenValidImportStatementExist_thenNoErrorsReturned() {
+ void testGivenDefinitionFile_whenValidImportStatementExist_thenNoErrorsReturned() {
final ManifestBuilder manifestBuilder = getPnfManifestSampleBuilder();
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
@@ -285,12 +285,12 @@ public class SOL004MetaDirectoryValidatorTest {
manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
- final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler);
- assertEquals(0, errors.size());
+ final ValidationResult validationResult = sol004MetaDirectoryValidator.validate(handler);
+ assertEquals(0, validationResult.getErrors().size());
}
@Test
- public void testGivenDefinitionFile_whenMultipleDefinitionsImportStatementExist_thenNoErrorsReturned() {
+ void testGivenDefinitionFile_whenMultipleDefinitionsImportStatementExist_thenNoErrorsReturned() {
final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
@@ -320,12 +320,13 @@ public class SOL004MetaDirectoryValidatorTest {
manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
- final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler);
- assertEquals(0, errors.size());
+ final ValidationResult validationResult = sol004MetaDirectoryValidator.validate(handler);
+ assertTrue(validationResult.isValid());
+ assertTrue(validationResult.getErrors().isEmpty());
}
@Test
- public void testGivenDefinitionFile_whenInvalidImportStatementExist_thenErrorIsReturned() {
+ void testGivenDefinitionFile_whenInvalidImportStatementExist_thenErrorIsReturned() {
final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
@@ -346,15 +347,15 @@ public class SOL004MetaDirectoryValidatorTest {
String manifest = manifestBuilder.build();
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifest.getBytes(StandardCharsets.UTF_8));
- final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler);
- assertExpectedErrors("", errors, getManifestDefinitionErrorCount());
+ final ValidationResult validationResult = sol004MetaDirectoryValidator.validate(handler);
+ assertExpectedErrors("", validationResult.getErrors(), getManifestDefinitionErrorCount());
}
/**
* Manifest referenced import file missing
*/
@Test
- public void testGivenDefinitionFile_whenReferencedImportDoesNotExist_thenErrorIsReturned() {
+ void testGivenDefinitionFile_whenReferencedImportDoesNotExist_thenErrorIsReturned() {
final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
@@ -376,12 +377,12 @@ public class SOL004MetaDirectoryValidatorTest {
manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
- final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler);
- assertExpectedErrors("Manifest referenced import file missing", errors, getManifestDefinitionErrorCount());
+ final ValidationResult validationResult = sol004MetaDirectoryValidator.validate(handler);
+ assertExpectedErrors("Manifest referenced import file missing", validationResult.getErrors(), getManifestDefinitionErrorCount());
}
@Test
- public void testGivenDefinitionFile_whenFileInPackageNotInManifest_thenErrorIsReturned() {
+ void testGivenDefinitionFile_whenFileInPackageNotInManifest_thenErrorIsReturned() {
final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
@@ -403,12 +404,12 @@ public class SOL004MetaDirectoryValidatorTest {
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
- final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler);
- assertExpectedErrors("Artifact is not being referenced in manifest file", errors, 1);
+ final ValidationResult validationResult = sol004MetaDirectoryValidator.validate(handler);
+ assertExpectedErrors("Artifact is not being referenced in manifest file", validationResult.getErrors(), 1);
}
@Test
- public void testGivenDefinitionFile_whenManifestNotreferencedInManifest_thenNoErrorIsReturned() {
+ void testGivenDefinitionFile_whenManifestNotreferencedInManifest_thenNoErrorIsReturned() {
final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
@@ -431,15 +432,16 @@ public class SOL004MetaDirectoryValidatorTest {
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
- final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler);
- assertEquals(0, errors.size());
+ final ValidationResult validationResult = sol004MetaDirectoryValidator.validate(handler);
+ assertTrue(validationResult.isValid());
+ assertTrue(validationResult.getErrors().isEmpty());
}
/**
* Reference with invalid YAML format.
*/
@Test
- public void testGivenDefinitionFile_withInvalidYAML_thenErrorIsReturned() {
+ void testGivenDefinitionFile_withInvalidYAML_thenErrorIsReturned() {
final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
@@ -458,12 +460,12 @@ public class SOL004MetaDirectoryValidatorTest {
manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
- final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler);
- assertExpectedErrors("Reference with invalid YAML format", errors, getManifestDefinitionErrorCount());
+ final ValidationResult validationResult = sol004MetaDirectoryValidator.validate(handler);
+ assertExpectedErrors("Reference with invalid YAML format", validationResult.getErrors(), getManifestDefinitionErrorCount());
}
@Test
- public void testGivenManifestFile_withValidSourceAndNonManoSources_thenNoErrorIsReturned() throws IOException {
+ void testGivenManifestFile_withValidSourceAndNonManoSources_thenNoErrorIsReturned() throws IOException {
final ManifestBuilder manifestBuilder = getPnfManifestSampleBuilder();
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
@@ -488,15 +490,16 @@ public class SOL004MetaDirectoryValidatorTest {
manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
- final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler);
- assertEquals(0, errors.size());
+ final ValidationResult validationResult = sol004MetaDirectoryValidator.validate(handler);
+ assertTrue(validationResult.isValid());
+ assertTrue(validationResult.getErrors().isEmpty());
}
/**
* Manifest with non existent source files should return error.
*/
@Test
- public void testGivenManifestFile_withNonExistentSourceFile_thenErrorIsReturned() throws IOException {
+ void testGivenManifestFile_withNonExistentSourceFile_thenErrorIsReturned() throws IOException {
final ManifestBuilder manifestBuilder = getPnfManifestSampleBuilder();
//non existent reference
manifestBuilder.withSource("Artifacts/Deployment/Events/RadioNode_pnf_v1.yaml");
@@ -520,27 +523,27 @@ public class SOL004MetaDirectoryValidatorTest {
manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
- final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler);
- assertExpectedErrors("Manifest with non existent source files", errors, 1);
+ final ValidationResult validationResult = sol004MetaDirectoryValidator.validate(handler);
+ assertExpectedErrors("Manifest with non existent source files", validationResult.getErrors(), 1);
}
/**
* Tests the validation for a TOSCA Manifest with invalid data.
*/
@Test
- public void testGivenManifestFile_withInvalidData_thenErrorIsReturned() {
+ void testGivenManifestFile_withInvalidData_thenErrorIsReturned() {
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
handler.addFile(TOSCA_MANIFEST_FILEPATH, getResourceBytesOrFail("validation.files/manifest/invalidManifest.mf"));
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytesOrFail(SAMPLE_DEFINITION_FILE_PATH));
handler.addFile(SAMPLE_DEFINITION_IMPORT_FILE_PATH, "".getBytes());
- final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler);
- assertExpectedErrors("TOSCA manifest with invalid data", errors, 1);
+ final ValidationResult validationResult = sol004MetaDirectoryValidator.validate(handler);
+ assertExpectedErrors("TOSCA manifest with invalid data", validationResult.getErrors(), 1);
}
@Test
- public void testGivenManifestAndDefinitionFile_withSameNames_thenNoErrorReturned() {
+ void testGivenManifestAndDefinitionFile_withSameNames_thenNoErrorReturned() {
final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
@@ -558,15 +561,16 @@ public class SOL004MetaDirectoryValidatorTest {
manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
- final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler);
- assertEquals(0, errors.size());
+ final ValidationResult validationResult = sol004MetaDirectoryValidator.validate(handler);
+ assertTrue(validationResult.isValid());
+ assertTrue(validationResult.getErrors().isEmpty());
}
/**
* Main TOSCA definitions file and Manifest file with different name should return error.
*/
@Test
- public void testGivenManifestAndMainDefinitionFile_withDifferentNames_thenErrorIsReturned() {
+ void testGivenManifestAndMainDefinitionFile_withDifferentNames_thenErrorIsReturned() {
metaFileBuilder = new StringBuilder()
.append(TOSCA_META_FILE_VERSION_ENTRY.getName())
.append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" 1.0").append("\n")
@@ -598,13 +602,13 @@ public class SOL004MetaDirectoryValidatorTest {
manifestBuilder.withSource("Definitions/MainServiceTemplate2.mf");
handler.addFile("Definitions/MainServiceTemplate2.mf", manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
- final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler);
+ final ValidationResult validationResult = sol004MetaDirectoryValidator.validate(handler);
assertExpectedErrors("Main TOSCA definitions file and Manifest file with different name should return error",
- errors, 1);
+ validationResult.getErrors(), 1);
}
@Test
- public void testGivenManifestFile_withDifferentExtension_thenErrorIsReturned() {
+ void testGivenManifestFile_withDifferentExtension_thenErrorIsReturned() {
metaFileBuilder = new StringBuilder()
.append(TOSCA_META_FILE_VERSION_ENTRY.getName())
.append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" 1.0").append("\n")
@@ -636,13 +640,13 @@ public class SOL004MetaDirectoryValidatorTest {
manifestBuilder.withSource("Definitions/MainServiceTemplate.txt");
handler.addFile("Definitions/MainServiceTemplate.txt", manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
- final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler);
+ final ValidationResult validationResult = sol004MetaDirectoryValidator.validate(handler);
assertExpectedErrors("Manifest file with different extension than .mf should return error",
- errors, 1);
+ validationResult.getErrors(), 1);
}
@Test
- public void testGivenManifestFile_withValidVnfMetadata_thenNoErrorsReturned() {
+ void testGivenManifestFile_withValidVnfMetadata_thenNoErrorsReturned() {
final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
@@ -655,12 +659,13 @@ public class SOL004MetaDirectoryValidatorTest {
manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
- final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler);
- assertExpectedErrors("Manifest with valid vnf mandatory values should not return any errors", errors, 0);
+ final ValidationResult validationResult = sol004MetaDirectoryValidator.validate(handler);
+ assertTrue(validationResult.isValid(), "Manifest with valid vnf mandatory values should be valid");
+ assertExpectedErrors("Manifest with valid vnf mandatory values should not return any errors", validationResult.getErrors(), 0);
}
@Test
- public void testGivenManifestFile_withValidPnfMetadata_thenNoErrorsReturned() {
+ void testGivenManifestFile_withValidPnfMetadata_thenNoErrorsReturned() {
final ManifestBuilder manifestBuilder = getPnfManifestSampleBuilder();
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
@@ -676,15 +681,15 @@ public class SOL004MetaDirectoryValidatorTest {
manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
- final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler);
- assertExpectedErrors("Manifest with valid pnf mandatory values should not return any errors", errors, 0);
+ final ValidationResult validationResult = sol004MetaDirectoryValidator.validate(handler);
+ assertExpectedErrors("Manifest with valid pnf mandatory values should not return any errors", validationResult.getErrors(), 0);
}
/**
* Manifest with mixed metadata should return error.
*/
@Test
- public void testGivenManifestFile_withMetadataContainingMixedPnfVnfMetadata_thenErrorIsReturned() {
+ void testGivenManifestFile_withMetadataContainingMixedPnfVnfMetadata_thenErrorIsReturned() {
final ManifestBuilder manifestBuilder = new ManifestBuilder()
.withMetaData(PNFD_NAME.getToken(), "RadioNode")
.withMetaData(VNF_PROVIDER_ID.getToken(), "Bilal Iqbal")
@@ -701,13 +706,13 @@ public class SOL004MetaDirectoryValidatorTest {
manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
- final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler);
- assertExpectedErrors("Manifest with mixed metadata should return error", errors, 1);
+ final ValidationResult validationResult = sol004MetaDirectoryValidator.validate(handler);
+ assertExpectedErrors("Manifest with mixed metadata should return error", validationResult.getErrors(), 1);
}
@Test
- public void testGivenManifestFile_withMetadataMissingPnfOrVnfMandatoryEntries_thenErrorIsReturned() {
+ void testGivenManifestFile_withMetadataMissingPnfOrVnfMandatoryEntries_thenErrorIsReturned() {
final ManifestBuilder manifestBuilder = new ManifestBuilder()
.withMetaData("invalid_product_name", "RadioNode")
.withMetaData("invalid_provider_id", "Bilal Iqbal")
@@ -726,12 +731,12 @@ public class SOL004MetaDirectoryValidatorTest {
manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
- final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler);
- assertExpectedErrors("Manifest with missing vnf or pnf mandatory entries should return error", errors, 1);
+ final ValidationResult validationResult = sol004MetaDirectoryValidator.validate(handler);
+ assertExpectedErrors("Manifest with missing vnf or pnf mandatory entries should return error", validationResult.getErrors(), 1);
}
@Test
- public void testGivenManifestFile_withMetadataMissingMandatoryPnfEntries_thenErrorIsReturned() {
+ void testGivenManifestFile_withMetadataMissingMandatoryPnfEntries_thenErrorIsReturned() {
final ManifestBuilder manifestBuilder = new ManifestBuilder();
manifestBuilder.withMetaData(PNFD_NAME.getToken(), "RadioNode");
@@ -749,13 +754,13 @@ public class SOL004MetaDirectoryValidatorTest {
manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
- final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler);
- assertExpectedErrors("Manifest with metadata missing pnf mandatory entries should return error", errors, 1);
+ final ValidationResult validationResult = sol004MetaDirectoryValidator.validate(handler);
+ assertExpectedErrors("Manifest with metadata missing pnf mandatory entries should return error", validationResult.getErrors(), 1);
}
@Test
- public void testGivenManifestFile_withMetadataMissingMandatoryVnfEntries_thenErrorIsReturned() {
+ void testGivenManifestFile_withMetadataMissingMandatoryVnfEntries_thenErrorIsReturned() {
final ManifestBuilder manifestBuilder = new ManifestBuilder();
manifestBuilder.withMetaData(VNF_PRODUCT_NAME.getToken(), "RadioNode");
@@ -772,8 +777,9 @@ public class SOL004MetaDirectoryValidatorTest {
manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
- final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler);
- assertExpectedErrors("Manifest with metadata missing vnf mandatory entries should return error", errors, 1);
+ final ValidationResult validationResult = sol004MetaDirectoryValidator.validate(handler);
+
+ assertExpectedErrors("Manifest with metadata missing vnf mandatory entries should return error", validationResult.getErrors(), 1);
}
@@ -781,7 +787,7 @@ public class SOL004MetaDirectoryValidatorTest {
* Manifest with more than 4 metadata entries should return error.
*/
@Test
- public void testGivenManifestFile_withMetadataEntriesExceedingTheLimit_thenErrorIsReturned() {
+ void testGivenManifestFile_withMetadataEntriesExceedingTheLimit_thenErrorIsReturned() {
final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder()
.withMetaData(PNFD_NAME.getToken(), "RadioNode")
.withMetaData(ManifestTokenType.PNFD_PROVIDER.getToken(), "Bilal Iqbal")
@@ -800,12 +806,12 @@ public class SOL004MetaDirectoryValidatorTest {
manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
- final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler);
- assertExpectedErrors("Manifest with more than 4 metadata entries should return error", errors, 1);
+ final ValidationResult validationResult = sol004MetaDirectoryValidator.validate(handler);
+ assertExpectedErrors("Manifest with more than 4 metadata entries should return error", validationResult.getErrors(), 1);
}
@Test
- public void testGivenManifestFile_withPnfMetadataAndVfEntries_thenErrorIsReturned() {
+ void testGivenManifestFile_withPnfMetadataAndVfEntries_thenErrorIsReturned() {
final ManifestBuilder manifestBuilder = getPnfManifestSampleBuilder();
metaFileBuilder
.append(ETSI_ENTRY_TESTS.getName())
@@ -824,8 +830,9 @@ public class SOL004MetaDirectoryValidatorTest {
manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
- final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler);
- assertExpectedErrors("Tosca.meta should not have entries applicable only to VF", errors, 2);
+
+ final ValidationResult validationResult = sol004MetaDirectoryValidator.validate(handler);
+ assertExpectedErrors("Tosca.meta should not have entries applicable only to VF", validationResult.getErrors(), 2);
}
@@ -833,7 +840,7 @@ public class SOL004MetaDirectoryValidatorTest {
* Tests an imported descriptor with a missing imported file.
*/
@Test
- public void testGivenDefinitionFileWithImportedDescriptor_whenImportedDescriptorImportsMissingFile_thenMissingImportErrorOccur() {
+ void testGivenDefinitionFileWithImportedDescriptor_whenImportedDescriptorImportsMissingFile_thenMissingImportErrorOccur() {
final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
@@ -857,7 +864,7 @@ public class SOL004MetaDirectoryValidatorTest {
manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
- final Map<String, List<ErrorMessage>> actualErrorMap = sol004MetaDirectoryValidator.validateContent(handler);
+ final ValidationResult validationResult = sol004MetaDirectoryValidator.validate(handler);
final List<ErrorMessage> expectedErrorList = new ArrayList<>();
for (int i =0;i < getManifestDefinitionErrorCount();i++)
@@ -865,14 +872,14 @@ public class SOL004MetaDirectoryValidatorTest {
, Messages.MISSING_IMPORT_FILE.formatMessage("Definitions/etsi_nfv_sol001_pnfd_2_5_2_types.yaml"))
);
- assertExpectedErrors(actualErrorMap.get(SdcCommon.UPLOAD_FILE), expectedErrorList);
+ assertExpectedErrors(validationResult.getErrors(), expectedErrorList);
}
/**
* Tests an imported descriptor with invalid import statement.
*/
@Test
- public void testGivenDefinitionFileWithImportedDescriptor_whenInvalidImportStatementExistInImportedDescriptor_thenInvalidImportErrorOccur() {
+ void testGivenDefinitionFileWithImportedDescriptor_whenInvalidImportStatementExistInImportedDescriptor_thenInvalidImportErrorOccur() {
final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
@@ -896,7 +903,7 @@ public class SOL004MetaDirectoryValidatorTest {
manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
- final Map<String, List<ErrorMessage>> actualErrorMap = sol004MetaDirectoryValidator.validateContent(handler);
+ final ValidationResult validationResult = sol004MetaDirectoryValidator.validate(handler);
final List<ErrorMessage> expectedErrorList = new ArrayList<>();
for (int i =0;i < getManifestDefinitionErrorCount();i++)
@@ -904,11 +911,11 @@ public class SOL004MetaDirectoryValidatorTest {
, Messages.INVALID_IMPORT_STATEMENT.formatMessage(definitionImportOne, "null"))
);
- assertExpectedErrors(actualErrorMap.get(SdcCommon.UPLOAD_FILE), expectedErrorList);
+ assertExpectedErrors(validationResult.getErrors(), expectedErrorList);
}
@Test
- public void givenManifestWithNonManoPmAndVesArtifacts_whenNonManoArtifactsAreValid_thenNoErrorsOccur() {
+ void givenManifestWithNonManoPmAndVesArtifacts_whenNonManoArtifactsAreValid_thenNoErrorsOccur() {
final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
@@ -933,14 +940,13 @@ public class SOL004MetaDirectoryValidatorTest {
manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
- final Map<String, List<ErrorMessage>> actualErrorMap = sol004MetaDirectoryValidator
- .validateContent(handler);
+ final ValidationResult validationResult = sol004MetaDirectoryValidator.validate(handler);
- assertExpectedErrors(actualErrorMap.get(SdcCommon.UPLOAD_FILE), Collections.emptyList());
+ assertExpectedErrors(validationResult.getErrors(), Collections.emptyList());
}
@Test
- public void givenManifestWithNonManoPmOrVesArtifacts_whenNonManoArtifactsYamlAreInvalid_thenInvalidYamlErrorOccur() {
+ void givenManifestWithNonManoPmOrVesArtifacts_whenNonManoArtifactsYamlAreInvalid_thenInvalidYamlErrorOccur() {
final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
@@ -966,12 +972,12 @@ public class SOL004MetaDirectoryValidatorTest {
expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR, "while scanning a simple key in 'reader', line 2, column 1: key {} ^could not find expected ':' in 'reader', line 2, column 7: key {} ^")
);
- final Map<String, List<ErrorMessage>> actualErrorMap = sol004MetaDirectoryValidator.validateContent(handler);
- assertExpectedErrors(actualErrorMap.get(SdcCommon.UPLOAD_FILE), expectedErrorList);
+ final ValidationResult validationResult = sol004MetaDirectoryValidator.validate(handler);
+ assertExpectedErrors(validationResult.getErrors(), expectedErrorList);
}
@Test
- public void givenManifestWithNonManoPmOrVesArtifacts_whenNonManoArtifactsYamlAreEmpty_thenEmptyYamlErrorOccur() {
+ void givenManifestWithNonManoPmOrVesArtifacts_whenNonManoArtifactsYamlAreEmpty_thenEmptyYamlErrorOccur() {
final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
@@ -1005,14 +1011,12 @@ public class SOL004MetaDirectoryValidatorTest {
, "PM_Dictionary YAML file is empty")
);
- final Map<String, List<ErrorMessage>> actualErrorMap = sol004MetaDirectoryValidator
- .validateContent(handler);
-
- assertExpectedErrors(actualErrorMap.get(SdcCommon.UPLOAD_FILE), expectedErrorList);
+ final ValidationResult validationResult = sol004MetaDirectoryValidator.validate(handler);
+ assertExpectedErrors(validationResult.getErrors(), expectedErrorList);
}
@Test
- public void givenManifestWithNonManoPmOrVesArtifacts_whenNonManoArtifactsHaveNotYamlExtension_thenInvalidYamlExtensionErrorOccur() {
+ void givenManifestWithNonManoPmOrVesArtifacts_whenNonManoArtifactsHaveNotYamlExtension_thenInvalidYamlExtensionErrorOccur() {
final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
@@ -1047,14 +1051,13 @@ public class SOL004MetaDirectoryValidatorTest {
);
- final Map<String, List<ErrorMessage>> actualErrorMap = sol004MetaDirectoryValidator
- .validateContent(handler);
+ final ValidationResult validationResult = sol004MetaDirectoryValidator.validate(handler);
- assertExpectedErrors(actualErrorMap.get(SdcCommon.UPLOAD_FILE), expectedErrorList);
+ assertExpectedErrors(validationResult.getErrors(), expectedErrorList);
}
@Test
- public void givenPackageWithValidSoftwareInformationNonMano_whenThePackageIsValidated_thenNoErrorsAreReturned() {
+ void givenPackageWithValidSoftwareInformationNonMano_whenThePackageIsValidated_thenNoErrorsAreReturned() {
//given a package with software information non-mano artifact
final ManifestBuilder manifestBuilder = getPnfManifestSampleBuilder();
final String nonManoSoftwareInformationPath = "Artifacts/software-information/pnf-sw-information-valid.yaml";
@@ -1072,13 +1075,13 @@ public class SOL004MetaDirectoryValidatorTest {
manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
//when package is validated
- final Map<String, List<ErrorMessage>> actualErrorMap = sol004MetaDirectoryValidator.validateContent(handler);
+ final ValidationResult validationResult = sol004MetaDirectoryValidator.validate(handler);
//then no errors
- assertExpectedErrors(actualErrorMap.get(SdcCommon.UPLOAD_FILE), Collections.emptyList());
+ assertExpectedErrors(validationResult.getErrors(), Collections.emptyList());
}
@Test
- public void givenPackageWithUnparsableSwInformationNonMano_whenThePackageIsValidated_thenInvalidErrorIsReturned() {
+ void givenPackageWithUnparsableSwInformationNonMano_whenThePackageIsValidated_thenInvalidErrorIsReturned() {
//given a package with unparsable software information non-mano artifact
final ManifestBuilder manifestBuilder = getPnfManifestSampleBuilder();
final String nonManoSoftwareInformationPath = "Artifacts/software-information/pnf-sw-information-valid.yaml";
@@ -1096,17 +1099,17 @@ public class SOL004MetaDirectoryValidatorTest {
manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
//when package is validated
- final Map<String, List<ErrorMessage>> actualErrorMap = sol004MetaDirectoryValidator.validateContent(handler);
+ final ValidationResult validationResult = sol004MetaDirectoryValidator.validate(handler);
//then invalid error returned
final List<ErrorMessage> expectedErrorList = new ArrayList<>();
expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR
, Messages.INVALID_SW_INFORMATION_NON_MANO_ERROR.formatMessage(nonManoSoftwareInformationPath))
);
- assertExpectedErrors(actualErrorMap.get(SdcCommon.UPLOAD_FILE), expectedErrorList);
+ assertExpectedErrors(validationResult.getErrors(), expectedErrorList);
}
@Test
- public void givenPackageWithIncorrectSwInformationNonMano_whenThePackageIsValidated_thenInvalidErrorIsReturned() {
+ void givenPackageWithIncorrectSwInformationNonMano_whenThePackageIsValidated_thenInvalidErrorIsReturned() {
//given a package with incorrect software information non-mano artifact
final ManifestBuilder manifestBuilder = getPnfManifestSampleBuilder();
final String nonManoSoftwareInformationPath = "Artifacts/software-information/pnf-sw-information-invalid.yaml";
@@ -1124,17 +1127,17 @@ public class SOL004MetaDirectoryValidatorTest {
manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
//when package is validated
- final Map<String, List<ErrorMessage>> actualErrorMap = sol004MetaDirectoryValidator.validateContent(handler);
+ final ValidationResult validationResult = sol004MetaDirectoryValidator.validate(handler);
//then incorrect error returned
final List<ErrorMessage> expectedErrorList = new ArrayList<>();
expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR
, Messages.INCORRECT_SW_INFORMATION_NON_MANO_ERROR.formatMessage(nonManoSoftwareInformationPath))
);
- assertExpectedErrors(actualErrorMap.get(SdcCommon.UPLOAD_FILE), expectedErrorList);
+ assertExpectedErrors(validationResult.getErrors(), expectedErrorList);
}
@Test
- public void givenPackageWithTwoSoftwareInformationNonMano_whenThePackageIsValidated_thenUniqueErrorIsReturned() {
+ void givenPackageWithTwoSoftwareInformationNonMano_whenThePackageIsValidated_thenUniqueErrorIsReturned() {
//given a package with two software information non-mano artifacts
final ManifestBuilder manifestBuilder = getPnfManifestSampleBuilder();
final String nonManoSoftwareInformation1Path = "Artifacts/software-information/pnf-sw-information-valid1.yaml";
@@ -1156,7 +1159,7 @@ public class SOL004MetaDirectoryValidatorTest {
manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
//when package is validated
- final Map<String, List<ErrorMessage>> actualErrorMap = sol004MetaDirectoryValidator.validateContent(handler);
+ final ValidationResult validationResult = sol004MetaDirectoryValidator.validate(handler);
//then unique error returned
final List<ErrorMessage> expectedErrorList = new ArrayList<>();
final String errorFiles = Stream.of(nonManoSoftwareInformation1Path, nonManoSoftwareInformation2Path)
@@ -1165,11 +1168,11 @@ public class SOL004MetaDirectoryValidatorTest {
expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR
, Messages.UNIQUE_SW_INFORMATION_NON_MANO_ERROR.formatMessage(errorFiles))
);
- assertExpectedErrors(actualErrorMap.get(SdcCommon.UPLOAD_FILE), expectedErrorList);
+ assertExpectedErrors(validationResult.getErrors(), expectedErrorList);
}
@Test
- public void signedPackage() throws SecurityManagerException {
+ void signedPackage() throws SecurityManagerException {
//given
final ManifestBuilder manifestBuilder = getPnfManifestSampleBuilder();
final String fakeArtifactPath = "Artifacts/aArtifact.yaml";
@@ -1200,30 +1203,30 @@ public class SOL004MetaDirectoryValidatorTest {
sol004MetaDirectoryValidator = getSol004WithSecurity(securityManagerMock);
//when
- Map<String, List<ErrorMessage>> actualErrorMap = sol004MetaDirectoryValidator.validateContent(handler);
+ ValidationResult validationResult = sol004MetaDirectoryValidator.validate(handler);
//then
- assertExpectedErrors(actualErrorMap.get(SdcCommon.UPLOAD_FILE), Collections.emptyList());
+ assertExpectedErrors(validationResult.getErrors(), Collections.emptyList());
//given
sol004MetaDirectoryValidator = getSol004WithSecurity(securityManagerMock);
when(securityManagerMock.verifySignedData(any(), any(), any())).thenReturn(false);
//when
- actualErrorMap = sol004MetaDirectoryValidator.validateContent(handler);
+ validationResult = sol004MetaDirectoryValidator.validate(handler);
//then
List<ErrorMessage> expectedErrorList = new ArrayList<>();
expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR
, Messages.ARTIFACT_INVALID_SIGNATURE.formatMessage(fakeArtifactCmsPath, fakeArtifactPath))
);
- assertExpectedErrors(actualErrorMap.get(SdcCommon.UPLOAD_FILE), expectedErrorList);
+ assertExpectedErrors(validationResult.getErrors(), expectedErrorList);
//given
sol004MetaDirectoryValidator = getSol004WithSecurity(securityManagerMock);
when(securityManagerMock.verifySignedData(any(), any(), any()))
.thenThrow(new SecurityManagerException("SecurityManagerException"));
//when
- actualErrorMap = sol004MetaDirectoryValidator.validateContent(handler);
+ validationResult = sol004MetaDirectoryValidator.validate(handler);
//then
expectedErrorList = new ArrayList<>();
@@ -1233,23 +1236,26 @@ public class SOL004MetaDirectoryValidatorTest {
fakeArtifactPath, fakeCertificatePath, "SecurityManagerException")
)
);
- assertExpectedErrors(actualErrorMap.get(SdcCommon.UPLOAD_FILE), expectedErrorList);
+ assertExpectedErrors(validationResult.getErrors(), expectedErrorList);
}
protected void assertExpectedErrors(final String testCase, final Map<String, List<ErrorMessage>> errors, final int expectedErrors){
- final List<ErrorMessage> errorMessages = errors.get(SdcCommon.UPLOAD_FILE);
+ assertExpectedErrors(testCase, errors.get(SdcCommon.UPLOAD_FILE), expectedErrors);
+ }
+
+ protected void assertExpectedErrors(final String testCase, final List<ErrorMessage> errorMessages, final int expectedErrors){
printErrorMessages(errorMessages);
if (expectedErrors > 0) {
- assertEquals(testCase, expectedErrors, errorMessages.size());
+ assertEquals(expectedErrors, errorMessages.size(), testCase);
} else {
- assertEquals(testCase, expectedErrors, errors.size());
+ assertTrue(errorMessages.isEmpty(), testCase);
}
}
private void printErrorMessages(final List<ErrorMessage> errorMessages) {
if (CollectionUtils.isNotEmpty(errorMessages)) {
errorMessages.forEach(errorMessage ->
- System.out.println(String.format("%s: %s", errorMessage.getLevel(), errorMessage.getMessage()))
+ System.out.printf("%s: %s%n", errorMessage.getLevel(), errorMessage.getMessage())
);
}
}
@@ -1267,7 +1273,7 @@ public class SOL004MetaDirectoryValidatorTest {
actualErrorList.forEach(error -> {
Predicate<ErrorMessage> matching = e -> e.getLevel() == error.getLevel() && sanitize(e.getMessage()).equalsIgnoreCase(sanitize(error.getMessage()));
- assertTrue("The actual error and expected error lists should be the same", expectedErrorList.stream().anyMatch(matching));
+ assertTrue(expectedErrorList.stream().anyMatch(matching), "The actual error and expected error lists should be the same");
});
}
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 75047aa2f0..f26ff584c8 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
@@ -27,8 +27,6 @@ import org.openecomp.sdc.vendorsoftwareproduct.security.SecurityManager;
public class SOL004Version3MetaDirectoryValidatorTest extends SOL004MetaDirectoryValidatorTest {
- private static int MANIFEST_DEFINITION_ERROR_COUNT_VERSION_3 = 2;
-
@Override
public SOL004MetaDirectoryValidator getSOL004MetaDirectoryValidator() {
return new SOL004Version3MetaDirectoryValidator();
@@ -62,6 +60,6 @@ public class SOL004Version3MetaDirectoryValidatorTest extends SOL004MetaDirector
@Override
protected int getManifestDefinitionErrorCount() {
- return MANIFEST_DEFINITION_ERROR_COUNT_VERSION_3;
+ return 2;
}
}
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 ee62f91226..9587f59e72 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
@@ -20,7 +20,7 @@
package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.openecomp.sdc.be.config.NonManoArtifactType.ONAP_CNF_HELM;
import static org.openecomp.sdc.be.test.util.TestResourcesHandler.getResourceBytesOrFail;
import static org.openecomp.sdc.tosca.csar.ManifestTokenType.ATTRIBUTE_VALUE_SEPARATOR;
@@ -35,16 +35,11 @@ import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.va
import java.io.IOException;
import java.nio.charset.StandardCharsets;
-import java.util.List;
-import java.util.Map;
import org.junit.jupiter.api.Test;
-import org.openecomp.sdc.datatypes.error.ErrorMessage;
import org.openecomp.sdc.tosca.csar.ManifestTokenType;
import org.openecomp.sdc.vendorsoftwareproduct.security.SecurityManager;
-public class SOL004Version4MetaDirectoryValidatorTest extends SOL004MetaDirectoryValidatorTest {
-
- private static int manifestDefinitionErrorCountVersion4 = 2;
+class SOL004Version4MetaDirectoryValidatorTest extends SOL004MetaDirectoryValidatorTest {
@Override
public SOL004MetaDirectoryValidator getSOL004MetaDirectoryValidator() {
@@ -83,11 +78,11 @@ public class SOL004Version4MetaDirectoryValidatorTest extends SOL004MetaDirector
@Override
protected int getManifestDefinitionErrorCount() {
- return manifestDefinitionErrorCountVersion4;
+ return 2;
}
@Test
- public void testGivenManifestFile_withValidSourceAndNonManoSources_thenNoErrorIsReturned() throws IOException {
+ void testGivenManifestFile_withValidSourceAndNonManoSources_thenNoErrorIsReturned() throws IOException {
final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
@@ -113,14 +108,12 @@ public class SOL004Version4MetaDirectoryValidatorTest extends SOL004MetaDirector
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
final Validator validator = ValidatorFactory.getValidator(handler);
- final Map<String, List<ErrorMessage>> errors = validator.validateContent(handler);
- assertEquals(0, errors.size());
-
-
+ final ValidationResult validationResult = validator.validate(handler);
+ assertTrue(validationResult.getErrors().isEmpty());
}
@Test
- public void testGivenManifestFile_withNotReferencedNonManoSources_thenErrorIsReturned() throws IOException {
+ void testGivenManifestFile_withNotReferencedNonManoSources_thenErrorIsReturned() throws IOException {
final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
@@ -145,12 +138,12 @@ public class SOL004Version4MetaDirectoryValidatorTest extends SOL004MetaDirector
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
final Validator validator = ValidatorFactory.getValidator(handler);
- final Map<String, List<ErrorMessage>> errors = validator.validateContent(handler);
- assertExpectedErrors("Non-MANO file does not exist", errors, 1);
+ final ValidationResult validationResult = validator.validate(handler);
+ assertExpectedErrors("Non-MANO file does not exist", validationResult.getErrors(), 1);
}
@Test
- public void testGivenManifestFile_withNonExistentSourceFile_thenErrorIsReturned() throws IOException {
+ void testGivenManifestFile_withNonExistentSourceFile_thenErrorIsReturned() throws IOException {
final ManifestBuilder manifestBuilder = getPnfManifestSampleBuilder();
//non existent reference
manifestBuilder.withSource("Artifacts/Deployment/non-mano/RadioNode.yaml");
@@ -175,8 +168,8 @@ public class SOL004Version4MetaDirectoryValidatorTest extends SOL004MetaDirector
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
final Validator validator = ValidatorFactory.getValidator(handler);
- final Map<String, List<ErrorMessage>> errors = validator.validateContent(handler);
- assertExpectedErrors("Manifest with non existent source files", errors, 1);
+ final ValidationResult validationResult = validator.validate(handler);
+ assertExpectedErrors("Manifest with non existent source files", validationResult.getErrors(), 1);
}
}