From 870a89675528664aa5c0aca57f50c584b76a8b8f Mon Sep 17 00:00:00 2001 From: Bogumil Zebek Date: Fri, 9 Aug 2019 13:54:44 +0200 Subject: Improve code quality Change-Id: I60090d9da403bf8e6c3e5ba77ef4acfd6f41ec2b Issue-ID: VNFSDK-449 Signed-off-by: Zebek Bogumil --- .../org/onap/cvc/csar/PnfManifestParserTest.java | 26 ++++++++- .../org/onap/cvc/csar/VTPValidateCSARTest.java | 56 ++++++++++++++++++ .../MainServiceTemplateDifferentSectionOrder.mf | 68 ++++++++++++++++++++++ 3 files changed, 149 insertions(+), 1 deletion(-) create mode 100644 csarvalidation/src/test/java/org/onap/cvc/csar/VTPValidateCSARTest.java create mode 100644 csarvalidation/src/test/resources/pnf/MainServiceTemplateDifferentSectionOrder.mf (limited to 'csarvalidation/src/test') diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/PnfManifestParserTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/PnfManifestParserTest.java index 3ba37aa..6e56959 100644 --- a/csarvalidation/src/test/java/org/onap/cvc/csar/PnfManifestParserTest.java +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/PnfManifestParserTest.java @@ -162,4 +162,28 @@ public class PnfManifestParserTest { assertThat(errors.size()).isEqualTo(1); assertThat(errors.get(0).getMessage()).isEqualTo("Invalid. Entry [CMS section is not at the end of file!]"); } -} \ No newline at end of file + + @Test + public void shouldFetchSourcesSectionFromFileWithChangedSectionOrder() throws IOException { + + pnfManifestParser = PnfManifestParser.getInstance(new File("./src/test/resources/pnf/MainServiceTemplateDifferentSectionOrder.mf")); + Pair, List> sourcesPair = pnfManifestParser.fetchSourcesSection(); + List sources = sourcesPair.getKey(); + List errors = sourcesPair.getValue(); + + assertThat(sources).contains( + new SourcesParser.Source("MRF.yaml", "SHA-256", "09e5a788acb180162c51679ae4c998039fa6644505db2415e35107d1ee213943"), + new SourcesParser.Source("scripts/install.sh", "SHA-256", "d0e7828293355a07c2dccaaa765c80b507e60e6167067c950dc2e6b0da0dbd8b"), + new SourcesParser.Source("https://www.vendor_org.com/MRF/v4.1/scripts/scale/scale.sh", "SHA-256", "36f945953929812aca2701b114b068c71bd8c95ceb3609711428c26325649165"), + new SourcesParser.Source("Artifacts/Events/VES_registration.yml", "SHA-256", "36f945953929812aca2701b114b068c71bd8c95ceb3609711428c26325649165"), + new SourcesParser.Source("Artifacts/Measurements/PM_Dictionary.yaml", "SHA-256", "36f945953929812aca2701b114b068c71bd8c95ceb3609711428c26325649165"), + new SourcesParser.Source("Artifacts/Yang_module/Yang_module.yaml", "SHA-256", "36f945953929812aca2701b114b068c71bd8c95ceb3609711428c26325649165"), + new SourcesParser.Source("Artifacts/scripts/install.sh", "SHA-256", "36f945953929812aca2701b114b068c71bd8c95ceb3609711428c26325649165"), + new SourcesParser.Source("Artifacts/Informational/user_guide.txt", "SHA-256", "36f945953929812aca2701b114b068c71bd8c95ceb3609711428c26325649165"), + new SourcesParser.Source("Artifacts/Other/installation_guide.txt", "SHA-256", "36f945953929812aca2701b114b068c71bd8c95ceb3609711428c26325649165"), + new SourcesParser.Source("Artifacts/Other/review_log.txt", "SHA-256", "36f945953929812aca2701b114b068c71bd8c95ceb3609711428c26325649165") + + ); + assertThat(errors.size()).isEqualTo(0); + } +} diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/VTPValidateCSARTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/VTPValidateCSARTest.java new file mode 100644 index 0000000..69b92f6 --- /dev/null +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/VTPValidateCSARTest.java @@ -0,0 +1,56 @@ +/* + * Copyright 2019 Nokia + *

+ * 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. + * + */ + +package org.onap.cvc.csar; + +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + + +public class VTPValidateCSARTest { + + @Test + public void shouldConfigureCsarValidatorBasedOnCsarArchive(){ + // given + final CSARArchive csarArchive = givenCsarArchive(); + + // when + final VTPValidateCSAR.CSARValidation csarValidation = VTPValidateCSAR.createCsarValidationFor(csarArchive); + + // then + final VTPValidateCSAR.CSARValidation.VNF vnf = csarValidation.getVnf(); + assertThat(vnf.getName()).isEqualTo("productName"); + assertThat(vnf.getVendor()).isEqualTo("vendorName"); + assertThat(vnf.getVersion()).isEqualTo("version"); + assertThat(vnf.getType()).isEqualTo("TOSCA"); + assertThat(vnf.getMode()).isEqualTo(CSARArchive.Mode.WITH_TOSCA_META_DIR.toString()); + } + + private CSARArchive givenCsarArchive() { + final CSARArchive csarArchive = new CSARArchive(); + csarArchive.getToscaMeta().setMode(CSARArchive.Mode.WITH_TOSCA_META_DIR); + csarArchive.getToscaMeta().setCompanyName("vendorName"); + + final CSARArchive.Manifest.Metadata metadata = new CSARArchive.Manifest.Metadata(); + metadata.setProductName("productName"); + metadata.setPackageVersion("version"); + csarArchive.getManifest().setMetadata(metadata); + return csarArchive; + } + +} diff --git a/csarvalidation/src/test/resources/pnf/MainServiceTemplateDifferentSectionOrder.mf b/csarvalidation/src/test/resources/pnf/MainServiceTemplateDifferentSectionOrder.mf new file mode 100644 index 0000000..4bff664 --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/MainServiceTemplateDifferentSectionOrder.mf @@ -0,0 +1,68 @@ +metadata: + pnfd_name: RadioNode + pnfd_provider: Ericsson + pnfd_archive_version: 1.0 + pnfd_release_date_time: 2019-01-14T11:25:00+00:00 + +non_mano_artifact_sets: + + onap_ves_events: + source: Artifacts/Events/VES_registration.yml + + onap_pm_dictionary: + source: Artifacts/Measurements/PM_Dictionary.yaml + + onap_yang_module: + source: Artifacts/Yang_module/Yang_module.yaml + + onap_others: + source: Artifacts/scripts/install.sh + source: Artifacts/Informational/user_guide.txt + source: Artifacts/Other/installation_guide.txt + source: Artifacts/Other/review_log.txt + +Source: MRF.yaml +Algorithm: SHA-256 +Hash: 09e5a788acb180162c51679ae4c998039fa6644505db2415e35107d1ee213943 + +Source: scripts/install.sh +Algorithm: SHA-256 +Hash: d0e7828293355a07c2dccaaa765c80b507e60e6167067c950dc2e6b0da0dbd8b + +Source: https://www.vendor_org.com/MRF/v4.1/scripts/scale/scale.sh +Algorithm: SHA-256 +Hash: 36f945953929812aca2701b114b068c71bd8c95ceb3609711428c26325649165 + +Source: Artifacts/Events/VES_registration.yml +Algorithm: SHA-256 +Hash: 36f945953929812aca2701b114b068c71bd8c95ceb3609711428c26325649165 + +Source: Artifacts/Measurements/PM_Dictionary.yaml +Algorithm: SHA-256 +Hash: 36f945953929812aca2701b114b068c71bd8c95ceb3609711428c26325649165 + +Source: Artifacts/Yang_module/Yang_module.yaml +Algorithm: SHA-256 +Hash: 36f945953929812aca2701b114b068c71bd8c95ceb3609711428c26325649165 + +Source: Artifacts/scripts/install.sh +Algorithm: SHA-256 +Hash: 36f945953929812aca2701b114b068c71bd8c95ceb3609711428c26325649165 + +Source: Artifacts/Informational/user_guide.txt +Algorithm: SHA-256 +Hash: 36f945953929812aca2701b114b068c71bd8c95ceb3609711428c26325649165 + +Source: Artifacts/Other/installation_guide.txt +Algorithm: SHA-256 +Hash: 36f945953929812aca2701b114b068c71bd8c95ceb3609711428c26325649165 + +Source: Artifacts/Other/review_log.txt +Algorithm: SHA-256 +Hash: 36f945953929812aca2701b114b068c71bd8c95ceb3609711428c26325649165 + +-----BEGIN CMS----- +MIGDBgsqhkiG9w0BCRABCaB0MHICAQAwDQYLKoZIhvcNAQkQAwgwXgYJKoZIhvcN +AQcBoFEET3icc87PK0nNK9ENqSxItVIoSa0o0S/ISczMs1ZIzkgsKk4tsQ0N1nUM +dvb05OXi5XLPLEtViMwvLVLwSE0sKlFIVHAqSk3MBkkBAJv0Fx0= +-----END CMS----- -- cgit 1.2.3-korg