diff options
Diffstat (limited to 'csarvalidation/src/test')
92 files changed, 3460 insertions, 186 deletions
diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/CSARArchiveTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/CSARArchiveTest.java index 2831532..3b18a1b 100644 --- a/csarvalidation/src/test/java/org/onap/cvc/csar/CSARArchiveTest.java +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/CSARArchiveTest.java @@ -20,8 +20,9 @@ import java.io.IOException; import java.util.Arrays; import org.junit.Test; - import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + public class CSARArchiveTest { @Test @@ -35,6 +36,7 @@ public class CSARArchiveTest { csar.init("./src/test/resources/" + csarFileName + ".csar"); csar.parse(); csar.cleanup(); + assertTrue(csar.getErrors().size() > 0); System.out.println(csar.getErrors()); } catch (Exception e) { // TODO Auto-generated catch block diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/CsarValidatorTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/CsarValidatorTest.java deleted file mode 100644 index 2969b42..0000000 --- a/csarvalidation/src/test/java/org/onap/cvc/csar/CsarValidatorTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * Copyright 2017 Huawei Technologies Co., Ltd. - * - * 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 org.onap.cli.main.OnapCli; - -import java.net.URISyntaxException; - -import static org.junit.Assert.assertEquals; -import static org.onap.cvc.csar.cc.sol004.IntegrationTestUtils.absoluteFilePath; - - -public class CsarValidatorTest { - - - @Test - public void testAllTestCasesForVNF() throws URISyntaxException { - OnapCli cli = new OnapCli(new String [] { - "--product", "onap-dublin", - "csar-validate", - "--format", "json", - "--csar", absoluteFilePath("VoLTE.csar")}); - cli.handle(); - assertEquals(0, cli.getExitCode()); - } - - - @Test - public void testAllTestCasesForPNF_CsarCase() throws URISyntaxException { - OnapCli cli = new OnapCli(new String [] { - "--product", "onap-dublin", - "csar-validate", - "--format", "json", - "--pnf", - "--csar", absoluteFilePath("pnf/r57019/allMandatoryEntriesDefinedInMetadataManifest.csar")}); - cli.handle(); - assertEquals(0, cli.getExitCode()); - } - - - @Test - public void testAllTestCasesForPNF_ZipCase() throws URISyntaxException { - OnapCli cli = new OnapCli(new String [] { - "--product", "onap-dublin", - "csar-validate", - "--format", "json", - "--pnf", - "--csar", absoluteFilePath("pnf/signed-package-valid-signature.zip")}); - cli.handle(); - assertEquals(0, cli.getExitCode()); - } - -} diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/PnfCSARArchiveTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/PnfCSARArchiveTest.java index cf24e53..4f46b74 100644 --- a/csarvalidation/src/test/java/org/onap/cvc/csar/PnfCSARArchiveTest.java +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/PnfCSARArchiveTest.java @@ -19,11 +19,11 @@ package org.onap.cvc.csar; import com.google.common.collect.Lists; import org.junit.Test; import org.onap.cvc.csar.parser.SourcesParser; - import java.util.List; import java.util.Map; - import static org.assertj.core.api.Assertions.assertThat; +import java.util.Collections; +import java.util.HashMap; public class PnfCSARArchiveTest { @@ -45,7 +45,7 @@ public class PnfCSARArchiveTest { verifyThatCmsSectionWasSet(manifest); verifyThatSourcesSectionWasSet(manifest); verifyThatNonManoArtifactsWereSet(manifest); - assertThat(pnfCSARArchive.getErrors().size()).isEqualTo(0); + assertThat(pnfCSARArchive.getErrors().size()).isZero(); } } @@ -76,23 +76,27 @@ public class PnfCSARArchiveTest { private void verifyThatNonManoArtifactsWereSet(CSARArchive.Manifest manifest) { Map<String, Map<String, List<String>>> nonManoArtifacts = manifest.getNonMano(); - assertThat(nonManoArtifacts.get("onap_ves_events").get(SOURCE_TAG)) - .isEqualTo(Lists.newArrayList("Artifacts/Events/VES_registration.yml") - ); - assertThat(nonManoArtifacts.get("onap_pm_dictionary").get(SOURCE_TAG)) - .isEqualTo(Lists.newArrayList("Artifacts/Measurements/PM_Dictionary.yaml") - ); - assertThat(nonManoArtifacts.get("onap_yang_modules").get(SOURCE_TAG)) - .isEqualTo(Lists.newArrayList("Artifacts/Yang_module/Yang_module.yaml") - ); - assertThat(nonManoArtifacts.get("onap_others").get(SOURCE_TAG)) - .isEqualTo(Lists.newArrayList( - "Artifacts/scripts/install.sh", + Map<String, List<String>>mapValue1=new HashMap<>(); + Map<String, List<String>>mapValue2=new HashMap<>(); + Map<String, List<String>>mapValue3=new HashMap<>(); + Map<String, List<String>>mapValue4=new HashMap<>(); + + mapValue1.put("", Collections.singletonList("")); + mapValue1.put(SOURCE_TAG,Lists.newArrayList("Artifacts/Events/VES_registration.yml")); + mapValue2.put("", Collections.singletonList("")); + mapValue2.put(SOURCE_TAG,Lists.newArrayList("Artifacts/Measurements/PM_Dictionary.yaml")); + mapValue3.put("", Collections.singletonList("")); + mapValue3.put(SOURCE_TAG,Lists.newArrayList("Artifacts/Yang_module/Yang_module.yaml")); + mapValue4.put("", Collections.singletonList("")); + mapValue4.put(SOURCE_TAG,Lists.newArrayList + ("Artifacts/scripts/install.sh", "Artifacts/Informational/user_guide.txt", "Artifacts/Other/installation_guide.txt", - "Artifacts/Other/review_log.txt" - ) - ); + "Artifacts/Other/review_log.txt")); + assertThat(nonManoArtifacts).containsEntry("onap_ves_events",mapValue1); + assertThat(nonManoArtifacts).containsEntry("onap_pm_dictionary",mapValue2); + assertThat(nonManoArtifacts).containsEntry("onap_yang_modules",mapValue3); + assertThat(nonManoArtifacts).containsEntry("onap_others",mapValue4); } }
\ No newline at end of file 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 a708f47..5749a73 100644 --- a/csarvalidation/src/test/java/org/onap/cvc/csar/PnfManifestParserTest.java +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/PnfManifestParserTest.java @@ -25,6 +25,8 @@ import java.io.File; import java.io.IOException; import java.util.List; import java.util.Map; +import java.util.Collections; +import java.util.HashMap; import static org.assertj.core.api.Assertions.assertThat; @@ -48,7 +50,7 @@ public class PnfManifestParserTest { assertThat(metadata.getProviderId()).isEqualTo("Ericsson"); assertThat(metadata.getPackageVersion()).isEqualTo("1.0"); assertThat(metadata.getReleaseDateTime()).isEqualTo("2019-01-14T11:25:00+00:00"); - assertThat(errors.size()).isEqualTo(0); + assertThat(errors.size()).isZero(); } @@ -64,7 +66,7 @@ public class PnfManifestParserTest { 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") ); - assertThat(errors.size()).isEqualTo(0); + assertThat(errors.size()).isZero(); } @@ -81,7 +83,7 @@ public class PnfManifestParserTest { new SourcesParser.Source("some_file.sh", "", ""), new SourcesParser.Source("scripts/install.sh", "", "d0e7828293355a07c2dccaaa765c80b507e60e6167067c950dc2e6b0da0dbd8b"), new SourcesParser.Source("https://www.vendor_org.com/MRF/v4.1/scripts/scale/scale.sh", "SHA-256", "")); - assertThat(errors.size()).isEqualTo(0); + assertThat(errors.size()).isZero(); } @@ -90,25 +92,28 @@ public class PnfManifestParserTest { Pair<Map<String, Map<String, List<String>>>, List<CSARArchive.CSARError>> mapListPair = pnfManifestParser.fetchNonManoArtifacts().get(); Map<String, Map<String, List<String>>> nonManoArtifacts = mapListPair.getKey(); List<CSARArchive.CSARError> errors = mapListPair.getValue(); - - assertThat(nonManoArtifacts.get("onap_ves_events").get("source")) - .isEqualTo(Lists.newArrayList("Artifacts/Events/VES_registration.yml") - ); - assertThat(nonManoArtifacts.get("onap_pm_dictionary").get("source")) - .isEqualTo(Lists.newArrayList("Artifacts/Measurements/PM_Dictionary.yaml") - ); - assertThat(nonManoArtifacts.get("onap_yang_module").get("source")) - .isEqualTo(Lists.newArrayList("Artifacts/Yang_module/Yang_module.yaml") - ); - assertThat(nonManoArtifacts.get("onap_others").get("source")) - .isEqualTo(Lists.newArrayList( - "Artifacts/scripts/install.sh", + Map<String, List<String>>mapValue1=new HashMap<>(); + Map<String, List<String>>mapValue2=new HashMap<>(); + Map<String, List<String>>mapValue3=new HashMap<>(); + Map<String, List<String>>mapValue4=new HashMap<>(); + + mapValue1.put("", Collections.singletonList("")); + mapValue1.put("source",Lists.newArrayList("Artifacts/Events/VES_registration.yml")); + mapValue2.put("", Collections.singletonList("")); + mapValue2.put("source",Lists.newArrayList("Artifacts/Measurements/PM_Dictionary.yaml")); + mapValue3.put("", Collections.singletonList("")); + mapValue3.put("source",Lists.newArrayList("Artifacts/Yang_module/Yang_module.yaml")); + mapValue4.put("", Collections.singletonList("")); + mapValue4.put("source",Lists.newArrayList + ("Artifacts/scripts/install.sh", "Artifacts/Informational/user_guide.txt", "Artifacts/Other/installation_guide.txt", - "Artifacts/Other/review_log.txt" - ) - ); - assertThat(errors.size()).isEqualTo(0); + "Artifacts/Other/review_log.txt")); + assertThat(nonManoArtifacts).containsEntry("onap_ves_events",mapValue1); + assertThat(nonManoArtifacts).containsEntry("onap_pm_dictionary",mapValue2); + assertThat(nonManoArtifacts).containsEntry("onap_yang_module",mapValue3); + assertThat(nonManoArtifacts).containsEntry("onap_others",mapValue4); + assertThat(errors.size()).isZero(); } @@ -154,7 +159,7 @@ public class PnfManifestParserTest { "HhE7UbSCHDlDDgrOosJkbuI4UCX/njXrU2ukXbrWz/FjH84Mek039z+w4M6fBnl5"+ "4xuyO1o65LlKHoxwnRH9lQ==" ); - assertThat(errors.size()).isEqualTo(0); + assertThat(errors.size()).isZero(); } @Test @@ -214,6 +219,6 @@ public class PnfManifestParserTest { new SourcesParser.Source("Artifacts/Other/review_log.txt", "SHA-256", "36f945953929812aca2701b114b068c71bd8c95ceb3609711428c26325649165") ); - assertThat(errors.size()).isEqualTo(0); + assertThat(errors.size()).isZero(); } } diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/PnfMetadataParserTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/PnfMetadataParserTest.java index c409efc..4a08a5d 100644 --- a/csarvalidation/src/test/java/org/onap/cvc/csar/PnfMetadataParserTest.java +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/PnfMetadataParserTest.java @@ -122,7 +122,7 @@ public class PnfMetadataParserTest { //then List<CSARArchive.CSARError> errors = data.getRight(); - assertThat(errors.size()).isEqualTo(0); + assertThat(errors.size()).isZero(); } diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/PnfNonManoArtifactsParserTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/PnfNonManoArtifactsParserTest.java index 388a98f..2cd648a 100644 --- a/csarvalidation/src/test/java/org/onap/cvc/csar/PnfNonManoArtifactsParserTest.java +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/PnfNonManoArtifactsParserTest.java @@ -56,7 +56,7 @@ public class PnfNonManoArtifactsParserTest { pnfManifestParser.fetchNonManoArtifacts(); //then - assertThat(nonManoArtifacts.isPresent()).isFalse(); + assertThat(nonManoArtifacts).isNotPresent(); } @Test @@ -88,7 +88,7 @@ public class PnfNonManoArtifactsParserTest { //then List<CSARArchive.CSARError> errors = data.getRight(); - assertThat(errors.size()).isEqualTo(0); + assertThat(errors.size()).isZero(); } } diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/VnfManifestParserTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/VnfManifestParserTest.java index 91bb6b1..7fa73a7 100644 --- a/csarvalidation/src/test/java/org/onap/cvc/csar/VnfManifestParserTest.java +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/VnfManifestParserTest.java @@ -43,7 +43,7 @@ public class VnfManifestParserTest { CSARArchive.Manifest.Metadata metadata = metadataListPair.getKey(); List<CSARArchive.CSARError> errors = metadataListPair.getValue(); - assertThat(errors.size()).isEqualTo(0); + assertThat(errors.size()).isZero(); assertThat(metadata.getProductName()).isEqualTo(" vCSCF"); assertThat(metadata.getProviderId()).isEqualTo(" ZTE"); assertThat(metadata.getPackageVersion()).isEqualTo(" 1.0"); @@ -64,7 +64,7 @@ public class VnfManifestParserTest { 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") ); - assertThat(errors.size()).isEqualTo(0); + assertThat(errors.size()).isZero(); } @Test @@ -79,6 +79,6 @@ public class VnfManifestParserTest { "AQcBoFEET3icc87PK0nNK9ENqSxItVIoSa0o0S/ISczMs1ZIzkgsKk4tsQ0N1nUM" + "dvb05OXi5XLPLEtViMwvLVLwSE0sKlFIVHAqSk3MBkkBAJv0Fx0=" ); - assertThat(errors.size()).isEqualTo(0); + assertThat(errors.size()).isZero(); } } diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/IntegrationTestUtils.java b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/IntegrationTestUtils.java index 6f183d7..6d90b23 100644 --- a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/IntegrationTestUtils.java +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/IntegrationTestUtils.java @@ -87,4 +87,8 @@ public class IntegrationTestUtils { public static List<String> convertToMessagesList(List<CSARArchive.CSARError> errors) { return errors.stream().map(CSARArchive.CSARError::getMessage).collect(Collectors.toList()); } + + public static List<String> convertToFilesList(List<CSARArchive.CSARError> errors) { + return errors.stream().map(CSARArchive.CSARError::getFile).collect(Collectors.toList()); + } } diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR01123IntegrationTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR01123IntegrationTest.java new file mode 100644 index 0000000..a3112ce --- /dev/null +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR01123IntegrationTest.java @@ -0,0 +1,176 @@ +/* + * Copyright 2020 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.cc.sol004; + +import org.assertj.core.api.Condition; +import org.assertj.core.api.HamcrestCondition; +import org.junit.Before; +import org.junit.Test; +import org.onap.cvc.csar.CSARArchive; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.CoreMatchers.allOf; +import static org.hamcrest.CoreMatchers.containsString; +import static org.onap.cvc.csar.cc.sol004.IntegrationTestUtils.configureTestCase; +import static org.onap.cvc.csar.cc.sol004.IntegrationTestUtils.convertToMessagesList; + +public class VTPValidateCSARR01123IntegrationTest { + + private static final boolean IS_PNF = true; + private static final String TEST_CSAR_DIRECTORY = "pnf/r01123/"; + + private VTPValidateCSARR01123 testCase; + + @Before + public void setUp() { + testCase = new VTPValidateCSARR01123(); + } + + @Test + public void shouldReturnProperRequestNumber() { + assertThat(testCase.getVnfReqsNo()).isEqualTo("R01123"); + } + + @Test + public void shouldReportThatVendorNameAndVersionAreMissing() throws Exception { + // given + configureTestCase(testCase, TEST_CSAR_DIRECTORY + "csar-option1-invalid-noVendor.csar", "vtp-validate-csar-r01123.yaml", IS_PNF); + + // when + testCase.execute(); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(3); + assertThat(convertToMessagesList(errors)).contains( + "Missing. Entry [TOSCA-Meta-File-Version]", + "Missing. Entry [VNF Vendor details]", + "Missing. Entry [Created-by]" + ); + } + + @Test + public void shouldReportThatFileAvailableInCsarIsNotPresentInManifestSources() throws Exception { + // given + configureTestCase(testCase, TEST_CSAR_DIRECTORY + "csar-option1-invalid-noFileInManifest.csar", "vtp-validate-csar-r01123.yaml", IS_PNF); + + // when + testCase.execute(); + + Condition<String> containingMissingFiles = new HamcrestCondition<>(allOf( + containsString("TOSCA-Metadata/TOSCA.meta"), + containsString("Artifacts/Deployment/Yang_module/yang-module2.yang"), + containsString("Artifacts/Deployment/Yang_module/yang-module1.yang"), + containsString("Artifacts/Informational/user_guide.txt"), + containsString("Artifacts/sample-pnf.cert") + )); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(1); + assertThat(convertToMessagesList(errors)).haveExactly(1, containingMissingFiles); + } + + @Test + public void shouldReportThatFilePresentInManifestIsNotPresentInCsarFile() throws Exception { + // given + configureTestCase(testCase, TEST_CSAR_DIRECTORY + "csar-option1-invalid-missing-files.csar", "vtp-validate-csar-r01123.yaml", IS_PNF); + + // when + testCase.execute(); + + Condition<String> containingMissingFiles = new HamcrestCondition<>(allOf( + containsString("Definitions/a.yaml"), + containsString("Definitions/b.yaml") + )); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(1); + assertThat(convertToMessagesList(errors)).haveExactly(1, containingMissingFiles); + } + + @Test + public void shouldReportThatVendorNameIsMissingAndThatFileIsNotPresentInSource() throws Exception { + // given + configureTestCase(testCase, TEST_CSAR_DIRECTORY + "csar-option1-invalid-noVendor-noFileInManifest.csar", "vtp-validate-csar-r01123.yaml", IS_PNF); + + // when + testCase.execute(); + + Condition<String> containingMissingFiles = new HamcrestCondition<>(allOf( + containsString("Artifacts/Informational/user_guide.txt") + )); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(3); + assertThat(convertToMessagesList(errors)).contains( + "Missing. Entry [VNF Vendor details]", + "Missing. Entry [Created-by]" + ); + assertThat(convertToMessagesList(errors)).haveExactly(1, containingMissingFiles); + } + + @Test + public void shouldNotReportAnyErrorWhenAllFilesPresentInCsarArePresentInSources() throws Exception { + // given + configureTestCase(testCase, TEST_CSAR_DIRECTORY + "csar-option1-valid.csar", "vtp-validate-csar-r01123.yaml", IS_PNF); + + // when + testCase.execute(); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isZero(); + } + + @Test + public void shouldNotReportAnyErrorWhenValidCsarIsZippedWithCmsFile() throws Exception { + // given + configureTestCase(testCase, TEST_CSAR_DIRECTORY + "csar-option2-valid-with-cms.zip", "vtp-validate-csar-r01123.yaml", IS_PNF); + + // when + testCase.execute(); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isZero(); + } + + @Test + public void shouldReportThatFileIsNotPresentInSourcesWhenInvalidCsarFileIsZippedWithCmsFile() throws Exception { + // given + configureTestCase(testCase, TEST_CSAR_DIRECTORY + "csar-option2-invalid-with-cms.zip", "vtp-validate-csar-r01123.yaml", IS_PNF); + + // when + testCase.execute(); + + Condition<String> containingMissingFiles = new HamcrestCondition<>( + containsString("Artifacts/Informational/user_guide.txt") + ); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(1); + assertThat(convertToMessagesList(errors)).haveExactly(1, containingMissingFiles); + } + +} diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR10087IntegrationTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR10087IntegrationTest.java index 921e903..2cc739c 100644 --- a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR10087IntegrationTest.java +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR10087IntegrationTest.java @@ -63,6 +63,19 @@ public class VTPValidateCSARR10087IntegrationTest { } @Test + public void testWithoutTOSCAMetaDir() throws Exception { + // given + configureTestCase(testCase, "pnf/toscaMetaFile.csar", "vtp-validate-csar-r10087.yaml", IS_PNF); + + // when + testCase.execute(); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(7); + } + + @Test public void shouldReportThatDefinitionYAMLDoesNotExist() throws Exception { // given configureTestCase(testCase, "pnf/r10087/invalidEntryDefinitionsInToscaMeta.csar", "vtp-validate-csar-r10087.yaml", IS_PNF); diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR130206IntegrationTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR130206IntegrationTest.java index 036e169..2d6d058 100644 --- a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR130206IntegrationTest.java +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR130206IntegrationTest.java @@ -20,8 +20,10 @@ package org.onap.cvc.csar.cc.sol004; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; +import org.onap.cli.fw.error.OnapCommandException; import org.onap.cvc.csar.CSARArchive; +import java.net.URISyntaxException; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; @@ -49,24 +51,110 @@ public class VTPValidateCSARR130206IntegrationTest { "To verify signed package please please follow instructions from test/resources/README.txt file and comment @Ignore tag. " + "Use instructions for option 1. Test was created for manual verification." ) - public void manual_shouldValidateProperCsar() throws Exception { + public void manual_shouldValidateProperCsarWithCms() throws Exception { // given - configureTestCase(testCase, "pnf/r130206/csar-option1-valid.csar", "vtp-validate-csar-r130206.yaml", IS_PNF); + configureTestCase(testCase, "pnf/r130206/csar-cert-in-cms-valid.csar", "vtp-validate-csar-r130206.yaml", IS_PNF); // when testCase.execute(); // then List<CSARArchive.CSARError> errors = testCase.getErrors(); - assertThat(errors.size()).isEqualTo(0); + assertThat(errors.size()).isZero(); } @Test - public void shouldReportThatOnlySignatureIsInvalid() throws Exception { + @Ignore("It is impossible to write test which will always pass, because certificate used to sign the file has time validity." + + "To verify signed package please please follow instructions from test/resources/README.txt file and comment @Ignore tag. " + + "Use instructions for option 1. Test was created for manual verification." + ) + public void manual_shouldValidateCsarWithCertificateInToscaEtsiWithValidSignature() throws Exception { + + // given + configureTestCase(testCase, "pnf/r130206/csar-cert-in-tosca-valid.csar", "vtp-validate-csar-r130206.yaml", IS_PNF); + + // when + testCase.execute(); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isZero(); + } + + @Test + public void shouldReportWarningForMissingCertInCmsToscaMetaAndRootCatalogAndMissingHashCodesInManifest() + throws Exception{ + // given + configureTestCase(testCase, "pnf/r130206/csar-not-secure-warning.csar", "vtp-validate-csar-r130206.yaml", IS_PNF); + + // when + testCase.execute(); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(1); + assertThat(convertToMessagesList(errors)).contains( + "Warning. Consider adding package integrity and authenticity assurance according to ETSI NFV-SOL 004 Security Option 1" + ); + } + + @Test + public void shouldReturnNoErrorWhenCertIsOnlyInCmsAndAlgorithmAndHashesAreCorrect() + throws Exception{ + // given + configureTestCase(testCase, "pnf/r130206/csar-cert-in-cms.csar", "vtp-validate-csar-r130206.yaml", IS_PNF); + + // when + testCase.execute(); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(1); + assertThat(convertToMessagesList(errors)).contains( + "File has invalid signature!" + ); + } + + @Test + public void shouldReturnNoErrorWhenCertIsOnlyInToscaAndAlgorithmAndHashesAreCorrect() + throws Exception{ + // given + configureTestCase(testCase, "pnf/r130206/csar-cert-in-tosca.csar", "vtp-validate-csar-r130206.yaml", IS_PNF); + + // when + testCase.execute(); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(1); + assertThat(convertToMessagesList(errors)).contains( + "File has invalid signature!" + ); + } + + @Test + public void shouldReturnErrorWhenCsarContainsToscaFileHoweverToscaDoesNotContainsCertEntryAndAlgorithmAndHashesAreCorrect() + throws Exception{ + // given + configureTestCase(testCase, "pnf/r130206/csar-with-tosca-no-cert-entry.csar", "vtp-validate-csar-r130206.yaml", IS_PNF); + + // when + testCase.execute(); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(1); + assertThat(convertToMessagesList(errors)).contains( + "Unable to find ETSI-Entry-Certificate in Tosca file" + ); + } + @Test + public void shouldReturnErrorWhenCertIsOnlyInCmsHoweverHashesAreIncorrect() + throws Exception{ // given - configureTestCase(testCase, "pnf/r130206/csar-option1-validSection.csar", "vtp-validate-csar-r130206.yaml", IS_PNF); + configureTestCase(testCase, "pnf/r130206/csar-cert-in-cms-incorrect-hash.csar", "vtp-validate-csar-r130206.yaml", IS_PNF); // when testCase.execute(); @@ -75,52 +163,307 @@ public class VTPValidateCSARR130206IntegrationTest { List<CSARArchive.CSARError> errors = testCase.getErrors(); assertThat(errors.size()).isEqualTo(2); assertThat(convertToMessagesList(errors)).contains( - "File has invalid CMS signature!", - "Mismatch between contents of non-mano-artifact-sets and source files of the package" + "Source 'Artifacts/Other/my_script.csh' has wrong hash!", + "File has invalid signature!" ); } @Test - public void shouldReportErrorsForInvalidCsar() throws Exception { + public void shouldReturnErrorWhenCertIsOnlyInToscaHoweverHashesAreIncorrect() + throws Exception{ + // given + configureTestCase(testCase, "pnf/r130206/csar-cert-in-tosca-incorrect-hash.csar", "vtp-validate-csar-r130206.yaml", IS_PNF); + + // when + testCase.execute(); + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(2); + assertThat(convertToMessagesList(errors)).contains( + "Source 'Artifacts/Deployment/Measurements/PM_Dictionary.yml' has wrong hash!", + "File has invalid signature!" + ); + } + + @Test + public void shouldReturnErrorWhenCertIsOnlyInRootDirectoryHoweverHashesAreIncorrect() + throws Exception{ // given - configureTestCase(testCase, "pnf/r130206/csar-option1-invalid.csar", "vtp-validate-csar-r130206.yaml", IS_PNF); + configureTestCase(testCase, "pnf/r130206/csar-cert-in-root-incorrect-hash.csar", "vtp-validate-csar-r130206.yaml", IS_PNF); // when testCase.execute(); // then List<CSARArchive.CSARError> errors = testCase.getErrors(); - assertThat(errors.size()).isEqualTo(6); + assertThat(errors.size()).isEqualTo(3); assertThat(convertToMessagesList(errors)).contains( - "Unable to find CMS section in manifest!", - "Source 'Definitions/MainServiceTemplate.yaml' has wrong hash!", - "Source 'Artifacts/Other/my_script.csh' has hash, but unable to find algorithm tag!", - "Unable to calculate digest - file missing: Artifacts/NonExisting2.txt", - "Mismatch between contents of non-mano-artifact-sets and source files of the package", - "File has invalid CMS signature!" + "Source 'Artifacts/Deployment/Events/RadioNode_Pnf_v1.yaml' has wrong hash!", + "Unable to find ETSI-Entry-Certificate in Tosca file", + "Certificate present in root catalog despite the TOSCA.meta file" ); } + @Test + public void shouldReturnErrorWhenToscaEtsiEntryCertificatePointToNotExistingFile() + throws Exception{ + // given + configureTestCase(testCase, "pnf/r130206/csar-with-tosca-cert-pointing-non-existing-cert.csar", "vtp-validate-csar-r130206.yaml", IS_PNF); + + // when + testCase.execute(); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(2); + assertThat(convertToMessagesList(errors)).contains( + "Unable to find cert file defined by ETSI-Entry-Certificate!", + "Invalid value. Entry [Entry-Certificate]. Artifacts/sample-pnf.cert does not exist" + ); + } + + @Test + public void shouldReturnErrorWhenCertificateIsLocatedInCmsAndInTosca() + throws Exception{ + // given + configureTestCase(testCase, "pnf/r130206/csar-cert-in-cms-and-tosca.csar", "vtp-validate-csar-r130206.yaml", IS_PNF); + + // when + testCase.execute(); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(3); + assertThat(convertToMessagesList(errors)).contains( + "ETSI-Entry-Certificate entry in Tosca.meta is defined despite the certificate is included in the signature container", + "ETSI-Entry-Certificate certificate present despite the certificate is included in the signature container", + "File has invalid signature!" + ); + } @Test - public void shouldReportThanInVnfPackageCertFileWasNotDefined() throws Exception { + public void shouldReturnErrorWhenCertificateIsLocatedInCmsAndInToscaAndHashIsIncorrect() + throws Exception{ + // given + configureTestCase(testCase, "pnf/r130206/csar-cert-in-cms-and-tosca-incorrect-hash.csar", "vtp-validate-csar-r130206.yaml", IS_PNF); + // when + testCase.execute(); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(4); + assertThat(convertToMessagesList(errors)).contains( + "ETSI-Entry-Certificate entry in Tosca.meta is defined despite the certificate is included in the signature container", + "ETSI-Entry-Certificate certificate present despite the certificate is included in the signature container", + "Source 'Artifacts/Informational/user_guide.txt' has wrong hash!", + "File has invalid signature!" + ); + } + + @Test + public void shouldReturnErrorWhenCertificateIsLocatedInCmsAndInToscaAndInRootDirectory() + throws Exception{ // given - configureTestCase(testCase, "sample2.csar", "vtp-validate-csar-r130206.yaml", false); + configureTestCase(testCase, "pnf/r130206/csar-cert-in-cms-and-root-and-tosca.csar", "vtp-validate-csar-r130206.yaml", IS_PNF); // when testCase.execute(); // then List<CSARArchive.CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(4); assertThat(convertToMessagesList(errors)).contains( - "Unable to find cert file defined by Entry-Certificate!", - "Unable to find CMS section in manifest!", - "Missing. Entry [tosca_definitions_version]" + "ETSI-Entry-Certificate entry in Tosca.meta is defined despite the certificate is included in the signature container", + "ETSI-Entry-Certificate certificate present despite the certificate is included in the signature container", + "Certificate present in root catalog despite the certificate is included in the signature container", + "File has invalid signature!" ); } + @Test + public void shouldReturnErrorWhenCertificateIsLocatedInCmsAndInToscaAndInRootDirectoryAndHashIsIncorrect() + throws Exception{ + // given + configureTestCase(testCase, "pnf/r130206/csar-cert-in-cms-and-root-and-tosca-incorrect-hash.csar", "vtp-validate-csar-r130206.yaml", IS_PNF); + + // when + testCase.execute(); + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(5); + assertThat(convertToMessagesList(errors)).contains( + "ETSI-Entry-Certificate entry in Tosca.meta is defined despite the certificate is included in the signature container", + "ETSI-Entry-Certificate certificate present despite the certificate is included in the signature container", + "Certificate present in root catalog despite the certificate is included in the signature container", + "Source 'Artifacts/Informational/user_guide.txt' has wrong hash!", + "File has invalid signature!" + ); + } + + @Test + public void shouldReturnErrorWhenCertificateIsLocatedInCmsAndInRootDirectory() + throws Exception{ + // given + configureTestCase(testCase, "pnf/r130206/csar-cert-in-cms-and-root.csar", "vtp-validate-csar-r130206.yaml", IS_PNF); + + // when + testCase.execute(); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(2); + assertThat(convertToMessagesList(errors)).contains( + "Certificate present in root catalog despite the certificate is included in the signature container", + "File has invalid signature!" + ); + } + + @Test + public void shouldReturnErrorWhenCertificateIsLocatedInCmsAndInRootDirectoryAndHashIsIncorrect() + throws Exception{ + // given + configureTestCase(testCase, "pnf/r130206/csar-cert-in-cms-and-root-incorrect-hash.csar", "vtp-validate-csar-r130206.yaml", IS_PNF); + + // when + testCase.execute(); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(3); + assertThat(convertToMessagesList(errors)).contains( + "Certificate present in root catalog despite the certificate is included in the signature container", + "Source 'Artifacts/Informational/user_guide.txt' has wrong hash!", + "File has invalid signature!" + ); + } + + @Test + public void shouldReturnErrorWhenCertificateIsLocatedInToscaAndInRootDirectory() + throws Exception{ + // given + configureTestCase(testCase, "pnf/r130206/csar-cert-in-root-and-tosca.csar", "vtp-validate-csar-r130206.yaml", IS_PNF); + + // when + testCase.execute(); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(2); + assertThat(convertToMessagesList(errors)).contains( + "Certificate present in root catalog despite the TOSCA.meta file", + "File has invalid signature!" + ); + } + + @Test + public void shouldReturnErrorWhenCertificateIsLocatedInToscaAndInRootDirectoryAdnHashIsIncorrect() + throws Exception{ + // given + configureTestCase(testCase, "pnf/r130206/csar-cert-in-root-and-tosca-incorrect-hash.csar", "vtp-validate-csar-r130206.yaml", IS_PNF); + + // when + testCase.execute(); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(3); + assertThat(convertToMessagesList(errors)).contains( + "Certificate present in root catalog despite the TOSCA.meta file", + "Source 'Artifacts/Deployment/Yang_module/yang-module1.yang' has wrong hash!", + "File has invalid signature!" + ); + } + + @Test + public void shouldReturnNoErrorWhenCertificateIsLocatedInToscaAndInRootDirectoryHoweverEtsiEntryIsPointingCertificateInRoot() + throws Exception{ + // given + configureTestCase(testCase, "pnf/r130206/csar-cert-in-root-pointed-by-tosca.csar", "vtp-validate-csar-r130206.yaml", IS_PNF); + + // when + testCase.execute(); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(1); + assertThat(convertToMessagesList(errors)).contains( + "File has invalid signature!" + ); + } + + @Test + public void shouldReturnErrorWhenCertificateIsLocatedInToscaHoweverManifestDoesNotContainsCms() + throws Exception{ + // given + configureTestCase(testCase, "pnf/r130206/csar-cert-in-tosca-no-cms.csar", "vtp-validate-csar-r130206.yaml", IS_PNF); + + // when + testCase.execute(); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(1); + assertThat(convertToMessagesList(errors)).contains( + "Unable to find cms signature!" + ); + } + + @Test + public void shouldReturnErrorWhenCsarDoesNotContainsCmsAndCertsHoweverManifestContainsHash() + throws Exception{ + // given + configureTestCase(testCase, "pnf/r130206/csar-no-cms-no-cert-with-hash.csar", "vtp-validate-csar-r130206.yaml", IS_PNF); + + // when + testCase.execute(); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(1); + assertThat(convertToMessagesList(errors)).contains( + "Unable to find cms signature!" + ); + } + + @Test + public void shouldReturnNoCertificationErrorWhenCertIsOnlyInRoot() throws Exception { + + // given + configureTestCase(testCase, "pnf/r130206/csar-cert-in-root.csar", "vtp-validate-csar-r130206.yaml", IS_PNF); + + // when + testCase.execute(); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + + // This test returns other errors that are connected with missing tosca entry, + // in order to simplify testing, assertion only checks if certificate in root was found and used to validate CMS + assertThat(convertToMessagesList(errors)).contains( + "File has invalid signature!" + ); + } + + @Test + public void shouldReturnCertificateNotFoundErrorWhenCertIsNotPresentInCmsInRootAndTocsaDirectoryIsMissing() throws Exception { + + // given + configureTestCase(testCase, "pnf/r130206/csar-no-cert-no-tosca-dir.csar", "vtp-validate-csar-r130206.yaml", IS_PNF); + + // when + testCase.execute(); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + + // This test returns other errors that are connected with missing tosca entry, + // in order to simplify testing, assertion only checks if "certificate not found" error was reported + assertThat(convertToMessagesList(errors)).contains( + "Unable to find cert file!" + ); + } } diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR146092IntegrationTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR146092IntegrationTest.java index bf9b094..a10aa91 100644 --- a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR146092IntegrationTest.java +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR146092IntegrationTest.java @@ -19,10 +19,9 @@ package org.onap.cvc.csar.cc.sol004; import org.junit.Before; import org.junit.Test; -import org.onap.cvc.csar.CSARArchive; +import org.onap.cvc.csar.CSARArchive.CSARError; import java.util.List; -import org.onap.cvc.csar.CSARArchive.CSARError; import static org.assertj.core.api.Assertions.assertThat; import static org.onap.cvc.csar.cc.sol004.IntegrationTestUtils.configureTestCase; @@ -45,24 +44,38 @@ public class VTPValidateCSARR146092IntegrationTest { } @Test - public void shouldDoNotReportErrorWhenNonManoArtifactIsNotAvailable() throws Exception { + public void shouldNotReportErrorWhenCSARValid() throws Exception { + //given + configureTestCase(testCase, "pnf/r146092/validFile.csar", + "vtp-validate-csar-r146092.yaml", IS_PNF); + + // when + testCase.execute(); + + // then + final List<CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isZero(); + } + + @Test + public void shouldNotReportErrorWhenNonManoArtifactIsNotAvailable() throws Exception { // given configureTestCase(testCase, "pnf/r146092/missingNonManoArtifactInManifest.csar", - "vtp-validate-csar-r146092.yaml", IS_PNF); + "vtp-validate-csar-r146092.yaml", IS_PNF); // when testCase.execute(); // then final List<CSARError> errors = testCase.getErrors(); - assertThat(errors.size()).isEqualTo(0); + assertThat(errors.size()).isZero(); } @Test public void shouldReportThatMandatoryNonManoArtifactSetEntryHasNotAllFields() throws Exception { // given configureTestCase(testCase, "pnf/r146092/missingFieldsInNonManoArtifactManifest.csar", - "vtp-validate-csar-r146092.yaml", IS_PNF); + "vtp-validate-csar-r146092.yaml", IS_PNF); // when testCase.execute(); @@ -71,7 +84,7 @@ public class VTPValidateCSARR146092IntegrationTest { final List<CSARError> errors = testCase.getErrors(); assertThat(errors.size()).isEqualTo(1); assertThat(convertToMessagesList(errors)).contains( - "Missing. Entry [[onap_ansible_playbooks, onap_others, onap_pm_dictionary, onap_pnf_sw_information, onap_scripts, onap_ves_events, onap_yang_modules]]" + "Missing. Entry [[onap_ansible_playbooks, onap_others, onap_pm_dictionary, onap_pnf_sw_information, onap_scripts, onap_ves_events, onap_yang_modules]]" ); } @@ -79,7 +92,7 @@ public class VTPValidateCSARR146092IntegrationTest { public void shouldReportThatNonManoArtifactEntryHasAnySource() throws Exception { // given configureTestCase(testCase, "pnf/r146092/noSourceElementInNonManoArtifactEntryManifest.csar", - "vtp-validate-csar-r146092.yaml", IS_PNF); + "vtp-validate-csar-r146092.yaml", IS_PNF); // when testCase.execute(); @@ -88,7 +101,7 @@ public class VTPValidateCSARR146092IntegrationTest { final List<CSARError> errors = testCase.getErrors(); assertThat(errors.size()).isEqualTo(1); assertThat(convertToMessagesList(errors)).contains( - "Missing. Entry [Source under onap_ves_events]" + "Missing. Entry [Source under onap_ves_events]" ); } @@ -104,7 +117,7 @@ public class VTPValidateCSARR146092IntegrationTest { final List<CSARError> errors = testCase.getErrors(); assertThat(errors.size()).isEqualTo(1); assertThat(convertToMessagesList(errors)).contains( - "Invalid. Entry [Source under onap_ves_events has invalid 'Artifacts/Deployment/Events/RadioNode.yml' path]" + "Invalid. Entry [Source under onap_ves_events has invalid 'Artifacts/Deployment/Events/RadioNode.yml' path]" ); } @@ -120,7 +133,7 @@ public class VTPValidateCSARR146092IntegrationTest { final List<CSARError> errors = testCase.getErrors(); assertThat(errors.size()).isEqualTo(4); assertThat(convertToMessagesList(errors)).contains( - "Missing. Entry [Definition YAML]" + "Missing. Entry [Definition YAML]" ); } @@ -128,7 +141,7 @@ public class VTPValidateCSARR146092IntegrationTest { public void shouldReportThatEntryHasInvalidPathWhenYamlFileIsNotPresent() throws Exception { // given configureTestCase(testCase, "pnf/r146092/missingYamlFileReferedInSourceSessionOfManifest.csar", "vtp-validate-csar-r146092.yaml", - IS_PNF); + IS_PNF); // when testCase.execute(); @@ -137,7 +150,7 @@ public class VTPValidateCSARR146092IntegrationTest { final List<CSARError> errors = testCase.getErrors(); assertThat(errors.size()).isEqualTo(1); assertThat(convertToMessagesList(errors)).contains( - "Invalid. Entry [Source under onap_pnf_sw_information has invalid 'Files/pnf-sw-information/pnf-sw-information.yaml' path]" + "Invalid. Entry [Source under onap_pnf_sw_information has invalid 'Files/pnf-sw-information/pnf-sw-information.yaml' path]" ); } diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR293901IntegrationTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR293901IntegrationTest.java index 2835772..2b9b4f4 100644 --- a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR293901IntegrationTest.java +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR293901IntegrationTest.java @@ -71,7 +71,7 @@ public class VTPValidateCSARR293901IntegrationTest { // then List<CSARArchive.CSARError> errors = testCase.getErrors(); - assertThat(errors.size()).isEqualTo(0); + assertThat(errors.size()).isZero(); } @Test diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR57019IntegrationTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR57019IntegrationTest.java index 088eab7..d6d06b3 100644 --- a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR57019IntegrationTest.java +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR57019IntegrationTest.java @@ -73,7 +73,7 @@ public class VTPValidateCSARR57019IntegrationTest { // then List<CSARArchive.CSARError> errors = testCase.getErrors(); - assertThat(errors.size()).isEqualTo(0); + assertThat(errors.size()).isZero(); } @Test diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR787965IntegrationTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR787965IntegrationTest.java index 49696e6..33a1754 100644 --- a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR787965IntegrationTest.java +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR787965IntegrationTest.java @@ -76,7 +76,7 @@ public class VTPValidateCSARR787965IntegrationTest { // then List<CSARArchive.CSARError> errors = testCase.getErrors(); - assertThat(errors.size()).isEqualTo(0); + assertThat(errors.size()).isZero(); } @Test @@ -111,7 +111,7 @@ public class VTPValidateCSARR787965IntegrationTest { // then List<CSARArchive.CSARError> errors = testCase.getErrors(); - assertThat(errors.size()).isEqualTo(0); + assertThat(errors.size()).isZero(); } } diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR816745IntegrationTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR816745IntegrationTest.java new file mode 100644 index 0000000..17e9de3 --- /dev/null +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR816745IntegrationTest.java @@ -0,0 +1,229 @@ +/* + * Copyright 2020 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.cc.sol004; + +import org.assertj.core.api.Condition; +import org.assertj.core.api.HamcrestCondition; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.onap.cvc.csar.CSARArchive; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.CoreMatchers.allOf; +import static org.hamcrest.CoreMatchers.containsString; +import static org.onap.cvc.csar.cc.sol004.IntegrationTestUtils.configureTestCase; +import static org.onap.cvc.csar.cc.sol004.IntegrationTestUtils.convertToMessagesList; +import static org.onap.cvc.csar.cc.sol004.IntegrationTestUtils.convertToFilesList; + +public class VTPValidateCSARR816745IntegrationTest { + + private static final boolean IS_PNF = true; + private static final String TEST_CSAR_DIRECTORY = "pnf/r816745/"; + private static final int NUMBER_OF_EXPECTED_ERRORS = 4; + private static final String LETTER_S_WITH_ASCII_CODE = "s(115)"; + + private VTPValidateCSARR816745 testCase; + + @Rule + public ExpectedException exceptionRule = ExpectedException.none(); + + @Before + public void setUp() { + testCase = new VTPValidateCSARR816745(); + } + + @Test + public void shouldAddPmDictionaryLoadingErrorWhenPmDictionaryHaveNoSourceInManifest() throws Exception { + // given + configureTestCase(testCase, TEST_CSAR_DIRECTORY + "csar-with-missing-source-value-for-pm-dictionary-in-manifest.csar", "vtp-validate-csar-r816745.yaml", IS_PNF); + + // when + testCase.execute(); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(1); + assertThat(convertToMessagesList(errors)).contains("Fail to load PM_Dictionary With error: onap_pm_dictionary in manifest does not contains key 'Source'"); + } + + @Test + public void shouldNotReportAnyErrorWhenCsarIsNotContainingPmDictionary() throws Exception { + // given + configureTestCase(testCase, TEST_CSAR_DIRECTORY + "csar-with-no-pm-dictionary.csar", "vtp-validate-csar-r816745.yaml", IS_PNF); + + // when + testCase.execute(); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isZero(); + } + + @Test + public void shouldReturnNoErrorsWhenCsarContainsValidPmDictionary() throws Exception { + // given + configureTestCase(testCase, TEST_CSAR_DIRECTORY + "csar-with-valid-pm-dictionary.csar", "vtp-validate-csar-r816745.yaml", IS_PNF); + + // when + testCase.execute(); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(0); + } + + @Test + public void shouldReturnNoErrorsWhenZipContainsCsarWithValidPmDictionary() throws Exception { + // given + configureTestCase(testCase, TEST_CSAR_DIRECTORY + "zip-with-valid-pm-dictionary.zip", "vtp-validate-csar-r816745.yaml", IS_PNF); + + // when + testCase.execute(); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(0); + } + + @Test + public void shouldReturnListOfErrorsWhenCsarContainsInvalidPmDictionary() throws Exception { + // given + configureTestCase(testCase, TEST_CSAR_DIRECTORY + "csar-with-invalid-pm-dictionary.csar", "vtp-validate-csar-r816745.yaml", IS_PNF); + + // when + testCase.execute(); + + // then + assertThatReturnedErrorsAreCorrect(testCase.getErrors()); + } + + @Test + public void shouldReturnListOfErrorsWhenZipContainsCsarWithInvalidPmDictionary() throws Exception { + // given + configureTestCase(testCase, TEST_CSAR_DIRECTORY + "zip-with-invalid-pm-dictionary.zip", "vtp-validate-csar-r816745.yaml", IS_PNF); + + // when + testCase.execute(); + + // then + assertThatReturnedErrorsAreCorrect(testCase.getErrors()); + } + + @Test + public void shouldAddPmDictionaryLoadingErrorWhenGivenInvalidPath() throws Exception { + // given + configureTestCase(testCase, TEST_CSAR_DIRECTORY + "csar-with-empty-pm-dictionary.csar", "vtp-validate-csar-r816745.yaml", IS_PNF); + + // when then + testCase.execute(); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(1); + assertThat(convertToMessagesList(errors)).contains("Fail to load PM_Dictionary With error: PM_Dictionary YAML file is empty"); + } + + @Test + public void shouldReturnListContainingOneErrorsWhenCsarContainsPmDictionaryWithInvalidKeyMapping() throws Exception { + // given + configureTestCase(testCase, TEST_CSAR_DIRECTORY + "csar-with-invalid-pm-dictionary-invalid-mapping.csar", "vtp-validate-csar-r816745.yaml", IS_PNF); + + // when + testCase.execute(); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(1); + assertThat(convertToMessagesList(errors).get(0)).contains( + "Fail to load PM_Dictionary With error: mapping values are not allowed here" + ); + } + + @Test + public void shouldReturnListContainingOneErrorsWhenCsarContainsPmDictionaryWithIncorrectEscapeCharacter() throws Exception { + // given + configureTestCase(testCase, TEST_CSAR_DIRECTORY + "csar-with-invalid-pm-dictionary-unknown-escape-character.csar", "vtp-validate-csar-r816745.yaml", IS_PNF); + + // when + testCase.execute(); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(1); + assertThat(convertToMessagesList(errors).get(0)).contains( + "Fail to load PM_Dictionary With error: while scanning a double-quoted scalar", + "found unknown escape character " + LETTER_S_WITH_ASCII_CODE + ); + } + + @Test + public void shouldReturnProperRequestNumber() { + assertThat(testCase.getVnfReqsNo()).isEqualTo("R816745"); + } + + private void assertThatReturnedErrorsAreCorrect(List<CSARArchive.CSARError> errors) { + assertThat(errors.size()).isEqualTo(NUMBER_OF_EXPECTED_ERRORS); + + Condition<String> containingSameFileForAllErrors = new HamcrestCondition<>( + containsString("Artifacts/Deployment/Measurements/PM_Dictionary.yml") + ); + assertThat(convertToFilesList(errors)) + .haveExactly(NUMBER_OF_EXPECTED_ERRORS, containingSameFileForAllErrors); + + Condition<String> containingErrorForMissingValueInFirstDocument = new HamcrestCondition<>(allOf( + containsString("Invalid YAML document in PM_Dictionary file."), + containsString("In document number 1"), + containsString("Path: /pmMetaData/pmFields/"), + containsString("Key not found: measChangeType") + )); + assertThat(convertToMessagesList(errors)).haveExactly(1, containingErrorForMissingValueInFirstDocument); + + Condition<String> containingErrorForWrongValueInFirstDocument = new HamcrestCondition<>(allOf( + containsString("Invalid YAML document in PM_Dictionary file."), + containsString("In document number 1"), + containsString("Path: /pmMetaData/pmFields/measResultType"), + containsString("Value(s) is/are not in array of accepted values."), + containsString("value(s): integer"), + containsString("accepted value(s): [float, uint32, uint64]") + )); + assertThat(convertToMessagesList(errors)).haveExactly(1, containingErrorForWrongValueInFirstDocument); + + Condition<String> containingErrorForMissingValueInSecondDocument = new HamcrestCondition<>(allOf( + containsString("Invalid YAML document in PM_Dictionary file."), + containsString("In document number 2"), + containsString("Path: /pmMetaData/pmFields/"), + containsString("Key not found: measChangeType") + )); + assertThat(convertToMessagesList(errors)).haveExactly(1, containingErrorForMissingValueInSecondDocument); + + Condition<String> containingErrorForWrongValueInArrayInThirdDocument = new HamcrestCondition<>(allOf( + containsString("Invalid YAML document in PM_Dictionary file."), + containsString("In document number 3"), + containsString("Path: /pmMetaData/pmFields/measAdditionalFields/vendorField1"), + containsString("Value(s) is/are not in array of accepted values."), + containsString("value(s): [Z, A]"), + containsString("accepted value(s): [X, Y, Z]") + )); + assertThat(convertToMessagesList(errors)).haveExactly(1, containingErrorForWrongValueInArrayInThirdDocument); + } + +} diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR972082IntegrationTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR972082IntegrationTest.java index fb9e431..868fad2 100644 --- a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR972082IntegrationTest.java +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR972082IntegrationTest.java @@ -21,10 +21,12 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.onap.cvc.csar.cc.sol004.IntegrationTestUtils.configureTestCase; import static org.onap.cvc.csar.cc.sol004.IntegrationTestUtils.convertToMessagesList; +import java.net.URISyntaxException; import java.util.List; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; +import org.onap.cli.fw.error.OnapCommandException; import org.onap.cvc.csar.CSARArchive; import org.onap.cvc.csar.CSARArchive.CSARError; @@ -55,7 +57,37 @@ public class VTPValidateCSARR972082IntegrationTest { // then final List<CSARError> errors = testCase.getErrors(); - assertThat(errors.size()).isEqualTo(0); + assertThat(errors.size()).isZero(); + } + + @Test + public void shouldReturnErrorWhenFileExtensionIsNotYaml() throws Exception { + // given + configureTestCase(testCase, PNF_R_972082 + "fileExtensionOfArtifactIsNotYaml.csar", VTP_VALIDATE_CSAR_R_972082_YAML, IS_PNF); + + // when + testCase.execute(); + + // then + final List<CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(1); + assertThat(convertToMessagesList(errors)).contains( + "Invalid. File extension Files/pnf-sw-information/pnf-sw-information.json is invalid" + ); + } + + @Test + public void shouldReturnNoErrorWhenOptionalNonManoArtifactSetEntryIsNotPresent() throws Exception { + // given + configureTestCase(testCase, PNF_R_972082 + "missingOnapPnfSwInformationArtifactSetEntry.csar", + VTP_VALIDATE_CSAR_R_972082_YAML, IS_PNF); + + // when + testCase.execute(); + + // then + final List<CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isZero(); } @Test @@ -77,9 +109,9 @@ public class VTPValidateCSARR972082IntegrationTest { } @Test - public void shouldReportThatMandatoryNonManoArtifactSetEntryHasNotAllFields_() throws Exception { + public void shouldReportMissingPnfSoftwareVersionInYamlFile() throws Exception { // given - configureTestCase(testCase, PNF_R_972082 + "missingFieldsInNonManoArtifactManifest.csar", + configureTestCase(testCase, PNF_R_972082 + "missingPnfSoftwareVersionInYamlFile.csar", VTP_VALIDATE_CSAR_R_972082_YAML, IS_PNF); // when @@ -89,15 +121,15 @@ public class VTPValidateCSARR972082IntegrationTest { final List<CSARError> errors = testCase.getErrors(); assertThat(errors.size()).isEqualTo(1); assertThat(convertToMessagesList(errors)).contains( - "Missing. Entry [[onap_pnf_sw_information]]" + "Missing. Entry [pnf_software_version in Files/pnf-sw-information/pnf-sw-information.yaml]" ); } @Test - public void shouldReportMissingPnfSoftwareVersionInYamlFile() throws Exception { + public void shouldReportMissingSourceElementUnderAttribute() throws OnapCommandException, URISyntaxException { // given - configureTestCase(testCase, PNF_R_972082 + "missingPnfSoftwareVersionInYamlFile.csar", - VTP_VALIDATE_CSAR_R_972082_YAML, IS_PNF); + configureTestCase(testCase, PNF_R_972082 + "missingSourceElementUnderAttributeError.csar", + VTP_VALIDATE_CSAR_R_972082_YAML, IS_PNF); // when testCase.execute(); @@ -106,8 +138,24 @@ public class VTPValidateCSARR972082IntegrationTest { final List<CSARError> errors = testCase.getErrors(); assertThat(errors.size()).isEqualTo(1); assertThat(convertToMessagesList(errors)).contains( - "Missing. Entry [pnf_software_version in Files/pnf-sw-information/pnf-sw-information.yaml]" + "Missing. Entry [Source under onap_pnf_sw_information]" ); } + @Test + public void shouldReportInvalidYamlStructure() throws OnapCommandException, URISyntaxException { + // given + configureTestCase(testCase, PNF_R_972082 + "invalidYamlStructure.csar", + VTP_VALIDATE_CSAR_R_972082_YAML, IS_PNF); + + // when + testCase.execute(); + + // then + final List<CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(1); + assertThat(convertToMessagesList(errors)).contains( + "Invalid. Yaml file Files/pnf-sw-information/pnf-sw-information.yaml is invalid" + ); + } }
\ No newline at end of file diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/security/ShaHashCodeGeneratorTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/security/ShaHashCodeGeneratorTest.java index 1ea5dd5..b5c4efa 100644 --- a/csarvalidation/src/test/java/org/onap/cvc/csar/security/ShaHashCodeGeneratorTest.java +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/security/ShaHashCodeGeneratorTest.java @@ -39,8 +39,9 @@ public class ShaHashCodeGeneratorTest { final String hashCode = shaHashCodeGenerator.generateSha256("test".getBytes()); - assertThat(hashCode).isEqualTo(shaHashCodeGenerator.generateSha256("test".getBytes())); - assertThat(hashCode).isNotEqualTo(shaHashCodeGenerator.generateSha256("Test".getBytes())); + assertThat(hashCode) + .isEqualTo(shaHashCodeGenerator.generateSha256("test".getBytes())) + .isNotEqualTo(shaHashCodeGenerator.generateSha256("Test".getBytes())); } @Test @@ -48,7 +49,8 @@ public class ShaHashCodeGeneratorTest { final String hashCode = shaHashCodeGenerator.generateSha512("test".getBytes()); - assertThat(hashCode).isEqualTo(shaHashCodeGenerator.generateSha512("test".getBytes())); - assertThat(hashCode).isNotEqualTo(shaHashCodeGenerator.generateSha512("Test".getBytes())); + assertThat(hashCode) + .isEqualTo(shaHashCodeGenerator.generateSha512("test".getBytes())) + .isNotEqualTo(shaHashCodeGenerator.generateSha512("Test".getBytes())); } }
\ No newline at end of file diff --git a/csarvalidation/src/test/java/org/onap/functional/CsarValidationUtility.java b/csarvalidation/src/test/java/org/onap/functional/CsarValidationUtility.java new file mode 100644 index 0000000..24ef778 --- /dev/null +++ b/csarvalidation/src/test/java/org/onap/functional/CsarValidationUtility.java @@ -0,0 +1,65 @@ +/** + * Copyright 2020 Nokia + * <p> + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.functional; + +import com.google.gson.Gson; +import org.onap.cli.fw.output.OnapCommandResult; +import org.onap.functional.cli.OnapCliValidationResponseWrapper; +import org.onap.functional.cli.OnapCliWrapper; + +import java.util.Arrays; + +import static org.assertj.core.api.Assertions.assertThat; + +public final class CsarValidationUtility { + + private static final int NOR_ERROR_CODE = 0; + private static final String UNKNOWN_LINE_NUMBER = "-1"; + private static final String UNKNOWN_FILE = ""; + + private CsarValidationUtility(){} + + public static final String CERTIFICATION_RULE = "r130206"; + public static final String OPERATION_STATUS_FAILED = "FAILED"; + public static final String OPERATION_STATUS_PASS = "PASS"; + + public static OnapCliValidationResponseWrapper getCliCommandValidationResult(OnapCliWrapper cli) { + final OnapCommandResult onapCommandResult = cli.getCommandResult(); + return new Gson().fromJson(onapCommandResult.getOutput().toString(), OnapCliValidationResponseWrapper.class); + } + + public static OnapCliValidationResponseWrapper.ValidationResultWrapper.ValidationErrorWrapper createExpectedError( + String rule, String errorCode, String errorMessage + ) { + return new OnapCliValidationResponseWrapper.ValidationResultWrapper.ValidationErrorWrapper( + rule.toUpperCase(), errorCode, + errorMessage, + UNKNOWN_FILE, UNKNOWN_LINE_NUMBER + ); + } + + public static boolean ruleHaveOneOfCodes(String ruleCode, String... codes ) { + return Arrays.asList(codes).contains(ruleCode); + } + + public static void verifyThatOperationFinishedWithoutAnyError(OnapCliWrapper cli) { + assertThat(cli.getExitCode()).isEqualTo(NOR_ERROR_CODE); + } + + + +} diff --git a/csarvalidation/src/test/java/org/onap/functional/PnfValidationFunctionalTest.java b/csarvalidation/src/test/java/org/onap/functional/PnfValidationFunctionalTest.java new file mode 100644 index 0000000..903691e --- /dev/null +++ b/csarvalidation/src/test/java/org/onap/functional/PnfValidationFunctionalTest.java @@ -0,0 +1,132 @@ +/** + * Copyright 2020 Nokia + * <p> + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.functional; + +import org.junit.Test; +import org.onap.functional.cli.OnapCliValidationResponseWrapper; +import org.onap.functional.cli.OnapCliWrapper; + +import java.net.URISyntaxException; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.onap.cvc.csar.cc.sol004.IntegrationTestUtils.absoluteFilePath; +import static org.onap.functional.CsarValidationUtility.CERTIFICATION_RULE; +import static org.onap.functional.CsarValidationUtility.OPERATION_STATUS_FAILED; +import static org.onap.functional.CsarValidationUtility.OPERATION_STATUS_PASS; +import static org.onap.functional.CsarValidationUtility.createExpectedError; +import static org.onap.functional.CsarValidationUtility.getCliCommandValidationResult; +import static org.onap.functional.CsarValidationUtility.verifyThatOperationFinishedWithoutAnyError; + + +public class PnfValidationFunctionalTest { + + @Test + public void shouldReportOnlyWarningWhenCsarDoNotHaveCertificateAndHashesInManifest() throws URISyntaxException { + // given + OnapCliValidationResponseWrapper.ValidationResultWrapper.ValidationErrorWrapper expectedWarning = + createExpectedError(CERTIFICATION_RULE, "0x1006", + "Warning. Consider adding package integrity and authenticity assurance according to ETSI NFV-SOL 004 Security Option 1"); + + OnapCliWrapper cli = new OnapCliWrapper(createPnfValidationRequestInfo( "pnf/validFile.csar")); + + // when + cli.handle(); + + // then + final OnapCliValidationResponseWrapper result = getCliCommandValidationResult(cli); + + assertThat(result.criteria).isEqualTo(OPERATION_STATUS_PASS); + result.results.forEach((ruleValidationResult)->{ + assertThat(ruleValidationResult.errors).hasSize(0); + if (ruleValidationResult.vnfreqName.equals(CERTIFICATION_RULE)) { + assertThat(ruleValidationResult.warnings) + .hasSize(1) + .containsOnly(expectedWarning); + } else { + assertThat(ruleValidationResult.warnings).hasSize(0); + } + }); + verifyThatOperationFinishedWithoutAnyError(cli); + } + + @Test + public void shouldNotReportThatPnfValidationFailedWhenZipDoNotHaveCertificatesAndHashesInManifest() throws URISyntaxException { + // given + OnapCliWrapper cli = new OnapCliWrapper(createPnfValidationRequestInfo( "pnf/signed-package-valid-signature.zip")); + + // when + cli.handle(); + + // then + final OnapCliValidationResponseWrapper result = getCliCommandValidationResult(cli); + + assertThat(result.criteria).isEqualTo(OPERATION_STATUS_PASS); + verifyThatOperationFinishedWithoutAnyError(cli); + } + + @Test + public void shouldReportThatPnfValidationFailedWhenCsarContainsCertificateInCmsAndInToscaAndInRootAndHashIsIncorrect_allOtherRulesShouldPass() throws URISyntaxException { + // given + + List<OnapCliValidationResponseWrapper.ValidationResultWrapper.ValidationErrorWrapper> expectedErrors = + List.of( + createExpectedError(CERTIFICATION_RULE, "0x4007", + "File has invalid signature!"), + createExpectedError(CERTIFICATION_RULE, "0x4004", + "Source 'Files/pnf-sw-information/pnf-sw-information.yaml' has wrong hash!"), + createExpectedError(CERTIFICATION_RULE, "0x4011", + "ETSI-Entry-Certificate entry in Tosca.meta is defined despite the certificate is included in the signature container"), + createExpectedError(CERTIFICATION_RULE, "0x4012", + "ETSI-Entry-Certificate certificate present despite the certificate is included in the signature container"), + createExpectedError(CERTIFICATION_RULE, "0x4013", + "Certificate present in root catalog despite the certificate is included in the signature container") + ); + OnapCliWrapper cli = new OnapCliWrapper(createPnfValidationRequestInfo( "pnf/r130206/cert-in-cms-and-root-and-tosca-incorrect-hash.csar")); + + // when + cli.handle(); + + // then + final OnapCliValidationResponseWrapper result = getCliCommandValidationResult(cli); + + assertThat(result.criteria).isEqualTo(OPERATION_STATUS_FAILED); + result.results.forEach((ruleValidationResult)->{ + assertThat(ruleValidationResult.warnings).hasSize(0); + if (ruleValidationResult.vnfreqName.equals(CERTIFICATION_RULE)) { + assertThat(ruleValidationResult.errors) + .hasSize(5) + .containsAll(expectedErrors); + } else { + assertThat(ruleValidationResult.errors).hasSize(0); + } + }); + verifyThatOperationFinishedWithoutAnyError(cli); + } + + private String[] createPnfValidationRequestInfo(String csarPath) throws URISyntaxException { + return new String[]{ + "--product", "onap-dublin", + "csar-validate", + "--format", "json", + "--pnf", + "--csar", absoluteFilePath(csarPath) + }; + } + + +} diff --git a/csarvalidation/src/test/java/org/onap/functional/VnfValidationFunctionalTest.java b/csarvalidation/src/test/java/org/onap/functional/VnfValidationFunctionalTest.java new file mode 100644 index 0000000..adaea59 --- /dev/null +++ b/csarvalidation/src/test/java/org/onap/functional/VnfValidationFunctionalTest.java @@ -0,0 +1,75 @@ +/** + * Copyright 2017 Huawei Technologies Co., Ltd. + * Copyright 2020 Nokia + * <p> + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.functional; + +import org.junit.Test; +import org.onap.functional.cli.OnapCliValidationResponseWrapper; +import org.onap.functional.cli.OnapCliWrapper; + +import java.net.URISyntaxException; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.onap.cvc.csar.cc.sol004.IntegrationTestUtils.absoluteFilePath; +import static org.onap.functional.CsarValidationUtility.OPERATION_STATUS_FAILED; +import static org.onap.functional.CsarValidationUtility.getCliCommandValidationResult; +import static org.onap.functional.CsarValidationUtility.ruleHaveOneOfCodes; +import static org.onap.functional.CsarValidationUtility.verifyThatOperationFinishedWithoutAnyError; + +public class VnfValidationFunctionalTest { + + + @Test + public void shouldReportThanVnfValidationFailed() throws URISyntaxException { + // given + OnapCliWrapper cli = new OnapCliWrapper(createVnfValidationRequestInfo("VoLTE.csar")); + + // when + cli.handle(); + + // then + final OnapCliValidationResponseWrapper result = getCliCommandValidationResult(cli); + assertThat(result.criteria).isEqualTo(OPERATION_STATUS_FAILED); + result.results.forEach((ruleValidationResult)->{ + if ( ruleHaveOneOfCodes(ruleValidationResult.vnfreqName, + "r01123", "r09467") + ) { + assertThat(ruleValidationResult.errors) + .hasSize(2); + } else if ( ruleHaveOneOfCodes(ruleValidationResult.vnfreqName, + "r21322","r26885","r43958" ,"r66070","r130206") + ) { + assertThat(ruleValidationResult.errors) + .hasSize(1); + } else { + assertThat(ruleValidationResult.errors).hasSize(0); + } + }); + + verifyThatOperationFinishedWithoutAnyError(cli); + } + + private String[] createVnfValidationRequestInfo(String csarPath) throws URISyntaxException { + return new String[]{ + "--product", "onap-dublin", + "csar-validate", + "--format", "json", + "--csar", absoluteFilePath(csarPath) + }; + } + +} diff --git a/csarvalidation/src/test/java/org/onap/functional/cli/OnapCliValidationResponseWrapper.java b/csarvalidation/src/test/java/org/onap/functional/cli/OnapCliValidationResponseWrapper.java new file mode 100644 index 0000000..d011a6e --- /dev/null +++ b/csarvalidation/src/test/java/org/onap/functional/cli/OnapCliValidationResponseWrapper.java @@ -0,0 +1,84 @@ +/** + * Copyright 2020 Nokia + * <p> + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.functional.cli; + + +import java.util.List; +import java.util.Objects; + +public class OnapCliValidationResponseWrapper { + + public final VnfDataWrapper vnf; + public final String data; + public final String criteria; + public final List<ValidationResultWrapper> results; + public final String contact; + public final String platform; + + public OnapCliValidationResponseWrapper(VnfDataWrapper vnf, String data, String criteria, List<ValidationResultWrapper> results, String contact, String platform) { + this.vnf = vnf; + this.data = data; + this.criteria = criteria; + this.results = results; + this.contact = contact; + this.platform = platform; + } + + public static class VnfDataWrapper { + public String name; + public String vendor; + public String version; + public String type; + public String mode; + } + + public static class ValidationResultWrapper { + public Boolean passed; + public String vnfreqName; + public String description; + public List<ValidationErrorWrapper> errors; + public List<ValidationErrorWrapper> warnings; + + public static class ValidationErrorWrapper { + public String vnfreqNo; + public String code; + public String message; + public String file; + public String lineNumber; + + public ValidationErrorWrapper(String vnfreqNo, String code, String message, String file, String lineNumber) { + this.vnfreqNo = vnfreqNo; + this.code = code; + this.message = message; + this.file = file; + this.lineNumber = lineNumber; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + return o.hashCode() == this.hashCode(); + } + + @Override + public int hashCode() { + return Objects.hash(vnfreqNo, code, message, file, lineNumber); + } + } + } +} diff --git a/csarvalidation/src/test/java/org/onap/functional/cli/OnapCliWrapper.java b/csarvalidation/src/test/java/org/onap/functional/cli/OnapCliWrapper.java new file mode 100644 index 0000000..b5cf589 --- /dev/null +++ b/csarvalidation/src/test/java/org/onap/functional/cli/OnapCliWrapper.java @@ -0,0 +1,42 @@ +/** + * Copyright 2020 Nokia + * <p> + * 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.functional.cli; + + +import org.onap.cli.fw.cmd.OnapCommand; +import org.onap.cli.fw.error.OnapCommandException; +import org.onap.cli.fw.output.OnapCommandResult; +import org.onap.cli.main.OnapCli; + +public class OnapCliWrapper extends OnapCli { + + private OnapCommandResult commandResult; + + public OnapCliWrapper(String[] args) { + super(args); + } + + @Override + public void handleTracking(OnapCommand cmd) throws OnapCommandException { + super.handleTracking(cmd); + this.commandResult = cmd.getResult(); + } + + public OnapCommandResult getCommandResult() { + return this.commandResult; + } +} diff --git a/csarvalidation/src/test/java/org/onap/validation/csarvalidationtest/CsarValidatorTest.java b/csarvalidation/src/test/java/org/onap/validation/csar/CsarValidatorTest.java index f9a8d8a..bd363fc 100644 --- a/csarvalidation/src/test/java/org/onap/validation/csarvalidationtest/CsarValidatorTest.java +++ b/csarvalidation/src/test/java/org/onap/validation/csar/CsarValidatorTest.java @@ -1,27 +1,30 @@ -/** +/* * Copyright 2017 Huawei Technologies Co., Ltd. - * + * Copyright 2020 Nokia + * <p> * 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 - * + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> * 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.validation.csarvalidationtest; +package org.onap.validation.csar; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; import java.io.File; import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -31,11 +34,12 @@ import java.util.regex.Pattern; import java.util.zip.ZipException; import java.util.zip.ZipFile; -import org.junit.Test; -import org.onap.validation.csar.CommonConstants; -import org.onap.validation.csar.CsarValidator; -import org.onap.validation.csar.FileUtil; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; + +@RunWith(MockitoJUnitRunner.class) public class CsarValidatorTest { String regex = "^\\/[a-zA-Z]\\:\\/"; @@ -156,12 +160,20 @@ public class CsarValidatorTest { } @Test - public void testCloseInputStream() { + public void testCloseInputStreamForNonExistingDirectory() { InputStream dir = null; FileUtil.closeInputStream(dir); assertTrue(true); } + @Test(expected = ValidationException.class) + public void testCloseInputStream() throws IOException { + InputStream inputStream = mock(InputStream.class); + Mockito.doThrow(new IOException()).when(inputStream).close(); + FileUtil.closeInputStream(inputStream); + assertTrue(true); + } + @Test public void testCloseZipFile() throws ZipException, IOException { File file = new File(sample1); @@ -170,10 +182,19 @@ public class CsarValidatorTest { assertTrue(true); } - @Test - public void testCloseFileStream() throws FileNotFoundException { + @Test(expected = IOException.class) + public void testCloseFileStream() throws IOException { FileInputStream dir3 = new FileInputStream(sample1); FileUtil.closeFileStream(dir3); + dir3.available(); + + } + + @Test(expected = ValidationException.class) + public void testCloseFileStream_reportErrorWhenIOExceptionOccurs() throws IOException { + FileInputStream fileInputStream = mock(FileInputStream.class); + Mockito.doThrow(new IOException()).when(fileInputStream).close(); + FileUtil.closeFileStream(fileInputStream); } @Test @@ -186,6 +207,14 @@ public class CsarValidatorTest { } }; FileUtil.closeOutputStream(dir4); + assertTrue(true); + } + + @Test(expected = ValidationException.class) + public void testCloseOutptutStream_reportErrorWhenIOExceptionOccurs() throws IOException { + OutputStream outputStream = mock(OutputStream.class); + Mockito.doThrow(new IOException()).when(outputStream).close(); + FileUtil.closeOutputStream(outputStream); } private void testValidateCsarMeta(CsarValidator cv) { @@ -219,4 +248,44 @@ public class CsarValidatorTest { String result = CsarValidator.r02454(); assertEquals(true, result == CommonConstants.SUCCESS_STR); } + + @Test + public void testValidateCsar_csarMetaFailed() { + CsarValidator.CsarValidatorSeam csarValidatorSeam = mock(CsarValidator.CsarValidatorSeam.class); + Mockito.when(csarValidatorSeam.validateCsarMeta()).thenReturn("FAIL"); + Mockito.when(csarValidatorSeam.validateAndScanToscaMeta()).thenReturn("SUCCESS"); + Mockito.when(csarValidatorSeam.validateMainService()).thenReturn("FAIL"); + + + String res=CsarValidator.validateCsarContent(csarValidatorSeam); + assertEquals("FAIL OR FAIL",res); + + } + + @Test + public void testValidateCsar_toscaMetaFailed() { + CsarValidator.CsarValidatorSeam csarValidatorSeam = mock(CsarValidator.CsarValidatorSeam.class); + Mockito.when(csarValidatorSeam.validateCsarMeta()).thenReturn("SUCCESS"); + Mockito.when(csarValidatorSeam.validateAndScanToscaMeta()).thenReturn("FAIL"); + Mockito.when(csarValidatorSeam.validateMainService()).thenReturn("SUCCESS"); + + + String res=CsarValidator.validateCsarContent(csarValidatorSeam); + assertEquals("FAIL",res); + } + + @Test + public void testDeleteDir(){ + String dstPath = "./dstPathForTest1"; + File dst = new File(dstPath); + dst.mkdir(); + assertTrue(FileUtil.deleteFile(dstPath)); + } + + @Test + public void testCreateDirectory() { + String dirPath = "src//test//resources//TestDirectory"; + boolean res = FileUtil.createDirectory(dirPath); + assertTrue(res); + } } diff --git a/csarvalidation/src/test/java/org/onap/validation/csarvalidationtest/ValidationExceptionTest.java b/csarvalidation/src/test/java/org/onap/validation/csar/ValidationExceptionTest.java index 8ab498e..fcbc439 100644 --- a/csarvalidation/src/test/java/org/onap/validation/csarvalidationtest/ValidationExceptionTest.java +++ b/csarvalidation/src/test/java/org/onap/validation/csar/ValidationExceptionTest.java @@ -1,20 +1,21 @@ -/** - * Copyright 2017 Huawei Technologies Co., Ltd. +/* + * Copyright 2020 Nokia * <p> * 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 * <p> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> * 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.validation.csarvalidationtest; +package org.onap.validation.csar; import static org.junit.Assert.assertTrue; diff --git a/csarvalidation/src/test/java/org/onap/validation/yaml/YamlFileValidatorTest.java b/csarvalidation/src/test/java/org/onap/validation/yaml/YamlFileValidatorTest.java new file mode 100644 index 0000000..f89cc68 --- /dev/null +++ b/csarvalidation/src/test/java/org/onap/validation/yaml/YamlFileValidatorTest.java @@ -0,0 +1,117 @@ +/* + * Copyright 2020 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.validation.yaml; + +import org.assertj.core.util.Lists; +import org.junit.Test; +import org.onap.validation.yaml.error.YamlDocumentValidationError; +import org.onap.validation.yaml.exception.YamlProcessingException; +import org.yaml.snakeyaml.parser.ParserException; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class YamlFileValidatorTest { + + @Test + public void shouldReturnCorrectErrorsWhenGivenPathToValidPmDictionaryFile() throws YamlProcessingException { + // given + String path = getFullPathForGivenResources(YamlLoadingUtils.PATH_TO_VALID_YAML); + + // when + List<YamlDocumentValidationError> validationErrors = + new YamlFileValidator().validateYamlFileWithSchema(path); + + // then + assertValidationReturnedExpectedErrors(validationErrors); + + } + + @Test + public void shouldReturnCorrecErrorsWhenGivenPathToValidJsonStylePmDictionaryFile() throws YamlProcessingException { + // given + String path = getFullPathForGivenResources(YamlLoadingUtils.PATH_TO_VALID_JSON_STYLE_YAML); + + // when + List<YamlDocumentValidationError> validationErrors = + new YamlFileValidator().validateYamlFileWithSchema(path); + + // then + assertValidationReturnedExpectedErrors(validationErrors); + } + + + private void assertValidationReturnedExpectedErrors(List<YamlDocumentValidationError> validationErrors) { + assertThat(validationErrors).isNotNull(); + assertThat(validationErrors).hasSize(4); + assertThat(validationErrors).usingRecursiveFieldByFieldElementComparator().containsAll( + Lists.list( + new YamlDocumentValidationError(1, + "/pmMetaData/pmFields/measResultType", + "Value(s) is/are not in array of accepted values.\n" + + " value(s): integer\n" + + " accepted value(s): [float, uint32, uint64]"), + new YamlDocumentValidationError(1, + "/pmMetaData/pmFields/", + "Key not found: measChangeType"), + new YamlDocumentValidationError(2, + "/pmMetaData/pmFields/", + "Key not found: measChangeType"), + new YamlDocumentValidationError(3, + "/pmMetaData/pmFields/measAdditionalFields/vendorField1", + "Value(s) is/are not in array of accepted values.\n" + + " value(s): [Z, A]\n" + + " accepted value(s): [X, Y, Z]") + ) + ); + } + @Test + public void shouldThrowErrorWhenGivenPathToInvalidPmDictionaryFile() { + // given + String path = getFullPathForGivenResources(YamlLoadingUtils.PATH_TO_MULTI_DOCUMENT_INVALID_YAML); + // when then + assertThatThrownBy(() -> + new YamlFileValidator().validateYamlFileWithSchema(path) + ).isInstanceOf(ParserException.class) + .hasMessageContaining( + "expected the node content, but found '<document end>'" + ); + } + + @Test + public void shouldThrowErrorWhenGivenInvalidPath() { + // given + String path ="invalid/path/to/pm_dictionary"; + + // when then + assertThatThrownBy(() -> + new YamlFileValidator().validateYamlFileWithSchema(path) + ).isInstanceOf(YamlProcessingException.class) + .hasMessageContaining( + "PM_Dictionary YAML file is empty" + ); + } + + private String getFullPathForGivenResources(String pathToValidYaml) { + return this.getClass().getClassLoader().getResource( + pathToValidYaml + ).getPath(); + } +} diff --git a/csarvalidation/src/test/java/org/onap/validation/yaml/YamlLoaderTest.java b/csarvalidation/src/test/java/org/onap/validation/yaml/YamlLoaderTest.java new file mode 100644 index 0000000..4c68d60 --- /dev/null +++ b/csarvalidation/src/test/java/org/onap/validation/yaml/YamlLoaderTest.java @@ -0,0 +1,99 @@ +/* + * Copyright 2020 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.validation.yaml; + +import org.junit.Test; +import org.onap.validation.yaml.exception.YamlProcessingException; +import org.onap.validation.yaml.model.YamlDocument; +import org.onap.validation.yaml.model.YamlDocumentFactory; +import org.yaml.snakeyaml.parser.ParserException; +import org.yaml.snakeyaml.scanner.ScannerException; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + + +public class YamlLoaderTest { + + private static final int EXPECTED_NUMBER_OF_DOCUMENTS = 5; + private static final String LETTER_S_WITH_ASCII_CODE = "s(115)"; + + @Test + public void shouldLoadAllDocumentsFromYamlFile() throws YamlDocumentFactory.YamlDocumentParsingException { + // when + List<YamlDocument> documents = YamlLoadingUtils.loadValidMultiDocumentYamlFile(); + + // then + assertThat(documents).hasSize(EXPECTED_NUMBER_OF_DOCUMENTS); + } + + @Test + public void shouldLoadAllDocumentsFromJsonStyleYamlFile() throws YamlDocumentFactory.YamlDocumentParsingException { + // when + List<YamlDocument> documents = YamlLoadingUtils.loadValidJsonStyleMultiDocumentYamlFile(); + + // then + assertThat(documents).hasSize(EXPECTED_NUMBER_OF_DOCUMENTS); + } + + @Test + public void shouldLoadAllDocumentsFromYamlFileUsingPathInString() throws YamlProcessingException { + // when + List<YamlDocument> documents = YamlLoadingUtils.loadValidMultiDocumentYamlFileUsingStringPath(); + + // then + assertThat(documents).hasSize(EXPECTED_NUMBER_OF_DOCUMENTS); + } + + @Test + public void shouldThrowExceptionWhenLoadingDocumentsFromInvalidYamlFile() { + // when then + assertThatThrownBy(YamlLoadingUtils::tryToLoadMultiDocumentInvalidYamlFile + ).isInstanceOf(ParserException.class) + .hasMessageContaining("expected the node content, but found '<document end>'"); + } + + @Test + public void shouldThrowExceptionWhenLoadingDocumentsFromInvalidYamlFileUsingPathInString() { + // when then + assertThatThrownBy(YamlLoadingUtils::tryToLoadMultiDocumentInvalidYamlFileUsingStringPath + ).isInstanceOf(ParserException.class) + .hasMessageContaining("expected the node content, but found '<document end>'"); + } + + + @Test + public void shouldThrowExceptionWhenLoadingInvalidYamlFileWithIncorrectKeyMapping() { + // when then + assertThatThrownBy(YamlLoadingUtils::tryToLoadInvalidYamlFileWithIncorrectKeyMapping + ).isInstanceOf(ScannerException.class) + .hasMessageContaining("mapping values are not allowed here"); + } + + + @Test + public void shouldThrowExceptionWhenLoadingInvalidYamlFileWithUnknownEscapeCharacter() { + // when then + assertThatThrownBy(YamlLoadingUtils::tryToLoadInvalidYamlFileWithUnknownEscapeCharacter + ).isInstanceOf(ScannerException.class) + .hasMessageContaining("found unknown escape character " + LETTER_S_WITH_ASCII_CODE); + } + +} diff --git a/csarvalidation/src/test/java/org/onap/validation/yaml/YamlLoadingUtils.java b/csarvalidation/src/test/java/org/onap/validation/yaml/YamlLoadingUtils.java new file mode 100644 index 0000000..8d03910 --- /dev/null +++ b/csarvalidation/src/test/java/org/onap/validation/yaml/YamlLoadingUtils.java @@ -0,0 +1,94 @@ +/* + * Copyright 2020 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.validation.yaml; + +import org.onap.validation.yaml.exception.YamlProcessingException; +import org.onap.validation.yaml.model.YamlDocument; + +import java.net.URL; +import java.util.List; + +import static org.onap.validation.yaml.model.YamlDocumentFactory.YamlDocumentParsingException; + +public final class YamlLoadingUtils { + + private YamlLoadingUtils() {} + + public static final int VALID_YAML_DOCUMENT_INDEX = 4; + public static final int YAML_DOCUMENT_WITH_WRONG_VALUE_IN_ARRAY_INDEX = 3; + public static final int YAML_DOCUMENT_WITH_MISSING_FIELD_INDEX = 2; + public static final int YAML_DOCUMENT_WITH_MISSING_FIELD_AND_WRONG_VALUE_INDEX = 1; + + static final String PATH_TO_VALID_YAML = "yaml_schema/PM_Dictionary.yaml"; + static final String PATH_TO_VALID_JSON_STYLE_YAML = "yaml_schema/PM_Dictionary_JSON_Style.yaml"; + private static final String PATH_TO_SIMPLE_VALID_SCHEMA = "yaml_schema/Simple_Valid_Schema.yaml"; + private static final String PATH_TO_SIMPLE_VALID_SCHEMA_MULTI_ROOT = "yaml_schema/Simple_Valid_Schema_Multi_Root.yaml"; + private static final String PATH_TO_SIMPLE_INVALID_SCHEMA = "yaml_schema/Simple_Invalid_Schema_Construction.yaml"; + private static final String PATH_TO_SIMPLE_INVALID_SCHEMA_FOR_LAZY_LOADING = "yaml_schema/Simple_Invalid_Schema_LazyLoading.yaml"; + static final String PATH_TO_MULTI_DOCUMENT_INVALID_YAML = "yaml_schema/Multi_Document_Invalid.yaml"; + private static final String PATH_TO_INVALID_YAML_WITH_INCORRECT_KEY_MAPPING = "yaml_schema/Simple_Invalid_Mapping_Value.yaml"; + private static final String PATH_TO_INVALID_YAML_WITH_UNKNOWN_ESCAPE_CHARACTER = "yaml_schema/Simple_Unknown_Escape_Character.yaml"; + + public static List<YamlDocument> loadValidMultiDocumentYamlFile() throws YamlDocumentParsingException { + return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_VALID_YAML)); + } + + public static List<YamlDocument> loadValidJsonStyleMultiDocumentYamlFile() throws YamlDocumentParsingException { + return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_VALID_JSON_STYLE_YAML)); + } + + public static List<YamlDocument> loadValidMultiDocumentYamlFileUsingStringPath() throws YamlProcessingException { + return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_VALID_YAML).getPath()); + } + + public static YamlDocument loadSimpleValidYamlSchemaFile() throws YamlDocumentParsingException { + return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_SIMPLE_VALID_SCHEMA)).get(0); + } + + public static YamlDocument loadSimpleInvalidYamlSchemaFile() throws YamlDocumentParsingException { + return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_SIMPLE_INVALID_SCHEMA)).get(0); + } + + public static YamlDocument loadSimpleInvalidYamlSchemaForLazyLoadingFile() throws YamlDocumentParsingException { + return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_SIMPLE_INVALID_SCHEMA_FOR_LAZY_LOADING)).get(0); + } + + public static YamlDocument loadSimpleValidYamlSchemaWithMultiRootFile() throws YamlDocumentParsingException { + return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_SIMPLE_VALID_SCHEMA_MULTI_ROOT)).get(0); + } + + public static List<YamlDocument> tryToLoadMultiDocumentInvalidYamlFile() throws YamlDocumentParsingException { + return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_MULTI_DOCUMENT_INVALID_YAML)); + } + + public static List<YamlDocument> tryToLoadMultiDocumentInvalidYamlFileUsingStringPath() throws YamlProcessingException { + return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_MULTI_DOCUMENT_INVALID_YAML).getPath()); + } + + public static List<YamlDocument> tryToLoadInvalidYamlFileWithIncorrectKeyMapping() throws YamlDocumentParsingException { + return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_INVALID_YAML_WITH_INCORRECT_KEY_MAPPING)); + } + + public static List<YamlDocument> tryToLoadInvalidYamlFileWithUnknownEscapeCharacter() throws YamlDocumentParsingException { + return new YamlLoader().loadMultiDocumentYamlFile(getUrlForGivenPath(PATH_TO_INVALID_YAML_WITH_UNKNOWN_ESCAPE_CHARACTER)); + } + + private static URL getUrlForGivenPath(String path) { + return YamlLoadingUtils.class.getClassLoader().getResource(path); + } +} diff --git a/csarvalidation/src/test/java/org/onap/validation/yaml/YamlValidatorTest.java b/csarvalidation/src/test/java/org/onap/validation/yaml/YamlValidatorTest.java new file mode 100644 index 0000000..efe9d69 --- /dev/null +++ b/csarvalidation/src/test/java/org/onap/validation/yaml/YamlValidatorTest.java @@ -0,0 +1,123 @@ +/* + * Copyright 2020 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.validation.yaml; + +import org.assertj.core.util.Lists; +import org.junit.Test; +import org.onap.validation.yaml.exception.YamlProcessingException; +import org.onap.validation.yaml.error.SchemaValidationError; +import org.onap.validation.yaml.model.YamlDocument; +import org.onap.validation.yaml.schema.YamlSchemaFactory; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.onap.validation.yaml.YamlLoadingUtils.VALID_YAML_DOCUMENT_INDEX; +import static org.onap.validation.yaml.YamlLoadingUtils.YAML_DOCUMENT_WITH_MISSING_FIELD_INDEX; +import static org.onap.validation.yaml.YamlLoadingUtils.YAML_DOCUMENT_WITH_MISSING_FIELD_AND_WRONG_VALUE_INDEX; +import static org.onap.validation.yaml.YamlLoadingUtils.YAML_DOCUMENT_WITH_WRONG_VALUE_IN_ARRAY_INDEX; + +public class YamlValidatorTest { + + + @Test + public void shouldCreateValidatorUsingSchemaLoadedFromYamlFileAndValidatedJsonStyleDocumentsFromThatFile() + throws YamlProcessingException { + + // given + List<YamlDocument> documents = YamlLoadingUtils.loadValidJsonStyleMultiDocumentYamlFile(); + YamlValidator validator = new YamlValidator(new YamlSchemaFactory().createTreeStructuredYamlSchema(documents.get(0))); + Map<Integer,List<SchemaValidationError>> validationErrors = new HashMap<>(); + + // when + for (int documentIndex = 1 ; documentIndex < documents.size() ; documentIndex++) { + validationErrors.put(documentIndex, validator.validate(documents.get(documentIndex))); + } + + // then + assertValidatorReturnedCorrectErrors(validationErrors); + } + + @Test + public void shouldCreateValidatorUsingSchemaLoadedFromYamlFileAndValidatedDocumentsFromThatFile() + throws YamlProcessingException { + + // given + List<YamlDocument> documents = YamlLoadingUtils.loadValidMultiDocumentYamlFile(); + YamlValidator validator = new YamlValidator(new YamlSchemaFactory().createTreeStructuredYamlSchema(documents.get(0))); + Map<Integer,List<SchemaValidationError>> validationErrors = new HashMap<>(); + + // when + for (int documentIndex = 1 ; documentIndex < documents.size() ; documentIndex++) { + validationErrors.put(documentIndex, validator.validate(documents.get(documentIndex))); + } + + // then + assertValidatorReturnedCorrectErrors(validationErrors); + } + + private void assertValidatorReturnedCorrectErrors(Map<Integer, List<SchemaValidationError>> validationErrors) { + + SchemaValidationError expectedValidationValueError = + new SchemaValidationError( + "/pmMetaData/pmFields/measResultType", + "Value(s) is/are not in array of accepted values.\n" + + " value(s): integer\n" + + " accepted value(s): [float, uint32, uint64]" + ); + SchemaValidationError expectedValidationKeyError = + new SchemaValidationError( + "/pmMetaData/pmFields/", + "Key not found: measChangeType" + ); + SchemaValidationError expectedValidationValuesInArrayError = + new SchemaValidationError( + "/pmMetaData/pmFields/measAdditionalFields/vendorField1", + "Value(s) is/are not in array of accepted values.\n" + + " value(s): [Z, A]\n" + + " accepted value(s): [X, Y, Z]" + ); + + assertThat(validationErrors.size()).isEqualTo(4); + assertThat(validationErrors).containsKeys(1,2,3); + assertThat(validationErrors.get(YAML_DOCUMENT_WITH_MISSING_FIELD_AND_WRONG_VALUE_INDEX)).hasSize(2); + assertThat(validationErrors.get(YAML_DOCUMENT_WITH_MISSING_FIELD_AND_WRONG_VALUE_INDEX)) + .usingFieldByFieldElementComparator() + .containsAll( + Lists.list( + expectedValidationValueError, + expectedValidationKeyError + )); + assertThat(validationErrors.get(YAML_DOCUMENT_WITH_MISSING_FIELD_INDEX)).hasSize(1); + assertThat(validationErrors.get(YAML_DOCUMENT_WITH_MISSING_FIELD_INDEX)) + .usingFieldByFieldElementComparator() + .contains( + expectedValidationKeyError + ); + assertThat(validationErrors.get(YAML_DOCUMENT_WITH_WRONG_VALUE_IN_ARRAY_INDEX)).hasSize(1); + assertThat(validationErrors.get(YAML_DOCUMENT_WITH_WRONG_VALUE_IN_ARRAY_INDEX)) + .usingFieldByFieldElementComparator() + .contains( + expectedValidationValuesInArrayError + ); + assertThat(validationErrors.get(VALID_YAML_DOCUMENT_INDEX)).hasSize(0); + } + +} diff --git a/csarvalidation/src/test/java/org/onap/validation/yaml/model/YamlDocumentFactoryTest.java b/csarvalidation/src/test/java/org/onap/validation/yaml/model/YamlDocumentFactoryTest.java new file mode 100644 index 0000000..7879d4e --- /dev/null +++ b/csarvalidation/src/test/java/org/onap/validation/yaml/model/YamlDocumentFactoryTest.java @@ -0,0 +1,154 @@ +/* + * Copyright 2020 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.validation.yaml.model; + +import org.assertj.core.util.Lists; +import org.junit.Test; + +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.onap.validation.yaml.model.YamlDocumentFactory.YamlDocumentParsingException; + +public class YamlDocumentFactoryTest { + + @Test + public void shouldTurnMapOfUnknownKeyTypeToMapWithStringKeysAndBeAbleToReturnStringifyValues() + throws YamlDocumentParsingException { + // given + Map<Object, Object> inputMap = new HashMap<>(); + List<String> testList = Lists.list("element1", "element11"); + Map<Object, Object> testEmptyMap = Collections.emptyMap(); + + inputMap.put("test", testList); + inputMap.put(345, "element2"); + inputMap.put("test2", "element3"); + inputMap.put(2.67, testEmptyMap); + + // when + YamlDocument document = new YamlDocumentFactory().createYamlDocument(inputMap); + + // then + assertThat(document).isNotNull(); + assertThat(document.getYaml()).containsKeys("test", "345", "test2", "2.67"); + + assertThat(document.getYaml()).containsEntry("test", testList); + assertThat(document.getValue("test")).isEqualTo("[element1, element11]"); + + assertThat(document.getValue("345")).isEqualTo("element2"); + assertThat(document.getValue("test2")).isEqualTo("element3"); + + assertThat(document.getYaml()).containsEntry("2.67", testEmptyMap); + assertThat(document.getValue("2.67")).isEqualTo("{}"); + } + + @Test + public void shouldTurnMapOfUnknownKeyTypeToMapWithStringKeysAndBeAbleToExtractSubStructure() + throws YamlDocumentParsingException { + // given + Map<Object, Object> inputMap = new HashMap<>(); + Map<Object, Object> subStructureMap = new HashMap<>(); + + inputMap.put("test", "element1"); + inputMap.put("structure", subStructureMap); + + subStructureMap.put("subTest1", "subElement1"); + subStructureMap.put("subTest2", "subElement2"); + + // when + YamlDocument document = new YamlDocumentFactory().createYamlDocument(inputMap); + + // then + assertThat(document).isNotNull(); + assertThat(document.getYaml()).containsKeys("test", "structure"); + assertThat(document.getValue("test")).isEqualTo("element1"); + + assertThat(document.getSubStructure("structure")).isNotNull(); + assertThat(document.getSubStructure("structure").getValue("subTest1")).isEqualTo("subElement1"); + assertThat(document.getSubStructure("structure").getValue("subTest2")).isEqualTo("subElement2"); + } + + @Test + public void shouldTurnMapOfUnknownKeyTypeToMapWithStringKeysAndBeAbleToExtractParametersList() + throws YamlDocumentParsingException { + // given + Map<Object, Object> inputMap = new HashMap<>(); + List<String> parametersList = new LinkedList<>(); + + inputMap.put("test", "element1"); + inputMap.put("parameters", parametersList); + + parametersList.add("parameter1"); + parametersList.add("parameter2"); + + // when + YamlDocument document = new YamlDocumentFactory().createYamlDocument(inputMap); + + // then + assertThat(document).isNotNull(); + assertThat(document.getYaml()).containsKeys("test", "parameters"); + assertThat(document.getValue("test")).isEqualTo("element1"); + + assertThat(document.getListOfValues("parameters")).isNotNull(); + assertThat(document.getListOfValues("parameters").getParameters()).contains("parameter1","parameter2"); + } + + @Test + public void shouldThrowExceptionIfGetSubStructureIsCalledOnList() + throws YamlDocumentParsingException { + // given + Map<Object, Object> inputMap = new HashMap<>(); + List<String> testList = Lists.list("element1", "element2"); + + inputMap.put("test", testList); + + YamlDocument document = new YamlDocumentFactory().createYamlDocument(inputMap); + + // when then + assertThatThrownBy(() -> + document.getSubStructure("test") + ).isInstanceOf(YamlDocumentParsingException.class) + .hasMessageContaining( + String.format("Fail to parse given objects: %s as yaml document", testList) + ); + } + + @Test + public void shouldThrowExceptionIfGetSubStructureIsCalledOnString() + throws YamlDocumentParsingException { + // given + Map<Object, Object> inputMap = new HashMap<>(); + + inputMap.put("test", "testElement"); + + YamlDocument document = new YamlDocumentFactory().createYamlDocument(inputMap); + + // when then + assertThatThrownBy(() -> + document.getSubStructure("test") + ).isInstanceOf(YamlDocumentParsingException.class) + .hasMessageContaining( + String.format("Fail to parse given objects: %s as yaml document.", "testElement") + ); + } +} diff --git a/csarvalidation/src/test/java/org/onap/validation/yaml/model/YamlParameterListFactoryTest.java b/csarvalidation/src/test/java/org/onap/validation/yaml/model/YamlParameterListFactoryTest.java new file mode 100644 index 0000000..34e61c5 --- /dev/null +++ b/csarvalidation/src/test/java/org/onap/validation/yaml/model/YamlParameterListFactoryTest.java @@ -0,0 +1,81 @@ +/* + * Copyright 2020 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.validation.yaml.model; + +import org.assertj.core.util.Lists; +import org.junit.Test; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +public class YamlParameterListFactoryTest { + + @Test + public void shouldCreateEmptyParametersList() { + // when + YamlParametersList parametersList = new YamlParameterListFactory().createEmptyYamlParameterList(); + + // then + assertThat(parametersList).isNotNull(); + assertThat(parametersList.getParameters()).isEmpty(); + } + + @Test + public void shouldCreateParametersListContainingStringsFromListContainingSimpleTypes() { + // given + List<Object> testList = Lists.list("test1",3,23.45,'a',"test2"); + + // when + YamlParametersList parametersList = new YamlParameterListFactory().createYamlParameterList(testList); + + // then + assertThat(parametersList).isNotNull(); + assertThat(parametersList.getParameters()).hasSize(5); + assertThat(parametersList.getParameters()).contains("test1","test2","3","23.45","a"); + } + + @Test + public void shouldCreateParametersListContainingStringsFromListContainingVariousTypes() { + // given + List<Object> testList = Lists.list("test1",3,Lists.list(2,3,4),"test2"); + + // when + YamlParametersList parametersList = new YamlParameterListFactory().createYamlParameterList(testList); + + // then + assertThat(parametersList).isNotNull(); + assertThat(parametersList.getParameters()).hasSize(4); + assertThat(parametersList.getParameters()).contains("test1","test2","3","[2, 3, 4]"); + } + + @Test + public void shouldCreateListWithOneStringWhenGivenObjectIsNotList() { + // given + Object testObject = "test"; + + // when + YamlParametersList parametersList = new YamlParameterListFactory().createYamlParameterList(testObject); + + // then + assertThat(parametersList).isNotNull(); + assertThat(parametersList.getParameters()).hasSize(1); + assertThat(parametersList.getParameters()).contains("test"); + } + +} diff --git a/csarvalidation/src/test/java/org/onap/validation/yaml/process/YamlValidationProcessTest.java b/csarvalidation/src/test/java/org/onap/validation/yaml/process/YamlValidationProcessTest.java new file mode 100644 index 0000000..12fe9ec --- /dev/null +++ b/csarvalidation/src/test/java/org/onap/validation/yaml/process/YamlValidationProcessTest.java @@ -0,0 +1,101 @@ +/* + * Copyright 2020 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.validation.yaml.process; + +import org.junit.Test; +import org.onap.validation.yaml.YamlLoadingUtils; +import org.onap.validation.yaml.exception.YamlProcessingException; +import org.onap.validation.yaml.error.SchemaValidationError; +import org.onap.validation.yaml.model.YamlDocument; +import org.onap.validation.yaml.schema.YamlSchema; +import org.onap.validation.yaml.schema.YamlSchemaFactory; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.onap.validation.yaml.YamlLoadingUtils.VALID_YAML_DOCUMENT_INDEX; +import static org.onap.validation.yaml.YamlLoadingUtils.YAML_DOCUMENT_WITH_MISSING_FIELD_INDEX; +import static org.onap.validation.yaml.YamlLoadingUtils.YAML_DOCUMENT_WITH_MISSING_FIELD_AND_WRONG_VALUE_INDEX; + + +public class YamlValidationProcessTest { + + @Test + public void shouldReturnNoErrorWhenProcessingValidPmDictionaryYaml() + throws YamlProcessingException { + // given + List<YamlDocument> documents = YamlLoadingUtils.loadValidMultiDocumentYamlFile(); + YamlSchema schema = new YamlSchemaFactory().createTreeStructuredYamlSchema(documents.get(0)); + YamlDocument document = documents.get(VALID_YAML_DOCUMENT_INDEX); + + // when + List<SchemaValidationError> errors = new YamlValidationProcess(schema,document).validate(); + + // then + assertThat(errors).isEmpty(); + } + + @Test + public void shouldReturnOneErrorWhenProcessingPmDictionaryYamlWithMissingField() + throws YamlProcessingException { + // given + List<YamlDocument> documents = YamlLoadingUtils.loadValidMultiDocumentYamlFile(); + YamlSchema schema = new YamlSchemaFactory().createTreeStructuredYamlSchema(documents.get(0)); + YamlDocument document = documents.get(YAML_DOCUMENT_WITH_MISSING_FIELD_INDEX); + + // when + List<SchemaValidationError> errors = new YamlValidationProcess(schema,document).validate(); + + // then + assertThat(errors).hasSize(1); + } + + @Test + public void shouldReturnTwoErrorsWhenProcessingPmDictionaryYamlWithMissingFieldAndIncorrectValue() + throws YamlProcessingException { + // given + List<YamlDocument> documents = YamlLoadingUtils.loadValidMultiDocumentYamlFile(); + YamlSchema schema = new YamlSchemaFactory().createTreeStructuredYamlSchema(documents.get(0)); + YamlDocument document = documents.get(YAML_DOCUMENT_WITH_MISSING_FIELD_AND_WRONG_VALUE_INDEX); + + // when + List<SchemaValidationError> errors = new YamlValidationProcess(schema,document).validate(); + + // then + assertThat(errors).hasSize(2); + } + + @Test + public void shouldThrowExceptionWhenProcessingPmDictionaryIsNotValidYaml() + throws YamlProcessingException { + // given + List<YamlDocument> documents = YamlLoadingUtils.loadValidMultiDocumentYamlFile(); + YamlDocument schemaInYaml = YamlLoadingUtils.loadSimpleInvalidYamlSchemaForLazyLoadingFile(); + YamlSchema schema = new YamlSchemaFactory().createTreeStructuredYamlSchema(schemaInYaml); + YamlDocument document = documents.get(VALID_YAML_DOCUMENT_INDEX); + + // when then + assertThatThrownBy(() -> + new YamlValidationProcess(schema,document).validate() + ).isInstanceOf(YamlProcessingException.class) + .hasMessageContaining( + String.format("Lazy loading failed, due to yaml parsing exception.") + ); + } +} diff --git a/csarvalidation/src/test/java/org/onap/validation/yaml/schema/YamlSchemaFactoryTest.java b/csarvalidation/src/test/java/org/onap/validation/yaml/schema/YamlSchemaFactoryTest.java new file mode 100644 index 0000000..4c05d71 --- /dev/null +++ b/csarvalidation/src/test/java/org/onap/validation/yaml/schema/YamlSchemaFactoryTest.java @@ -0,0 +1,122 @@ +/* + * Copyright 2020 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.validation.yaml.schema; + +import org.junit.Test; +import org.onap.validation.yaml.YamlLoadingUtils; +import org.onap.validation.yaml.exception.YamlProcessingException; +import org.onap.validation.yaml.model.YamlDocument; +import org.onap.validation.yaml.schema.node.YamlSchemaNode; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.onap.validation.yaml.model.YamlDocumentFactory.YamlDocumentParsingException; +import static org.onap.validation.yaml.schema.node.YamlSchemaNodeFactory.EMPTY_COMMENT; +import static org.onap.validation.yaml.schema.node.YamlSchemaNodeFactoryTest.assertThatBranchNodeIsValid; +import static org.onap.validation.yaml.schema.node.YamlSchemaNodeFactoryTest.assertThatLeafNodeIsValid; + + +public class YamlSchemaFactoryTest { + + @Test + public void shouldCreateYamlSchemaFromYamlDocumentWithMultipleRoots() + throws YamlProcessingException { + + // given + YamlDocument documents = YamlLoadingUtils.loadSimpleValidYamlSchemaWithMultiRootFile(); + + // when + YamlSchema schema = new YamlSchemaFactory().createTreeStructuredYamlSchema(documents); + + // then + assertThat(schema).isNotNull(); + assertThat(schema.getRootNodes()).hasSize(3); + assertThat(schema.getRootNodes().get(0).getName()).isEqualTo("root1"); + assertThat(schema.getRootNodes().get(1).getName()).isEqualTo("root2"); + assertThat(schema.getRootNodes().get(2).getName()).isEqualTo("root3"); + } + + + @Test + public void shouldCreateYamlSchemaFromYamlDocument() + throws YamlProcessingException { + + // given + YamlDocument documents = YamlLoadingUtils.loadSimpleValidYamlSchemaFile(); + + // when + YamlSchema schema = new YamlSchemaFactory().createTreeStructuredYamlSchema(documents); + + // then + assertThat(schema).isNotNull(); + assertThat(schema.getRootNodes()).hasSize(1); + YamlSchemaNode pmMetaData = schema.getRootNodes().get(0); + assertThatBranchNodeIsValid(pmMetaData, "pmMetaData","/", true, EMPTY_COMMENT, + 2); + + YamlSchemaNode pmHeader = pmMetaData.getNextNodes().get(1); + assertThatBranchNodeIsValid(pmHeader, "pmHeader","/pmMetaData/", true, EMPTY_COMMENT, + 1); + + YamlSchemaNode nfType = pmHeader.getNextNodes().get(0); + assertThatLeafNodeIsValid(nfType, "nfType", "/pmMetaData/pmHeader/", true, "nfType comment"); + + YamlSchemaNode pmFields = pmMetaData.getNextNodes().get(0); + assertThatBranchNodeIsValid(pmFields, "pmFields", "/pmMetaData/", true, EMPTY_COMMENT, + 2); + + YamlSchemaNode measChangeType = pmFields.getNextNodes().get(1); + assertThatLeafNodeIsValid(measChangeType, "measChangeType", "/pmMetaData/pmFields/", + true, "measChangeType comment", + "added", "modified", "deleted"); + + YamlSchemaNode measAdditionalFields = pmFields.getNextNodes().get(0); + assertThatBranchNodeIsValid(measAdditionalFields, "measAdditionalFields", "/pmMetaData/pmFields/", + true, "measAdditionalFields comment", + 2); + + YamlSchemaNode vendorField1 = measAdditionalFields.getNextNodes().get(0); + assertThatLeafNodeIsValid(vendorField1, "vendorField1", "/pmMetaData/pmFields/measAdditionalFields/", + true, "vendorField1 comment", + "X", "Y", "Z"); + YamlSchemaNode vendorField2 = measAdditionalFields.getNextNodes().get(1); + assertThatLeafNodeIsValid(vendorField2, "vendorField2", "/pmMetaData/pmFields/measAdditionalFields/", + false, "vendorField2 comment", + "A", "B"); + } + + @Test + public void shouldThrowYamlParsingExceptionWhenLoadedSchemaIsInvalid() + throws YamlDocumentParsingException { + + // given + YamlDocument documents = YamlLoadingUtils.loadSimpleInvalidYamlSchemaFile(); + + // when/then + assertThatThrownBy(() -> + new YamlSchemaFactory().createTreeStructuredYamlSchema(documents) + ).isInstanceOf(YamlDocumentParsingException.class) + .hasMessageContaining( + String.format( + "Fail to parse given objects: %s as yaml document", + documents.getSubStructure("pmMetaData").getYaml().get("structure") + ) + ); + } + +} diff --git a/csarvalidation/src/test/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactoryTest.java b/csarvalidation/src/test/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactoryTest.java new file mode 100644 index 0000000..d35e3b2 --- /dev/null +++ b/csarvalidation/src/test/java/org/onap/validation/yaml/schema/node/YamlSchemaNodeFactoryTest.java @@ -0,0 +1,153 @@ +/* + * Copyright 2020 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.validation.yaml.schema.node; + +import org.assertj.core.util.Lists; +import org.junit.Test; +import org.onap.validation.yaml.YamlLoadingUtils; +import org.onap.validation.yaml.exception.YamlProcessingException; +import org.onap.validation.yaml.model.YamlDocument; +import org.onap.validation.yaml.model.YamlDocumentFactory; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.onap.validation.yaml.schema.node.YamlSchemaNodeFactory.EMPTY_COMMENT; + +public class YamlSchemaNodeFactoryTest { + + private static final String ROOT_PATH = "/"; + + @Test + public void shouldThrowExceptionDuringLazyLoadingWhenLoadedSchemaHaveInvalidSubStructure() + throws YamlProcessingException { + // given + String nodeName = "pmMetaData"; + + YamlDocument document = YamlLoadingUtils.loadSimpleInvalidYamlSchemaForLazyLoadingFile(); + YamlSchemaNode node = new YamlSchemaNodeFactory() + .createNode(nodeName, ROOT_PATH, document.getSubStructure(nodeName)); + + // when/then + assertThatThrownBy(node::getNextNodes + ).isInstanceOf(YamlSchemaNode.YamlSchemaProcessingException.class) + .hasMessageContaining( + "Lazy loading failed, due to yaml parsing exception." + ); + } + + @Test + public void shouldCreateLeafNodeIfGivenYamlDocumentHaveNoSubStructure() + throws YamlProcessingException { + // given + String nodeName = "leaf_test"; + String comment = "test leaf node"; + List<String> acceptedValues = Lists.list("val1", "val2"); + Map<Object, Object> nodeInYamlFormat = new HashMap<>(); + nodeInYamlFormat.put(YamlSchemaNodeFactory.PRESENCE_KEY, YamlSchemaNodeFactory.PRESENCE_REQUIRED_KEY); + nodeInYamlFormat.put(YamlSchemaNodeFactory.COMMENT_KEY, comment); + nodeInYamlFormat.put(YamlSchemaNodeFactory.VALUE_KET, acceptedValues); + YamlDocument document = new YamlDocumentFactory().createYamlDocument( + nodeInYamlFormat + ); + + // when + YamlSchemaNode yamlSchemaNode = new YamlSchemaNodeFactory().createNode(nodeName, ROOT_PATH, document); + + // then + assertThatLeafNodeIsValid( + yamlSchemaNode, nodeName, ROOT_PATH, true, comment, + acceptedValues.toArray(new String[acceptedValues.size()]) + ); + } + + @Test + public void shouldCreateBranchNodeIfGivenYamlDocumentHaveSubStructure() + throws YamlProcessingException { + // given + String nodeName = "branch_test"; + String comment = "test branch node"; + + Map<Object, Object> subStructure = new HashMap<>(); + String subNode1Name = "branch_test_node1"; + String subNode2Name = "branch_test_node2"; + subStructure.put(subNode1Name, new HashMap<>()); + subStructure.put(subNode2Name, new HashMap<>()); + + Map<Object, Object> nodeInYamlFormat = new HashMap<>(); + nodeInYamlFormat.put(YamlSchemaNodeFactory.PRESENCE_KEY, YamlSchemaNodeFactory.PRESENCE_REQUIRED_KEY); + nodeInYamlFormat.put(YamlSchemaNodeFactory.COMMENT_KEY, comment); + nodeInYamlFormat.put(YamlSchemaNodeFactory.STRUCTURE_KEY, subStructure); + YamlDocument document = new YamlDocumentFactory().createYamlDocument( + nodeInYamlFormat + ); + + // when + YamlSchemaNode yamlSchemaNode = new YamlSchemaNodeFactory().createNode(nodeName, ROOT_PATH, document); + + // then + assertThatBranchNodeIsValid( + yamlSchemaNode, nodeName, ROOT_PATH, true, comment, 2); + + List<YamlSchemaNode> subNodes = yamlSchemaNode.getNextNodes(); + assertThat(subNodes).hasSize(2); + assertThatLeafNodeIsValid( + subNodes.get(1), subNode1Name, ROOT_PATH + nodeName + "/", false, EMPTY_COMMENT); + assertThatLeafNodeIsValid( + subNodes.get(0), subNode2Name, ROOT_PATH + nodeName + "/", false, EMPTY_COMMENT); + } + + public static void assertThatBranchNodeIsValid( + YamlSchemaNode yamlSchemaNode, String name, String path, boolean isRequired, String comment, + int numberOfSubNodes + ) throws YamlSchemaNode.YamlSchemaProcessingException { + assertThatNodeIsValid(yamlSchemaNode, name, path, isRequired, comment); + + assertThat(yamlSchemaNode.getClass()).isEqualTo(YamlSchemaBranchNode.class); + assertThat(yamlSchemaNode.isContainingSubStructure()).isTrue(); + assertThat(yamlSchemaNode.getNextNodes()).hasSize(numberOfSubNodes); + assertThat(yamlSchemaNode.getAcceptedValues()).isEmpty(); + } + + public static void assertThatLeafNodeIsValid( + YamlSchemaNode yamlSchemaNode, String name, String path, boolean isRequired, String comment, + String... acceptedValues + ) throws YamlSchemaNode.YamlSchemaProcessingException { + assertThatNodeIsValid(yamlSchemaNode, name, path, isRequired, comment); + + assertThat(yamlSchemaNode.getClass()).isEqualTo(YamlSchemaLeafNode.class); + assertThat(yamlSchemaNode.isContainingSubStructure()).isFalse(); + assertThat(yamlSchemaNode.getAcceptedValues()).containsExactly(acceptedValues); + assertThat(yamlSchemaNode.getNextNodes()).isEmpty(); + } + + private static void assertThatNodeIsValid(YamlSchemaNode yamlSchemaNode, String name, String path, boolean isRequired, String comment) { + assertThat(yamlSchemaNode).isNotNull(); + assertThat(yamlSchemaNode.getName()).isEqualTo(name); + assertThat(yamlSchemaNode.getPath()).isEqualTo(path); + if (comment.isEmpty()) { + assertThat(yamlSchemaNode.getComment()).isNotEmpty(); + } else { + assertThat(yamlSchemaNode.getComment()).isEqualTo(comment); + } + assertThat(yamlSchemaNode.isRequired()).isEqualTo(isRequired); + } +} diff --git a/csarvalidation/src/test/resources/pnf/r01123/csar-option1-invalid-missing-files.csar b/csarvalidation/src/test/resources/pnf/r01123/csar-option1-invalid-missing-files.csar Binary files differnew file mode 100644 index 0000000..bab095d --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r01123/csar-option1-invalid-missing-files.csar diff --git a/csarvalidation/src/test/resources/pnf/r130206/csar-option1-invalid.csar b/csarvalidation/src/test/resources/pnf/r01123/csar-option1-invalid-noFileInManifest.csar Binary files differindex 187c008..26e3971 100644 --- a/csarvalidation/src/test/resources/pnf/r130206/csar-option1-invalid.csar +++ b/csarvalidation/src/test/resources/pnf/r01123/csar-option1-invalid-noFileInManifest.csar diff --git a/csarvalidation/src/test/resources/pnf/r01123/csar-option1-invalid-noVendor-noFileInManifest.csar b/csarvalidation/src/test/resources/pnf/r01123/csar-option1-invalid-noVendor-noFileInManifest.csar Binary files differnew file mode 100644 index 0000000..b9136c8 --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r01123/csar-option1-invalid-noVendor-noFileInManifest.csar diff --git a/csarvalidation/src/test/resources/pnf/r01123/csar-option1-invalid-noVendor.csar b/csarvalidation/src/test/resources/pnf/r01123/csar-option1-invalid-noVendor.csar Binary files differnew file mode 100644 index 0000000..11bddbb --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r01123/csar-option1-invalid-noVendor.csar diff --git a/csarvalidation/src/test/resources/pnf/r01123/csar-option1-valid.csar b/csarvalidation/src/test/resources/pnf/r01123/csar-option1-valid.csar Binary files differnew file mode 100644 index 0000000..62b18eb --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r01123/csar-option1-valid.csar diff --git a/csarvalidation/src/test/resources/pnf/r01123/csar-option2-invalid-with-cms.zip b/csarvalidation/src/test/resources/pnf/r01123/csar-option2-invalid-with-cms.zip Binary files differnew file mode 100644 index 0000000..8c30c68 --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r01123/csar-option2-invalid-with-cms.zip diff --git a/csarvalidation/src/test/resources/pnf/r01123/csar-option2-valid-with-cms.zip b/csarvalidation/src/test/resources/pnf/r01123/csar-option2-valid-with-cms.zip Binary files differnew file mode 100644 index 0000000..6965b95 --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r01123/csar-option2-valid-with-cms.zip diff --git a/csarvalidation/src/test/resources/pnf/r130206/cert-in-cms-and-root-and-tosca-incorrect-hash.csar b/csarvalidation/src/test/resources/pnf/r130206/cert-in-cms-and-root-and-tosca-incorrect-hash.csar Binary files differnew file mode 100644 index 0000000..bf19010 --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r130206/cert-in-cms-and-root-and-tosca-incorrect-hash.csar diff --git a/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-cms-and-root-and-tosca-incorrect-hash.csar b/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-cms-and-root-and-tosca-incorrect-hash.csar Binary files differnew file mode 100644 index 0000000..c8a4c39 --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-cms-and-root-and-tosca-incorrect-hash.csar diff --git a/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-cms-and-root-and-tosca.csar b/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-cms-and-root-and-tosca.csar Binary files differnew file mode 100644 index 0000000..b47f565 --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-cms-and-root-and-tosca.csar diff --git a/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-cms-and-root-incorrect-hash.csar b/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-cms-and-root-incorrect-hash.csar Binary files differnew file mode 100644 index 0000000..392d41e --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-cms-and-root-incorrect-hash.csar diff --git a/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-cms-and-root.csar b/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-cms-and-root.csar Binary files differnew file mode 100644 index 0000000..f9112c7 --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-cms-and-root.csar diff --git a/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-cms-and-tosca-incorrect-hash.csar b/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-cms-and-tosca-incorrect-hash.csar Binary files differnew file mode 100644 index 0000000..f331233 --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-cms-and-tosca-incorrect-hash.csar diff --git a/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-cms-and-tosca.csar b/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-cms-and-tosca.csar Binary files differnew file mode 100644 index 0000000..0854291 --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-cms-and-tosca.csar diff --git a/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-cms-incorrect-hash.csar b/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-cms-incorrect-hash.csar Binary files differnew file mode 100644 index 0000000..12c90a2 --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-cms-incorrect-hash.csar diff --git a/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-cms-valid.csar b/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-cms-valid.csar Binary files differnew file mode 100644 index 0000000..ece4064 --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-cms-valid.csar diff --git a/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-cms.csar b/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-cms.csar Binary files differnew file mode 100644 index 0000000..5ddbe1a --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-cms.csar diff --git a/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-root-and-tosca-incorrect-hash.csar b/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-root-and-tosca-incorrect-hash.csar Binary files differnew file mode 100644 index 0000000..be19521 --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-root-and-tosca-incorrect-hash.csar diff --git a/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-root-and-tosca.csar b/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-root-and-tosca.csar Binary files differnew file mode 100644 index 0000000..e4dbef9 --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-root-and-tosca.csar diff --git a/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-root-incorrect-hash.csar b/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-root-incorrect-hash.csar Binary files differnew file mode 100644 index 0000000..b926aac --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-root-incorrect-hash.csar diff --git a/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-root-pointed-by-tosca.csar b/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-root-pointed-by-tosca.csar Binary files differnew file mode 100644 index 0000000..0d9c3f3 --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-root-pointed-by-tosca.csar diff --git a/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-root.csar b/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-root.csar Binary files differnew file mode 100644 index 0000000..66c1a71 --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-root.csar diff --git a/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-tosca-incorrect-hash.csar b/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-tosca-incorrect-hash.csar Binary files differnew file mode 100644 index 0000000..9b651d0 --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-tosca-incorrect-hash.csar diff --git a/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-tosca-no-cms.csar b/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-tosca-no-cms.csar Binary files differnew file mode 100644 index 0000000..fe34a61 --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-tosca-no-cms.csar diff --git a/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-tosca-valid.csar b/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-tosca-valid.csar Binary files differnew file mode 100644 index 0000000..3446aaf --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-tosca-valid.csar diff --git a/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-tosca.csar b/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-tosca.csar Binary files differnew file mode 100644 index 0000000..c4168dc --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r130206/csar-cert-in-tosca.csar diff --git a/csarvalidation/src/test/resources/pnf/r130206/csar-no-cert-no-tosca-dir.csar b/csarvalidation/src/test/resources/pnf/r130206/csar-no-cert-no-tosca-dir.csar Binary files differnew file mode 100644 index 0000000..0b00af1 --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r130206/csar-no-cert-no-tosca-dir.csar diff --git a/csarvalidation/src/test/resources/pnf/r130206/csar-no-cms-no-cert-with-hash.csar b/csarvalidation/src/test/resources/pnf/r130206/csar-no-cms-no-cert-with-hash.csar Binary files differnew file mode 100644 index 0000000..826425e --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r130206/csar-no-cms-no-cert-with-hash.csar diff --git a/csarvalidation/src/test/resources/pnf/r130206/csar-not-secure-warning.csar b/csarvalidation/src/test/resources/pnf/r130206/csar-not-secure-warning.csar Binary files differnew file mode 100644 index 0000000..6520a61 --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r130206/csar-not-secure-warning.csar diff --git a/csarvalidation/src/test/resources/pnf/r130206/csar-option1-valid.csar b/csarvalidation/src/test/resources/pnf/r130206/csar-option1-valid.csar Binary files differdeleted file mode 100644 index 08c3605..0000000 --- a/csarvalidation/src/test/resources/pnf/r130206/csar-option1-valid.csar +++ /dev/null diff --git a/csarvalidation/src/test/resources/pnf/r130206/csar-option1-validSection.csar b/csarvalidation/src/test/resources/pnf/r130206/csar-option1-validSection.csar Binary files differdeleted file mode 100644 index bc90a75..0000000 --- a/csarvalidation/src/test/resources/pnf/r130206/csar-option1-validSection.csar +++ /dev/null diff --git a/csarvalidation/src/test/resources/pnf/r130206/csar-with-tosca-cert-pointing-non-existing-cert.csar b/csarvalidation/src/test/resources/pnf/r130206/csar-with-tosca-cert-pointing-non-existing-cert.csar Binary files differnew file mode 100644 index 0000000..b392fac --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r130206/csar-with-tosca-cert-pointing-non-existing-cert.csar diff --git a/csarvalidation/src/test/resources/pnf/r130206/csar-with-tosca-no-cert-entry.csar b/csarvalidation/src/test/resources/pnf/r130206/csar-with-tosca-no-cert-entry.csar Binary files differnew file mode 100644 index 0000000..d5c27e1 --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r130206/csar-with-tosca-no-cert-entry.csar diff --git a/csarvalidation/src/test/resources/pnf/r146092/validFile.csar b/csarvalidation/src/test/resources/pnf/r146092/validFile.csar Binary files differnew file mode 100644 index 0000000..e805765 --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r146092/validFile.csar diff --git a/csarvalidation/src/test/resources/pnf/r816745/csar-with-empty-pm-dictionary.csar b/csarvalidation/src/test/resources/pnf/r816745/csar-with-empty-pm-dictionary.csar Binary files differnew file mode 100644 index 0000000..d0dbdf0 --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r816745/csar-with-empty-pm-dictionary.csar diff --git a/csarvalidation/src/test/resources/pnf/r816745/csar-with-invalid-pm-dictionary-invalid-mapping.csar b/csarvalidation/src/test/resources/pnf/r816745/csar-with-invalid-pm-dictionary-invalid-mapping.csar Binary files differnew file mode 100644 index 0000000..b69b79a --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r816745/csar-with-invalid-pm-dictionary-invalid-mapping.csar diff --git a/csarvalidation/src/test/resources/pnf/r816745/csar-with-invalid-pm-dictionary-unknown-escape-character.csar b/csarvalidation/src/test/resources/pnf/r816745/csar-with-invalid-pm-dictionary-unknown-escape-character.csar Binary files differnew file mode 100644 index 0000000..9ed6270 --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r816745/csar-with-invalid-pm-dictionary-unknown-escape-character.csar diff --git a/csarvalidation/src/test/resources/pnf/r816745/csar-with-invalid-pm-dictionary.csar b/csarvalidation/src/test/resources/pnf/r816745/csar-with-invalid-pm-dictionary.csar Binary files differnew file mode 100644 index 0000000..81a0e23 --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r816745/csar-with-invalid-pm-dictionary.csar diff --git a/csarvalidation/src/test/resources/pnf/r816745/csar-with-missing-source-value-for-pm-dictionary-in-manifest.csar b/csarvalidation/src/test/resources/pnf/r816745/csar-with-missing-source-value-for-pm-dictionary-in-manifest.csar Binary files differnew file mode 100644 index 0000000..cd35d37 --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r816745/csar-with-missing-source-value-for-pm-dictionary-in-manifest.csar diff --git a/csarvalidation/src/test/resources/pnf/r816745/csar-with-no-pm-dictionary.csar b/csarvalidation/src/test/resources/pnf/r816745/csar-with-no-pm-dictionary.csar Binary files differnew file mode 100644 index 0000000..f0d4216 --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r816745/csar-with-no-pm-dictionary.csar diff --git a/csarvalidation/src/test/resources/pnf/r816745/csar-with-valid-pm-dictionary.csar b/csarvalidation/src/test/resources/pnf/r816745/csar-with-valid-pm-dictionary.csar Binary files differnew file mode 100644 index 0000000..528a002 --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r816745/csar-with-valid-pm-dictionary.csar diff --git a/csarvalidation/src/test/resources/pnf/r816745/zip-with-invalid-pm-dictionary.zip b/csarvalidation/src/test/resources/pnf/r816745/zip-with-invalid-pm-dictionary.zip Binary files differnew file mode 100644 index 0000000..032dc78 --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r816745/zip-with-invalid-pm-dictionary.zip diff --git a/csarvalidation/src/test/resources/pnf/r816745/zip-with-valid-pm-dictionary.zip b/csarvalidation/src/test/resources/pnf/r816745/zip-with-valid-pm-dictionary.zip Binary files differnew file mode 100644 index 0000000..b8c26d3 --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r816745/zip-with-valid-pm-dictionary.zip diff --git a/csarvalidation/src/test/resources/pnf/r972082/fileExtensionOfArtifactIsNotYaml.csar b/csarvalidation/src/test/resources/pnf/r972082/fileExtensionOfArtifactIsNotYaml.csar Binary files differnew file mode 100644 index 0000000..f485172 --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r972082/fileExtensionOfArtifactIsNotYaml.csar diff --git a/csarvalidation/src/test/resources/pnf/r972082/invalidYamlStructure.csar b/csarvalidation/src/test/resources/pnf/r972082/invalidYamlStructure.csar Binary files differnew file mode 100644 index 0000000..3360ce4 --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r972082/invalidYamlStructure.csar diff --git a/csarvalidation/src/test/resources/pnf/r972082/missingOnapPnfSwInformationArtifactSetEntry.csar b/csarvalidation/src/test/resources/pnf/r972082/missingOnapPnfSwInformationArtifactSetEntry.csar Binary files differnew file mode 100644 index 0000000..518aaa8 --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r972082/missingOnapPnfSwInformationArtifactSetEntry.csar diff --git a/csarvalidation/src/test/resources/pnf/r972082/missingSourceElementUnderAttributeError.csar b/csarvalidation/src/test/resources/pnf/r972082/missingSourceElementUnderAttributeError.csar Binary files differnew file mode 100644 index 0000000..e11093c --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/r972082/missingSourceElementUnderAttributeError.csar diff --git a/csarvalidation/src/test/resources/pnf/toscaMetaFile.csar b/csarvalidation/src/test/resources/pnf/toscaMetaFile.csar Binary files differnew file mode 100644 index 0000000..9370df9 --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/toscaMetaFile.csar diff --git a/csarvalidation/src/test/resources/pnf/validFile.csar b/csarvalidation/src/test/resources/pnf/validFile.csar Binary files differnew file mode 100644 index 0000000..11d1945 --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/validFile.csar diff --git a/csarvalidation/src/test/resources/yaml_schema/Multi_Document_Invalid.yaml b/csarvalidation/src/test/resources/yaml_schema/Multi_Document_Invalid.yaml new file mode 100644 index 0000000..aab34fa --- /dev/null +++ b/csarvalidation/src/test/resources/yaml_schema/Multi_Document_Invalid.yaml @@ -0,0 +1,86 @@ +... +# PM Dictionary perf3gpp measurements for the gnb-Nokia NF (bracket style yaml) +--- +pmMetaData: { + pmHeader: { + nfType: gnb-Nokia, + pmDefSchemaVsn: 2.0, + pmDefVsn: 5G19_1906_002 + }, + pmFields: { + iMeasInfoId: 2204, + iMeasType: 1, + + measCollectionMethod: CC, + measCondition: "This measurement is updated when X2AP: SgNB Modification Required message is sent to MeNB + with the SCG Change Indication set as PSCellChange.", + measDescription: "This counter indicates the number of intra gNB intra frequency PSCell change attempts.", + measFamily: NINFC, + measInfoId: "NR Intra Frequency PSCell Change", + measLastChange: 5G18A_1807_003, + measObjClass: NGCELL, + measResultRange: 0-4096, + measResultType: integer, + measResultUnits: number, + measType: VS.NINFC.IntraFrPscelChAttempt, + measAdditionalFields: { + vendorField1: X, + vendorField2: B + } + } +} +--- +pmMetaData: { + pmHeader: { + nfType: gnb-Nokia, + pmDefSchemaVsn: 2.0, + pmDefVsn: 5G19_1906_002 + }, + pmFields: { + iMeasInfoId: 2204, + iMeasType: 2, + measCollectionMethod: CC, + measCondition: "This measurement is updated when the TDCoverall timer has elapsed before gNB receives the X2AP: SgNB Modification Confirm message.", + measDescription: "This measurement the number of intra gNB intra frequency PSCell change failures due to TDCoverall timer expiry.", + measFamily: NINFC, + measInfoId: "NR Intra Frequency PSCell Change", + measLastChange: 5G18A_1807_003, + measObjClass: NGCELL, + measResultRange: 0-4096, + measResultType: float, + measResultUnits: number, + measType: VS.NINFC.IntraFrPscelChFailTdcExp, + measAdditionalFields: { + vendorField1: Y + } + } +} +... +--- +pmMetaData: { + pmHeader: { + nfType: gnb-Nokia, + pmDefSchemaVsn: 2.0, + pmDefVsn: 5G19_1906_002 + }, + pmFields: { + iMeasInfoId: 2206, + iMeasType: 1, + measCondition: "This measurement is updated when MeNB replies to X2AP: SgNB Modification Required message with the X2AP: SgNB Modification Refuse message.", + measCollectionMethod: CC, + measDescription: "This counter indicates the number of intra gNB intra frequency PSCell change failures due to MeNB refusal.", + measFamily: NINFC, + measInfoId: "NR Intra Frequency PSCell Change", + measLastChange: 5G19_1906_002, + measObjClass: NGCELL, + measResultRange: 0-4096, + measResultType: float, + measChangeType: added, + measResultUnits: number, + measType: VS.NINFC.IntraFrPscelChFailMenbRef, + measAdditionalFields: { + vendorField1: Z, + vendorField2: A + } + } +... diff --git a/csarvalidation/src/test/resources/yaml_schema/PM_Dictionary.yaml b/csarvalidation/src/test/resources/yaml_schema/PM_Dictionary.yaml new file mode 100644 index 0000000..12a4af9 --- /dev/null +++ b/csarvalidation/src/test/resources/yaml_schema/PM_Dictionary.yaml @@ -0,0 +1,228 @@ +--- +# PM Dictionary schema specifying and describing the meta information +# used to define perf3gpp measurements in the PM Dictionary +pmMetaData: { presence: required, structure: { + pmHeader: { + presence: required, + structure: { + nfType: { + presence: required, + comment: "NF type; should match the nfName-vendor string used in + the fileReady or perf3gpp eventName" + }, + pmDefSchemaVsn: { + presence: required, + value: 2.0, + comment: "PM Dictionary Schema Version from the VES Event + Registration specification" + }, + pmDefVsn: { + presence: required, + comment: "vendor-defined PM Dictionary version" + } + } + }, + pmFields: { + presence: required, + structure: { + iMeasInfoId: { + presence: required, + comment: "vendor-defined integer measurement group identifier" + }, + iMeasType: { + presence: required, + comment: "vendor-defined integer identifier for the measType; + must be combined with measInfoId to identify a + specific measurement." + }, + measChangeType: { + presence: required, + value: [added, modified, deleted], + comment: "indicates the type of change that occurred during + measLastChange" + }, + measCollectionMethod: { + presence: required, + value: [CC, SI, DER, Gauge, Average], + comment: "the measurement collection method; CC, SI, DER and + Gauge are as defined in 3GPP; average contains the + average value of the measurement during the + granularity period" + }, + measCondition: { + presence: required, + comment: "description of the condition causing the measurement" + }, + measDescription: { + presence: required, + comment: "description of the measurement information + and purpose" + }, + measFamily: { + presence: required, + comment: "abbreviation for a family of measurements, in + 3GPP format, or vendor defined" + }, + measInfoId: { + presence: required, + comment: "name for a group of related measurements in + 3GPP format or vendor defined" + }, + measLastChange: { + presence: required, + comment: "version of the PM Dictionary the last time this + measurement was added, modified or deleted" + }, + measObjClass: { + presence: required, + value: [NGBTS, NGCELL, IPNO, IPSEC, ETHIF], + comment: "measurement object class" + }, + measResultRange: { + presence: optional, + comment: "range of the measurement result; only necessary when + the range is smaller than the full range of the + data type" + }, + measResultType: { + presence: required, + value: [float, uint32, uint64], + comment: "data type of the measurement result" + }, + measResultUnits: { + presence: required, + value: [seconds, minutes, nanoseconds, microseconds, dB, + number, kilobytes, bytes, ethernetFrames, + packets, users], + comment: "units of measure for the measurement result" + }, + measType: { + presence: required, + comment: "measurement name in 3GPP or vendor-specific format; + vendor specific names are preceded with VS" + }, + measAdditionalFields: { + presence: required, + comment: "vendor-specific PM Dictionary fields", + structure: { + vendorField1: { + presence: required, + value: [X, Y, Z], + comment: "vendor field 1 description" + }, + vendorField2: { + presence: optional, + value: [A, B], + comment: "vendor field 2 description." + } + } + } + } + } +}} +... +# PM Dictionary perf3gpp measurements for the gnb-Nokia NF (bracket style yaml) +--- +pmMetaData: + pmHeader: + nfType: gnb-Nokia + pmDefSchemaVsn: 2.0 + pmDefVsn: 5G19_1906_002 + pmFields: + iMeasInfoId: 2204 + iMeasType: 1 + measCollectionMethod: CC + measCondition: "This measurement is updated when X2AP: SgNB Modification Required message is sent to MeNB + with the SCG Change Indication set as PSCellChange." + measDescription: "This counter indicates the number of intra gNB intra frequency PSCell change attempts." + measFamily: NINFC + measInfoId: "NR Intra Frequency PSCell Change" + measLastChange: 5G18A_1807_003 + measObjClass: NGCELL + measResultRange: 0-4096 + measResultType: integer + measResultUnits: number + measType: VS.NINFC.IntraFrPscelChAttempt + measAdditionalFields: + vendorField1: X + vendorField2: B +... +--- +pmMetaData: + pmHeader: + nfType: gnb-Nokia + pmDefSchemaVsn: 2.0 + pmDefVsn: 5G19_1906_002 + pmFields: + iMeasInfoId: 2204 + iMeasType: 2 + measCollectionMethod: CC + measCondition: "This measurement is updated when the TDCoverall timer has elapsed before gNB receives the X2AP: SgNB Modification Confirm message." + measDescription: "This measurement the number of intra gNB intra frequency PSCell change failures due to TDCoverall timer expiry." + measFamily: NINFC + measInfoId: "NR Intra Frequency PSCell Change" + measLastChange: 5G18A_1807_003 + measObjClass: NGCELL + measResultRange: 0-4096 + measResultType: float + measResultUnits: number + measType: VS.NINFC.IntraFrPscelChFailTdcExp + measAdditionalFields: + vendorField1: + - Y + - X +... +--- +pmMetaData: + pmHeader: + nfType: gnb-Nokia + pmDefSchemaVsn: 2.0 + pmDefVsn: 5G19_1906_002 + pmFields: + iMeasInfoId: 2206 + iMeasType: 1 + measCondition: "This measurement is updated when MeNB replies to X2AP: SgNB Modification Required message with the X2AP: SgNB Modification Refuse message." + measCollectionMethod: CC + measDescription: "This counter indicates the number of intra gNB intra frequency PSCell change failures due to MeNB refusal." + measFamily: NINFC + measInfoId: "NR Intra Frequency PSCell Change" + measLastChange: 5G19_1906_002 + measObjClass: NGCELL + measResultRange: 0-4096 + measResultType: float + measChangeType: added + measResultUnits: number + measType: VS.NINFC.IntraFrPscelChFailMenbRef + measAdditionalFields: + vendorField1: + - Z + - A + vendorField2: A +... +--- +pmMetaData: + pmHeader: + nfType: gnb-Nokia + pmDefSchemaVsn: 2.0 + pmDefVsn: 5G19_1906_002 + pmFields: + iMeasInfoId: 2206 + iMeasType: 1 + measCondition: "This measurement is updated when MeNB replies to X2AP: SgNB Modification Required message with the X2AP: SgNB Modification Refuse message." + measCollectionMethod: CC + measDescription: "This counter indicates the number of intra gNB intra frequency PSCell change failures due to MeNB refusal." + measFamily: NINFC + measInfoId: "NR Intra Frequency PSCell Change" + measLastChange: 5G19_1906_002 + measObjClass: NGCELL + measResultRange: 0-4096 + measResultType: float + measChangeType: added + measResultUnits: number + measType: VS.NINFC.IntraFrPscelChFailMenbRef + measAdditionalFields: + vendorField1: + - X + - Y + vendorField2: A +... diff --git a/csarvalidation/src/test/resources/yaml_schema/PM_Dictionary_JSON_Style.yaml b/csarvalidation/src/test/resources/yaml_schema/PM_Dictionary_JSON_Style.yaml new file mode 100644 index 0000000..f4cbddf --- /dev/null +++ b/csarvalidation/src/test/resources/yaml_schema/PM_Dictionary_JSON_Style.yaml @@ -0,0 +1,239 @@ +--- +# PM Dictionary schema specifying and describing the meta information +# used to define perf3gpp measurements in the PM Dictionary +pmMetaData: { presence: required, structure: { + pmHeader: { + presence: required, + structure: { + nfType: { + presence: required, + comment: "NF type; should match the nfName-vendor string used in + the fileReady or perf3gpp eventName" + }, + pmDefSchemaVsn: { + presence: required, + value: 2.0, + comment: "PM Dictionary Schema Version from the VES Event + Registration specification" + }, + pmDefVsn: { + presence: required, + comment: "vendor-defined PM Dictionary version" + } + } + }, + pmFields: { + presence: required, + structure: { + iMeasInfoId: { + presence: required, + comment: "vendor-defined integer measurement group identifier" + }, + iMeasType: { + presence: required, + comment: "vendor-defined integer identifier for the measType; + must be combined with measInfoId to identify a + specific measurement." + }, + measChangeType: { + presence: required, + value: [added, modified, deleted], + comment: "indicates the type of change that occurred during + measLastChange" + }, + measCollectionMethod: { + presence: required, + value: [CC, SI, DER, Gauge, Average], + comment: "the measurement collection method; CC, SI, DER and + Gauge are as defined in 3GPP; average contains the + average value of the measurement during the + granularity period" + }, + measCondition: { + presence: required, + comment: "description of the condition causing the measurement" + }, + measDescription: { + presence: required, + comment: "description of the measurement information + and purpose" + }, + measFamily: { + presence: required, + comment: "abbreviation for a family of measurements, in + 3GPP format, or vendor defined" + }, + measInfoId: { + presence: required, + comment: "name for a group of related measurements in + 3GPP format or vendor defined" + }, + measLastChange: { + presence: required, + comment: "version of the PM Dictionary the last time this + measurement was added, modified or deleted" + }, + measObjClass: { + presence: required, + value: [NGBTS, NGCELL, IPNO, IPSEC, ETHIF], + comment: "measurement object class" + }, + measResultRange: { + presence: optional, + comment: "range of the measurement result; only necessary when + the range is smaller than the full range of the + data type" + }, + measResultType: { + presence: required, + value: [float, uint32, uint64], + comment: "data type of the measurement result" + }, + measResultUnits: { + presence: required, + value: [seconds, minutes, nanoseconds, microseconds, dB, + number, kilobytes, bytes, ethernetFrames, + packets, users], + comment: "units of measure for the measurement result" + }, + measType: { + presence: required, + comment: "measurement name in 3GPP or vendor-specific format; + vendor specific names are preceded with VS" + }, + measAdditionalFields: { + presence: required, + comment: "vendor-specific PM Dictionary fields", + structure: { + vendorField1: { + presence: required, + value: [X, Y, Z], + comment: "vendor field 1 description" + }, + vendorField2: { + presence: optional, + value: [A, B], + comment: "vendor field 2 description." + } + } + } + } + } +}} +... +# PM Dictionary perf3gpp measurements for the gnb-Nokia NF (bracket style yaml) +--- +pmMetaData: { + pmHeader: { + nfType: gnb-Nokia, + pmDefSchemaVsn: 2.0, + pmDefVsn: 5G19_1906_002 + }, + pmFields: { + iMeasInfoId: 2204, + iMeasType: 1, + + measCollectionMethod: CC, + measCondition: "This measurement is updated when X2AP: SgNB Modification Required message is sent to MeNB + with the SCG Change Indication set as PSCellChange.", + measDescription: "This counter indicates the number of intra gNB intra frequency PSCell change attempts.", + measFamily: NINFC, + measInfoId: "NR Intra Frequency PSCell Change", + measLastChange: 5G18A_1807_003, + measObjClass: NGCELL, + measResultRange: 0-4096, + measResultType: integer, + measResultUnits: number, + measType: VS.NINFC.IntraFrPscelChAttempt, + measAdditionalFields: { + vendorField1: X, + vendorField2: B + } + } +} +... +--- +pmMetaData: { + pmHeader: { + nfType: gnb-Nokia, + pmDefSchemaVsn: 2.0, + pmDefVsn: 5G19_1906_002 + }, + pmFields: { + iMeasInfoId: 2204, + iMeasType: 2, + measCollectionMethod: CC, + measCondition: "This measurement is updated when the TDCoverall timer has elapsed before gNB receives the X2AP: SgNB Modification Confirm message.", + measDescription: "This measurement the number of intra gNB intra frequency PSCell change failures due to TDCoverall timer expiry.", + measFamily: NINFC, + measInfoId: "NR Intra Frequency PSCell Change", + measLastChange: 5G18A_1807_003, + measObjClass: NGCELL, + measResultRange: 0-4096, + measResultType: float, + measResultUnits: number, + measType: VS.NINFC.IntraFrPscelChFailTdcExp, + measAdditionalFields: { + vendorField1: [Y,Z] + } + } +} +... +--- +pmMetaData: { + pmHeader: { + nfType: gnb-Nokia, + pmDefSchemaVsn: 2.0, + pmDefVsn: 5G19_1906_002 + }, + pmFields: { + iMeasInfoId: 2206, + iMeasType: 1, + measCondition: "This measurement is updated when MeNB replies to X2AP: SgNB Modification Required message with the X2AP: SgNB Modification Refuse message.", + measCollectionMethod: CC, + measDescription: "This counter indicates the number of intra gNB intra frequency PSCell change failures due to MeNB refusal.", + measFamily: NINFC, + measInfoId: "NR Intra Frequency PSCell Change", + measLastChange: 5G19_1906_002, + measObjClass: NGCELL, + measResultRange: 0-4096, + measResultType: float, + measChangeType: added, + measResultUnits: number, + measType: VS.NINFC.IntraFrPscelChFailMenbRef, + measAdditionalFields: { + vendorField1: [Z,A], + vendorField2: A + } + } +} +... +--- +pmMetaData: { + pmHeader: { + nfType: gnb-Nokia, + pmDefSchemaVsn: 2.0, + pmDefVsn: 5G19_1906_002 + }, + pmFields: { + iMeasInfoId: 2206, + iMeasType: 1, + measCondition: "This measurement is updated when MeNB replies to X2AP: SgNB Modification Required message with the X2AP: SgNB Modification Refuse message.", + measCollectionMethod: CC, + measDescription: "This counter indicates the number of intra gNB intra frequency PSCell change failures due to MeNB refusal.", + measFamily: NINFC, + measInfoId: "NR Intra Frequency PSCell Change", + measLastChange: 5G19_1906_002, + measObjClass: NGCELL, + measResultRange: 0-4096, + measResultType: float, + measChangeType: added, + measResultUnits: number, + measType: VS.NINFC.IntraFrPscelChFailMenbRef, + measAdditionalFields: { + vendorField1: [X,Y], + vendorField2: A + } + } +} +... diff --git a/csarvalidation/src/test/resources/yaml_schema/Simple_Invalid_Mapping_Value.yaml b/csarvalidation/src/test/resources/yaml_schema/Simple_Invalid_Mapping_Value.yaml new file mode 100644 index 0000000..25c72cd --- /dev/null +++ b/csarvalidation/src/test/resources/yaml_schema/Simple_Invalid_Mapping_Value.yaml @@ -0,0 +1,149 @@ +--- +# PM Dictionary schema specifying and describing the meta information +# used to define perf3gpp measurements in the PM Dictionary +pmMetaData: { presence: required, structure: { + pmHeader: { + presence: required, + structure: { + nfType: { + presence: required, + comment: "NF type; should match the nfName-vendor string used in + the fileReady or perf3gpp eventName" + }, + pmDefSchemaVsn: { + presence: required, + value: 2.0, + comment: "PM Dictionary Schema Version from the VES Event + Registration specification" + }, + pmDefVsn: { + presence: required, + comment: "vendor-defined PM Dictionary version" + } + } + }, + pmFields: { + presence: required, + structure: { + iMeasInfoId: { + presence: required, + comment: "vendor-defined integer measurement group identifier" + }, + iMeasType: { + presence: required, + comment: "vendor-defined integer identifier for the measType; + must be combined with measInfoId to identify a + specific measurement." + }, + measChangeType: { + presence: required, + value: [added, modified, deleted], + comment: "indicates the type of change that occurred during + measLastChange" + }, + measCollectionMethod: { + presence: required, + value: [CC, SI, DER, Gauge, Average], + comment: "the measurement collection method; CC, SI, DER and + Gauge are as defined in 3GPP; average contains the + average value of the measurement during the + granularity period" + }, + measCondition: { + presence: required, + comment: "description of the condition causing the measurement" + }, + measDescription: { + presence: required, + comment: "description of the measurement information + and purpose" + }, + measFamily: { + presence: required, + comment: "abbreviation for a family of measurements, in + 3GPP format, or vendor defined" + }, + measInfoId: { + presence: required, + comment: "name for a group of related measurements in + 3GPP format or vendor defined" + }, + measLastChange: { + presence: required, + comment: "version of the PM Dictionary the last time this + measurement was added, modified or deleted" + }, + measObjClass: { + presence: required, + value: [NGBTS, NGCELL, IPNO, IPSEC, ETHIF], + comment: "measurement object class" + }, + measResultRange: { + presence: optional, + comment: "range of the measurement result; only necessary when + the range is smaller than the full range of the + data type" + }, + measResultType: { + presence: required, + value: [float, uint32, uint64], + comment: "data type of the measurement result" + }, + measResultUnits: { + presence: required, + value: [seconds, minutes, nanoseconds, microseconds, dB, + number, kilobytes, bytes, ethernetFrames, + packets, users], + comment: "units of measure for the measurement result" + }, + measType: { + presence: required, + comment: "measurement name in 3GPP or vendor-specific format; + vendor specific names are preceded with VS" + }, + measAdditionalFields: { + presence: required, + comment: "vendor-specific PM Dictionary fields", + structure: { + vendorField1: { + presence: required, + value: [X, Y, Z], + comment: "vendor field 1 description" + }, + vendorField2: { + presence: optional, + value: [A, B], + comment: "vendor field 2 description." + } + } + } + } + } +}} +... +# PM Dictionary perf3gpp measurements for the gnb-Nokia NF (bracket style yaml) +--- +pmMetaData: + pmHeader: + nfType: gnb-Nokia + pmDefSchemaVsn: 2.0 + pmDefVsn: 5G19_1906_002 + pmFields: + iMeasInfoId: 2204 + iMeasType: 1 + measCollectionMethod: CC + measCondition: This measurement is updated when X2AP: SgNB Modification Required message is sent to MeNB + with the SCG Change Indication set as PSCellChange. + measDescription: This counter indicates the number of intra gNB intra frequency PSCell change attempts. + measFamily: NINFC + measInfoId: "NR Intra Frequency PSCell Change" + measLastChange: 5G18A_1807_003 + measObjClass: NGCELL + measResultRange: 0-4096 + measResultType: integer + measResultUnits: number + measType: VS.NINFC.IntraFrPscelChAttempt + measAdditionalFields: + vendorField1: X + vendorField2: B +... diff --git a/csarvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_Construction.yaml b/csarvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_Construction.yaml new file mode 100644 index 0000000..c5e7b7c --- /dev/null +++ b/csarvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_Construction.yaml @@ -0,0 +1,39 @@ +--- +pmMetaData: { presence: required, structure: [ + -pmHeader: { + presence: required, + structure: { + nfType: { + presence: required, + comment: "nfType comment" + } + } + }, + -pmFields: { + presence: required, + structure: { + measChangeType: { + presence: required, + value: [added, modified, deleted], + comment: "measChangeType comment" + }, + measAdditionalFields: { + presence: required, + comment: "measAdditionalFields comment", + structure: { + vendorField1: { + presence: required, + value: [X, Y, Z], + comment: "vendorField1 comment" + }, + vendorField2: { + presence: optional, + value: [A, B], + comment: "vendorField2 comment" + } + } + } + } + } +]} +... diff --git a/csarvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_LazyLoading.yaml b/csarvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_LazyLoading.yaml new file mode 100644 index 0000000..7f9f946 --- /dev/null +++ b/csarvalidation/src/test/resources/yaml_schema/Simple_Invalid_Schema_LazyLoading.yaml @@ -0,0 +1,39 @@ +--- +pmMetaData: { presence: required, structure: { + pmHeader: { + presence: required, + structure: { + nfType: { + presence: required, + comment: "nfType comment" + } + } + }, + pmFields: { + presence: required, + structure: [ + -measChangeType: { + presence: required, + value: [added, modified, deleted], + comment: "measChangeType comment" + }, + -measAdditionalFields: { + presence: required, + comment: "measAdditionalFields comment", + structure: { + vendorField1: { + presence: required, + value: [X, Y, Z], + comment: "vendorField1 comment" + }, + vendorField2: { + presence: optional, + value: [A, B], + comment: "vendorField2 comment" + } + } + } + ] + } +}} +... diff --git a/csarvalidation/src/test/resources/yaml_schema/Simple_Unknown_Escape_Character.yaml b/csarvalidation/src/test/resources/yaml_schema/Simple_Unknown_Escape_Character.yaml new file mode 100644 index 0000000..2cac9e6 --- /dev/null +++ b/csarvalidation/src/test/resources/yaml_schema/Simple_Unknown_Escape_Character.yaml @@ -0,0 +1,149 @@ +--- +# PM Dictionary schema specifying and describing the meta information +# used to define perf3gpp measurements in the PM Dictionary +pmMetaData: { presence: required, structure: { + pmHeader: { + presence: required, + structure: { + nfType: { + presence: required, + comment: "NF type; should match the nfName-vendor string used in + the fileReady or perf3gpp eventName" + }, + pmDefSchemaVsn: { + presence: required, + value: 2.0, + comment: "PM Dictionary Schema Version from the VES Event + Registration specification" + }, + pmDefVsn: { + presence: required, + comment: "vendor-defined PM Dictionary version" + } + } + }, + pmFields: { + presence: required, + structure: { + iMeasInfoId: { + presence: required, + comment: "vendor-defined integer measurement group identifier" + }, + iMeasType: { + presence: required, + comment: "vendor-defined integer identifier for the measType; + must be combined with measInfoId to identify a + specific measurement." + }, + measChangeType: { + presence: required, + value: [added, modified, deleted], + comment: "indicates the type of change that occurred during + measLastChange" + }, + measCollectionMethod: { + presence: required, + value: [CC, SI, DER, Gauge, Average], + comment: "the measurement collection method; CC, SI, DER and + Gauge are as defined in 3GPP; average contains the + average value of the measurement during the + granularity period" + }, + measCondition: { + presence: required, + comment: "description of the condition causing the measurement" + }, + measDescription: { + presence: required, + comment: "description of the measurement information + and purpose" + }, + measFamily: { + presence: required, + comment: "abbreviation for a family of measurements, in + 3GPP format, or vendor defined" + }, + measInfoId: { + presence: required, + comment: "name for a group of related measurements in + 3GPP format or vendor defined" + }, + measLastChange: { + presence: required, + comment: "version of the PM Dictionary the last time this + measurement was added, modified or deleted" + }, + measObjClass: { + presence: required, + value: [NGBTS, NGCELL, IPNO, IPSEC, ETHIF], + comment: "measurement object class" + }, + measResultRange: { + presence: optional, + comment: "range of the measurement result; only necessary when + the range is smaller than the full range of the + data type" + }, + measResultType: { + presence: required, + value: [float, uint32, uint64], + comment: "data type of the measurement result" + }, + measResultUnits: { + presence: required, + value: [seconds, minutes, nanoseconds, microseconds, dB, + number, kilobytes, bytes, ethernetFrames, + packets, users], + comment: "units of measure for the measurement result" + }, + measType: { + presence: required, + comment: "measurement name in 3GPP or vendor-specific format; + vendor specific names are preceded with VS" + }, + measAdditionalFields: { + presence: required, + comment: "vendor-specific PM Dictionary fields", + structure: { + vendorField1: { + presence: required, + value: [X, Y, Z], + comment: "vendor field 1 description" + }, + vendorField2: { + presence: optional, + value: [A, B], + comment: "vendor field 2 description." + } + } + } + } + } +}} +... +# PM Dictionary perf3gpp measurements for the gnb-Nokia NF (bracket style yaml) +--- +pmMetaData: + pmHeader: + nfType: gnb-Nokia + pmDefSchemaVsn: 2.0 + pmDefVsn: 5G19_1906_002 + pmFields: + iMeasInfoId: 2204 + iMeasType: 1 + measCollectionMethod: CC + measCondition: "This measurement is updated when X2AP: SgNB Modification Required message is \sent\ to MeNB + with the SCG Change Indication set as PSCellChange." + measDescription: This counter indicates the number of intra gNB intra frequency PSCell change attempts. + measFamily: NINFC + measInfoId: "NR Intra Frequency PSCell Change" + measLastChange: 5G18A_1807_003 + measObjClass: NGCELL + measResultRange: 0-4096 + measResultType: integer + measResultUnits: number + measType: VS.NINFC.IntraFrPscelChAttempt + measAdditionalFields: + vendorField1: X + vendorField2: B +... diff --git a/csarvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema.yaml b/csarvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema.yaml new file mode 100644 index 0000000..a125b13 --- /dev/null +++ b/csarvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema.yaml @@ -0,0 +1,39 @@ +--- +pmMetaData: { presence: required, structure: { + pmHeader: { + presence: required, + structure: { + nfType: { + presence: required, + comment: "nfType comment" + } + } + }, + pmFields: { + presence: required, + structure: { + measChangeType: { + presence: required, + value: [added, modified, deleted], + comment: "measChangeType comment" + }, + measAdditionalFields: { + presence: required, + comment: "measAdditionalFields comment", + structure: { + vendorField1: { + presence: required, + value: [X, Y, Z], + comment: "vendorField1 comment" + }, + vendorField2: { + presence: optional, + value: [A, B], + comment: "vendorField2 comment" + } + } + } + } + } +}} +... diff --git a/csarvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema_Multi_Root.yaml b/csarvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema_Multi_Root.yaml new file mode 100644 index 0000000..d73ca4f --- /dev/null +++ b/csarvalidation/src/test/resources/yaml_schema/Simple_Valid_Schema_Multi_Root.yaml @@ -0,0 +1,23 @@ +--- +root1: { presence: required, structure: { + field1: { + presence: required, + value: [X, Y, Z], + comment: "field 1 description" + } +}} +root2: { presence: required, structure: { + field2: { + presence: required, + value: [X, Y, Z], + comment: "field 1 description" + } +}} +root3: { presence: required, structure: { + field3: { + presence: required, + value: [X, Y, Z], + comment: "field 1 description" + } +}} +... |