summaryrefslogtreecommitdiffstats
path: root/csarvalidation/src/test
diff options
context:
space:
mode:
authorGao Weitao <victor.gao@huawei.com>2019-03-25 13:46:06 +0000
committerGerrit Code Review <gerrit@onap.org>2019-03-25 13:46:06 +0000
commitd34c02725d33d4b9cfa3ac70742b47be65b31066 (patch)
treece03c44c382357155aac9c1c0e6f96ccddc5d47a /csarvalidation/src/test
parent873fbb49dcd3092d2591a4eca13470713ca443ea (diff)
parent5873269dcf426377a037e28a0b16bd18af582a7e (diff)
Merge "PNF TC R293901"
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