diff options
author | Kanagaraj Manickam <kanagaraj.manickam@huawei.com> | 2019-04-09 09:33:40 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-04-09 09:33:40 +0000 |
commit | 00e2233d95577a78c47cbabcce818191287a2a63 (patch) | |
tree | 8aba0792e5dc446375ea2d130e2ef0ce9c397e0d /csarvalidation/src/test/java/org/onap | |
parent | 4827d14388d40fdffd95d560ae6500604aff578f (diff) | |
parent | e58e011a89ae5c8ada209a82d9b0f3ad1b0ca58f (diff) |
Merge "PNF TC R146092"
Diffstat (limited to 'csarvalidation/src/test/java/org/onap')
6 files changed, 320 insertions, 74 deletions
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 b29470c..ca85c7a 100644 --- a/csarvalidation/src/test/java/org/onap/cvc/csar/PnfCSARArchiveTest.java +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/PnfCSARArchiveTest.java @@ -1,12 +1,12 @@ /** * Copyright 2019 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. @@ -19,8 +19,6 @@ package org.onap.cvc.csar; import com.google.common.collect.Lists; import org.junit.Test; -import java.io.IOException; -import java.net.URISyntaxException; import java.util.List; import java.util.Map; @@ -35,18 +33,34 @@ public class PnfCSARArchiveTest { .toURI().getPath(); // when - try( PnfCSARArchive pnfCSARArchive = new PnfCSARArchive()) { + try (PnfCSARArchive pnfCSARArchive = new PnfCSARArchive()) { pnfCSARArchive.init(fileName); pnfCSARArchive.parse(); // then - verifyThatMetadataWasSet(pnfCSARArchive); - verifyThatNonManoArtifactsWereSet(pnfCSARArchive); + PnfCSARArchive.PnfManifest manifest = (PnfCSARArchive.PnfManifest) pnfCSARArchive.getManifest(); + verifyThatMetadataWasSet(manifest); + verifyThatSourcesSectionWasSet(manifest); + verifyThatNonManoArtifactsWereSet(manifest); } } - private void verifyThatNonManoArtifactsWereSet(PnfCSARArchive pnfCSARArchive) { - Map<String, Map<String, List<String>>> nonManoArtifacts = pnfCSARArchive.getManifest().getNonMano(); + private void verifyThatMetadataWasSet(PnfCSARArchive.PnfManifest manifest) { + CSARArchive.Manifest.Metadata metadata = manifest.getMetadata(); + assertThat(metadata.getProductName()).isEqualTo("RadioNode"); + assertThat(metadata.getProviderId()).isEqualTo("Ericsson"); + assertThat(metadata.getPackageVersion()).isEqualTo("1.0"); + assertThat(metadata.getReleaseDateTime()).isEqualTo("2019-01-14T11:25:00+00:00"); + } + + private void verifyThatSourcesSectionWasSet(PnfCSARArchive.PnfManifest manifest) { + + List<String> sources = manifest.getSources(); + assertThat(sources).contains("Definitions/MainServiceTemplate.yaml", "Definitions/etsi_nfv_sol001_vnfd_2_5_1_types.yaml"); + } + + private void verifyThatNonManoArtifactsWereSet(PnfCSARArchive.PnfManifest manifest) { + Map<String, Map<String, List<String>>> nonManoArtifacts = manifest.getNonMano(); assertThat(nonManoArtifacts.get("onap_ves_events").get("source")) .isEqualTo(Lists.newArrayList("Artifacts/Events/VES_registration.yml") ); @@ -66,12 +80,4 @@ public class PnfCSARArchiveTest { ); } - private void verifyThatMetadataWasSet(PnfCSARArchive pnfCSARArchive) { - CSARArchive.Manifest.Metadata metadata = pnfCSARArchive.getManifest().getMetadata(); - assertThat(metadata.getProductName()).isEqualTo("RadioNode"); - assertThat(metadata.getProviderId()).isEqualTo("Ericsson"); - assertThat(metadata.getPackageVersion()).isEqualTo("1.0"); - assertThat(metadata.getReleaseDateTime()).isEqualTo("2019-01-14T11:25:00+00:00"); - } - }
\ 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 f680438..2f3a050 100644 --- a/csarvalidation/src/test/java/org/onap/cvc/csar/PnfManifestParserTest.java +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/PnfManifestParserTest.java @@ -20,6 +20,7 @@ import org.apache.commons.lang3.tuple.Pair; import org.junit.Before; import org.junit.Test; +import java.io.File; import java.io.IOException; import java.net.URISyntaxException; import java.util.List; @@ -34,7 +35,7 @@ public class PnfManifestParserTest { @Before public void setUp() throws URISyntaxException, IOException { - pnfManifestParser = PnfManifestParser.getInstance("./src/test/resources/pnf/MainServiceTemplate.mf"); + pnfManifestParser = PnfManifestParser.getInstance(new File("./src/test/resources/pnf/MainServiceTemplate.mf")); } @Test @@ -52,6 +53,19 @@ public class PnfManifestParserTest { @Test + public void shouldFetchSourcesSectionFromFile() { + + Pair<List<String>, List<CSARArchive.CSARError>> sourcesPair = pnfManifestParser.fetchSourcesSection(); + List<String> sources = sourcesPair.getKey(); + List<CSARArchive.CSARError> errors = sourcesPair.getValue(); + + assertThat(sources).contains("Definitions/MainServiceTemplate.yaml", "Definitions/etsi_nfv_sol001_vnfd_2_5_1_types.yaml"); + assertThat(errors.size()).isEqualTo(0); + } + + + + @Test public void shouldFetchNonManoArtifactsFromFile() { Pair<Map<String, Map<String, List<String>>>, List<CSARArchive.CSARError>> mapListPair = pnfManifestParser.fetchNonManoArtifacts(); Map<String, Map<String, List<String>>> nonManoArtifacts = mapListPair.getKey(); 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 new file mode 100644 index 0000000..32ac187 --- /dev/null +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/IntegrationTestUtils.java @@ -0,0 +1,78 @@ +/* + * Copyright 2019 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.cvc.csar.cc.sol004; + +import com.google.common.collect.Lists; +import org.onap.cli.fw.error.OnapCommandException; +import org.onap.cli.fw.error.OnapCommandInvalidParameterValue; +import org.onap.cli.fw.input.OnapCommandParameter; +import org.onap.cli.fw.output.OnapCommandResult; +import org.onap.cli.fw.output.OnapCommandResultAttribute; +import org.onap.cvc.csar.CSARArchive; +import org.onap.cvc.csar.cc.VTPValidatePnfCSARBase; + +import java.net.URISyntaxException; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +class IntegrationTestUtils { + + private IntegrationTestUtils() { + + } + + private static String absoluteFilePath(String relativeFilePath) throws URISyntaxException { + return VTPValidatePnfCSARBase.class.getClassLoader().getResource(relativeFilePath) + .toURI().getPath(); + } + + static void configureTestCase(VTPValidatePnfCSARBase testCase, String fileName) throws OnapCommandException, URISyntaxException { + configureCommandAttributes(testCase); + + testCase.initializeSchema("vtp-validate-csar-r146092.yaml"); + + configurePathToCsar(testCase, fileName); + } + + private static void configureCommandAttributes(VTPValidatePnfCSARBase testCase) { + OnapCommandResult onapCommandResult = new OnapCommandResult(); + OnapCommandResultAttribute onapCommandResultAttributeCode = new OnapCommandResultAttribute(); + onapCommandResultAttributeCode.setName("code"); + OnapCommandResultAttribute onapCommandResultAttributeMessage = new OnapCommandResultAttribute(); + onapCommandResultAttributeMessage.setName("message"); + OnapCommandResultAttribute onapCommandResultAttributeFile = new OnapCommandResultAttribute(); + onapCommandResultAttributeFile.setName("file"); + OnapCommandResultAttribute onapCommandResultAttributeLineNo = new OnapCommandResultAttribute(); + onapCommandResultAttributeLineNo.setName("line-no"); + List<OnapCommandResultAttribute> records = Lists.newArrayList(onapCommandResultAttributeCode, onapCommandResultAttributeMessage, onapCommandResultAttributeFile, onapCommandResultAttributeLineNo); + onapCommandResult.setRecords(records); + testCase.setResult(onapCommandResult); + } + + private static void configurePathToCsar(VTPValidatePnfCSARBase testCase, String fileName) throws URISyntaxException, OnapCommandInvalidParameterValue { + String pathToFile = absoluteFilePath(fileName); + Set<OnapCommandParameter> parameters = testCase.getParameters(); + OnapCommandParameter csar = parameters.stream().filter(op -> op.getName().equals("csar")).findFirst().get(); + csar.setValue(pathToFile); + } + + static List<String> convertToMessagesList(List<CSARArchive.CSARError> errors) { + return errors.stream().map(CSARArchive.CSARError::getMessage).collect(Collectors.toList()); + } +} 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 new file mode 100644 index 0000000..d5cb153 --- /dev/null +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR146092IntegrationTest.java @@ -0,0 +1,118 @@ +/* + * Copyright 2019 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.cvc.csar.cc.sol004; + +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.onap.cvc.csar.cc.sol004.IntegrationTestUtils.configureTestCase; +import static org.onap.cvc.csar.cc.sol004.IntegrationTestUtils.convertToMessagesList; + + +public class VTPValidateCSARR146092IntegrationTest { + + private VTPValidateCSARR146092 testCase; + + @Before + public void setUp() { + testCase = new VTPValidateCSARR146092(); + } + + @Test + public void shouldReturnProperRequestNumber() { + assertThat(testCase.getVnfReqsNo()).isEqualTo("R146092"); + } + + @Test + public void shouldReportThatMandatoryNonManoArtifactsAreNotAvailable() throws Exception { + // given + configureTestCase(testCase, "pnf/r146092/missingNonManoArtifactInManifest.csar"); + + // when + testCase.execute(); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(5); + assertThat(convertToMessagesList(errors)).contains( + "Missing. Entry [non_mano_artifact_sets]", + "Missing. Entry [onap_ves_events]", + "Missing. Entry [onap_pm_dictionary]", + "Missing. Entry [onap_yang_module]", + "Missing. Entry [onap_others]" + ); + } + + @Test + public void shouldReportThatMandatoryNonManoArtifactSetEntryHasNotAllFields() throws Exception { + // given + configureTestCase(testCase, "pnf/r146092/missingFieldsInNonManoArtifactManifest.csar"); + + // when + testCase.execute(); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(4); + assertThat(convertToMessagesList(errors)).contains( + "Missing. Entry [onap_ves_events]", + "Missing. Entry [onap_pm_dictionary]", + "Missing. Entry [onap_yang_module]", + "Missing. Entry [onap_others]" + ); + } + + + @Test + public void shouldReportThatNonManoArtifactEntryHasAnySource() throws Exception { + // given + configureTestCase(testCase, "pnf/r146092/noSourceElementInNonManoArtifactEntryManifest.csar"); + + // when + testCase.execute(); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(1); + assertThat(convertToMessagesList(errors)).contains( + "Missing. Entry [source under onap_ves_events]" + ); + } + + + @Test + public void shouldReportThatNonManoArtifactEntryHasSourceWithUnknownFile() throws Exception { + // given + configureTestCase(testCase, "pnf/r146092/sourceElementWithUnknownFileInNonManoArtifactEntryManifest.csar"); + + // when + testCase.execute(); + + // then + List<CSARArchive.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]" + ); + } + +}
\ No newline at end of file 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 eca3c1a..cd1dc06 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 @@ -17,22 +17,15 @@ package org.onap.cvc.csar.cc.sol004; -import com.google.common.collect.Lists; import org.junit.Before; import org.junit.Test; -import org.onap.cli.fw.error.OnapCommandException; -import org.onap.cli.fw.error.OnapCommandInvalidParameterValue; -import org.onap.cli.fw.input.OnapCommandParameter; -import org.onap.cli.fw.output.OnapCommandResult; -import org.onap.cli.fw.output.OnapCommandResultAttribute; import org.onap.cvc.csar.CSARArchive; -import java.net.URISyntaxException; import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; 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; public class VTPValidateCSARR293901IntegrationTest { @@ -40,7 +33,7 @@ public class VTPValidateCSARR293901IntegrationTest { private VTPValidateCSARR293901 testCase; @Before - public void setUp(){ + public void setUp() { testCase = new VTPValidateCSARR293901(); } @@ -52,7 +45,7 @@ public class VTPValidateCSARR293901IntegrationTest { @Test public void shouldReportThatMandatoryEntriesAreNotAvailable() throws Exception { // given - configureTestCase(testCase, "pnf/noMandatoryEntriesInTOSCAMeta.csar"); + configureTestCase(testCase, "pnf/r293901/noMandatoryEntriesInTOSCAMeta.csar"); // when testCase.execute(); @@ -70,7 +63,7 @@ public class VTPValidateCSARR293901IntegrationTest { @Test public void shouldDoNotReportAnyErrorWhenAllMandatoryEntriesWereDefined() throws Exception { // given - configureTestCase(testCase, "pnf/allMandatoryEntriesDefinedInTOSCAMeta.csar"); + configureTestCase(testCase, "pnf/r293901/allMandatoryEntriesDefinedInTOSCAMeta.csar"); // when testCase.execute(); @@ -83,7 +76,7 @@ public class VTPValidateCSARR293901IntegrationTest { @Test public void shouldReportAnyErrorWhneThereIsNoTOSCAMetaFileInTOSCADirectory() throws Exception { // given - configureTestCase(testCase, "pnf/noTOSCAMetaInTOSCADirectory.csar"); + configureTestCase(testCase, "pnf/r293901/noTOSCAMetaInTOSCADirectory.csar"); // when testCase.execute(); @@ -98,45 +91,4 @@ public class VTPValidateCSARR293901IntegrationTest { "Missing. Entry [ETSI-Entry-Change-Log]" ); } - - private String resolvePathToFile(String s) throws URISyntaxException { - return VTPValidateCSARR293901IntegrationTest.class.getClassLoader().getResource(s) - .toURI().getPath(); - } - - private void configureTestCase(VTPValidateCSARR293901 testCase, String fileName) throws OnapCommandException, URISyntaxException { - configureCommandAttributes(testCase); - - testCase.initializeSchema("vtp-validate-csar-r293901.yaml"); - - configurePathToCsar(testCase, fileName); - } - - private void configureCommandAttributes(VTPValidateCSARR293901 testCase) { - OnapCommandResult onapCommandResult = new OnapCommandResult(); - OnapCommandResultAttribute onapCommandResultAttributeCode = new OnapCommandResultAttribute(); - onapCommandResultAttributeCode.setName("code"); - OnapCommandResultAttribute onapCommandResultAttributeMessage = new OnapCommandResultAttribute(); - onapCommandResultAttributeMessage.setName("message"); - OnapCommandResultAttribute onapCommandResultAttributeFile = new OnapCommandResultAttribute(); - onapCommandResultAttributeFile.setName("file"); - OnapCommandResultAttribute onapCommandResultAttributeLineNo = new OnapCommandResultAttribute(); - onapCommandResultAttributeLineNo.setName("line-no"); - List<OnapCommandResultAttribute> records = Lists.newArrayList(onapCommandResultAttributeCode, onapCommandResultAttributeMessage, onapCommandResultAttributeFile, onapCommandResultAttributeLineNo); - onapCommandResult.setRecords(records); - testCase.setResult(onapCommandResult); - } - - private void configurePathToCsar(VTPValidateCSARR293901 testCase, String fileName) throws URISyntaxException, OnapCommandInvalidParameterValue { - String pathToFile = resolvePathToFile(fileName); - Set<OnapCommandParameter> parameters = testCase.getParameters(); - OnapCommandParameter csar = parameters.stream().filter(op -> op.getName().equals("csar")).findFirst().get(); - csar.setValue(pathToFile); - } - - private List<String> convertToMessagesList(List<CSARArchive.CSARError> errors) { - return errors.stream().map(CSARArchive.CSARError::getMessage).collect(Collectors.toList()); - } - - }
\ No newline at end of file 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 new file mode 100644 index 0000000..8ec88ea --- /dev/null +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR57019IntegrationTest.java @@ -0,0 +1,78 @@ +/* + * Copyright 2019 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.cvc.csar.cc.sol004; + +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.onap.cvc.csar.cc.sol004.IntegrationTestUtils.configureTestCase; +import static org.onap.cvc.csar.cc.sol004.IntegrationTestUtils.convertToMessagesList; + + +public class VTPValidateCSARR57019IntegrationTest { + + private VTPValidateCSARR57019 testCase; + + @Before + public void setUp() { + testCase = new VTPValidateCSARR57019(); + } + + @Test + public void shouldReturnProperRequestNumber() { + assertThat(testCase.getVnfReqsNo()).isEqualTo("R57019"); + } + + @Test + public void shouldReportThatMandatoryEntriesInMetadataAreNotAvailable() throws Exception { + // given + configureTestCase(testCase, "pnf/r57019/noMandatoryEntriesInMetadataManifest.csar"); + + // when + testCase.execute(); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(5); + assertThat(convertToMessagesList(errors)).contains( + "Missing. Entry [pnfd_provider]", + "Missing. Entry [pnfd_name]", + "Missing. Entry [pnfd_release_date_time]", + "Missing. Entry [pnfd_archive_version]", + "Invalid. Entry [pnfd_archivee_version]" + ); + } + + @Test + public void shouldDoNotReportAnyErrorWhenAllMandatoryEntriesInMetadataWereDefined() throws Exception { + // given + configureTestCase(testCase, "pnf/r57019/allMandatoryEntriesDefinedInMetadataManifest.csar"); + + // when + testCase.execute(); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(0); + } + +}
\ No newline at end of file |