diff options
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test')
6 files changed, 206 insertions, 21 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ManifestBuilderTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ManifestBuilderTest.java index b91a1156ce..e966a12b65 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ManifestBuilderTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ManifestBuilderTest.java @@ -36,8 +36,8 @@ import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.TreeMap; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openecomp.sdc.tosca.csar.Manifest; import org.openecomp.sdc.tosca.csar.SOL004ManifestOnboarding; @@ -45,7 +45,7 @@ public class ManifestBuilderTest { private ManifestBuilder manifestBuilder; - @Before + @BeforeEach public void setUp() { manifestBuilder = new ManifestBuilder(); } @@ -162,4 +162,4 @@ public class ManifestBuilderTest { private void mockManifestSource() { manifestBuilder.withSource("/test.yaml"); } -}
\ No newline at end of file +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/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 15a7d6c9f9..c3c220079b 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 @@ -26,8 +26,8 @@ import static org.openecomp.sdc.be.test.util.TestResourcesHandler.getResourceByt import java.io.IOException; import java.util.List; import java.util.Map; -import org.junit.Before; -import org.junit.Test; +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; @@ -38,7 +38,7 @@ public class ONAPCsarValidatorTest { private ONAPCsarValidator onapCsarValidator; private FileContentHandler contentHandler; - @Before + @BeforeEach public void setUp() throws IOException{ onapCsarValidator = new ONAPCsarValidator(); contentHandler = new FileContentHandler(); 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 9461648d2e..2053373dce 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 @@ -61,6 +61,7 @@ import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.va import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.TOSCA_DEFINITION_FILEPATH; import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.TOSCA_MANIFEST_FILEPATH; +import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collections; @@ -68,10 +69,9 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; import java.util.stream.Stream; - import org.apache.commons.collections.CollectionUtils; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.openecomp.sdc.common.errors.Messages; import org.openecomp.sdc.common.utils.SdcCommon; import org.openecomp.sdc.datatypes.error.ErrorLevel; @@ -89,7 +89,7 @@ public class SOL004MetaDirectoryValidatorTest { protected OnboardingPackageContentHandler handler; protected StringBuilder metaFileBuilder; - @Before + @BeforeEach public void setUp() { sol004MetaDirectoryValidator = getSOL004MetaDirectoryValidator(); handler = new OnboardingPackageContentHandler(); @@ -140,7 +140,7 @@ public class SOL004MetaDirectoryValidatorTest { * ETSI Version 2.7.1 below contains one Definition File reference * ETSI Version 2.7.1 onwards contains two possible Definition File reference */ - protected int getManifestDefintionErrorCount() { + protected int getManifestDefinitionErrorCount() { return MANIFEST_DEFINITION_ERROR_COUNT; } @@ -259,7 +259,7 @@ public class SOL004MetaDirectoryValidatorTest { 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 + getManifestDefintionErrorCount()))); + assertThat("Total of errors messages should be as expected", errorMessages.size(), is((2 + getManifestDefinitionErrorCount()))); } @@ -349,7 +349,7 @@ public class SOL004MetaDirectoryValidatorTest { handler.addFile(TOSCA_MANIFEST_FILEPATH, manifest.getBytes(StandardCharsets.UTF_8)); final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler); - assertExpectedErrors("", errors, getManifestDefintionErrorCount()); + assertExpectedErrors("", errors, getManifestDefinitionErrorCount()); } /** @@ -379,7 +379,7 @@ public class SOL004MetaDirectoryValidatorTest { 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, getManifestDefintionErrorCount()); + assertExpectedErrors("Manifest referenced import file missing", errors, getManifestDefinitionErrorCount()); } @Test @@ -461,11 +461,11 @@ public class SOL004MetaDirectoryValidatorTest { 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, getManifestDefintionErrorCount()); + assertExpectedErrors("Reference with invalid YAML format", errors, getManifestDefinitionErrorCount()); } @Test - public void testGivenManifestFile_withValidSourceAndNonManoSources_thenNoErrorIsReturned() { + public void testGivenManifestFile_withValidSourceAndNonManoSources_thenNoErrorIsReturned() throws IOException { final ManifestBuilder manifestBuilder = getPnfManifestSampleBuilder(); handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8)); @@ -498,7 +498,7 @@ public class SOL004MetaDirectoryValidatorTest { * Manifest with non existent source files should return error. */ @Test - public void testGivenManifestFile_withNonExistentSourceFile_thenErrorIsReturned() { + public void testGivenManifestFile_withNonExistentSourceFile_thenErrorIsReturned() throws IOException { final ManifestBuilder manifestBuilder = getPnfManifestSampleBuilder(); //non existent reference manifestBuilder.withSource("Artifacts/Deployment/Events/RadioNode_pnf_v1.yaml"); @@ -862,7 +862,7 @@ public class SOL004MetaDirectoryValidatorTest { final Map<String, List<ErrorMessage>> actualErrorMap = sol004MetaDirectoryValidator.validateContent(handler); final List<ErrorMessage> expectedErrorList = new ArrayList<>(); - for (int i =0;i < getManifestDefintionErrorCount();i++) + for (int i =0;i < getManifestDefinitionErrorCount();i++) expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR , Messages.MISSING_IMPORT_FILE.formatMessage("Definitions/etsi_nfv_sol001_pnfd_2_5_2_types.yaml")) ); @@ -901,7 +901,7 @@ public class SOL004MetaDirectoryValidatorTest { final Map<String, List<ErrorMessage>> actualErrorMap = sol004MetaDirectoryValidator.validateContent(handler); final List<ErrorMessage> expectedErrorList = new ArrayList<>(); - for (int i =0;i < getManifestDefintionErrorCount();i++) + for (int i =0;i < getManifestDefinitionErrorCount();i++) expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR , Messages.INVALID_IMPORT_STATEMENT.formatMessage(definitionImportOne, "null")) ); 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 02ea3f2af3..75047aa2f0 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 @@ -61,7 +61,7 @@ public class SOL004Version3MetaDirectoryValidatorTest extends SOL004MetaDirector } @Override - protected int getManifestDefintionErrorCount() { + protected int getManifestDefinitionErrorCount() { return MANIFEST_DEFINITION_ERROR_COUNT_VERSION_3; } } 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 new file mode 100644 index 0000000000..ee62f91226 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004Version4MetaDirectoryValidatorTest.java @@ -0,0 +1,182 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation; + +import static org.junit.Assert.assertEquals; +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; +import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.OTHER_DEFINITIONS; +import static org.openecomp.sdc.tosca.csar.ToscaMetadataFileInfo.TOSCA_META_PATH_FILE_NAME; +import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.SAMPLE_DEFINITION_FILE_PATH; +import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.SAMPLE_DEFINITION_IMPORT_FILE_PATH; +import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.SAMPLE_SOURCE; +import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.TOSCA_CHANGELOG_FILEPATH; +import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.TOSCA_DEFINITION_FILEPATH; +import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.TOSCA_MANIFEST_FILEPATH; + +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; + + @Override + public SOL004MetaDirectoryValidator getSOL004MetaDirectoryValidator() { + return new SOL004Version4MetaDirectoryValidator(); + } + + @Override + public StringBuilder getMetaFileBuilder() { + return super.getMetaFileBuilder().append(OTHER_DEFINITIONS.getName()) + .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" ").append(TOSCA_DEFINITION_FILEPATH).append("\n"); + } + + @Override + protected SOL004MetaDirectoryValidator getSol004WithSecurity(SecurityManager securityManagerMock) { + return new SOL004Version4MetaDirectoryValidator(securityManagerMock); + } + + @Override + protected ManifestBuilder getVnfManifestSampleBuilder() { + return super.getVnfManifestSampleBuilder() + .withMetaData(ManifestTokenType.VNF_SOFTWARE_VERSION.getToken(), "1.0.0") + .withMetaData(ManifestTokenType.VNFD_ID.getToken(), "2116fd24-83f2-416b-bf3c-ca1964793aca") + .withMetaData(ManifestTokenType.COMPATIBLE_SPECIFICATION_VERSIONS.getToken(), "2.6.1, 2.7.1, 3.3.1") + .withMetaData(ManifestTokenType.VNF_PROVIDER_ID.getToken(), "ACME") + .withMetaData(ManifestTokenType.VNF_RELEASE_DATE_TIME.getToken(), "2021-02-11T11:25:00+00:00") + .withMetaData(ManifestTokenType.VNF_PACKAGE_VERSION.getToken(), "1.0") + .withMetaData(ManifestTokenType.VNFM_INFO.getToken(), "etsivnfm:v2.3.1,0:myGreatVnfm-1") + .withMetaData(ManifestTokenType.VNF_PRODUCT_NAME.getToken(), "RadioNode"); + } + + @Override + protected ManifestBuilder getPnfManifestSampleBuilder() { + return super.getPnfManifestSampleBuilder() + .withMetaData(ManifestTokenType.COMPATIBLE_SPECIFICATION_VERSIONS.getToken(), "2.6.1, 2.7.1, 3.3.1"); + } + + @Override + protected int getManifestDefinitionErrorCount() { + return manifestDefinitionErrorCountVersion4; + } + + @Test + public void testGivenManifestFile_withValidSourceAndNonManoSources_thenNoErrorIsReturned() throws IOException { + final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder(); + + handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8)); + manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME); + + handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes()); + manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH); + + handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytesOrFail(SAMPLE_DEFINITION_FILE_PATH)); + manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH); + + handler.addFile(SAMPLE_SOURCE, "".getBytes()); + manifestBuilder.withSource(SAMPLE_SOURCE); + + handler.addFile(SAMPLE_DEFINITION_IMPORT_FILE_PATH, getResourceBytesOrFail(SAMPLE_DEFINITION_FILE_PATH)); + manifestBuilder.withSource(SAMPLE_DEFINITION_IMPORT_FILE_PATH); + + final String nonManoSource = "Artifacts/Deployment/non-mano/onap-cnf-helm-valid.yaml"; + handler.addFile(nonManoSource, getResourceBytesOrFail("validation.files/empty.yaml")); + manifestBuilder.withNonManoArtifact(ONAP_CNF_HELM.getType(), nonManoSource); + + manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH); + 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()); + + + } + + @Test + public void testGivenManifestFile_withNotReferencedNonManoSources_thenErrorIsReturned() throws IOException { + final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder(); + + handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8)); + manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME); + + handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes()); + manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH); + + handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytesOrFail(SAMPLE_DEFINITION_FILE_PATH)); + manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH); + + handler.addFile(SAMPLE_SOURCE, "".getBytes()); + manifestBuilder.withSource(SAMPLE_SOURCE); + + handler.addFile(SAMPLE_DEFINITION_IMPORT_FILE_PATH, getResourceBytesOrFail(SAMPLE_DEFINITION_FILE_PATH)); + manifestBuilder.withSource(SAMPLE_DEFINITION_IMPORT_FILE_PATH); + + //non existent reference + manifestBuilder.withNonManoArtifact(ONAP_CNF_HELM.getType(), "validation.files/notReferencedFile.yaml"); + + manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH); + 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); + } + + @Test + public void testGivenManifestFile_withNonExistentSourceFile_thenErrorIsReturned() throws IOException { + final ManifestBuilder manifestBuilder = getPnfManifestSampleBuilder(); + //non existent reference + manifestBuilder.withSource("Artifacts/Deployment/non-mano/RadioNode.yaml"); + + handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8)); + manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME); + + handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes()); + manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH); + + handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytesOrFail(SAMPLE_DEFINITION_FILE_PATH)); + manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH); + + handler.addFile(SAMPLE_DEFINITION_IMPORT_FILE_PATH, "".getBytes()); + manifestBuilder.withSource(SAMPLE_DEFINITION_IMPORT_FILE_PATH); + + final String nonManoSource = "Artifacts/Deployment/non-mano/onap-cnf-helm-valid.yaml"; + handler.addFile(nonManoSource, getResourceBytesOrFail("validation.files/empty.yaml")); + manifestBuilder.withNonManoArtifact(ONAP_CNF_HELM.getType(), nonManoSource); + + manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH); + 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); + } + +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/non-mano/onap-cnf-helm-valid.yaml b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/non-mano/onap-cnf-helm-valid.yaml new file mode 100644 index 0000000000..08b7c2d1ad --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/validation.files/non-mano/onap-cnf-helm-valid.yaml @@ -0,0 +1,3 @@ +description: "ONAP CNF Helm Test Sample" +provider: "Ericsson" +version: "1.0" |