summaryrefslogtreecommitdiffstats
path: root/csarvalidation/src/test/java/org/onap
diff options
context:
space:
mode:
authorBogumil Zebek <bogumil.zebek@nokia.com>2020-05-20 14:53:35 +0200
committerZebek Bogumil <bogumil.zebek@nokia.com>2020-05-20 14:57:56 +0200
commit0bb03735689b28dee661bb2d59dfc56f44cf9e2c (patch)
treecb8c52963250239478959aa8625c8f6f6a8de204 /csarvalidation/src/test/java/org/onap
parent47d26d20674f85e75d406a1e459cc09666b8b84c (diff)
Fix validation process
Resolve problem that one failed rule has impact on other valid rules. Change-Id: Ib36eed71b16fbfc48af88faaf07bb7293fefaf38 Issue-ID: VNFSDK-586 Signed-off-by: Zebek Bogumil <bogumil.zebek@nokia.com>
Diffstat (limited to 'csarvalidation/src/test/java/org/onap')
-rw-r--r--csarvalidation/src/test/java/org/onap/cvc/csar/CsarValidatorTest.java115
1 files changed, 101 insertions, 14 deletions
diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/CsarValidatorTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/CsarValidatorTest.java
index 2969b42..2c39f74 100644
--- a/csarvalidation/src/test/java/org/onap/cvc/csar/CsarValidatorTest.java
+++ b/csarvalidation/src/test/java/org/onap/cvc/csar/CsarValidatorTest.java
@@ -1,12 +1,13 @@
/**
* 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.
@@ -16,7 +17,13 @@
package org.onap.cvc.csar;
+import org.apache.commons.lang3.StringUtils;
+import org.assertj.core.api.Assertions;
import org.junit.Test;
+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.fw.output.OnapCommandResultAttribute;
import org.onap.cli.main.OnapCli;
import java.net.URISyntaxException;
@@ -27,42 +34,122 @@ import static org.onap.cvc.csar.cc.sol004.IntegrationTestUtils.absoluteFilePath;
public class CsarValidatorTest {
+ public static final String NO_CERTIFICATE_RULE = "r130206";
+ public static final String OPERATION_STATUS_FAILED = "FAILED";
@Test
- public void testAllTestCasesForVNF() throws URISyntaxException {
- OnapCli cli = new OnapCli(new String [] {
+ public void shouldReportThanVnfValidationFailed() throws URISyntaxException {
+ // given
+ OnapCliWrapper cli = new OnapCliWrapper(new String[]{
"--product", "onap-dublin",
"csar-validate",
"--format", "json",
"--csar", absoluteFilePath("VoLTE.csar")});
+
+ // when
cli.handle();
- assertEquals(0, cli.getExitCode());
+
+ // then
+ final OnapCommandResult onapCommandResult = cli.getCommandResult();
+ verifyThatOperation(onapCommandResult, OPERATION_STATUS_FAILED);
+ verifyThatXRulesFails(onapCommandResult, 7);
+ verifyThatOperationFinishedWithoutAnyError(cli);
}
@Test
- public void testAllTestCasesForPNF_CsarCase() throws URISyntaxException {
- OnapCli cli = new OnapCli(new String [] {
+ public void shouldReportThatPnfValidationFailedWhenCsarDoNotHaveCertificate_allOtherRulesShouldPass() throws URISyntaxException {
+ // given
+ OnapCliWrapper cli = new OnapCliWrapper(new String[]{
"--product", "onap-dublin",
"csar-validate",
"--format", "json",
"--pnf",
- "--csar", absoluteFilePath("pnf/r57019/allMandatoryEntriesDefinedInMetadataManifest.csar")});
+ "--csar", absoluteFilePath("pnf/r972082/validFile.csar")});
+ // when
cli.handle();
- assertEquals(0, cli.getExitCode());
- }
+ // then
+ final OnapCommandResult onapCommandResult = cli.getCommandResult();
+ verifyThatOperation(onapCommandResult, OPERATION_STATUS_FAILED);
+ verifyThatXRulesFails(onapCommandResult, 1);
+ verifyThatRuleFails(onapCommandResult, NO_CERTIFICATE_RULE);
+ verifyThatOperationFinishedWithoutAnyError(cli);
+ }
@Test
- public void testAllTestCasesForPNF_ZipCase() throws URISyntaxException {
- OnapCli cli = new OnapCli(new String [] {
+ public void shouldReportThatPnfValidationFailedWhenZipDoNotHaveCertificate_allOtherRulesShouldPass() throws URISyntaxException {
+ // given
+ OnapCliWrapper cli = new OnapCliWrapper(new String[]{
"--product", "onap-dublin",
"csar-validate",
"--format", "json",
"--pnf",
"--csar", absoluteFilePath("pnf/signed-package-valid-signature.zip")});
+
+ // when
cli.handle();
+
+ // then
+ final OnapCommandResult onapCommandResult = cli.getCommandResult();
+ verifyThatOperation(onapCommandResult, OPERATION_STATUS_FAILED);
+ verifyThatXRulesFails(onapCommandResult, 1);
+ verifyThatRuleFails(onapCommandResult, NO_CERTIFICATE_RULE);
+ verifyThatOperationFinishedWithoutAnyError(cli);
+ }
+
+ private void verifyThatXRulesFails(OnapCommandResult onapCommandResult, int noOfRules) {
+ verifyDataOccurrenceInResult(onapCommandResult, "\"passed\":false", noOfRules);
+ }
+
+ private void verifyThatRuleFails(OnapCommandResult onapCommandResult, String nameOfRule) {
+ final String value = String.format("\"passed\":false,\"vnfreqName\":\"%s\"", nameOfRule);
+ verifyDataOccurrenceInResult(onapCommandResult, value, 1);
+ }
+
+ private void verifyDataOccurrenceInResult(OnapCommandResult onapCommandResult, String data, int dataOccurrence) {
+ final String json = getResultValue(onapCommandResult, "results");
+ int occurrence = StringUtils.countMatches(json, data);
+ Assertions.assertThat(occurrence).isEqualTo(dataOccurrence);
+ }
+
+ private void verifyThatOperation(OnapCommandResult onapCommandResult, String operationStatus) {
+ final String value = getResultValue(onapCommandResult, "criteria");
+ Assertions.assertThat(value).isEqualTo(operationStatus);
+ }
+
+ private String getResultValue(OnapCommandResult onapCommandResult, String attributeName) {
+ final OnapCommandResultAttribute results = getOnapCommandResultAttribute(onapCommandResult, attributeName);
+ return results.getValues().get(0);
+ }
+
+ private OnapCommandResultAttribute getOnapCommandResultAttribute(OnapCommandResult onapCommandResult, String name) {
+ return onapCommandResult.getRecords().stream()
+ .filter(it -> it.getName().equals(name))
+ .findFirst()
+ .orElseThrow(() -> new RuntimeException(String.format("Unable to find '%s' attribute!", name)));
+ }
+
+ private void verifyThatOperationFinishedWithoutAnyError(OnapCliWrapper cli) {
assertEquals(0, cli.getExitCode());
}
+ 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;
+ }
+ }
}