2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2021 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 static org.junit.jupiter.api.Assertions.assertTrue;
24 import static org.openecomp.sdc.be.config.NonManoArtifactType.ONAP_CNF_HELM;
25 import static org.openecomp.sdc.be.test.util.TestResourcesHandler.getResourceBytesOrFail;
26 import static org.openecomp.sdc.tosca.csar.ManifestTokenType.ATTRIBUTE_VALUE_SEPARATOR;
27 import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.OTHER_DEFINITIONS;
28 import static org.openecomp.sdc.tosca.csar.ToscaMetadataFileInfo.TOSCA_META_PATH_FILE_NAME;
29 import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.SAMPLE_DEFINITION_FILE_PATH;
30 import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.SAMPLE_DEFINITION_IMPORT_FILE_PATH;
31 import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.SAMPLE_SOURCE;
32 import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.TOSCA_CHANGELOG_FILEPATH;
33 import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.TOSCA_DEFINITION_FILEPATH;
34 import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.validation.TestConstants.TOSCA_MANIFEST_FILEPATH;
36 import java.io.IOException;
37 import java.nio.charset.StandardCharsets;
38 import org.junit.jupiter.api.Test;
39 import org.openecomp.sdc.tosca.csar.ManifestTokenType;
40 import org.openecomp.sdc.vendorsoftwareproduct.security.SecurityManager;
42 class SOL004Version4MetaDirectoryValidatorTest extends SOL004MetaDirectoryValidatorTest {
45 public SOL004MetaDirectoryValidator getSOL004MetaDirectoryValidator() {
46 return new SOL004Version4MetaDirectoryValidator();
50 public StringBuilder getMetaFileBuilder() {
51 return super.getMetaFileBuilder().append(OTHER_DEFINITIONS.getName())
52 .append(ATTRIBUTE_VALUE_SEPARATOR.getToken()).append(" ").append(TOSCA_DEFINITION_FILEPATH).append("\n");
56 protected SOL004MetaDirectoryValidator getSol004WithSecurity(SecurityManager securityManagerMock) {
57 return new SOL004Version4MetaDirectoryValidator(securityManagerMock);
61 protected ManifestBuilder getVnfManifestSampleBuilder() {
62 return super.getVnfManifestSampleBuilder()
63 .withMetaData(ManifestTokenType.VNF_SOFTWARE_VERSION.getToken(), "1.0.0")
64 .withMetaData(ManifestTokenType.VNFD_ID.getToken(), "2116fd24-83f2-416b-bf3c-ca1964793aca")
65 .withMetaData(ManifestTokenType.COMPATIBLE_SPECIFICATION_VERSIONS.getToken(), "2.6.1, 2.7.1, 3.3.1")
66 .withMetaData(ManifestTokenType.VNF_PROVIDER_ID.getToken(), "ACME")
67 .withMetaData(ManifestTokenType.VNF_RELEASE_DATE_TIME.getToken(), "2021-02-11T11:25:00+00:00")
68 .withMetaData(ManifestTokenType.VNF_PACKAGE_VERSION.getToken(), "1.0")
69 .withMetaData(ManifestTokenType.VNFM_INFO.getToken(), "etsivnfm:v2.3.1,0:myGreatVnfm-1")
70 .withMetaData(ManifestTokenType.VNF_PRODUCT_NAME.getToken(), "RadioNode");
74 protected ManifestBuilder getPnfManifestSampleBuilder() {
75 return super.getPnfManifestSampleBuilder()
76 .withMetaData(ManifestTokenType.COMPATIBLE_SPECIFICATION_VERSIONS.getToken(), "2.6.1, 2.7.1, 3.3.1");
80 protected int getManifestDefinitionErrorCount() {
85 void testGivenManifestFile_withValidSourceAndNonManoSources_thenNoErrorIsReturned() throws IOException {
86 final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
88 handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
89 manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
91 handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
92 manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
94 handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytesOrFail(SAMPLE_DEFINITION_FILE_PATH));
95 manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
97 handler.addFile(SAMPLE_SOURCE, "".getBytes());
98 manifestBuilder.withSource(SAMPLE_SOURCE);
100 handler.addFile(SAMPLE_DEFINITION_IMPORT_FILE_PATH, getResourceBytesOrFail(SAMPLE_DEFINITION_FILE_PATH));
101 manifestBuilder.withSource(SAMPLE_DEFINITION_IMPORT_FILE_PATH);
103 final String nonManoSource = "Artifacts/Deployment/non-mano/onap-cnf-helm-valid.yaml";
104 handler.addFile(nonManoSource, getResourceBytesOrFail("validation.files/empty.yaml"));
105 manifestBuilder.withNonManoArtifact(ONAP_CNF_HELM.getType(), nonManoSource);
107 manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
108 handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
110 final Validator validator = ValidatorFactory.getValidator(handler);
111 final ValidationResult validationResult = validator.validate(handler);
112 assertTrue(validationResult.getErrors().isEmpty());
116 void testGivenManifestFile_withNotReferencedNonManoSources_thenErrorIsReturned() throws IOException {
117 final ManifestBuilder manifestBuilder = getVnfManifestSampleBuilder();
119 handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
120 manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
122 handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
123 manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
125 handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytesOrFail(SAMPLE_DEFINITION_FILE_PATH));
126 manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
128 handler.addFile(SAMPLE_SOURCE, "".getBytes());
129 manifestBuilder.withSource(SAMPLE_SOURCE);
131 handler.addFile(SAMPLE_DEFINITION_IMPORT_FILE_PATH, getResourceBytesOrFail(SAMPLE_DEFINITION_FILE_PATH));
132 manifestBuilder.withSource(SAMPLE_DEFINITION_IMPORT_FILE_PATH);
134 //non existent reference
135 manifestBuilder.withNonManoArtifact(ONAP_CNF_HELM.getType(), "validation.files/notReferencedFile.yaml");
137 manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
138 handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
140 final Validator validator = ValidatorFactory.getValidator(handler);
141 final ValidationResult validationResult = validator.validate(handler);
142 assertExpectedErrors("Non-MANO file does not exist", validationResult.getErrors(), 1);
146 void testGivenManifestFile_withNonExistentSourceFile_thenErrorIsReturned() throws IOException {
147 final ManifestBuilder manifestBuilder = getPnfManifestSampleBuilder();
148 //non existent reference
149 manifestBuilder.withSource("Artifacts/Deployment/non-mano/RadioNode.yaml");
151 handler.addFile(TOSCA_META_PATH_FILE_NAME, metaFileBuilder.toString().getBytes(StandardCharsets.UTF_8));
152 manifestBuilder.withSource(TOSCA_META_PATH_FILE_NAME);
154 handler.addFile(TOSCA_CHANGELOG_FILEPATH, "".getBytes());
155 manifestBuilder.withSource(TOSCA_CHANGELOG_FILEPATH);
157 handler.addFile(TOSCA_DEFINITION_FILEPATH, getResourceBytesOrFail(SAMPLE_DEFINITION_FILE_PATH));
158 manifestBuilder.withSource(TOSCA_DEFINITION_FILEPATH);
160 handler.addFile(SAMPLE_DEFINITION_IMPORT_FILE_PATH, "".getBytes());
161 manifestBuilder.withSource(SAMPLE_DEFINITION_IMPORT_FILE_PATH);
163 final String nonManoSource = "Artifacts/Deployment/non-mano/onap-cnf-helm-valid.yaml";
164 handler.addFile(nonManoSource, getResourceBytesOrFail("validation.files/empty.yaml"));
165 manifestBuilder.withNonManoArtifact(ONAP_CNF_HELM.getType(), nonManoSource);
167 manifestBuilder.withSource(TOSCA_MANIFEST_FILEPATH);
168 handler.addFile(TOSCA_MANIFEST_FILEPATH, manifestBuilder.build().getBytes(StandardCharsets.UTF_8));
170 final Validator validator = ValidatorFactory.getValidator(handler);
171 final ValidationResult validationResult = validator.validate(handler);
172 assertExpectedErrors("Manifest with non existent source files", validationResult.getErrors(), 1);