summaryrefslogtreecommitdiffstats
path: root/csarvalidation/src/test
diff options
context:
space:
mode:
authorBogumil Zebek <bogumil.zebek@nokia.com>2019-03-19 09:59:02 +0100
committerZebek Bogumil <bogumil.zebek@nokia.com>2019-03-22 13:24:43 +0100
commit5873269dcf426377a037e28a0b16bd18af582a7e (patch)
treebfd24cc65aa4cd929f1864734449223eae7e035b /csarvalidation/src/test
parent0d4544eb82a2ca79d7724e5c1da70d3943db76eb (diff)
PNF TC R293901
Change-Id: I6acfa94ce0fac2b3c46688601c3ec553af4c8b66 Issue-ID: VNFSDK-386 Signed-off-by: Zebek Bogumil <bogumil.zebek@nokia.com>
Diffstat (limited to 'csarvalidation/src/test')
-rw-r--r--csarvalidation/src/test/java/org/onap/cvc/csar/PnfCSARArchiveTest.java15
-rw-r--r--csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR293901IntegrationTest.java142
-rw-r--r--csarvalidation/src/test/resources/pnf/allMandatoryEntriesDefinedInTOSCAMeta.csarbin0 -> 4117 bytes
-rw-r--r--csarvalidation/src/test/resources/pnf/noMandatoryEntriesInTOSCAMeta.csarbin0 -> 3943 bytes
-rw-r--r--csarvalidation/src/test/resources/pnf/noTOSCAMetaInTOSCADirectory.csarbin0 -> 164 bytes
5 files changed, 148 insertions, 9 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 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
+ * <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.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<CSARArchive.CSARError> 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<CSARArchive.CSARError> 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<CSARArchive.CSARError> 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<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/resources/pnf/allMandatoryEntriesDefinedInTOSCAMeta.csar b/csarvalidation/src/test/resources/pnf/allMandatoryEntriesDefinedInTOSCAMeta.csar
new file mode 100644
index 0000000..f22366a
--- /dev/null
+++ b/csarvalidation/src/test/resources/pnf/allMandatoryEntriesDefinedInTOSCAMeta.csar
Binary files differ
diff --git a/csarvalidation/src/test/resources/pnf/noMandatoryEntriesInTOSCAMeta.csar b/csarvalidation/src/test/resources/pnf/noMandatoryEntriesInTOSCAMeta.csar
new file mode 100644
index 0000000..9ef56cf
--- /dev/null
+++ b/csarvalidation/src/test/resources/pnf/noMandatoryEntriesInTOSCAMeta.csar
Binary files differ
diff --git a/csarvalidation/src/test/resources/pnf/noTOSCAMetaInTOSCADirectory.csar b/csarvalidation/src/test/resources/pnf/noTOSCAMetaInTOSCADirectory.csar
new file mode 100644
index 0000000..7ab26c3
--- /dev/null
+++ b/csarvalidation/src/test/resources/pnf/noTOSCAMetaInTOSCADirectory.csar
Binary files differ