summaryrefslogtreecommitdiffstats
path: root/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp
diff options
context:
space:
mode:
authorMaciej Malewski <maciej.malewski@nokia.com>2020-11-20 14:33:04 +0100
committerVasyl Razinkov <vasyl.razinkov@est.tech>2020-12-02 13:01:42 +0000
commit8f3f8797dc916be0215523fb3d36f020b4795089 (patch)
tree5d8c7966b669d90dc6123e830a19d652170eb47d /openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp
parentad99b805537fc8f3103fa5646abe5342924e10cd (diff)
Validate PMDictionary contents
Validate contents against schema for .csar packs compliant with NFV-SOL 004. Issue-ID: SDC-3390 Signed-off-by: Maciej Malewski <maciej.malewski@nokia.com> Change-Id: Ib768821ad8215105ca4a33953fa9974a63ed76f7
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp')
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/PMDictionaryValidatorTest.java77
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidatorTest.java279
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/utils/FileExtractorTest.java77
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/utils/InternalFilesFilterTest.java45
4 files changed, 346 insertions, 132 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/PMDictionaryValidatorTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/PMDictionaryValidatorTest.java
new file mode 100644
index 0000000000..22ef7720dc
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/PMDictionaryValidatorTest.java
@@ -0,0 +1,77 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 Nokia. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.openecomp.sdc.be.test.util.TestResourcesHandler.getResourceBytesOrFail;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Stream;
+import org.junit.jupiter.api.Test;
+
+class PMDictionaryValidatorTest {
+
+ @Test
+ void shouldReportNoErrors_whenPmDictionaryIsValid() {
+ // given
+ List<String> errors = new ArrayList<>();
+ final byte[] pmDictionaryContent = getResourceBytesOrFail(
+ "validation.files/measurements/pmEvents-valid.yaml");
+
+ // when
+ new PMDictionaryValidator().validate(Stream.of(pmDictionaryContent), errors::add);
+
+ // then
+ assertTrue(errors.isEmpty());
+ }
+
+ @Test
+ void shouldReportErrors_whenPmDictionaryIsInvalid() {
+ // given
+ List<String> errors = new ArrayList<>();
+ final byte[] pmDictionaryContent = getResourceBytesOrFail(
+ "validation.files/measurements/pmEvents-invalid.yaml");
+
+ // when
+ new PMDictionaryValidator().validate(Stream.of(pmDictionaryContent), errors::add);
+
+ // then
+ assertThat(errors.size(), is(1));
+ assertThat(errors.get(0), is("Key not found: pmDictionaryHeader"));
+ }
+
+ @Test
+ void shouldReportEmptyYamlMessage_whenPmDictionaryIsEmpty() {
+ // given
+ List<String> errors = new ArrayList<>();
+ final byte[] pmDictionaryContent = "".getBytes();
+
+ // when
+ new PMDictionaryValidator().validate(Stream.of(pmDictionaryContent), errors::add);
+
+ // then
+ assertThat(errors.size(), is(1));
+ assertThat(errors.get(0), is("PM_Dictionary YAML file is empty"));
+ }
+} \ No newline at end of file
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidatorTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidatorTest.java
index d6ff7022c3..dca4ecfce5 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidatorTest.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidatorTest.java
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications copyright (c) 2020 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
@@ -90,17 +92,17 @@ public class SOL004MetaDirectoryValidatorTest {
sol004MetaDirectoryValidator = new SOL004MetaDirectoryValidator();
handler = new OnboardingPackageContentHandler();
metaFileBuilder = new StringBuilder()
- .append(TOSCA_META_FILE_VERSION_ENTRY.getName())
+ .append(TOSCA_META_FILE_VERSION_ENTRY.getName())
.append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" 1.0").append("\n")
- .append(CSAR_VERSION_ENTRY.getName())
+ .append(CSAR_VERSION_ENTRY.getName())
.append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" 1.1").append("\n")
- .append(CREATED_BY_ENTRY.getName())
+ .append(CREATED_BY_ENTRY.getName())
.append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" Vendor").append("\n")
- .append(ENTRY_DEFINITIONS.getName())
+ .append(ENTRY_DEFINITIONS.getName())
.append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" ").append(TOSCA_DEFINITION_FILEPATH).append("\n")
- .append(ETSI_ENTRY_MANIFEST.getName())
+ .append(ETSI_ENTRY_MANIFEST.getName())
.append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" ").append(TOSCA_MANIFEST_FILEPATH).append("\n")
- .append(ETSI_ENTRY_CHANGE_LOG.getName())
+ .append(ETSI_ENTRY_CHANGE_LOG.getName())
.append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" ").append(TOSCA_CHANGELOG_FILEPATH).append("\n");
}
@@ -125,9 +127,9 @@ public class SOL004MetaDirectoryValidatorTest {
handler.addFolder("Files/Tests/");
handler.addFolder("Files/Licenses/");
metaFileBuilder
- .append(ETSI_ENTRY_TESTS.getName())
+ .append(ETSI_ENTRY_TESTS.getName())
.append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(entryTestFilePath).append("\n")
- .append(ETSI_ENTRY_LICENSES.getName())
+ .append(ETSI_ENTRY_LICENSES.getName())
.append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(entryLicenseFilePath).append("\n");
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
@@ -140,13 +142,13 @@ public class SOL004MetaDirectoryValidatorTest {
handler.addFile(entryLicenseFilePath, "".getBytes());
final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder()
- .withSource(TOSCA_META_PATH_FILE_NAME)
- .withSource(TOSCA_DEFINITION_FILEPATH)
- .withSource(TOSCA_CHANGELOG_FILEPATH)
- .withSource(TOSCA_MANIFEST_FILEPATH).withSource(SAMPLE_SOURCE)
- .withSource(SAMPLE_DEFINITION_IMPORT_FILE_PATH)
- .withSource(entryTestFilePath)
- .withSource(entryLicenseFilePath);
+ .withSource(TOSCA_META_PATH_FILE_NAME)
+ .withSource(TOSCA_DEFINITION_FILEPATH)
+ .withSource(TOSCA_CHANGELOG_FILEPATH)
+ .withSource(TOSCA_MANIFEST_FILEPATH).withSource(SAMPLE_SOURCE)
+ .withSource(SAMPLE_DEFINITION_IMPORT_FILE_PATH)
+ .withSource(entryTestFilePath)
+ .withSource(entryLicenseFilePath);
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
@@ -157,7 +159,7 @@ public class SOL004MetaDirectoryValidatorTest {
@Test
public void testGivenTOSCAMeta_withUnsupportedEntry_thenNoErrorIsReturned() {
metaFileBuilder
- .append("a-unknown-entry")
+ .append("a-unknown-entry")
.append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" ")
.append("Definitions/events.log");
@@ -165,10 +167,10 @@ public class SOL004MetaDirectoryValidatorTest {
handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytesOrFail(SAMPLE_DEFINITION_FILE_PATH));
handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder()
- .withSource(TOSCA_META_PATH_FILE_NAME)
- .withSource(TOSCA_DEFINITION_FILEPATH)
- .withSource(TOSCA_CHANGELOG_FILEPATH)
- .withSource(TOSCA_MANIFEST_FILEPATH);
+ .withSource(TOSCA_META_PATH_FILE_NAME)
+ .withSource(TOSCA_DEFINITION_FILEPATH)
+ .withSource(TOSCA_CHANGELOG_FILEPATH)
+ .withSource(TOSCA_MANIFEST_FILEPATH);
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler);
@@ -181,17 +183,17 @@ public class SOL004MetaDirectoryValidatorTest {
@Test
public void testGivenTOSCAMetaFile_withInvalidTOSCAMetaFileVersionAndCSARVersion_thenErrorIsReturned() {
final StringBuilder metaFileBuilder = new StringBuilder()
- .append(TOSCA_META_FILE_VERSION_ENTRY.getName())
+ .append(TOSCA_META_FILE_VERSION_ENTRY.getName())
.append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(Integer.MAX_VALUE).append("\n")
- .append(CSAR_VERSION_ENTRY.getName())
+ .append(CSAR_VERSION_ENTRY.getName())
.append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(Integer.MAX_VALUE).append("\n")
- .append(CREATED_BY_ENTRY.getName())
+ .append(CREATED_BY_ENTRY.getName())
.append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" Vendor").append("\n")
- .append(ENTRY_DEFINITIONS.getName())
+ .append(ENTRY_DEFINITIONS.getName())
.append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" ").append(TOSCA_DEFINITION_FILEPATH).append("\n")
- .append(ETSI_ENTRY_MANIFEST.getName())
+ .append(ETSI_ENTRY_MANIFEST.getName())
.append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" ").append(TOSCA_MANIFEST_FILEPATH).append("\n")
- .append(ETSI_ENTRY_CHANGE_LOG.getName())
+ .append(ETSI_ENTRY_CHANGE_LOG.getName())
.append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" ").append(TOSCA_CHANGELOG_FILEPATH);
final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
@@ -236,7 +238,7 @@ public class SOL004MetaDirectoryValidatorTest {
manifestBuilder.withSource(SAMPLE_SOURCE);
handler.addFile("Definitions/etsi_nfv_sol001_pnfd_2_5_1_types.yaml",
- getResourceBytesOrFail(SAMPLE_DEFINITION_FILE_PATH));
+ getResourceBytesOrFail(SAMPLE_DEFINITION_FILE_PATH));
manifestBuilder.withSource("Definitions/etsi_nfv_sol001_pnfd_2_5_1_types.yaml");
final String definitionFileWithValidImports = "validation.files/definition/definitionFileWithValidImports.yaml";
@@ -263,18 +265,18 @@ public class SOL004MetaDirectoryValidatorTest {
handler.addFile(SAMPLE_SOURCE, "".getBytes());
manifestBuilder.withSource(SAMPLE_SOURCE);
- final byte [] sampleDefinitionFile1 =
- getResourceBytesOrFail("validation.files/definition/sampleDefinitionFile1.yaml");
+ final byte[] sampleDefinitionFile1 =
+ getResourceBytesOrFail("validation.files/definition/sampleDefinitionFile1.yaml");
handler.addFile(TOSCA_DEFINITION_FILEPATH, sampleDefinitionFile1);
manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
- final byte [] sampleDefinitionFile2 =
- getResourceBytesOrFail("validation.files/definition/sampleDefinitionFile2.yaml");
+ final byte[] sampleDefinitionFile2 =
+ getResourceBytesOrFail("validation.files/definition/sampleDefinitionFile2.yaml");
handler.addFile("Definitions/etsi_nfv_sol001_pnfd_2_5_1_types.yaml", sampleDefinitionFile2);
manifestBuilder.withSource("Definitions/etsi_nfv_sol001_pnfd_2_5_1_types.yaml");
- final byte [] sampleDefinitionFile3 =
- getResourceBytesOrFail("validation.files/definition/sampleDefinitionFile1.yaml");
+ final byte[] sampleDefinitionFile3 =
+ getResourceBytesOrFail("validation.files/definition/sampleDefinitionFile1.yaml");
handler.addFile("Definitions/etsi_nfv_sol001_pnfd_2_5_2_types.yaml", sampleDefinitionFile3);
manifestBuilder.withSource("Definitions/etsi_nfv_sol001_pnfd_2_5_2_types.yaml");
@@ -299,7 +301,7 @@ public class SOL004MetaDirectoryValidatorTest {
manifestBuilder.withSource(SAMPLE_SOURCE);
final String definitionFileWithInvalidImports =
- "validation.files/definition/definitionFileWithInvalidImport.yaml";
+ "validation.files/definition/definitionFileWithInvalidImport.yaml";
handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytesOrFail(definitionFileWithInvalidImports));
manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
@@ -332,7 +334,7 @@ public class SOL004MetaDirectoryValidatorTest {
manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
handler.addFile(TOSCA_DEFINITION_FILEPATH,
- getResourceBytesOrFail("validation.files/definition/sampleDefinitionFile2.yaml"));
+ getResourceBytesOrFail("validation.files/definition/sampleDefinitionFile2.yaml"));
manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
@@ -340,7 +342,7 @@ public class SOL004MetaDirectoryValidatorTest {
final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler);
assertExpectedErrors("Manifest referenced import file missing", errors, 1);
}
-
+
@Test
public void testGivenDefinitionFile_whenFileInPackageNotInManifest_thenErrorIsReturned() {
final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
@@ -353,21 +355,21 @@ public class SOL004MetaDirectoryValidatorTest {
handler.addFile(SAMPLE_SOURCE, "".getBytes());
- final byte [] sampleDefinitionFile =
- getResourceBytesOrFail("validation.files/definition/sampleDefinitionFile2.yaml");
+ final byte[] sampleDefinitionFile =
+ getResourceBytesOrFail("validation.files/definition/sampleDefinitionFile2.yaml");
handler.addFile("Definitions/etsi_nfv_sol001_pnfd_2_5_2_types.yaml", sampleDefinitionFile);
manifestBuilder.withSource("Definitions/etsi_nfv_sol001_pnfd_2_5_2_types.yaml");
manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
handler.addFile(TOSCA_DEFINITION_FILEPATH,
- getResourceBytesOrFail("validation.files/definition/sampleDefinitionFile2.yaml"));
+ getResourceBytesOrFail("validation.files/definition/sampleDefinitionFile2.yaml"));
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler);
assertExpectedErrors("Artifact is not being referenced in manifest file", errors, 1);
}
-
+
@Test
public void testGivenDefinitionFile_whenManifestNotreferencedInManifest_thenNoErrorIsReturned() {
final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
@@ -381,14 +383,14 @@ public class SOL004MetaDirectoryValidatorTest {
handler.addFile(SAMPLE_SOURCE, "".getBytes());
manifestBuilder.withSource(SAMPLE_SOURCE);
- final byte [] sampleDefinitionFile =
- getResourceBytesOrFail("validation.files/definition/sampleDefinitionFile2.yaml");
+ final byte[] sampleDefinitionFile =
+ getResourceBytesOrFail("validation.files/definition/sampleDefinitionFile2.yaml");
handler.addFile("Definitions/etsi_nfv_sol001_pnfd_2_5_2_types.yaml", sampleDefinitionFile);
manifestBuilder.withSource("Definitions/etsi_nfv_sol001_pnfd_2_5_2_types.yaml");
manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
handler.addFile(TOSCA_DEFINITION_FILEPATH,
- getResourceBytesOrFail("validation.files/definition/sampleDefinitionFile2.yaml"));
+ getResourceBytesOrFail("validation.files/definition/sampleDefinitionFile2.yaml"));
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
@@ -501,7 +503,7 @@ public class SOL004MetaDirectoryValidatorTest {
}
@Test
- public void testGivenManifestAndDefinitionFile_withSameNames_thenNoErrorReturned() {
+ public void testGivenManifestAndDefinitionFile_withSameNames_thenNoErrorReturned() {
final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
@@ -529,17 +531,17 @@ public class SOL004MetaDirectoryValidatorTest {
@Test
public void testGivenManifestAndMainDefinitionFile_withDifferentNames_thenErrorIsReturned() {
metaFileBuilder = new StringBuilder()
- .append(TOSCA_META_FILE_VERSION_ENTRY.getName())
+ .append(TOSCA_META_FILE_VERSION_ENTRY.getName())
.append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" 1.0").append("\n")
- .append(CSAR_VERSION_ENTRY.getName())
+ .append(CSAR_VERSION_ENTRY.getName())
.append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" 1.1").append("\n")
- .append(CREATED_BY_ENTRY.getName())
+ .append(CREATED_BY_ENTRY.getName())
.append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" Vendor").append("\n")
- .append(ENTRY_DEFINITIONS.getName())
+ .append(ENTRY_DEFINITIONS.getName())
.append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" ").append(TOSCA_DEFINITION_FILEPATH).append("\n")
- .append(ETSI_ENTRY_MANIFEST.getName())
+ .append(ETSI_ENTRY_MANIFEST.getName())
.append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" Definitions/MainServiceTemplate2.mf\n")
- .append(ETSI_ENTRY_CHANGE_LOG.getName())
+ .append(ETSI_ENTRY_CHANGE_LOG.getName())
.append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" ").append(TOSCA_CHANGELOG_FILEPATH).append("\n");
final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
@@ -561,23 +563,23 @@ public class SOL004MetaDirectoryValidatorTest {
final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler);
assertExpectedErrors("Main TOSCA definitions file and Manifest file with different name should return error",
- errors, 1);
+ errors, 1);
}
@Test
public void testGivenManifestFile_withDifferentExtension_thenErrorIsReturned() {
metaFileBuilder = new StringBuilder()
- .append(TOSCA_META_FILE_VERSION_ENTRY.getName())
+ .append(TOSCA_META_FILE_VERSION_ENTRY.getName())
.append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" 1.0").append("\n")
- .append(CSAR_VERSION_ENTRY.getName())
+ .append(CSAR_VERSION_ENTRY.getName())
.append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" 1.1").append("\n")
- .append(CREATED_BY_ENTRY.getName())
+ .append(CREATED_BY_ENTRY.getName())
.append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" Vendor").append("\n")
- .append(ENTRY_DEFINITIONS.getName())
+ .append(ENTRY_DEFINITIONS.getName())
.append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" ").append(TOSCA_DEFINITION_FILEPATH).append("\n")
- .append(ETSI_ENTRY_MANIFEST.getName())
+ .append(ETSI_ENTRY_MANIFEST.getName())
.append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" Definitions/MainServiceTemplate.txt\n")
- .append(ETSI_ENTRY_CHANGE_LOG.getName())
+ .append(ETSI_ENTRY_CHANGE_LOG.getName())
.append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" ").append(TOSCA_CHANGELOG_FILEPATH).append("\n");
final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
@@ -631,7 +633,7 @@ public class SOL004MetaDirectoryValidatorTest {
manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
manifestBuilder.withSignedSource(TOSCA_DEFINITION_FILEPATH
- , "SHA-abc", "09e5a788acb180162c51679ae4c998039fa6644505db2415e35107d1ee213943");
+ , "SHA-abc", "09e5a788acb180162c51679ae4c998039fa6644505db2415e35107d1ee213943");
handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytesOrFail(SAMPLE_DEFINITION_FILE_PATH));
manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
@@ -647,10 +649,10 @@ public class SOL004MetaDirectoryValidatorTest {
@Test
public void testGivenManifestFile_withMetadataContainingMixedPnfVnfMetadata_thenErrorIsReturned() {
final ManifestBuilder manifestBuilder = new ManifestBuilder()
- .withMetaData(PNFD_NAME.getToken(), "RadioNode")
- .withMetaData(VNF_PROVIDER_ID.getToken(), "Bilal Iqbal")
- .withMetaData(PNFD_ARCHIVE_VERSION.getToken(), "1.0")
- .withMetaData(VNF_RELEASE_DATE_TIME.getToken(), "2019-12-14T11:25:00+00:00");
+ .withMetaData(PNFD_NAME.getToken(), "RadioNode")
+ .withMetaData(VNF_PROVIDER_ID.getToken(), "Bilal Iqbal")
+ .withMetaData(PNFD_ARCHIVE_VERSION.getToken(), "1.0")
+ .withMetaData(VNF_RELEASE_DATE_TIME.getToken(), "2019-12-14T11:25:00+00:00");
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
@@ -670,10 +672,10 @@ public class SOL004MetaDirectoryValidatorTest {
@Test
public void testGivenManifestFile_withMetadataMissingPnfOrVnfMandatoryEntries_thenErrorIsReturned() {
final ManifestBuilder manifestBuilder = new ManifestBuilder()
- .withMetaData("invalid_product_name", "RadioNode")
- .withMetaData("invalid_provider_id", "Bilal Iqbal")
- .withMetaData("invalid_package_version", "1.0")
- .withMetaData("invalid_release_date_time", "2019-12-14T11:25:00+00:00");
+ .withMetaData("invalid_product_name", "RadioNode")
+ .withMetaData("invalid_provider_id", "Bilal Iqbal")
+ .withMetaData("invalid_package_version", "1.0")
+ .withMetaData("invalid_release_date_time", "2019-12-14T11:25:00+00:00");
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
@@ -744,10 +746,10 @@ public class SOL004MetaDirectoryValidatorTest {
@Test
public void testGivenManifestFile_withMetadataEntriesExceedingTheLimit_thenErrorIsReturned() {
final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder()
- .withMetaData(PNFD_NAME.getToken(), "RadioNode")
- .withMetaData(ManifestTokenType.PNFD_PROVIDER.getToken(), "Bilal Iqbal")
- .withMetaData(PNFD_ARCHIVE_VERSION.getToken(), "1.0")
- .withMetaData(PNFD_RELEASE_DATE_TIME.getToken(), "2019-03-11T11:25:00+00:00");
+ .withMetaData(PNFD_NAME.getToken(), "RadioNode")
+ .withMetaData(ManifestTokenType.PNFD_PROVIDER.getToken(), "Bilal Iqbal")
+ .withMetaData(PNFD_ARCHIVE_VERSION.getToken(), "1.0")
+ .withMetaData(PNFD_RELEASE_DATE_TIME.getToken(), "2019-03-11T11:25:00+00:00");
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
@@ -769,9 +771,9 @@ public class SOL004MetaDirectoryValidatorTest {
public void testGivenManifestFile_withPnfMetadataAndVfEntries_thenErrorIsReturned() {
final ManifestBuilder manifestBuilder = getPnfManifestSampleBuilder();
metaFileBuilder
- .append(ETSI_ENTRY_TESTS.getName())
+ .append(ETSI_ENTRY_TESTS.getName())
.append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" Files/Tests").append("\n")
- .append(ETSI_ENTRY_LICENSES.getName())
+ .append(ETSI_ENTRY_LICENSES.getName())
.append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" Files/Licenses");
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
@@ -808,7 +810,7 @@ public class SOL004MetaDirectoryValidatorTest {
final String definitionImportOne = "Definitions/importOne.yaml";
handler.addFile(definitionImportOne,
- getResourceBytesOrFail("validation.files/definition/sampleDefinitionFile2.yaml"));
+ getResourceBytesOrFail("validation.files/definition/sampleDefinitionFile2.yaml"));
manifestBuilder.withSource(definitionImportOne);
final String definitionFileWithValidImports = "validation.files/definition/definitionFileWithOneImport.yaml";
@@ -822,7 +824,7 @@ public class SOL004MetaDirectoryValidatorTest {
final List<ErrorMessage> expectedErrorList = new ArrayList<>();
expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR
- , Messages.MISSING_IMPORT_FILE.formatMessage("Definitions/etsi_nfv_sol001_pnfd_2_5_2_types.yaml"))
+ , Messages.MISSING_IMPORT_FILE.formatMessage("Definitions/etsi_nfv_sol001_pnfd_2_5_2_types.yaml"))
);
assertExpectedErrors(actualErrorMap.get(SdcCommon.UPLOAD_FILE), expectedErrorList);
@@ -846,7 +848,7 @@ public class SOL004MetaDirectoryValidatorTest {
final String definitionImportOne = "Definitions/importOne.yaml";
handler.addFile(definitionImportOne,
- getResourceBytesOrFail("validation.files/definition/definitionFileWithInvalidImport.yaml"));
+ getResourceBytesOrFail("validation.files/definition/definitionFileWithInvalidImport.yaml"));
manifestBuilder.withSource(definitionImportOne);
final String definitionFileWithValidImports = "validation.files/definition/definitionFileWithOneImport.yaml";
@@ -860,7 +862,7 @@ public class SOL004MetaDirectoryValidatorTest {
final List<ErrorMessage> expectedErrorList = new ArrayList<>();
expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR
- , Messages.INVALID_IMPORT_STATEMENT.formatMessage(definitionImportOne, "null"))
+ , Messages.INVALID_IMPORT_STATEMENT.formatMessage(definitionImportOne, "null"))
);
assertExpectedErrors(actualErrorMap.get(SdcCommon.UPLOAD_FILE), expectedErrorList);
@@ -881,19 +883,19 @@ public class SOL004MetaDirectoryValidatorTest {
final String nonManoPmEventsSource = "Artifacts/Deployment/Measurements/PM_Dictionary.yaml";
handler.addFile(nonManoPmEventsSource,
- getResourceBytesOrFail("validation.files/measurements/pmEvents-valid.yaml"));
+ getResourceBytesOrFail("validation.files/measurements/pmEvents-valid.yaml"));
manifestBuilder.withNonManoArtifact(ONAP_PM_DICTIONARY.getType(), nonManoPmEventsSource);
final String nonManoVesEventsSource = "Artifacts/Deployment/Events/ves_events.yaml";
handler.addFile(nonManoVesEventsSource,
- getResourceBytesOrFail("validation.files/events/vesEvents-valid.yaml"));
+ getResourceBytesOrFail("validation.files/events/vesEvents-valid.yaml"));
manifestBuilder.withNonManoArtifact(ONAP_VES_EVENTS.getType(), nonManoVesEventsSource);
manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
final Map<String, List<ErrorMessage>> actualErrorMap = sol004MetaDirectoryValidator
- .validateContent(handler);
+ .validateContent(handler);
assertExpectedErrors(actualErrorMap.get(SdcCommon.UPLOAD_FILE), Collections.emptyList());
}
@@ -920,19 +922,27 @@ public class SOL004MetaDirectoryValidatorTest {
final List<ErrorMessage> expectedErrorList = new ArrayList<>();
expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR
- , Messages.INVALID_YAML_FORMAT_1.formatMessage(nonManoPmEventsSource, "while scanning a simple key\n"
- + " in 'reader', line 2, column 1:\n"
- + " key {}\n"
- + " ^\n"
- + "could not find expected ':'\n"
- + " in 'reader', line 2, column 7:\n"
- + " {}\n"
- + " ^\n"))
+ , Messages.INVALID_YAML_FORMAT_1.formatMessage(nonManoPmEventsSource, "while scanning a simple key\n"
+ + " in 'reader', line 2, column 1:\n"
+ + " key {}\n"
+ + " ^\n"
+ + "could not find expected ':'\n"
+ + " in 'reader', line 2, column 7:\n"
+ + " {}\n"
+ + " ^\n"))
+ );
+ expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR, "while scanning a simple key\n" +
+ " in 'reader', line 2, column 1:\n" +
+ " key {}\n" +
+ " ^\n" +
+ "could not find expected ':'\n" +
+ " in 'reader', line 2, column 7:\n" +
+ " {}\n" +
+ " ^\n")
);
final Map<String, List<ErrorMessage>> actualErrorMap = sol004MetaDirectoryValidator
- .validateContent(handler);
-
+ .validateContent(handler);
assertExpectedErrors(actualErrorMap.get(SdcCommon.UPLOAD_FILE), expectedErrorList);
}
@@ -962,14 +972,17 @@ public class SOL004MetaDirectoryValidatorTest {
final List<ErrorMessage> expectedErrorList = new ArrayList<>();
expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR
- , Messages.EMPTY_YAML_FILE_1.formatMessage(nonManoPmEventsSource))
+ , Messages.EMPTY_YAML_FILE_1.formatMessage(nonManoPmEventsSource))
);
expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR
- , Messages.EMPTY_YAML_FILE_1.formatMessage(nonManoVesEventsSource))
+ , Messages.EMPTY_YAML_FILE_1.formatMessage(nonManoVesEventsSource))
+ );
+ expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR
+ , "PM_Dictionary YAML file is empty")
);
final Map<String, List<ErrorMessage>> actualErrorMap = sol004MetaDirectoryValidator
- .validateContent(handler);
+ .validateContent(handler);
assertExpectedErrors(actualErrorMap.get(SdcCommon.UPLOAD_FILE), expectedErrorList);
}
@@ -1000,14 +1013,18 @@ public class SOL004MetaDirectoryValidatorTest {
final List<ErrorMessage> expectedErrorList = new ArrayList<>();
expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR
- , Messages.INVALID_YAML_EXTENSION.formatMessage(nonManoPmEventsSource))
+ , Messages.INVALID_YAML_EXTENSION.formatMessage(nonManoPmEventsSource))
+ );
+ expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR
+ , Messages.INVALID_YAML_EXTENSION.formatMessage(nonManoVesEventsSource))
);
expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR
- , Messages.INVALID_YAML_EXTENSION.formatMessage(nonManoVesEventsSource))
+ , "PM_Dictionary YAML file is empty")
);
+
final Map<String, List<ErrorMessage>> actualErrorMap = sol004MetaDirectoryValidator
- .validateContent(handler);
+ .validateContent(handler);
assertExpectedErrors(actualErrorMap.get(SdcCommon.UPLOAD_FILE), expectedErrorList);
}
@@ -1018,10 +1035,10 @@ public class SOL004MetaDirectoryValidatorTest {
final ManifestBuilder manifestBuilder = getPnfManifestSampleBuilder();
final String nonManoSoftwareInformationPath = "Artifacts/software-information/pnf-sw-information-valid.yaml";
handler.addFile(nonManoSoftwareInformationPath,
- getResourceBytesOrFail("validation.files/non-mano/pnf-sw-information-valid.yaml"));
+ getResourceBytesOrFail("validation.files/non-mano/pnf-sw-information-valid.yaml"));
manifestBuilder.withNonManoArtifact(ONAP_SW_INFORMATION.getType(), nonManoSoftwareInformationPath);
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString()
- .getBytes(StandardCharsets.UTF_8));
+ .getBytes(StandardCharsets.UTF_8));
manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytesOrFail(SAMPLE_DEFINITION_FILE_PATH));
manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
@@ -1042,10 +1059,10 @@ public class SOL004MetaDirectoryValidatorTest {
final ManifestBuilder manifestBuilder = getPnfManifestSampleBuilder();
final String nonManoSoftwareInformationPath = "Artifacts/software-information/pnf-sw-information-valid.yaml";
handler.addFile(nonManoSoftwareInformationPath,
- getResourceBytesOrFail("validation.files/invalid.yaml"));
+ getResourceBytesOrFail("validation.files/invalid.yaml"));
manifestBuilder.withNonManoArtifact(ONAP_SW_INFORMATION.getType(), nonManoSoftwareInformationPath);
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString()
- .getBytes(StandardCharsets.UTF_8));
+ .getBytes(StandardCharsets.UTF_8));
manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytesOrFail(SAMPLE_DEFINITION_FILE_PATH));
manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
@@ -1059,7 +1076,7 @@ public class SOL004MetaDirectoryValidatorTest {
//then invalid error returned
final List<ErrorMessage> expectedErrorList = new ArrayList<>();
expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR
- , Messages.INVALID_SW_INFORMATION_NON_MANO_ERROR.formatMessage(nonManoSoftwareInformationPath))
+ , Messages.INVALID_SW_INFORMATION_NON_MANO_ERROR.formatMessage(nonManoSoftwareInformationPath))
);
assertExpectedErrors(actualErrorMap.get(SdcCommon.UPLOAD_FILE), expectedErrorList);
}
@@ -1070,10 +1087,10 @@ public class SOL004MetaDirectoryValidatorTest {
final ManifestBuilder manifestBuilder = getPnfManifestSampleBuilder();
final String nonManoSoftwareInformationPath = "Artifacts/software-information/pnf-sw-information-invalid.yaml";
handler.addFile(nonManoSoftwareInformationPath,
- getResourceBytesOrFail("validation.files/non-mano/pnf-sw-information-invalid.yaml"));
+ getResourceBytesOrFail("validation.files/non-mano/pnf-sw-information-invalid.yaml"));
manifestBuilder.withNonManoArtifact(ONAP_SW_INFORMATION.getType(), nonManoSoftwareInformationPath);
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString()
- .getBytes(StandardCharsets.UTF_8));
+ .getBytes(StandardCharsets.UTF_8));
manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytesOrFail(SAMPLE_DEFINITION_FILE_PATH));
manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
@@ -1087,7 +1104,7 @@ public class SOL004MetaDirectoryValidatorTest {
//then incorrect error returned
final List<ErrorMessage> expectedErrorList = new ArrayList<>();
expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR
- , Messages.INCORRECT_SW_INFORMATION_NON_MANO_ERROR.formatMessage(nonManoSoftwareInformationPath))
+ , Messages.INCORRECT_SW_INFORMATION_NON_MANO_ERROR.formatMessage(nonManoSoftwareInformationPath))
);
assertExpectedErrors(actualErrorMap.get(SdcCommon.UPLOAD_FILE), expectedErrorList);
}
@@ -1098,14 +1115,14 @@ public class SOL004MetaDirectoryValidatorTest {
final ManifestBuilder manifestBuilder = getPnfManifestSampleBuilder();
final String nonManoSoftwareInformation1Path = "Artifacts/software-information/pnf-sw-information-valid1.yaml";
handler.addFile(nonManoSoftwareInformation1Path,
- getResourceBytesOrFail("validation.files/non-mano/pnf-sw-information-valid.yaml"));
+ getResourceBytesOrFail("validation.files/non-mano/pnf-sw-information-valid.yaml"));
manifestBuilder.withNonManoArtifact(ONAP_SW_INFORMATION.getType(), nonManoSoftwareInformation1Path);
final String nonManoSoftwareInformation2Path = "Artifacts/software-information/pnf-sw-information-valid2.yaml";
handler.addFile(nonManoSoftwareInformation2Path,
- getResourceBytesOrFail("validation.files/non-mano/pnf-sw-information-valid.yaml"));
+ getResourceBytesOrFail("validation.files/non-mano/pnf-sw-information-valid.yaml"));
manifestBuilder.withNonManoArtifact(ONAP_SW_INFORMATION.getType(), nonManoSoftwareInformation2Path);
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString()
- .getBytes(StandardCharsets.UTF_8));
+ .getBytes(StandardCharsets.UTF_8));
manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytesOrFail(SAMPLE_DEFINITION_FILE_PATH));
manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
@@ -1119,10 +1136,10 @@ public class SOL004MetaDirectoryValidatorTest {
//then unique error returned
final List<ErrorMessage> expectedErrorList = new ArrayList<>();
final String errorFiles = Stream.of(nonManoSoftwareInformation1Path, nonManoSoftwareInformation2Path)
- .map(s -> String.format("'%s'", s))
- .collect(Collectors.joining(", "));
+ .map(s -> String.format("'%s'", s))
+ .collect(Collectors.joining(", "));
expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR
- , Messages.UNIQUE_SW_INFORMATION_NON_MANO_ERROR.formatMessage(errorFiles))
+ , Messages.UNIQUE_SW_INFORMATION_NON_MANO_ERROR.formatMessage(errorFiles))
);
assertExpectedErrors(actualErrorMap.get(SdcCommon.UPLOAD_FILE), expectedErrorList);
}
@@ -1146,9 +1163,9 @@ public class SOL004MetaDirectoryValidatorTest {
manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
metaFileBuilder.append(ETSI_ENTRY_CERTIFICATE.getName())
- .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" ").append(fakeCertificatePath).append("\n");
+ .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" ").append(fakeCertificatePath).append("\n");
handler.addFile(TOSCA_META_PATH_FILE_NAME,
- metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
+ metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
@@ -1173,32 +1190,30 @@ public class SOL004MetaDirectoryValidatorTest {
//then
List<ErrorMessage> expectedErrorList = new ArrayList<>();
expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR
- , Messages.ARTIFACT_INVALID_SIGNATURE.formatMessage(fakeArtifactCmsPath, fakeArtifactPath))
+ , Messages.ARTIFACT_INVALID_SIGNATURE.formatMessage(fakeArtifactCmsPath, fakeArtifactPath))
);
assertExpectedErrors(actualErrorMap.get(SdcCommon.UPLOAD_FILE), expectedErrorList);
//given
sol004MetaDirectoryValidator = new SOL004MetaDirectoryValidator(securityManagerMock);
when(securityManagerMock.verifySignedData(any(), any(), any()))
- .thenThrow(new SecurityManagerException("SecurityManagerException"));
+ .thenThrow(new SecurityManagerException("SecurityManagerException"));
//when
actualErrorMap = sol004MetaDirectoryValidator.validateContent(handler);
//then
expectedErrorList = new ArrayList<>();
expectedErrorList.add(
- new ErrorMessage(ErrorLevel.ERROR,
- Messages.ARTIFACT_SIGNATURE_VALIDATION_ERROR.formatMessage(fakeArtifactCmsPath,
- fakeArtifactPath, fakeCertificatePath, "SecurityManagerException")
- )
+ new ErrorMessage(ErrorLevel.ERROR,
+ Messages.ARTIFACT_SIGNATURE_VALIDATION_ERROR.formatMessage(fakeArtifactCmsPath,
+ fakeArtifactPath, fakeCertificatePath, "SecurityManagerException")
+ )
);
assertExpectedErrors(actualErrorMap.get(SdcCommon.UPLOAD_FILE), expectedErrorList);
}
-
-
- private void assertExpectedErrors(final String testCase, final Map<String, List<ErrorMessage>> errors, final int expectedErrors){
+ private void assertExpectedErrors(final String testCase, final Map<String, List<ErrorMessage>> errors, final int expectedErrors) {
final List<ErrorMessage> errorMessages = errors.get(SdcCommon.UPLOAD_FILE);
printErrorMessages(errorMessages);
if (expectedErrors > 0) {
@@ -1211,25 +1226,25 @@ public class SOL004MetaDirectoryValidatorTest {
private void printErrorMessages(final List<ErrorMessage> errorMessages) {
if (CollectionUtils.isNotEmpty(errorMessages)) {
errorMessages.forEach(errorMessage ->
- System.out.println(String.format("%s: %s", errorMessage.getLevel(), errorMessage.getMessage()))
+ System.out.println(String.format("%s: %s", errorMessage.getLevel(), errorMessage.getMessage()))
);
}
}
private ManifestBuilder getPnfManifestSampleBuilder() {
return new ManifestBuilder()
- .withMetaData(PNFD_NAME.getToken(), "myPnf")
- .withMetaData(ManifestTokenType.PNFD_PROVIDER.getToken(), "ACME")
- .withMetaData(PNFD_ARCHIVE_VERSION.getToken(), "1.0")
- .withMetaData(PNFD_RELEASE_DATE_TIME.getToken(), "2019-03-11T11:25:00+00:00");
+ .withMetaData(PNFD_NAME.getToken(), "myPnf")
+ .withMetaData(ManifestTokenType.PNFD_PROVIDER.getToken(), "ACME")
+ .withMetaData(PNFD_ARCHIVE_VERSION.getToken(), "1.0")
+ .withMetaData(PNFD_RELEASE_DATE_TIME.getToken(), "2019-03-11T11:25:00+00:00");
}
private ManifestBuilder getVnfManifestSampleBuilder() {
return new ManifestBuilder()
- .withMetaData(VNF_PRODUCT_NAME.getToken(), "RadioNode")
- .withMetaData(VNF_PROVIDER_ID.getToken(), "ACME")
- .withMetaData(VNF_PACKAGE_VERSION.getToken(), "1.0")
- .withMetaData(VNF_RELEASE_DATE_TIME.getToken(), "2019-03-11T11:25:00+00:00");
+ .withMetaData(VNF_PRODUCT_NAME.getToken(), "RadioNode")
+ .withMetaData(VNF_PROVIDER_ID.getToken(), "ACME")
+ .withMetaData(VNF_PACKAGE_VERSION.getToken(), "1.0")
+ .withMetaData(VNF_RELEASE_DATE_TIME.getToken(), "2019-03-11T11:25:00+00:00");
}
private void assertExpectedErrors(List<ErrorMessage> actualErrorList, final List<ErrorMessage> expectedErrorList) {
@@ -1240,12 +1255,12 @@ public class SOL004MetaDirectoryValidatorTest {
printErrorMessages(actualErrorList);
assertThat("The actual error list should have the same size as the expected error list"
- , actualErrorList, hasSize(expectedErrorList.size())
+ , actualErrorList, hasSize(expectedErrorList.size())
);
assertThat("The actual error and expected error lists should be the same"
- , actualErrorList, containsInAnyOrder(expectedErrorList.toArray(new ErrorMessage[0]))
+ , actualErrorList, containsInAnyOrder(expectedErrorList.toArray(new ErrorMessage[0]))
);
}
-} \ No newline at end of file
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/utils/FileExtractorTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/utils/FileExtractorTest.java
new file mode 100644
index 0000000000..f50feae620
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/utils/FileExtractorTest.java
@@ -0,0 +1,77 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 Nokia. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.utils;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import static org.openecomp.sdc.be.config.NonManoArtifactType.ONAP_PM_DICTIONARY;
+import static org.openecomp.sdc.be.test.util.TestResourcesHandler.getResourceBytesOrFail;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.stream.Collectors;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.openecomp.sdc.vendorsoftwareproduct.impl.onboarding.OnboardingPackageContentHandler;
+
+
+public class FileExtractorTest {
+
+ private static final String PATH_TO_MANIFEST = "/PATH/TO/MANIFEST/";
+ private OnboardingPackageContentHandler contentHandler;
+
+ @BeforeEach
+ public void setUp() throws IOException {
+ contentHandler = new OnboardingPackageContentHandler();
+ }
+
+ @Test
+ void shouldExtractPMDictionaryFiles() {
+ // given
+ final byte[] pmDictionaryContent = "PM_DICTIONARY_CONTENT".getBytes();
+ contentHandler.addFile(PATH_TO_MANIFEST,
+ getResourceBytesOrFail("validation.files/manifest/manifestCompliantWithSOL004.mf"));
+ contentHandler.addFile("Files/Measurements/PM_Dictionary.yaml", pmDictionaryContent);
+
+ // when
+ final List<byte[]> filesContents = new FileExtractor(PATH_TO_MANIFEST, contentHandler)
+ .findFiles(ONAP_PM_DICTIONARY)
+ .collect(Collectors.toList());
+
+ // then
+ assertThat(filesContents.size(), is(1));
+ assertThat(filesContents.get(0), is(pmDictionaryContent));
+ }
+
+ @Test
+ void shouldReturnEmptyStream_whenPmDictionaryIsMissing() {
+ // given
+ contentHandler.addFile(PATH_TO_MANIFEST,
+ getResourceBytesOrFail("validation.files/manifest/sampleManifest2.mf"));
+
+ // when
+ final List<byte[]> filesContents = new FileExtractor(PATH_TO_MANIFEST, contentHandler)
+ .findFiles(ONAP_PM_DICTIONARY)
+ .collect(Collectors.toList());
+
+ // then
+ assertThat(filesContents.size(), is(0));
+ }
+}
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/utils/InternalFilesFilterTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/utils/InternalFilesFilterTest.java
new file mode 100644
index 0000000000..f402fc1e25
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/utils/InternalFilesFilterTest.java
@@ -0,0 +1,45 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2020 Nokia. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.utils;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+
+import java.util.List;
+import org.junit.jupiter.api.Test;
+
+class InternalFilesFilterTest {
+
+ @Test
+ void shouldFilterInternalFiles() {
+ // given
+ List<String> sources = List.of(
+ "http://test.com",
+ "ftp://test.com",
+ "/home/onap"
+ );
+
+ // when
+ final List<String> filteredSources = new InternalFilesFilter().filter(sources);
+
+ // then
+ assertThat(filteredSources, equalTo(List.of("/home/onap")));
+ }
+} \ No newline at end of file