diff options
author | Gao Weitao <victor.gao@huawei.com> | 2019-03-14 00:45:26 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-03-14 00:45:26 +0000 |
commit | 48275fb26da634a5c27716e73bd2234f903da08b (patch) | |
tree | a9b5950b9a8d7f773932613a04d286822e7bd388 /csarvalidation | |
parent | 6addbe8d3b660acbde9191edac2e8f36dcf16197 (diff) | |
parent | fc645e5bbdaba22c52b08121f754dbb6ee0ed1e6 (diff) |
Merge "Create pnf scar archive module"
Diffstat (limited to 'csarvalidation')
10 files changed, 722 insertions, 47 deletions
diff --git a/csarvalidation/pom.xml b/csarvalidation/pom.xml index 0f25ba6..e42f818 100644 --- a/csarvalidation/pom.xml +++ b/csarvalidation/pom.xml @@ -7,7 +7,8 @@ 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. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <!-- <parent> <groupId>org.onap.csarvalidation</groupId> <artifactId>csarvalidation</artifactId> <version>1.0.0-SNAPSHOT</version> </parent> --> @@ -126,13 +127,21 @@ <artifactId>cli-main</artifactId> <version>2.0.6</version> <scope>test</scope> -<!-- <exclusions> - <exclusion> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - </exclusion> - </exclusions> --> + <!-- <exclusions> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + </exclusion> + </exclusions> --> </dependency> + + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <version>3.11.1</version> + <scope>test</scope> + </dependency> + </dependencies> <profiles> @@ -178,50 +187,50 @@ </plugin> <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-dependency-plugin</artifactId> - <executions> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + <executions> <execution> - <id>copy-artifact</id> - <phase>package</phase> - <goals> - <goal>copy</goal> - </goals> - <configuration> - <artifactItems> - <artifactItem> - <groupId>${project.groupId}</groupId> - <artifactId>${project.artifactId}</artifactId> - <version>${project.version}</version> - <type>${project.packaging}</type> - </artifactItem> - </artifactItems> - <outputDirectory>./target/lib</outputDirectory> - </configuration> + <id>copy-artifact</id> + <phase>package</phase> + <goals> + <goal>copy</goal> + </goals> + <configuration> + <artifactItems> + <artifactItem> + <groupId>${project.groupId}</groupId> + <artifactId>${project.artifactId}</artifactId> + <version>${project.version}</version> + <type>${project.packaging}</type> + </artifactItem> + </artifactItems> + <outputDirectory>./target/lib</outputDirectory> + </configuration> </execution> - </executions> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-dependency-plugin</artifactId> - <version>3.0.0</version> - <executions> - <execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + <version>3.0.0</version> + <executions> + <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> - <goal>copy-dependencies</goal> + <goal>copy-dependencies</goal> </goals> <configuration> - <outputDirectory>./target/lib</outputDirectory> - <overWriteReleases>false</overWriteReleases> - <overWriteSnapshots>false</overWriteSnapshots> - <overWriteIfNewer>true</overWriteIfNewer> - <excludeArtifactIds>junit,jmockit</excludeArtifactIds> + <outputDirectory>./target/lib</outputDirectory> + <overWriteReleases>false</overWriteReleases> + <overWriteSnapshots>false</overWriteSnapshots> + <overWriteIfNewer>true</overWriteIfNewer> + <excludeArtifactIds>junit,jmockit</excludeArtifactIds> </configuration> - </execution> - </executions> - </plugin> + </execution> + </executions> + </plugin> <plugin> <artifactId>maven-war-plugin</artifactId> 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 a68bd9f..9f8b48f 100644 --- a/csarvalidation/src/main/java/org/onap/cvc/csar/CSARArchive.java +++ b/csarvalidation/src/main/java/org/onap/cvc/csar/CSARArchive.java @@ -783,7 +783,7 @@ public class CSARArchive { private Manifest.Metadata metadata = new Metadata(); - private Map<String, Map<String, String>> nonMano = new HashMap<>(); + private Map<String, Map<String, List<String>>> nonMano = new HashMap<>(); public Manifest.Metadata getMetadata() { return metadata; @@ -793,11 +793,11 @@ public class CSARArchive { this.metadata = metadata; } - public Map<String, Map<String, String>> getNonMano() { + public Map<String, Map<String, List<String>>> getNonMano() { return nonMano; } - public void setNonMano(Map<String, Map<String, String>> nonMano) { + public void setNonMano(Map<String, Map<String, List<String>>> nonMano) { this.nonMano = nonMano; } } @@ -923,7 +923,7 @@ public class CSARArchive { } } - private void parseManifest() throws IOException { + void parseManifest() throws IOException { //manifest is optional, so check for it if (this.manifestMfFile == null) { return; diff --git a/csarvalidation/src/main/java/org/onap/cvc/csar/PnfCSARArchive.java b/csarvalidation/src/main/java/org/onap/cvc/csar/PnfCSARArchive.java new file mode 100644 index 0000000..bb0a723 --- /dev/null +++ b/csarvalidation/src/main/java/org/onap/cvc/csar/PnfCSARArchive.java @@ -0,0 +1,48 @@ +/** + * Copyright 2019 Nokia + * + * 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 + * + * 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; + +import org.apache.commons.lang3.tuple.Pair; + +import java.io.IOException; +import java.util.List; +import java.util.Map; + +public class PnfCSARArchive extends CSARArchive { + + @Override + void parseManifest() throws IOException { + + //manifest is optional, so check for it + if (this.getManifestMfFile() == null) { + return; + } + + PnfManifestParser pnfManifestParser = PnfManifestParser.getInstance( + this.getManifestMfFile().getAbsolutePath() + ); + + Pair<Manifest.Metadata, List<CSARError>> metadataData = pnfManifestParser.fetchMetadata(); + Pair<Map<String, Map<String, List<String>>>, List<CSARError>> nonManoArtifactsData = pnfManifestParser.fetchNonManoArtifacts(); + + Manifest manifest = this.getManifest(); + manifest.setMetadata(metadataData.getKey()); + manifest.setNonMano(nonManoArtifactsData.getKey()); + this.getErrors().addAll(metadataData.getValue()); + this.getErrors().addAll(nonManoArtifactsData.getValue()); + } + +} diff --git a/csarvalidation/src/main/java/org/onap/cvc/csar/PnfManifestParser.java b/csarvalidation/src/main/java/org/onap/cvc/csar/PnfManifestParser.java new file mode 100644 index 0000000..a92ebd4 --- /dev/null +++ b/csarvalidation/src/main/java/org/onap/cvc/csar/PnfManifestParser.java @@ -0,0 +1,220 @@ +/** + * 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; + +import com.google.common.collect.Lists; +import org.apache.commons.lang3.tuple.Pair; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class PnfManifestParser { + + + public static final String METADATA_SECTION = "metadata"; + public static final String NON_MANO_ARTIFACT_SETS_SECTION = "non_mano_artifact_sets"; + + private final List<String> lines; + private final String fileName; + + PnfManifestParser(List<String> lines, String fileName) { + this.lines = lines; + this.fileName = fileName; + } + + public static PnfManifestParser getInstance(String fileName) throws IOException { + try (Stream<String> stream = Files.lines(Paths.get(fileName))) { + List<String> lines = stream + .map(String::trim) + .collect(Collectors.toList()); + + return new PnfManifestParser(lines, fileName); + } + } + + public Pair<CSARArchive.Manifest.Metadata, List<CSARArchive.CSARError>> fetchMetadata() { + CSARArchive.Manifest.Metadata metadata = new CSARArchive.Manifest.Metadata(); + List<CSARArchive.CSARError> errors = new ArrayList<>(); + + boolean isMetadataSectionAvailable = false; + int lineNumber = 0; + for (String line : lines) { + lineNumber++; + if (line.trim().isEmpty()){ + continue; + } else if (line.startsWith(METADATA_SECTION)) { + isMetadataSectionAvailable = true; + continue; + }else if (isMetadataSectionAvailable) { + Pair<String, String> data = parseLine(line); + + if (isNewSection(data)) { + if(!isSectionSupported(data.getKey())) { + errors.add(new PnfCSARErrorWarning(data.getKey(), this.fileName, lineNumber)); + } + break; + } + + handleMetadataLine(metadata, errors, lineNumber, data); + } + } + + if (!isMetadataSectionAvailable) { + errors.add(new PnfCSARErrorEntryMissing(METADATA_SECTION, this.fileName, -1)); + } + + return Pair.of(metadata, errors); + + } + + public Pair<Map<String, Map<String, List<String>>>, List<CSARArchive.CSARError>> fetchNonManoArtifacts() { + Map<String, Map<String, List<String>>> nonManoArtifacts = new HashMap<>(); + List<CSARArchive.CSARError> errors = new ArrayList<>(); + + boolean isNonManoArtifactsSectionAvailable = false; + String attributeName = null; + + for (String line : lines) { + + if (line.trim().isEmpty()) { + continue; + } else if (line.startsWith(NON_MANO_ARTIFACT_SETS_SECTION)) { + isNonManoArtifactsSectionAvailable = true; + continue; + } else if (isNonManoArtifactsSectionAvailable) { + Pair<String, String> data = parseLine(line); + + if (isNewSection(data)) { + attributeName = data.getKey(); + continue; + } + + handleNonManoArtifactLine(nonManoArtifacts, attributeName, data); + } + } + + if (!isNonManoArtifactsSectionAvailable) { + errors.add(new PnfCSARErrorEntryMissing(NON_MANO_ARTIFACT_SETS_SECTION, this.fileName, -1)); + } + + return Pair.of(nonManoArtifacts, errors); + } + + private void handleMetadataLine( + CSARArchive.Manifest.Metadata metadata, + List<CSARArchive.CSARError> errors, + int lineNumber, + Pair<String, String> data) { + + String paramName = data.getKey(); + String value = data.getValue(); + + switch (paramName) { + case "pnf_product_name": + metadata.setProductName(value); + break; + case "pnf_provider_id": + metadata.setProviderId(value); + break; + case "pnf_package_version": + metadata.setPackageVersion(value); + break; + case "pnf_release_date_time": + metadata.setReleaseDateTime(value); + break; + default: + errors.add(new PnfCSARErrorInvalidEntry( + paramName, + this.fileName, + lineNumber)); + break; + } + } + + private void handleNonManoArtifactLine( + Map<String, Map<String, List<String>>> nonManoArtifacts, + String attributeName, + Pair<String, String> data) { + + String key = data.getKey(); + String value = data.getValue(); + + Map<String, List<String>> attributeWithValues = nonManoArtifacts.getOrDefault(attributeName, new HashMap<>()); + List<String> values = attributeWithValues.getOrDefault(key, new ArrayList<>()); + values.add(value); + attributeWithValues.put(key, values); + nonManoArtifacts.put(attributeName, attributeWithValues); + } + + private boolean isSectionSupported(String key) { + return Lists.newArrayList(METADATA_SECTION, NON_MANO_ARTIFACT_SETS_SECTION).contains(key); + } + + + private boolean isNewSection(Pair<String, String> data) { + String value = data.getValue().trim(); + return value.isEmpty() || value.startsWith("#"); + } + + + private Pair<String, String> parseLine(String line) { + String[] elements = line.split(": "); + if (elements.length == 2) + return Pair.of(elements[0], elements[1]); + + if (line.endsWith(":")) + return Pair.of(line.substring(0, line.length() - 1), ""); + else + return Pair.of(line, ""); + + + } + + private static class PnfCSARError extends CSARArchive.CSARError { + public PnfCSARError(String errorCode, String message, int lineNumber, String file) { + super(errorCode); + this.message = message; + this.file = file; + this.lineNumber = lineNumber; + } + } + + public static class PnfCSARErrorInvalidEntry extends PnfCSARError { + public PnfCSARErrorInvalidEntry(String entry, String file, int lineNumber) { + super("0x2000", "Invalid. Entry [" + entry + "]", lineNumber, file); + } + } + + private static class PnfCSARErrorWarning extends PnfCSARError { + public PnfCSARErrorWarning(String entry, String file, int lineNumber) { + super("0x2001", "Warning. Entry [" + entry + "]", lineNumber, file); + } + } + + private static class PnfCSARErrorEntryMissing extends PnfCSARError { + public PnfCSARErrorEntryMissing(String entry, String file, int lineNumber) { + super("0x2002", "Missing. Entry [" + entry + "]", lineNumber, file); + } + } + +} diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/PnfCSARArchiveTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/PnfCSARArchiveTest.java new file mode 100644 index 0000000..4a211a5 --- /dev/null +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/PnfCSARArchiveTest.java @@ -0,0 +1,75 @@ +/** + * Copyright 2019 Nokia + * + * 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 + * + * 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; + + +import com.google.common.collect.Lists; +import org.junit.Test; + +import java.io.IOException; +import java.net.URISyntaxException; +import java.util.List; +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; + +public class PnfCSARArchiveTest { + + @Test + public void shouldUseDataStoredInManifestMfFileToConfigurePnfCSARArchive() throws IOException, URISyntaxException { + // given + String fileName = PnfCSARArchiveTest.class.getClassLoader().getResource("pnf/dummyPnfv2.csar") + .toURI().getPath(); + PnfCSARArchive pnfCSARArchive = new PnfCSARArchive(); + pnfCSARArchive.init(fileName); + + // when + try { + pnfCSARArchive.parse(); + }finally { + pnfCSARArchive.cleanup(); + } + + // then + verifyThatMetadataWasSet(pnfCSARArchive); + verifyThatNonManoArtifactsWereSet(pnfCSARArchive); + } + + private void verifyThatNonManoArtifactsWereSet(PnfCSARArchive pnfCSARArchive) { + Map<String, Map<String, List<String>>> nonManoArtifacts = pnfCSARArchive.getManifest().getNonMano(); + assertThat(nonManoArtifacts.get("prv.onap.ves_event").get("Source")) + .isEqualTo(Lists.newArrayList("Artifacts/Deployment/Events/RadioNode_Pnf_v1.yml") + ); + assertThat(nonManoArtifacts.get("prv.onap.pm_dictionary").get("Source")) + .isEqualTo(Lists.newArrayList("Artifacts/Deployment/Measurements/PM_Dictionary.yml") + ); + assertThat(nonManoArtifacts.get("prv.onap.yang_modules").get("Source")) + .isEqualTo(Lists.newArrayList( + "Artifacts/Deployment/Yang_module/yang-module1.yang", + "Artifacts/Deployment/Yang_module/yang-module2.yang" + ) + ); + } + + private void verifyThatMetadataWasSet(PnfCSARArchive pnfCSARArchive) { + CSARArchive.Manifest.Metadata metadata = pnfCSARArchive.getManifest().getMetadata(); + assertThat(metadata.getProductName()).isEqualTo("RadioNode"); + assertThat(metadata.getProviderId()).isEqualTo("Ericsson"); + assertThat(metadata.getPackageVersion()).isEqualTo("1.0"); + assertThat(metadata.getReleaseDateTime()).isEqualTo("2019-01-14T11:25:00+00:00"); + } + +}
\ No newline at end of file diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/PnfManifestParserTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/PnfManifestParserTest.java new file mode 100644 index 0000000..a925674 --- /dev/null +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/PnfManifestParserTest.java @@ -0,0 +1,76 @@ +/** + * 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; + +import com.google.common.collect.Lists; +import org.apache.commons.lang3.tuple.Pair; +import org.junit.Before; +import org.junit.Test; + +import java.io.IOException; +import java.net.URISyntaxException; +import java.util.List; +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; + + +public class PnfManifestParserTest { + + private PnfManifestParser pnfManifestParser; + + @Before + public void setUp() throws URISyntaxException, IOException { + String fileName = PnfManifestParserTest.class.getClassLoader().getResource("pnf/MainServiceTemplate.mf") + .toURI().getPath(); + pnfManifestParser = PnfManifestParser.getInstance(fileName); + } + + @Test + public void shouldFetchMetadataFromFile() { + Pair<CSARArchive.Manifest.Metadata, List<CSARArchive.CSARError>> metadataListPair = pnfManifestParser.fetchMetadata(); + CSARArchive.Manifest.Metadata metadata = metadataListPair.getKey(); + List<CSARArchive.CSARError> errors= metadataListPair.getValue(); + + assertThat(metadata.getProductName()).isEqualTo("RadioNode"); + assertThat(metadata.getProviderId()).isEqualTo("Ericsson"); + assertThat(metadata.getPackageVersion()).isEqualTo("1.0"); + assertThat(metadata.getReleaseDateTime()).isEqualTo("2019-01-14T11:25:00+00:00"); + assertThat(errors.size()).isEqualTo(0); + } + + + @Test + public void shouldFetchNonManoArtifactsFromFile() { + Pair<Map<String, Map<String, List<String>>>, List<CSARArchive.CSARError>> mapListPair = pnfManifestParser.fetchNonManoArtifacts(); + Map<String, Map<String, List<String>>> nonManoArtifacts = mapListPair.getKey(); + List<CSARArchive.CSARError> errors= mapListPair.getValue(); + + assertThat(nonManoArtifacts.get("prv.onap.ves_event").get("Source")) + .isEqualTo(Lists.newArrayList("Artifacts/Deployment/Events/RadioNode_Pnf_v1.yml") + ); + assertThat(nonManoArtifacts.get("prv.onap.pm_dictionary").get("Source")) + .isEqualTo(Lists.newArrayList("Artifacts/Deployment/Measurements/PM_Dictionary.yml") + ); + assertThat(nonManoArtifacts.get("prv.onap.yang_modules").get("Source")) + .isEqualTo(Lists.newArrayList( + "Artifacts/Deployment/Yang_module/yang-module1.yang", + "Artifacts/Deployment/Yang_module/yang-module2.yang" + ) + ); + assertThat(errors.size()).isEqualTo(0); + } +}
\ No newline at end of file diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/PnfMetadataParserTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/PnfMetadataParserTest.java new file mode 100644 index 0000000..500fdd6 --- /dev/null +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/PnfMetadataParserTest.java @@ -0,0 +1,155 @@ +/** + * Copyright 2019 Nokia + * + * 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 + * + * 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; + +import com.google.common.collect.Lists; +import org.apache.commons.lang3.tuple.Pair; +import org.junit.Test; + +import java.util.List; +import java.util.stream.Collectors; + +import static org.assertj.core.api.Assertions.assertThat; + +public class PnfMetadataParserTest { + + @Test + public void shouldReportAnErrorWhenMetadataSectionIsNotAvailable() { + // given + List<String> lines = Lists.newArrayList( + "someSection:", + "param_name: some value", + "nextSection:", + "param_name: some value" + ); + + + // when + PnfManifestParser pnfManifestParser = new PnfManifestParser(lines, "fileName"); + Pair<CSARArchive.Manifest.Metadata, List<CSARArchive.CSARError>> data = pnfManifestParser.fetchMetadata(); + + //then + List<CSARArchive.CSARError> errors = data.getRight(); + assertThat(errors.size()).isEqualTo(1); + assertThat(errors.stream().map(CSARArchive.CSARError::getMessage).collect(Collectors.toList())).contains( + "Missing. Entry [metadata]" + ); + } + + @Test + public void shouldReportInvalidEntriesInMetadataSection() { + + // given + List<String> lines = Lists.newArrayList( + "metadata:", + "pnf_product_name: RadioNode", + "pnf_provider_id: Ericsson", + "pnf_package_version: 1.0", + "pnf_release_date_time: 2019-01-14T11:25:00+00:00", + "extra_param_1: some value", + "extra_param_2: some value" + ); + + // when + PnfManifestParser pnfManifestParser = new PnfManifestParser(lines, "fileName"); + Pair<CSARArchive.Manifest.Metadata, List<CSARArchive.CSARError>> data = pnfManifestParser.fetchMetadata(); + + //then + List<CSARArchive.CSARError> errors = data.getRight(); + assertThat(errors.size()).isEqualTo(2); + assertThat(errors.stream().map(CSARArchive.CSARError::getMessage).collect(Collectors.toList())).contains( + "Invalid. Entry [extra_param_1]", + "Invalid. Entry [extra_param_2]" + ); + } + + + @Test + public void shouldParseMetadataToKnownSectionAndDoNotReportAnyError() { + + // given + List<String> lines = Lists.newArrayList( + "metadata:", + "pnf_product_name: RadioNode", + "pnf_provider_id: Ericsson", + "pnf_package_version: 1.0", + "pnf_release_date_time: 2019-01-14T11:25:00+00:00", + "non_mano_artifact_sets:", + "param_name: some value" + ); + + // when + PnfManifestParser pnfManifestParser = new PnfManifestParser(lines, "fileName"); + Pair<CSARArchive.Manifest.Metadata, List<CSARArchive.CSARError>> data = pnfManifestParser.fetchMetadata(); + + //then + List<CSARArchive.CSARError> errors = data.getRight(); + assertThat(errors.size()).isEqualTo(0); + + } + + + + @Test + public void shouldReportAWarningWhenUnrecognizedSectionWasFoundDuringMetadataSectionParsing() { + // given + List<String> lines = Lists.newArrayList( + "metadata:", + "pnf_product_name: RadioNode", + "pnf_provider_id: Ericsson", + "pnf_package_version: 1.0", + "pnf_release_date_time: 2019-01-14T11:25:00+00:00", + "unknown_section:", + "param_name: some value" + ); + + // when + PnfManifestParser pnfManifestParser = new PnfManifestParser(lines, "fileName"); + Pair<CSARArchive.Manifest.Metadata, List<CSARArchive.CSARError>> data = pnfManifestParser.fetchMetadata(); + + //then + List<CSARArchive.CSARError> errors = data.getRight(); + assertThat(errors.size()).isEqualTo(1); + assertThat(errors.stream().map(CSARArchive.CSARError::getMessage).collect(Collectors.toList())).contains( + "Warning. Entry [unknown_section]" + ); + } + + + @Test + public void shouldReportAWarningWhenTokenWithOutColonWasFoundDuringMetadataProcessing() { + // given + List<String> lines = Lists.newArrayList( + "metadata:", + "pnf_product_name RadioNode", + "pnf_provider_id: Ericsson", + "pnf_package_version: 1.0", + "pnf_release_date_time: 2019-01-14T11:25:00+00:00" + ); + + // when + PnfManifestParser pnfManifestParser = new PnfManifestParser(lines, "fileName"); + Pair<CSARArchive.Manifest.Metadata, List<CSARArchive.CSARError>> data = pnfManifestParser.fetchMetadata(); + + //then + List<CSARArchive.CSARError> errors = data.getRight(); + assertThat(errors.size()).isEqualTo(1); + assertThat(errors.stream().map(CSARArchive.CSARError::getMessage).collect(Collectors.toList())).contains( + "Warning. Entry [pnf_product_name RadioNode]" + ); + } + +} diff --git a/csarvalidation/src/test/java/org/onap/cvc/csar/PnfNonManoArtifactsParserTest.java b/csarvalidation/src/test/java/org/onap/cvc/csar/PnfNonManoArtifactsParserTest.java new file mode 100644 index 0000000..95526bb --- /dev/null +++ b/csarvalidation/src/test/java/org/onap/cvc/csar/PnfNonManoArtifactsParserTest.java @@ -0,0 +1,78 @@ +/** + * Copyright 2019 Nokia + * + * 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 + * + * 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; + +import com.google.common.collect.Lists; +import org.apache.commons.lang3.tuple.Pair; +import org.junit.Test; + +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import static org.assertj.core.api.Assertions.assertThat; + +public class PnfNonManoArtifactsParserTest { + + @Test + public void shouldReportAnErrorWhenNonManoArtifactSectionIsNotAvailable() { + // given + List<String> lines = Lists.newArrayList( + "someSection:", + "param_name: some value", + "nextSection:", + "param_name: some value" + ); + + + // when + PnfManifestParser pnfManifestParser = new PnfManifestParser(lines, "fileName"); + Pair<Map<String, Map<String, List<String>>>, List<CSARArchive.CSARError>> data = pnfManifestParser.fetchNonManoArtifacts(); + + //then + List<CSARArchive.CSARError> 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]" + ); + } + + @Test + public void shouldParseNonManoArtifactsInProperFormatAndDoNotReportAnyError() { + + // given + List<String> lines = Lists.newArrayList( + "non_mano_artifact_sets:", + "prv.onap.ves_event: # if private else onap_ves_event if public", + "Source: Artifacts/Deployment/Events/RadioNode_Pnf_v1.yml", + "extra_param_1: some value", + "extra_param_2: some value", + "prv.onap.pm_dictionary: # if private else onap_pm_dictionary if public", + "Source: Artifacts/Deployment/Measurements/PM_Dictionary.yml", + "param name: # if private else onap_yang_modules if public", + "key: value" + ); + + // when + PnfManifestParser pnfManifestParser = new PnfManifestParser(lines, "fileName"); + Pair<Map<String, Map<String, List<String>>>, List<CSARArchive.CSARError>> data = pnfManifestParser.fetchNonManoArtifacts(); + + //then + List<CSARArchive.CSARError> errors = data.getRight(); + assertThat(errors.size()).isEqualTo(0); + + } +} diff --git a/csarvalidation/src/test/resources/pnf/MainServiceTemplate.mf b/csarvalidation/src/test/resources/pnf/MainServiceTemplate.mf new file mode 100644 index 0000000..c5a498c --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/MainServiceTemplate.mf @@ -0,0 +1,14 @@ +metadata: + pnf_product_name: RadioNode + pnf_provider_id: Ericsson + pnf_package_version: 1.0 + pnf_release_date_time: 2019-01-14T11:25:00+00:00 + +non_mano_artifact_sets: + prv.onap.ves_event: # if private else onap_ves_event if public + Source: Artifacts/Deployment/Events/RadioNode_Pnf_v1.yml + prv.onap.pm_dictionary: # if private else onap_pm_dictionary if public + Source: Artifacts/Deployment/Measurements/PM_Dictionary.yml + prv.onap.yang_modules: # if private else onap_yang_modules if public + Source: Artifacts/Deployment/Yang_module/yang-module1.yang + Source: Artifacts/Deployment/Yang_module/yang-module2.yang
\ No newline at end of file diff --git a/csarvalidation/src/test/resources/pnf/dummyPnfv2.csar b/csarvalidation/src/test/resources/pnf/dummyPnfv2.csar Binary files differnew file mode 100644 index 0000000..2c626ed --- /dev/null +++ b/csarvalidation/src/test/resources/pnf/dummyPnfv2.csar |