From 5873269dcf426377a037e28a0b16bd18af582a7e Mon Sep 17 00:00:00 2001 From: Bogumil Zebek Date: Tue, 19 Mar 2019 09:59:02 +0100 Subject: PNF TC R293901 Change-Id: I6acfa94ce0fac2b3c46688601c3ec553af4c8b66 Issue-ID: VNFSDK-386 Signed-off-by: Zebek Bogumil --- .../java/org/onap/cvc/csar/PnfCSARArchiveTest.java | 15 +-- .../VTPValidateCSARR293901IntegrationTest.java | 142 +++++++++++++++++++++ 2 files changed, 148 insertions(+), 9 deletions(-) create mode 100644 csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR293901IntegrationTest.java (limited to 'csarvalidation/src/test/java/org/onap') 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 d7370e4..b29470c 100644 --- a/csarvalidation/src/test/java/org/onap/cvc/csar/PnfCSARArchiveTest.java +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/PnfCSARArchiveTest.java @@ -29,23 +29,20 @@ import static org.assertj.core.api.Assertions.assertThat; public class PnfCSARArchiveTest { @Test - public void shouldUseDataStoredInManifestMfFileToConfigurePnfCSARArchive() throws IOException, URISyntaxException { + public void shouldUseDataStoredInManifestMfFileToConfigurePnfCSARArchive() throws Exception { // given String fileName = PnfCSARArchiveTest.class.getClassLoader().getResource("pnf/dummyPnfv2.csar") .toURI().getPath(); - PnfCSARArchive pnfCSARArchive = new PnfCSARArchive(); - pnfCSARArchive.init(fileName); // when - try { + try( PnfCSARArchive pnfCSARArchive = new PnfCSARArchive()) { + pnfCSARArchive.init(fileName); pnfCSARArchive.parse(); - }finally { - pnfCSARArchive.cleanup(); + // then + verifyThatMetadataWasSet(pnfCSARArchive); + verifyThatNonManoArtifactsWereSet(pnfCSARArchive); } - // then - verifyThatMetadataWasSet(pnfCSARArchive); - verifyThatNonManoArtifactsWereSet(pnfCSARArchive); } private void verifyThatNonManoArtifactsWereSet(PnfCSARArchive pnfCSARArchive) { 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 new file mode 100644 index 0000000..eca3c1a --- /dev/null +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR293901IntegrationTest.java @@ -0,0 +1,142 @@ +/* + * Copyright 2019 Nokia + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.onap.cvc.csar.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; + + +public class VTPValidateCSARR293901IntegrationTest { + + private VTPValidateCSARR293901 testCase; + + @Before + public void setUp(){ + testCase = new VTPValidateCSARR293901(); + } + + @Test + public void shouldReturnProperRequestNumber() { + assertThat(testCase.getVnfReqsNo()).isEqualTo("R293901"); + } + + @Test + public void shouldReportThatMandatoryEntriesAreNotAvailable() throws Exception { + // given + configureTestCase(testCase, "pnf/noMandatoryEntriesInTOSCAMeta.csar"); + + // when + testCase.execute(); + + // then + List errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(3); + assertThat(convertToMessagesList(errors)).contains( + "Missing. Entry [Entry-Definitions]", + "Missing. Entry [ETSI-Entry-Manifest]", + "Missing. Entry [ETSI-Entry-Change-Log]" + ); + } + + @Test + public void shouldDoNotReportAnyErrorWhenAllMandatoryEntriesWereDefined() throws Exception { + // given + configureTestCase(testCase, "pnf/allMandatoryEntriesDefinedInTOSCAMeta.csar"); + + // when + testCase.execute(); + + // then + List errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(0); + } + + @Test + public void shouldReportAnyErrorWhneThereIsNoTOSCAMetaFileInTOSCADirectory() throws Exception { + // given + configureTestCase(testCase, "pnf/noTOSCAMetaInTOSCADirectory.csar"); + + // when + testCase.execute(); + + // then + List errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(4); + assertThat(convertToMessagesList(testCase.getErrors())).contains( + "Missing. Entry [Definition YAML]", + "Ignored. Entry [TOSCA-Metadata]", + "Missing. Entry [ETSI-Entry-Manifest]", + "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 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 parameters = testCase.getParameters(); + OnapCommandParameter csar = parameters.stream().filter(op -> op.getName().equals("csar")).findFirst().get(); + csar.setValue(pathToFile); + } + + private List convertToMessagesList(List errors) { + return errors.stream().map(CSARArchive.CSARError::getMessage).collect(Collectors.toList()); + } + + +} \ No newline at end of file -- cgit 1.2.3-korg