2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation;
23 import org.apache.commons.collections.CollectionUtils;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.openecomp.core.utilities.file.FileContentHandler;
27 import org.openecomp.sdc.common.errors.Messages;
28 import org.openecomp.sdc.common.utils.SdcCommon;
29 import org.openecomp.sdc.datatypes.error.ErrorLevel;
30 import org.openecomp.sdc.datatypes.error.ErrorMessage;
31 import java.io.IOException;
32 import java.nio.charset.StandardCharsets;
33 import java.util.ArrayList;
34 import java.util.Collections;
35 import java.util.List;
37 import org.openecomp.sdc.logging.api.Logger;
38 import org.openecomp.sdc.logging.api.LoggerFactory;
40 import static org.junit.Assert.assertEquals;
41 import static org.junit.Assert.assertSame;
42 import static org.junit.Assert.assertTrue;
43 import static org.junit.Assert.fail;
44 import static org.hamcrest.Matchers.containsInAnyOrder;
45 import static org.hamcrest.Matchers.hasSize;
46 import static org.hamcrest.MatcherAssert.assertThat;
47 import static org.openecomp.sdc.tosca.csar.CSARConstants.PNFD_NAME;
48 import static org.openecomp.sdc.tosca.csar.CSARConstants.PNFD_PROVIDER;
49 import static org.openecomp.sdc.tosca.csar.CSARConstants.PNFD_ARCHIVE_VERSION;
50 import static org.openecomp.sdc.tosca.csar.CSARConstants.PNFD_RELEASE_DATE_TIME;
51 import static org.openecomp.sdc.tosca.csar.CSARConstants.SEPARATOR_MF_ATTRIBUTE;
52 import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ENTRY_DEFINITIONS;
53 import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ETSI_ENTRY_CERTIFICATE;
54 import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ETSI_ENTRY_CHANGE_LOG;
55 import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ETSI_ENTRY_LICENSES;
56 import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ETSI_ENTRY_MANIFEST;
57 import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ETSI_ENTRY_TESTS;
58 import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_PATH_FILE_NAME;
59 import static org.openecomp.sdc.tosca.csar.CSARConstants.VNF_PRODUCT_NAME;
60 import static org.openecomp.sdc.tosca.csar.CSARConstants.VNF_PROVIDER_ID;
61 import static org.openecomp.sdc.tosca.csar.CSARConstants.VNF_PACKAGE_VERSION;
62 import static org.openecomp.sdc.tosca.csar.CSARConstants.VNF_RELEASE_DATE_TIME;
64 import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.NonManoArtifactType.ONAP_PM_DICTIONARY;
65 import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.NonManoArtifactType.ONAP_VES_EVENTS;
66 import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.*;
68 public class SOL004MetaDirectoryValidatorTest {
70 private static final Logger LOGGER = LoggerFactory.getLogger(SOL004MetaDirectoryValidatorTest.class);
72 private SOL004MetaDirectoryValidator sol004MetaDirectoryValidator;
73 private FileContentHandler handler;
74 private String metaFile;
78 sol004MetaDirectoryValidator = new SOL004MetaDirectoryValidator();
79 handler = new FileContentHandler();
81 "TOSCA-Meta-File-Version: 1.0\n"+
82 "CSAR-Version: 1.1\n"+
83 "Created-By: Vendor\n"+
84 TOSCA_META_ENTRY_DEFINITIONS + SEPARATOR_MF_ATTRIBUTE + "Definitions/MainServiceTemplate.yaml\n"+
85 TOSCA_META_ETSI_ENTRY_MANIFEST + SEPARATOR_MF_ATTRIBUTE + "Definitions/MainServiceTemplate.mf\n"+
86 TOSCA_META_ETSI_ENTRY_CHANGE_LOG + SEPARATOR_MF_ATTRIBUTE + "Artifacts/changeLog.text\n";
90 public void testGivenTOSCAMetaFile_whenEntryHasNoValue_thenErrorIsReturned() {
91 final String metaFileWithInvalidEntry = "TOSCA-Meta-File-Version: \n" +
92 "Entry-Definitions: Definitions/MainServiceTemplate.yaml";
94 handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileWithInvalidEntry.getBytes(StandardCharsets.UTF_8));
95 handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(TestConstants.SAMPLE_DEFINITION_FILE_PATH));
97 final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
98 assertExpectedErrors("TOSCA Meta file with no entries", errors, 1);
102 public void testGivenTOSCAMeta_withAllSupportedEntries_thenNoErrorsReturned() {
104 final String entryTestFilePath = "Files/Tests";
105 final String entryLicenseFilePath = "Files/Licenses";
107 final List<String> folderList = new ArrayList<>();
108 folderList.add("Files/Tests/");
109 folderList.add("Files/Licenses/");
111 metaFile = metaFile +
112 TOSCA_META_ETSI_ENTRY_TESTS + SEPARATOR_MF_ATTRIBUTE + entryTestFilePath + "\n" +
113 TOSCA_META_ETSI_ENTRY_LICENSES + SEPARATOR_MF_ATTRIBUTE + entryLicenseFilePath +"\n";
115 handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
116 handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
117 handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
119 handler.addFile(SAMPLE_SOURCE, "".getBytes());
120 handler.addFile(SAMPLE_DEFINITION_IMPORT_FILE_PATH, "".getBytes());
121 handler.addFile(entryTestFilePath, "".getBytes());
122 handler.addFile(entryLicenseFilePath, "".getBytes());
124 final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder()
125 .withSource(TOSCA_META_PATH_FILE_NAME)
126 .withSource(TOSCA_DEFINITION_FILEPATH)
127 .withSource(TOSCA_CHANGELOG_FILEPATH)
128 .withSource(TOSCA_MANIFEST_FILEPATH).withSource(SAMPLE_SOURCE)
129 .withSource(SAMPLE_DEFINITION_IMPORT_FILE_PATH)
130 .withSource(entryTestFilePath)
131 .withSource(entryLicenseFilePath);
133 handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
135 final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, folderList);
136 assertEquals(0, errors.size());
140 public void testGivenTOSCAMeta_withUnsupportedEntry_thenWarningIsReturned() {
141 metaFile = "Entry-Events: Definitions/events.log";
143 handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
144 final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
145 List<ErrorMessage> errorMessages = errors.get(SdcCommon.UPLOAD_FILE);
146 assertTrue(errors.size() == 1 && errorMessages.size() == 1);
147 assertSame(ErrorLevel.ERROR, errorMessages.get(0).getLevel());
151 * Tests if the meta file contains invalid versions in TOSCA-Meta-File-Version and CSAR-Version attributes.
154 public void testGivenTOSCAMetaFile_withInvalidTOSCAMetaFileVersionAndCSARVersion_thenErrorIsReturned() {
155 final String metaFile =
156 "TOSCA-Meta-File-Version: " + Integer.MAX_VALUE +
157 "\nCSAR-Version: " + Integer.MAX_VALUE +
158 "\nCreated-By: Bilal Iqbal\n" +
159 TOSCA_META_ENTRY_DEFINITIONS+ SEPARATOR_MF_ATTRIBUTE + "Definitions/MainServiceTemplate.yaml\n" +
160 TOSCA_META_ETSI_ENTRY_MANIFEST + SEPARATOR_MF_ATTRIBUTE + "Definitions/MainServiceTemplate.mf\n"+
161 TOSCA_META_ETSI_ENTRY_CHANGE_LOG + SEPARATOR_MF_ATTRIBUTE + "Artifacts/changeLog.text";
163 final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
165 handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
166 manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
168 handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(TestConstants.SAMPLE_DEFINITION_FILE_PATH));
169 manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
171 handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
172 manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
174 manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
175 handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
177 final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
178 assertExpectedErrors("Invalid TOSCA-Meta-File-Version and CSAR-Version attributes", errors, 2);
182 public void testGivenTOSCAMetaFile_withNonExistentFileReferenced_thenErrorsReturned() {
183 handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
185 final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
186 List<ErrorMessage> errorMessages = errors.get(SdcCommon.UPLOAD_FILE);
187 assertTrue(errors.size() == 1 && errorMessages.size() == 3);
192 public void testGivenDefinitionFile_whenValidImportStatementExist_thenNoErrorsReturned() {
193 final ManifestBuilder manifestBuilder = getPnfManifestSampleBuilder();
195 handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
196 manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
198 handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
199 manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
201 handler.addFile(SAMPLE_SOURCE, "".getBytes());
202 manifestBuilder.withSource(SAMPLE_SOURCE);
204 handler.addFile("Definitions/etsi_nfv_sol001_pnfd_2_5_1_types.yaml", getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
205 manifestBuilder.withSource("Definitions/etsi_nfv_sol001_pnfd_2_5_1_types.yaml");
207 final String definitionFileWithValidImports = "/validation.files/definition/definitionFileWithValidImports.yaml";
208 handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(definitionFileWithValidImports));
209 manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
211 manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
212 handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
214 final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
215 assertEquals(0, errors.size());
219 public void testGivenDefinitionFile_whenMultipleDefinitionsImportStatementExist_thenNoErrorsReturned() {
220 final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
222 handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
223 manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
225 handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
226 manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
228 handler.addFile(SAMPLE_SOURCE, "".getBytes());
229 manifestBuilder.withSource(SAMPLE_SOURCE);
231 final byte [] sampleDefinitionFile1 = getResourceBytes("/validation.files/definition/sampleDefinitionFile1.yaml");
232 handler.addFile(TOSCA_DEFINITION_FILEPATH, sampleDefinitionFile1);
233 manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
235 final byte [] sampleDefinitionFile2 = getResourceBytes("/validation.files/definition/sampleDefinitionFile2.yaml");
236 handler.addFile("Definitions/etsi_nfv_sol001_pnfd_2_5_1_types.yaml", sampleDefinitionFile2);
237 manifestBuilder.withSource("Definitions/etsi_nfv_sol001_pnfd_2_5_1_types.yaml");
239 final byte [] sampleDefinitionFile3 = getResourceBytes("/validation.files/definition/sampleDefinitionFile1.yaml");
240 handler.addFile("Definitions/etsi_nfv_sol001_pnfd_2_5_2_types.yaml", sampleDefinitionFile3);
241 manifestBuilder.withSource("Definitions/etsi_nfv_sol001_pnfd_2_5_2_types.yaml");
243 manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
244 handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
246 final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
247 assertEquals(0, errors.size());
251 public void testGivenDefinitionFile_whenInvalidImportStatementExist_thenErrorIsReturned() {
252 final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
254 handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
255 manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
257 handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
258 manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
260 handler.addFile(SAMPLE_SOURCE, "".getBytes());
261 manifestBuilder.withSource(SAMPLE_SOURCE);
263 final String definitionFileWithInvalidImports = "/validation.files/definition/definitionFileWithInvalidImport.yaml";
264 handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(definitionFileWithInvalidImports));
265 manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
267 manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
268 String manifest = manifestBuilder.build();
269 handler.addFile(TOSCA_MANIFEST_FILEPATH, manifest.getBytes(StandardCharsets.UTF_8));
271 final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
272 assertExpectedErrors("", errors, 1);
276 * Manifest referenced import file missing
279 public void testGivenDefinitionFile_whenReferencedImportDoesNotExist_thenErrorIsReturned() {
280 final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
282 handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
283 manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
285 handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
286 manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
288 handler.addFile(SAMPLE_SOURCE, "".getBytes());
289 manifestBuilder.withSource(SAMPLE_SOURCE);
291 handler.addFile("Definitions/etsi_nfv_sol001_pnfd_2_5_1_types.yaml", "".getBytes());
292 manifestBuilder.withSource("Definitions/etsi_nfv_sol001_pnfd_2_5_1_types.yaml");
294 manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
295 handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes("/validation.files/definition/sampleDefinitionFile2.yaml"));
297 manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
298 handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
300 final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
301 assertExpectedErrors("Manifest referenced import file missing", errors, 1);
305 * Reference with invalid YAML format.
308 public void testGivenDefinitionFile_withInvalidYAML_thenErrorIsReturned() {
309 final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
311 handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
312 manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
314 handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
315 manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
317 handler.addFile(SAMPLE_SOURCE, "".getBytes());
318 manifestBuilder.withSource(SAMPLE_SOURCE);
320 final String definitionFileWithInvalidYAML = "/validation.files/definition/invalidDefinitionFile.yaml";
321 handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(definitionFileWithInvalidYAML));
322 manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
324 manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
325 handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
327 final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
328 assertExpectedErrors("Reference with invalid YAML format", errors, 1);
332 public void testGivenManifestFile_withValidSourceAndNonManoSources_thenNoErrorIsReturned() {
333 final ManifestBuilder manifestBuilder = getPnfManifestSampleBuilder();
335 handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
336 manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
338 handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
339 manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
341 handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
342 manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
344 handler.addFile(SAMPLE_SOURCE, "".getBytes());
345 manifestBuilder.withSource(SAMPLE_SOURCE);
347 handler.addFile(SAMPLE_DEFINITION_IMPORT_FILE_PATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
348 manifestBuilder.withSource(SAMPLE_DEFINITION_IMPORT_FILE_PATH);
350 final String nonManoSource = "Artifacts/Deployment/Measurements/PM_Dictionary.yaml";
351 handler.addFile(nonManoSource, getResourceBytes("/validation.files/measurements/pmEvents-valid.yaml"));
352 manifestBuilder.withNonManoArtifact(ONAP_PM_DICTIONARY.getType(), nonManoSource);
354 manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
355 handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
357 final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
358 assertEquals(0, errors.size());
362 * Manifest with non existent source files should return error.
365 public void testGivenManifestFile_withNonExistentSourceFile_thenErrorIsReturned() {
366 final ManifestBuilder manifestBuilder = getPnfManifestSampleBuilder();
367 //non existent reference
368 manifestBuilder.withSource("Artifacts/Deployment/Events/RadioNode_pnf_v1.yaml");
370 handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
371 manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
373 handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
374 manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
376 handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
377 manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
379 handler.addFile(SAMPLE_DEFINITION_IMPORT_FILE_PATH, "".getBytes());
380 manifestBuilder.withSource(SAMPLE_DEFINITION_IMPORT_FILE_PATH);
382 String nonManoSource = "Artifacts/Deployment/Measurements/PM_Dictionary.yaml";
383 handler.addFile(nonManoSource, getResourceBytes("/validation.files/measurements/pmEvents-valid.yaml"));
384 manifestBuilder.withNonManoArtifact(ONAP_PM_DICTIONARY.getType(), nonManoSource);
386 manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
387 handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
389 final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
390 assertExpectedErrors("Manifest with non existent source files", errors, 1);
394 * Tests the validation for a TOSCA Manifest with invalid data.
397 public void testGivenManifestFile_withInvalidData_thenErrorIsReturned() {
398 handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
399 handler.addFile(TOSCA_MANIFEST_FILEPATH, getResourceBytes("/validation.files/manifest/invalidManifest.mf"));
400 handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
401 handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
402 handler.addFile(SAMPLE_DEFINITION_IMPORT_FILE_PATH, "".getBytes());
404 final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
405 assertExpectedErrors("TOSCA manifest with invalid data", errors, 1);
409 public void testGivenManifestAndDefinitionFile_withSameNames_thenNoErrorReturned() {
410 final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
412 handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
413 manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
415 handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
416 manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
418 handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
419 manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
421 handler.addFile(SAMPLE_DEFINITION_IMPORT_FILE_PATH, "".getBytes());
422 manifestBuilder.withSource(SAMPLE_DEFINITION_IMPORT_FILE_PATH);
424 manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
425 handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
427 final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
428 assertEquals(0, errors.size());
432 * Main TOSCA definitions file and Manifest file with different name should return error.
435 public void testGivenManifestAndMainDefinitionFile_withDifferentNames_thenErrorIsReturned() {
437 "TOSCA-Meta-File-Version: 1.0\n"+
438 "CSAR-Version: 1.1\n"+
439 "Created-By: Vendor\n"+
440 TOSCA_META_ENTRY_DEFINITIONS + SEPARATOR_MF_ATTRIBUTE + "Definitions/MainServiceTemplate.yaml\n"+
441 TOSCA_META_ETSI_ENTRY_MANIFEST + SEPARATOR_MF_ATTRIBUTE +"Definitions/MainServiceTemplate2.mf\n"+
442 TOSCA_META_ETSI_ENTRY_CHANGE_LOG + SEPARATOR_MF_ATTRIBUTE +"Artifacts/changeLog.text\n";
444 final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
446 handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
447 manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
449 handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
450 manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
452 handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
453 manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
455 handler.addFile(SAMPLE_DEFINITION_IMPORT_FILE_PATH, "".getBytes());
456 manifestBuilder.withSource(SAMPLE_DEFINITION_IMPORT_FILE_PATH);
458 manifestBuilder.withSource("Definitions/MainServiceTemplate2.mf");
459 handler.addFile("Definitions/MainServiceTemplate2.mf", manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
461 final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
462 assertExpectedErrors("Main TOSCA definitions file and Manifest file with different name should return error",
467 public void testGivenManifestFile_withDifferentExtension_thenErrorIsReturned() {
469 "TOSCA-Meta-File-Version: 1.0\n"+
470 "CSAR-Version: 1.1\n"+
471 "Created-By: Vendor\n"+
472 "Entry-Definitions: Definitions/MainServiceTemplate.yaml\n"+
473 TOSCA_META_ETSI_ENTRY_MANIFEST + SEPARATOR_MF_ATTRIBUTE + "Definitions/MainServiceTemplate.txt\n"+
474 TOSCA_META_ETSI_ENTRY_CHANGE_LOG + SEPARATOR_MF_ATTRIBUTE + "Artifacts/changeLog.text\n";
476 final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
478 handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
479 manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
481 handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
482 manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
484 handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
485 manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
487 handler.addFile(SAMPLE_DEFINITION_IMPORT_FILE_PATH, "".getBytes());
488 manifestBuilder.withSource(SAMPLE_DEFINITION_IMPORT_FILE_PATH);
490 manifestBuilder.withSource("Definitions/MainServiceTemplate.txt");
491 handler.addFile("Definitions/MainServiceTemplate.txt", manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
493 final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
494 assertExpectedErrors("Manifest file with different extension than .mf should return error",
499 public void testGivenManifestFile_withValidVnfMetadata_thenNoErrorsReturned() {
500 final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
502 handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
503 manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
504 handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
505 manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
506 handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
507 manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
509 manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
510 handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
512 final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
513 assertExpectedErrors("Manifest with valid vnf mandatory values should not return any errors", errors, 0);
517 public void testGivenManifestFile_withValidPnfMetadata_thenNoErrorsReturned() {
518 final ManifestBuilder manifestBuilder = getPnfManifestSampleBuilder();
520 handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
521 manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
523 handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
524 manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
526 manifestBuilder.withSignedSource(TOSCA_DEFINITION_FILEPATH
527 , "SHA-abc", "09e5a788acb180162c51679ae4c998039fa6644505db2415e35107d1ee213943");
528 handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
530 manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
531 handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
533 final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
534 assertExpectedErrors("Manifest with valid pnf mandatory values should not return any errors", errors, 0);
538 * Manifest with mixed metadata should return error.
541 public void testGivenManifestFile_withMetadataContainingMixedPnfVnfMetadata_thenErrorIsReturned() {
542 final ManifestBuilder manifestBuilder = new ManifestBuilder()
543 .withMetaData(PNFD_NAME, "RadioNode")
544 .withMetaData(VNF_PROVIDER_ID, "Bilal Iqbal")
545 .withMetaData(PNFD_ARCHIVE_VERSION, "1.0")
546 .withMetaData(VNF_RELEASE_DATE_TIME, "2019-12-14T11:25:00+00:00");
548 handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
549 manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
550 handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
551 manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
552 handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
553 manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
555 manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
556 handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
558 final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
559 assertExpectedErrors("Manifest with mixed metadata should return error", errors, 1);
564 public void testGivenManifestFile_withMetadataMissingPnfOrVnfMandatoryEntries_thenErrorIsReturned() {
565 final ManifestBuilder manifestBuilder = new ManifestBuilder()
566 .withMetaData("invalid_product_name", "RadioNode")
567 .withMetaData("invalid_provider_id", "Bilal Iqbal")
568 .withMetaData("invalid_package_version", "1.0")
569 .withMetaData("invalid_release_date_time", "2019-12-14T11:25:00+00:00");
571 handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
572 manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
574 handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
575 manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
577 handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
578 manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
580 manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
581 handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
583 final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
584 assertExpectedErrors("Manifest with missing vnf or pnf mandatory entries should return error", errors, 1);
588 public void testGivenManifestFile_withMetadataMissingMandatoryPnfEntries_thenErrorIsReturned() {
589 final ManifestBuilder manifestBuilder = new ManifestBuilder();
591 manifestBuilder.withMetaData(PNFD_NAME, "RadioNode");
592 manifestBuilder.withMetaData(PNFD_RELEASE_DATE_TIME, "2019-12-14T11:25:00+00:00");
594 handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
595 manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
597 handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
598 manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
600 handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
601 manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
603 manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
604 handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
606 final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
607 assertExpectedErrors("Manifest with metadata missing pnf mandatory entries should return error", errors, 3);
612 public void testGivenManifestFile_withMetadataMissingMandatoryVnfEntries_thenErrorIsReturned() {
613 final ManifestBuilder manifestBuilder = new ManifestBuilder();
615 manifestBuilder.withMetaData(VNF_PRODUCT_NAME, "RadioNode");
617 handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
618 manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
620 handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
621 manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
623 handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
624 manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
626 manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
627 handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
629 final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
630 assertExpectedErrors("Manifest with metadata missing vnf mandatory entries should return error", errors, 4);
635 * Manifest with more than 4 metadata entries should return error.
638 public void testGivenManifestFile_withMetadataEntriesExceedingTheLimit_thenErrorIsReturned() {
639 final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder()
640 .withMetaData(PNFD_NAME, "RadioNode")
641 .withMetaData(PNFD_PROVIDER, "Bilal Iqbal")
642 .withMetaData(PNFD_ARCHIVE_VERSION, "1.0")
643 .withMetaData(PNFD_RELEASE_DATE_TIME, "2019-03-11T11:25:00+00:00");
645 handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
646 manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
648 handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
649 manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
651 handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
652 manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
654 manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
655 handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
657 final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
658 assertExpectedErrors("Manifest with more than 4 metadata entries should return error", errors, 2);
662 public void testGivenManifestFile_withPnfMetadataAndVfEntries_thenErrorIsReturned() {
663 final ManifestBuilder manifestBuilder = getPnfManifestSampleBuilder();
665 metaFile = metaFile +
666 TOSCA_META_ETSI_ENTRY_TESTS + SEPARATOR_MF_ATTRIBUTE + "Files/Tests\n" +
667 TOSCA_META_ETSI_ENTRY_LICENSES + SEPARATOR_MF_ATTRIBUTE + "Files/Licenses\n" +
668 TOSCA_META_ETSI_ENTRY_CERTIFICATE + SEPARATOR_MF_ATTRIBUTE + "Files/Certificates";
670 handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
671 manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
673 handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
674 manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
676 handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
677 manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
679 manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
680 handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
682 final List<String> folderList = new ArrayList<>();
683 folderList.add("Files/Certificates/");
684 final Map<String, List<ErrorMessage>> errors = sol004MetaDirectoryValidator.validateContent(handler, folderList);
685 assertExpectedErrors("Tosca.meta should not have entries applicable only to VF", errors, 2);
690 * Tests an imported descriptor with a missing imported file.
693 public void testGivenDefinitionFileWithImportedDescriptor_whenImportedDescriptorImportsMissingFile_thenMissingImportErrorOccur() {
694 final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
696 handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
697 manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
699 handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
700 manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
702 handler.addFile(SAMPLE_SOURCE, "".getBytes());
703 manifestBuilder.withSource(SAMPLE_SOURCE);
705 final String definitionImportOne = "Definitions/importOne.yaml";
706 handler.addFile(definitionImportOne, getResourceBytes("/validation.files/definition/sampleDefinitionFile2.yaml"));
707 manifestBuilder.withSource(definitionImportOne);
709 final String definitionFileWithValidImports = "/validation.files/definition/definitionFileWithOneImport.yaml";
710 handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(definitionFileWithValidImports));
711 manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
713 manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
714 handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
716 final Map<String, List<ErrorMessage>> actualErrorMap = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
718 final List<ErrorMessage> expectedErrorList = new ArrayList<>();
719 expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR
720 , Messages.MISSING_IMPORT_FILE.formatMessage("Definitions/etsi_nfv_sol001_pnfd_2_5_2_types.yaml"))
723 assertExpectedErrors(actualErrorMap.get(SdcCommon.UPLOAD_FILE), expectedErrorList);
727 * Tests an imported descriptor with invalid import statement.
730 public void testGivenDefinitionFileWithImportedDescriptor_whenInvalidImportStatementExistInImportedDescriptor_thenInvalidImportErrorOccur() {
731 final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
733 handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
734 manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
736 handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
737 manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
739 handler.addFile(SAMPLE_SOURCE, "".getBytes());
740 manifestBuilder.withSource(SAMPLE_SOURCE);
742 final String definitionImportOne = "Definitions/importOne.yaml";
743 handler.addFile(definitionImportOne, getResourceBytes("/validation.files/definition/definitionFileWithInvalidImport.yaml"));
744 manifestBuilder.withSource(definitionImportOne);
746 final String definitionFileWithValidImports = "/validation.files/definition/definitionFileWithOneImport.yaml";
747 handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(definitionFileWithValidImports));
748 manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
750 manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
751 handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
753 final Map<String, List<ErrorMessage>> actualErrorMap = sol004MetaDirectoryValidator.validateContent(handler, Collections.emptyList());
755 final List<ErrorMessage> expectedErrorList = new ArrayList<>();
756 expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR
757 , Messages.INVALID_IMPORT_STATEMENT.formatMessage(definitionImportOne, "null"))
760 assertExpectedErrors(actualErrorMap.get(SdcCommon.UPLOAD_FILE), expectedErrorList);
764 public void givenManifestWithNonManoPmAndVesArtifacts_whenNonManoArtifactsAreValid_thenNoErrorsOccur() {
765 final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
767 handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
768 manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
770 handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
771 manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
773 handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
774 manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
776 final String nonManoPmEventsSource = "Artifacts/Deployment/Measurements/PM_Dictionary.yaml";
777 handler.addFile(nonManoPmEventsSource, getResourceBytes("/validation.files/measurements/pmEvents-valid.yaml"));
778 manifestBuilder.withNonManoArtifact(ONAP_PM_DICTIONARY.getType(), nonManoPmEventsSource);
780 final String nonManoVesEventsSource = "Artifacts/Deployment/Events/ves_events.yaml";
781 handler.addFile(nonManoVesEventsSource, getResourceBytes("/validation.files/events/vesEvents-valid.yaml"));
782 manifestBuilder.withNonManoArtifact(ONAP_VES_EVENTS.getType(), nonManoVesEventsSource);
784 manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
785 handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
787 final Map<String, List<ErrorMessage>> actualErrorMap = sol004MetaDirectoryValidator
788 .validateContent(handler, Collections.emptyList());
790 assertExpectedErrors(actualErrorMap.get(SdcCommon.UPLOAD_FILE), Collections.emptyList());
794 public void givenManifestWithNonManoPmOrVesArtifacts_whenNonManoArtifactsYamlAreInvalid_thenInvalidYamlErrorOccur() {
795 final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
797 handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
798 manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
800 handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
801 manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
803 handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
804 manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
806 final String nonManoPmEventsSource = "Artifacts/Deployment/Measurements/PM_Dictionary.yaml";
807 handler.addFile(nonManoPmEventsSource, getResourceBytes(INVALID_YAML_FILE_PATH));
808 manifestBuilder.withNonManoArtifact(ONAP_PM_DICTIONARY.getType(), nonManoPmEventsSource);
810 manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
811 handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
813 final List<ErrorMessage> expectedErrorList = new ArrayList<>();
814 expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR
815 , Messages.INVALID_YAML_FORMAT_1.formatMessage(nonManoPmEventsSource, "while scanning a simple key\n"
816 + " in 'reader', line 2, column 1:\n"
819 + "could not find expected ':'\n"
820 + " in 'reader', line 2, column 7:\n"
825 final Map<String, List<ErrorMessage>> actualErrorMap = sol004MetaDirectoryValidator
826 .validateContent(handler, Collections.emptyList());
828 assertExpectedErrors(actualErrorMap.get(SdcCommon.UPLOAD_FILE), expectedErrorList);
832 public void givenManifestWithNonManoPmOrVesArtifacts_whenNonManoArtifactsYamlAreEmpty_thenEmptyYamlErrorOccur() {
833 final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
835 handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
836 manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
838 handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
839 manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
841 handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
842 manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
844 final String nonManoPmEventsSource = "Artifacts/Deployment/Measurements/PM_Dictionary.yaml";
845 handler.addFile(nonManoPmEventsSource, getResourceBytes(EMPTY_YAML_FILE_PATH));
846 manifestBuilder.withNonManoArtifact(ONAP_PM_DICTIONARY.getType(), nonManoPmEventsSource);
848 final String nonManoVesEventsSource = "Artifacts/Deployment/Events/ves_events.yaml";
849 handler.addFile(nonManoVesEventsSource, getResourceBytes(EMPTY_YAML_FILE_PATH));
850 manifestBuilder.withNonManoArtifact(ONAP_VES_EVENTS.getType(), nonManoVesEventsSource);
852 manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
853 handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
855 final List<ErrorMessage> expectedErrorList = new ArrayList<>();
856 expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR
857 , Messages.EMPTY_YAML_FILE_1.formatMessage(nonManoPmEventsSource))
859 expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR
860 , Messages.EMPTY_YAML_FILE_1.formatMessage(nonManoVesEventsSource))
863 final Map<String, List<ErrorMessage>> actualErrorMap = sol004MetaDirectoryValidator
864 .validateContent(handler, Collections.emptyList());
866 assertExpectedErrors(actualErrorMap.get(SdcCommon.UPLOAD_FILE), expectedErrorList);
870 public void givenManifestWithNonManoPmOrVesArtifacts_whenNonManoArtifactsHaveNotYamlExtension_thenInvalidYamlExtensionErrorOccur() {
871 final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
873 handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFile.getBytes(StandardCharsets.UTF_8));
874 manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
876 handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytes(SAMPLE_DEFINITION_FILE_PATH));
877 manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
879 handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes(StandardCharsets.UTF_8));
880 manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
882 final String nonManoPmEventsSource = "Artifacts/Deployment/Measurements/PM_Dictionary.y1";
883 handler.addFile(nonManoPmEventsSource, "".getBytes());
884 manifestBuilder.withNonManoArtifact(ONAP_PM_DICTIONARY.getType(), nonManoPmEventsSource);
886 final String nonManoVesEventsSource = "Artifacts/Deployment/Events/ves_events.y2";
887 handler.addFile(nonManoVesEventsSource, "".getBytes());
888 manifestBuilder.withNonManoArtifact(ONAP_VES_EVENTS.getType(), nonManoVesEventsSource);
890 manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
891 handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
893 final List<ErrorMessage> expectedErrorList = new ArrayList<>();
894 expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR
895 , Messages.INVALID_YAML_EXTENSION.formatMessage(nonManoPmEventsSource))
897 expectedErrorList.add(new ErrorMessage(ErrorLevel.ERROR
898 , Messages.INVALID_YAML_EXTENSION.formatMessage(nonManoVesEventsSource))
901 final Map<String, List<ErrorMessage>> actualErrorMap = sol004MetaDirectoryValidator
902 .validateContent(handler, Collections.emptyList());
904 assertExpectedErrors(actualErrorMap.get(SdcCommon.UPLOAD_FILE), expectedErrorList);
907 private void assertExpectedErrors(final String testCase, final Map<String, List<ErrorMessage>> errors, final int expectedErrors){
908 final List<ErrorMessage> errorMessages = errors.get(SdcCommon.UPLOAD_FILE);
909 printErrorMessages(errorMessages);
910 if (expectedErrors > 0) {
911 assertEquals(testCase, errorMessages.size(), expectedErrors);
913 assertEquals(testCase, errors.size(), expectedErrors);
917 private void printErrorMessages(final List<ErrorMessage> errorMessages) {
918 if (CollectionUtils.isNotEmpty(errorMessages)) {
919 errorMessages.forEach(errorMessage ->
920 System.out.println(String.format("%s: %s", errorMessage.getLevel(), errorMessage.getMessage()))
925 private byte[] getResourceBytes(final String resourcePath) {
927 return ValidatorUtil.getFileResource(resourcePath);
928 } catch (final IOException e) {
929 final String errorMsg = String.format("Could not load resource '%s'", resourcePath);
930 LOGGER.error(errorMsg, e);
937 private ManifestBuilder getPnfManifestSampleBuilder() {
938 return new ManifestBuilder()
939 .withMetaData(PNFD_NAME, "myPnf")
940 .withMetaData(PNFD_PROVIDER, "ACME")
941 .withMetaData(PNFD_ARCHIVE_VERSION, "1.0")
942 .withMetaData(PNFD_RELEASE_DATE_TIME, "2019-03-11T11:25:00+00:00");
945 private ManifestBuilder getVnfManifestSampleBuilder() {
946 return new ManifestBuilder()
947 .withMetaData(VNF_PRODUCT_NAME, "RadioNode")
948 .withMetaData(VNF_PROVIDER_ID, "ACME")
949 .withMetaData(VNF_PACKAGE_VERSION, "1.0")
950 .withMetaData(VNF_RELEASE_DATE_TIME, "2019-03-11T11:25:00+00:00");
953 private void assertExpectedErrors(List<ErrorMessage> actualErrorList, final List<ErrorMessage> expectedErrorList) {
954 if (actualErrorList == null) {
955 actualErrorList = new ArrayList<>();
958 printErrorMessages(actualErrorList);
960 assertThat("The actual error list should have the same size as the expected error list"
961 , actualErrorList, hasSize(expectedErrorList.size())
964 assertThat("The actual error and expected error lists should be the same"
965 , actualErrorList, containsInAnyOrder(expectedErrorList.toArray(new ErrorMessage[0]))