diff options
author | 2020-07-15 05:03:08 +0000 | |
---|---|---|
committer | 2020-07-15 05:03:08 +0000 | |
commit | 417efc335c8d4ee2154e9e7466619153dc185cec (patch) | |
tree | 4a76321e3f7ae6cd61d012c0147c6ddb108b42f6 /csarvalidation/src/test/java/org/onap/cvc | |
parent | 12b638d643a95daa7b3b65835d9781558ad3030a (diff) | |
parent | 4ce8c75c2559bde35b5fca46ec2c94d6b5070b6f (diff) |
Merge "use YAML schema validator in rule R816745"
Diffstat (limited to 'csarvalidation/src/test/java/org/onap/cvc')
2 files changed, 100 insertions, 5 deletions
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 index 6f183d7..6d90b23 100644 --- 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 @@ -87,4 +87,8 @@ public class IntegrationTestUtils { public static List<String> convertToMessagesList(List<CSARArchive.CSARError> errors) { return errors.stream().map(CSARArchive.CSARError::getMessage).collect(Collectors.toList()); } + + public static List<String> convertToFilesList(List<CSARArchive.CSARError> errors) { + return errors.stream().map(CSARArchive.CSARError::getFile).collect(Collectors.toList()); + } } diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR816745IntegrationTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR816745IntegrationTest.java index efe6917..70a370e 100644 --- a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR816745IntegrationTest.java +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR816745IntegrationTest.java @@ -17,17 +17,22 @@ package org.onap.cvc.csar.cc.sol004; +import org.assertj.core.api.Condition; +import org.assertj.core.api.HamcrestCondition; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.onap.cli.fw.error.OnapCommandExecutionFailed; import org.onap.cvc.csar.CSARArchive; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.CoreMatchers.allOf; +import static org.hamcrest.CoreMatchers.containsString; import static org.onap.cvc.csar.cc.sol004.IntegrationTestUtils.configureTestCase; +import static org.onap.cvc.csar.cc.sol004.IntegrationTestUtils.convertToMessagesList; +import static org.onap.cvc.csar.cc.sol004.IntegrationTestUtils.convertToFilesList; public class VTPValidateCSARR816745IntegrationTest { @@ -58,16 +63,67 @@ public class VTPValidateCSARR816745IntegrationTest { } @Test - public void shouldThrowUnsupportedOperationExceptionWhenCsarContainsPmDictionary() throws Exception { + public void shouldReturnNoErrorsWhenCsarContainsValidPmDictionary() throws Exception { // given - configureTestCase(testCase, TEST_CSAR_DIRECTORY + "csar-with-pm-dictionary.csar", "vtp-validate-csar-r816745.yaml", IS_PNF); + configureTestCase(testCase, TEST_CSAR_DIRECTORY + "csar-with-valid-pm-dictionary.csar", "vtp-validate-csar-r816745.yaml", IS_PNF); + + // when + testCase.execute(); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(0); + } + + @Test + public void shouldReturnNoErrorsWhenZipContainsCsarWithValidPmDictionary() throws Exception { + // given + configureTestCase(testCase, TEST_CSAR_DIRECTORY + "zip-with-valid-pm-dictionary.zip", "vtp-validate-csar-r816745.yaml", IS_PNF); + + // when + testCase.execute(); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(0); + } + + @Test + public void shouldReturnListOfErrorsWhenCsarContainsInvalidPmDictionary() throws Exception { + // given + configureTestCase(testCase, TEST_CSAR_DIRECTORY + "csar-with-invalid-pm-dictionary.csar", "vtp-validate-csar-r816745.yaml", IS_PNF); + + // when + testCase.execute(); // then - exceptionRule.expect(OnapCommandExecutionFailed.class); - exceptionRule.expectMessage("Under development"); + assertThatReturnedErrorsAreCorrect(testCase.getErrors()); + } + + @Test + public void shouldReturnListOfErrorsWhenZipContainsCsarWithInvalidPmDictionary() throws Exception { + // given + configureTestCase(testCase, TEST_CSAR_DIRECTORY + "zip-with-invalid-pm-dictionary.zip", "vtp-validate-csar-r816745.yaml", IS_PNF); // when testCase.execute(); + + // then + assertThatReturnedErrorsAreCorrect(testCase.getErrors()); + } + + @Test + public void shouldAddPmDictionaryLoadingErrorWhenGivenInvalidPath() throws Exception { + // given + configureTestCase(testCase, TEST_CSAR_DIRECTORY + "csar-with-empty-pm-dictionary.csar", "vtp-validate-csar-r816745.yaml", IS_PNF); + + // when then + testCase.execute(); + + // then + List<CSARArchive.CSARError> errors = testCase.getErrors(); + assertThat(errors.size()).isEqualTo(1); + assertThat(convertToMessagesList(errors)).contains("Fail to load PM_Dictionary With error: PM_Dictionary YAML file is empty"); } @Test @@ -75,4 +131,39 @@ public class VTPValidateCSARR816745IntegrationTest { assertThat(testCase.getVnfReqsNo()).isEqualTo("R816745"); } + private void assertThatReturnedErrorsAreCorrect(List<CSARArchive.CSARError> errors) { + assertThat(errors.size()).isEqualTo(3); + + Condition<String> containingSameFileForAllErrors = new HamcrestCondition<>( + containsString("Artifacts/Deployment/Measurements/PM_Dictionary.yml") + ); + assertThat(convertToFilesList(errors)).haveExactly(3, containingSameFileForAllErrors); + + Condition<String> containingErrorForMissingValueInFirstDocument = new HamcrestCondition<>(allOf( + containsString("Invalid YAML document in PM_Dictionary file."), + containsString("In document number 1"), + containsString("Path: /pmMetaData/pmFields/"), + containsString("Key not found: measChangeType") + )); + assertThat(convertToMessagesList(errors)).haveExactly(1, containingErrorForMissingValueInFirstDocument); + + Condition<String> containingErrorForWrongValueInFirstDocument = new HamcrestCondition<>(allOf( + containsString("Invalid YAML document in PM_Dictionary file."), + containsString("In document number 1"), + containsString("Path: /pmMetaData/pmFields/measResultType"), + containsString("Value is not in array of accepted values."), + containsString("value: integer"), + containsString("accepted values: [float, uint32, uint64]") + )); + assertThat(convertToMessagesList(errors)).haveExactly(1, containingErrorForWrongValueInFirstDocument); + + Condition<String> containingErrorForMissingValueInSecondDocument = new HamcrestCondition<>(allOf( + containsString("Invalid YAML document in PM_Dictionary file."), + containsString("In document number 2"), + containsString("Path: /pmMetaData/pmFields/"), + containsString("Key not found: measChangeType") + )); + assertThat(convertToMessagesList(errors)).haveExactly(1, containingErrorForMissingValueInSecondDocument); + } + } |