From 84eb0c707c621e4855bf27e49be0cc69ded1f321 Mon Sep 17 00:00:00 2001 From: Bogumil Zebek Date: Mon, 27 May 2019 14:24:13 +0200 Subject: Specification change Change-Id: I7810f0310d6c2ae178c6d865494fff88c8751634 Issue-ID: VNFSDK-410 Signed-off-by: Zebek Bogumil --- .../src/main/java/org/onap/cvc/csar/CSARArchive.java | 7 +++++++ .../src/main/java/org/onap/cvc/csar/PnfCSARArchive.java | 14 ++++++++++---- .../main/java/org/onap/cvc/csar/PnfManifestParser.java | 7 ++++--- .../onap/cvc/csar/cc/sol004/VTPValidateCSARR146092.java | 10 ++++++---- .../java/org/onap/cvc/csar/PnfManifestParserTest.java | 2 +- .../org/onap/cvc/csar/PnfNonManoArtifactsParserTest.java | 15 ++++++--------- .../cc/sol004/VTPValidateCSARR146092IntegrationTest.java | 11 ++--------- 7 files changed, 36 insertions(+), 30 deletions(-) (limited to 'csarvalidation/src') diff --git a/csarvalidation/src/main/java/org/onap/cvc/csar/CSARArchive.java b/csarvalidation/src/main/java/org/onap/cvc/csar/CSARArchive.java index 0924de7..f1aff70 100644 --- a/csarvalidation/src/main/java/org/onap/cvc/csar/CSARArchive.java +++ b/csarvalidation/src/main/java/org/onap/cvc/csar/CSARArchive.java @@ -738,6 +738,8 @@ public class CSARArchive implements AutoCloseable { } public static class Manifest{ + private boolean isNonManoAvailable; + public static class Metadata { private String providerId; @@ -792,12 +794,17 @@ public class CSARArchive implements AutoCloseable { this.metadata = metadata; } + public boolean isNonManoAvailable(){ + return isNonManoAvailable; + } + public Map>> getNonMano() { return nonMano; } public void setNonMano(Map>> nonMano) { this.nonMano = nonMano; + this.isNonManoAvailable = true; } } diff --git a/csarvalidation/src/main/java/org/onap/cvc/csar/PnfCSARArchive.java b/csarvalidation/src/main/java/org/onap/cvc/csar/PnfCSARArchive.java index 5ac67cd..6438306 100644 --- a/csarvalidation/src/main/java/org/onap/cvc/csar/PnfCSARArchive.java +++ b/csarvalidation/src/main/java/org/onap/cvc/csar/PnfCSARArchive.java @@ -22,6 +22,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Optional; public class PnfCSARArchive extends CSARArchive { @@ -37,15 +38,20 @@ public class PnfCSARArchive extends CSARArchive { Pair> metadataData = pnfManifestParser.fetchMetadata(); Pair, List> sourcesSectionData = pnfManifestParser.fetchSourcesSection(); - Pair>>, List> nonManoArtifactsData = pnfManifestParser.fetchNonManoArtifacts(); + Optional>>, List>> nonManoArtifactsData = pnfManifestParser.fetchNonManoArtifacts(); PnfManifest manifest = (PnfManifest) this.getManifest(); manifest.setMetadata(metadataData.getKey()); - manifest.setSources(sourcesSectionData.getKey()); - manifest.setNonMano(nonManoArtifactsData.getKey()); this.getErrors().addAll(metadataData.getValue()); - this.getErrors().addAll(nonManoArtifactsData.getValue()); + + manifest.setSources(sourcesSectionData.getKey()); this.getErrors().addAll(sourcesSectionData.getValue()); + + if(nonManoArtifactsData.isPresent()){ + manifest.setNonMano(nonManoArtifactsData.get().getKey()); + this.getErrors().addAll(nonManoArtifactsData.get().getValue()); + } + } @Override diff --git a/csarvalidation/src/main/java/org/onap/cvc/csar/PnfManifestParser.java b/csarvalidation/src/main/java/org/onap/cvc/csar/PnfManifestParser.java index 5ef74fd..8831082 100644 --- a/csarvalidation/src/main/java/org/onap/cvc/csar/PnfManifestParser.java +++ b/csarvalidation/src/main/java/org/onap/cvc/csar/PnfManifestParser.java @@ -29,6 +29,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -118,7 +119,7 @@ class PnfManifestParser { return Pair.of(sources, errors); } - Pair>>, List> fetchNonManoArtifacts() { + Optional>>, List>> fetchNonManoArtifacts() { Map>> nonManoArtifacts = new HashMap<>(); List errors = new ArrayList<>(); @@ -143,10 +144,10 @@ class PnfManifestParser { } if (!isNonManoArtifactsSectionAvailable) { - errors.add(new PnfCSARErrorEntryMissing(NON_MANO_ARTIFACT_SETS_TAG_SECTION, this.fileName, -1)); + return Optional.empty(); } - return Pair.of(nonManoArtifacts, errors); + return Optional.of(Pair.of(nonManoArtifacts, errors)); } private boolean isLineExcluded(String line) { diff --git a/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR146092.java b/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR146092.java index 95b35bf..6150a04 100644 --- a/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR146092.java +++ b/csarvalidation/src/main/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR146092.java @@ -59,10 +59,12 @@ public class VTPValidateCSARR146092 extends VTPValidateCSARBase { @Override protected void validateCSAR(CSARArchive csar) { - Optional validateNonManoSection = ValidateNonManoSection.getInstance(csar); - if(validateNonManoSection.isPresent()) { - List csarErrors = validateNonManoSection.get().validate(); - this.errors.addAll(csarErrors); + if(csar.getManifest().isNonManoAvailable()) { + Optional validateNonManoSection = ValidateNonManoSection.getInstance(csar); + if(validateNonManoSection.isPresent()) { + List csarErrors = validateNonManoSection.get().validate(); + this.errors.addAll(csarErrors); + } } } diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/PnfManifestParserTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/PnfManifestParserTest.java index 2f3a050..09a2706 100644 --- a/csarvalidation/src/test/java/org/onap/cvc/csar/PnfManifestParserTest.java +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/PnfManifestParserTest.java @@ -67,7 +67,7 @@ public class PnfManifestParserTest { @Test public void shouldFetchNonManoArtifactsFromFile() { - Pair>>, List> mapListPair = pnfManifestParser.fetchNonManoArtifacts(); + Pair>>, List> mapListPair = pnfManifestParser.fetchNonManoArtifacts().get(); Map>> nonManoArtifacts = mapListPair.getKey(); List errors= mapListPair.getValue(); diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/PnfNonManoArtifactsParserTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/PnfNonManoArtifactsParserTest.java index 91d2648..92733bb 100644 --- a/csarvalidation/src/test/java/org/onap/cvc/csar/PnfNonManoArtifactsParserTest.java +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/PnfNonManoArtifactsParserTest.java @@ -21,14 +21,14 @@ import org.junit.Test; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; +import java.util.Optional; import static org.assertj.core.api.Assertions.assertThat; public class PnfNonManoArtifactsParserTest { @Test - public void shouldReportAnErrorWhenNonManoArtifactSectionIsNotAvailable() { + public void shouldDoNotReportAnErrorWhenNonManoArtifactSectionIsNotAvailable() { // given List lines = Lists.newArrayList( "someSection:", @@ -40,14 +40,11 @@ public class PnfNonManoArtifactsParserTest { // when PnfManifestParser pnfManifestParser = new PnfManifestParser(lines, "fileName"); - Pair>>, List> data = pnfManifestParser.fetchNonManoArtifacts(); + Optional>>, List>> nonManoArtifacts = + pnfManifestParser.fetchNonManoArtifacts(); //then - List errors = data.getRight(); - assertThat(errors.size()).isEqualTo(1); - assertThat(errors.stream().map(CSARArchive.CSARError::getMessage).collect(Collectors.toList())).contains( - "Missing. Entry [non_mano_artifact_sets]" - ); + assertThat(nonManoArtifacts.isPresent()).isFalse(); } @Test @@ -69,7 +66,7 @@ public class PnfNonManoArtifactsParserTest { // when PnfManifestParser pnfManifestParser = new PnfManifestParser(lines, "fileName"); - Pair>>, List> data = pnfManifestParser.fetchNonManoArtifacts(); + Pair>>, List> data = pnfManifestParser.fetchNonManoArtifacts().get(); //then List errors = data.getRight(); diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR146092IntegrationTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR146092IntegrationTest.java index a59282c..ba51882 100644 --- a/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR146092IntegrationTest.java +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/cc/sol004/VTPValidateCSARR146092IntegrationTest.java @@ -43,7 +43,7 @@ public class VTPValidateCSARR146092IntegrationTest { } @Test - public void shouldReportThatMandatoryNonManoArtifactsAreNotAvailable() throws Exception { + public void shouldDoNotReportErrorWhenNonManoArtifactIsNotAvailable() throws Exception { // given configureTestCase(testCase, "pnf/r146092/missingNonManoArtifactInManifest.csar"); @@ -52,14 +52,7 @@ public class VTPValidateCSARR146092IntegrationTest { // then List errors = testCase.getErrors(); - assertThat(errors.size()).isEqualTo(5); - assertThat(convertToMessagesList(errors)).contains( - "Missing. Entry [non_mano_artifact_sets]", - "Missing. Entry [onap_ves_events]", - "Missing. Entry [onap_pm_dictionary]", - "Missing. Entry [onap_yang_module]", - "Missing. Entry [onap_others]" - ); + assertThat(errors.size()).isEqualTo(0); } @Test -- cgit 1.2.3-korg