summaryrefslogtreecommitdiffstats
path: root/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp
diff options
context:
space:
mode:
authorandre.schmid <andre.schmid@est.tech>2019-07-24 08:57:20 +0000
committerOfir Sonsino <ofir.sonsino@intl.att.com>2019-08-06 09:03:52 +0000
commit031db8630dda9706e22aa3bbdf0f2dfba33fb86e (patch)
tree5c0d076c02c6d67e01a154fab5245692232ee89a /openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp
parentd7d87dc3a647e924bcf0e05e60c18f70cba3ed7b (diff)
Validate PM Dictionary and VES Events YAML Files
Validate, during the package onboarding, YAML files declared in the manifest as type onap_ves_events or onap_pm_dictionary under non_mano_artifact_sets. Check if the file is not empty, if has a yaml extension and if it has a valid yaml content. Change-Id: I260d0f5355e9e77b6499f553f8aa9f7e6d0693da Issue-ID: SDC-2475 Signed-off-by: andre.schmid <andre.schmid@est.tech>
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/ManifestBuilderTest.java6
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/SOL004MetaDirectoryValidatorTest.java177
-rw-r--r--openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/TestConstants.java2
3 files changed, 169 insertions, 16 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ManifestBuilderTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ManifestBuilderTest.java
index 72f235e287..e022e2fedb 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ManifestBuilderTest.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/ManifestBuilderTest.java
@@ -24,6 +24,8 @@ import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.isEmptyString;
+import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.NonManoArtifactType.ONAP_PM_DICTIONARY;
+import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.NonManoArtifactType.ONAP_VES_EVENTS;
import java.io.ByteArrayInputStream;
import java.util.Arrays;
@@ -109,8 +111,8 @@ public class ManifestBuilderTest {
mockManifestSource();
final Map<String, List<String>> expectedNonManoArtifactMap = new TreeMap<>();
- expectedNonManoArtifactMap.put("onap_ves_events", Arrays.asList("Files/Events/MyPnf_Pnf_v1.yaml"));
- expectedNonManoArtifactMap.put("onap_pm_dictionary", Arrays.asList("Files/Measurements/PM_Dictionary.yaml"));
+ expectedNonManoArtifactMap.put(ONAP_VES_EVENTS.getType(), Arrays.asList("Files/Events/MyPnf_Pnf_v1.yaml"));
+ expectedNonManoArtifactMap.put(ONAP_PM_DICTIONARY.getType(), Arrays.asList("Files/Measurements/PM_Dictionary.yaml"));
expectedNonManoArtifactMap.put("onap_yang_modules",
Arrays.asList("Files/Yang_module/mynetconf.yang", "Files/Yang_module/mynetconf2.yang"));
expectedNonManoArtifactMap
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 6a56db6e34..328f00ca90 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
@@ -38,6 +38,7 @@ import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.hamcrest.Matchers.containsInAnyOrder;
@@ -60,6 +61,8 @@ import static org.openecomp.sdc.tosca.csar.CSARConstants.VNF_PROVIDER_ID;
import static org.openecomp.sdc.tosca.csar.CSARConstants.VNF_PACKAGE_VERSION;
import static org.openecomp.sdc.tosca.csar.CSARConstants.VNF_RELEASE_DATE_TIME;
+import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.NonManoArtifactType.ONAP_PM_DICTIONARY;
+import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.NonManoArtifactType.ONAP_VES_EVENTS;
import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.*;
public class SOL004MetaDirectoryValidatorTest {
@@ -130,7 +133,7 @@ public class SOL004MetaDirectoryValidatorTest {
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, folderList);
- assertTrue(errors.size() == 0);
+ assertEquals(0, errors.size());
}
@Test
@@ -141,7 +144,7 @@ public class SOL004MetaDirectoryValidatorTest {
final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
List<ErrorMessage> errorMessages = errors.get(SdcCommon.UPLOAD_FILE);
assertTrue(errors.size() == 1 && errorMessages.size() == 1);
- assertTrue(errorMessages.get(0).getLevel() == ErrorLevel.ERROR);
+ assertSame(ErrorLevel.ERROR, errorMessages.get(0).getLevel());
}
/**
@@ -209,7 +212,7 @@ public class SOL004MetaDirectoryValidatorTest {
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
- assertTrue(errors.size() == 0);
+ assertEquals(0, errors.size());
}
@Test
@@ -241,7 +244,7 @@ public class SOL004MetaDirectoryValidatorTest {
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
- assertTrue(errors.size() == 0);
+ assertEquals(0, errors.size());
}
@Test
@@ -345,14 +348,14 @@ public class SOL004MetaDirectoryValidatorTest {
manifestBuilder.withSource(SAMPLE_DEFINITION_IMPORT_FILE_PATH);
final String nonManoSource = "Artifacts/Deployment/Measurements/PM_Dictionary.yaml";
- handler.addFile(nonManoSource, "".getBytes());
- manifestBuilder.withNonManoArtifact("onap_pm_events", nonManoSource);
+ handler.addFile(nonManoSource, getResourceBytes("/validation.files/measurements/pmEvents-valid.yaml"));
+ manifestBuilder.withNonManoArtifact(ONAP_PM_DICTIONARY.getType(), nonManoSource);
manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
- assertTrue(errors.size() == 0);
+ assertEquals(0, errors.size());
}
/**
@@ -377,8 +380,8 @@ public class SOL004MetaDirectoryValidatorTest {
manifestBuilder.withSource(SAMPLE_DEFINITION_IMPORT_FILE_PATH);
String nonManoSource = "Artifacts/Deployment/Measurements/PM_Dictionary.yaml";
- handler.addFile(nonManoSource, "".getBytes());
- manifestBuilder.withNonManoArtifact("onap_pm_events", nonManoSource);
+ handler.addFile(nonManoSource, getResourceBytes("/validation.files/measurements/pmEvents-valid.yaml"));
+ manifestBuilder.withNonManoArtifact(ONAP_PM_DICTIONARY.getType(), nonManoSource);
manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
@@ -422,7 +425,7 @@ public class SOL004MetaDirectoryValidatorTest {
handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
- assertTrue(errors.size() == 0);
+ assertEquals(0, errors.size());
}
/**
@@ -687,7 +690,7 @@ public class SOL004MetaDirectoryValidatorTest {
* Tests an imported descriptor with a missing imported file.
*/
@Test
- public void testGivenDefinitionFileWithImportedDescriptor_whenImportedDescriptorImportsMissingFile_thenMissingImportErrorOccur() throws IOException {
+ public void testGivenDefinitionFileWithImportedDescriptor_whenImportedDescriptorImportsMissingFile_thenMissingImportErrorOccur() {
final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
@@ -757,6 +760,150 @@ public class SOL004MetaDirectoryValidatorTest {
assertExpectedErrors(actualErrorMap.get(SdcCommon.UPLOAD_FILE), expectedErrorList);
}
+ @Test
+ public void givenManifestWithNonManoPmAndVesArtifacts_whenNonManoArtifactsAreValid_thenNoErrorsOccur() {
+ final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
+
+ handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
+ manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
+
+ handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
+ manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
+
+ final String nonManoPmEventsSource = "Artifacts/Deployment/Measurements/PM_Dictionary.yaml";
+ handler.addFile(nonManoPmEventsSource, getResourceBytes("/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, getResourceBytes("/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, Collections.emptyList());
+
+ assertExpectedErrors(actualErrorMap.get(SdcCommon.UPLOAD_FILE), Collections.emptyList());
+ }
+
+ @Test
+ public void givenManifestWithNonManoPmOrVesArtifacts_whenNonManoArtifactsYamlAreInvalid_thenInvalidYamlErrorOccur() {
+ final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
+
+ handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
+ manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
+
+ handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
+ manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
+
+ final String nonManoPmEventsSource = "Artifacts/Deployment/Measurements/PM_Dictionary.yaml";
+ handler.addFile(nonManoPmEventsSource, getResourceBytes(INVALID_YAML_FILE_PATH));
+ manifestBuilder.withNonManoArtifact(ONAP_PM_DICTIONARY.getType(), nonManoPmEventsSource);
+
+ manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
+ handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
+
+ 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"))
+ );
+
+ final Map<String, List<ErrorMessage>> actualErrorMap = sol004MetaDirectoryValidator
+ .validateContent(handler, Collections.emptyList());
+
+ assertExpectedErrors(actualErrorMap.get(SdcCommon.UPLOAD_FILE), expectedErrorList);
+ }
+
+ @Test
+ public void givenManifestWithNonManoPmOrVesArtifacts_whenNonManoArtifactsYamlAreEmpty_thenEmptyYamlErrorOccur() {
+ final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
+
+ handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
+ manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
+
+ handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
+ manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
+
+ final String nonManoPmEventsSource = "Artifacts/Deployment/Measurements/PM_Dictionary.yaml";
+ handler.addFile(nonManoPmEventsSource, getResourceBytes(EMPTY_YAML_FILE_PATH));
+ manifestBuilder.withNonManoArtifact(ONAP_PM_DICTIONARY.getType(), nonManoPmEventsSource);
+
+ final String nonManoVesEventsSource = "Artifacts/Deployment/Events/ves_events.yaml";
+ handler.addFile(nonManoVesEventsSource, getResourceBytes(EMPTY_YAML_FILE_PATH));
+ manifestBuilder.withNonManoArtifact(ONAP_VES_EVENTS.getType(), nonManoVesEventsSource);
+
+ manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
+ handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
+
+ final List<ErrorMessage> expectedErrorList = new ArrayList<>();
+ expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR
+ , Messages.EMPTY_YAML_FILE_1.formatMessage(nonManoPmEventsSource))
+ );
+ expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR
+ , Messages.EMPTY_YAML_FILE_1.formatMessage(nonManoVesEventsSource))
+ );
+
+ final Map<String, List<ErrorMessage>> actualErrorMap = sol004MetaDirectoryValidator
+ .validateContent(handler, Collections.emptyList());
+
+ assertExpectedErrors(actualErrorMap.get(SdcCommon.UPLOAD_FILE), expectedErrorList);
+ }
+
+ @Test
+ public void givenManifestWithNonManoPmOrVesArtifacts_whenNonManoArtifactsHaveNotYamlExtension_thenInvalidYamlExtensionErrorOccur() {
+ final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
+
+ handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
+ manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
+
+ handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
+ manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
+
+ handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
+ manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
+
+ final String nonManoPmEventsSource = "Artifacts/Deployment/Measurements/PM_Dictionary.y1";
+ handler.addFile(nonManoPmEventsSource, "".getBytes());
+ manifestBuilder.withNonManoArtifact(ONAP_PM_DICTIONARY.getType(), nonManoPmEventsSource);
+
+ final String nonManoVesEventsSource = "Artifacts/Deployment/Events/ves_events.y2";
+ handler.addFile(nonManoVesEventsSource, "".getBytes());
+ manifestBuilder.withNonManoArtifact(ONAP_VES_EVENTS.getType(), nonManoVesEventsSource);
+
+ manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
+ handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
+
+ final List<ErrorMessage> expectedErrorList = new ArrayList<>();
+ expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR
+ , Messages.INVALID_YAML_EXTENSION.formatMessage(nonManoPmEventsSource))
+ );
+ expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR
+ , Messages.INVALID_YAML_EXTENSION.formatMessage(nonManoVesEventsSource))
+ );
+
+ final Map<String, List<ErrorMessage>> actualErrorMap = sol004MetaDirectoryValidator
+ .validateContent(handler, Collections.emptyList());
+
+ assertExpectedErrors(actualErrorMap.get(SdcCommon.UPLOAD_FILE), expectedErrorList);
+ }
+
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);
@@ -769,9 +916,9 @@ 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()));
- });
+ errorMessages.forEach(errorMessage ->
+ System.out.println(String.format("%s: %s", errorMessage.getLevel(), errorMessage.getMessage()))
+ );
}
}
@@ -808,6 +955,8 @@ public class SOL004MetaDirectoryValidatorTest {
actualErrorList = new ArrayList<>();
}
+ printErrorMessages(actualErrorList);
+
assertThat("The actual error list should have the same size as the expected error list"
, actualErrorList, hasSize(expectedErrorList.size())
);
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/TestConstants.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/TestConstants.java
index 57619646c9..42022fc90b 100644
--- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/TestConstants.java
+++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/validation/TestConstants.java
@@ -30,6 +30,8 @@ class TestConstants {
public static final String TOSCA_DEFINITION_FILEPATH = "Definitions/MainServiceTemplate.yaml";
public static final String TOSCA_MANIFEST_FILEPATH = "Definitions/MainServiceTemplate.mf";
public static final String TOSCA_CHANGELOG_FILEPATH = "Artifacts/changeLog.text";
+ public static final String EMPTY_YAML_FILE_PATH = "/validation.files/empty.yaml";
+ public static final String INVALID_YAML_FILE_PATH = "/validation.files/invalid.yaml";
private TestConstants(){