2 * Copyright © 2016-2018 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.openecomp.sdc.vendorsoftwareproduct.impl;
19 import static org.hamcrest.CoreMatchers.containsString;
20 import static org.hamcrest.MatcherAssert.assertThat;
21 import static org.hamcrest.Matchers.equalTo;
22 import static org.hamcrest.Matchers.hasItem;
23 import static org.hamcrest.Matchers.not;
24 import static org.junit.jupiter.api.Assertions.assertEquals;
25 import static org.junit.jupiter.api.Assertions.assertFalse;
26 import static org.junit.jupiter.api.Assertions.assertNotNull;
27 import static org.junit.jupiter.api.Assertions.assertNull;
28 import static org.junit.jupiter.api.Assertions.assertThrows;
29 import static org.mockito.ArgumentMatchers.any;
30 import static org.mockito.ArgumentMatchers.anyString;
31 import static org.mockito.ArgumentMatchers.nullable;
32 import static org.mockito.Mockito.doNothing;
33 import static org.mockito.Mockito.doReturn;
34 import static org.mockito.Mockito.doThrow;
35 import static org.mockito.Mockito.verify;
36 import static org.mockito.Mockito.when;
37 import static org.openecomp.sdc.tosca.csar.CSARConstants.MAIN_SERVICE_TEMPLATE_MF_FILE_NAME;
38 import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ORIG_PATH_FILE_NAME;
39 import static org.openecomp.sdc.tosca.csar.ToscaMetadataFileInfo.TOSCA_META_PATH_FILE_NAME;
41 import java.io.IOException;
42 import java.io.InputStream;
43 import java.util.ArrayList;
44 import java.util.Arrays;
45 import java.util.Collections;
46 import java.util.HashMap;
47 import java.util.List;
48 import java.util.Optional;
49 import org.apache.commons.io.IOUtils;
50 import org.junit.jupiter.api.AfterEach;
51 import org.junit.jupiter.api.BeforeEach;
52 import org.junit.jupiter.api.Test;
53 import org.mockito.ArgumentCaptor;
54 import org.mockito.Captor;
55 import org.mockito.InjectMocks;
56 import org.mockito.Mock;
57 import org.mockito.MockitoAnnotations;
58 import org.mockito.Spy;
59 import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
60 import org.onap.sdc.tosca.services.YamlUtil;
61 import org.openecomp.core.model.dao.EnrichedServiceModelDao;
62 import org.openecomp.core.model.dao.ServiceModelDao;
63 import org.openecomp.core.utilities.file.FileContentHandler;
64 import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity;
65 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
66 import org.openecomp.sdc.common.errors.CoreException;
67 import org.openecomp.sdc.common.errors.ErrorCategory;
68 import org.openecomp.sdc.common.errors.ErrorCode;
69 import org.openecomp.sdc.healing.api.HealingManager;
70 import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
71 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
72 import org.openecomp.sdc.vendorlicense.licenseartifacts.VendorLicenseArtifactsService;
73 import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManager;
74 import org.openecomp.sdc.vendorsoftwareproduct.ManualVspToscaManager;
75 import org.openecomp.sdc.vendorsoftwareproduct.MonitoringUploadsManager;
76 import org.openecomp.sdc.vendorsoftwareproduct.OrchestrationTemplateCandidateManager;
77 import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants;
78 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDependencyModelDao;
79 import org.openecomp.sdc.vendorsoftwareproduct.dao.DeploymentFlavorDao;
80 import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao;
81 import org.openecomp.sdc.vendorsoftwareproduct.dao.PackageInfoDao;
82 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao;
83 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.DeploymentFlavorEntity;
84 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData;
85 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.PackageInfo;
86 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
87 import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.InformationArtifactGenerator;
88 import org.openecomp.sdc.vendorsoftwareproduct.types.ValidationResponse;
89 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.DeploymentFlavor;
90 import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.SchemaTemplateInput;
91 import org.openecomp.sdc.versioning.ActionVersioningManager;
92 import org.openecomp.sdc.versioning.dao.types.Version;
93 import org.openecomp.sdc.versioning.dao.types.VersionStatus;
94 import org.openecomp.sdc.versioning.types.VersionInfo;
95 import org.openecomp.sdc.versioning.types.VersionableEntityAction;
97 class VendorSoftwareProductManagerImplTest {
99 private static final String VSP_ID = "vspId";
100 private static final Version VERSION01 = new Version("0, 1");
101 private static final Version VERSION10 = new Version("1, 0");
102 private static final String USER1 = "vspTestUser1";
103 private static final String USER2 = "vspTestUser2";
106 private ActionVersioningManager versioningManagerMock;
108 private OrchestrationTemplateDao orchestrationTemplateDataDaoMock;
110 private VendorLicenseFacade vendorLicenseFacadeMock;
112 private ServiceModelDao<ToscaServiceModel> serviceModelDaoMock;
114 private EnrichedServiceModelDao<ToscaServiceModel> enrichedServiceModelDaoMock;
116 private HealingManager healingManagerMock;
118 private VendorLicenseArtifactsService licenseArtifactsServiceMock;
120 private CompositionEntityDataManager compositionEntityDataManagerMock;
122 private InformationArtifactGenerator informationArtifactGeneratorMock;
124 private PackageInfoDao packageInfoDao;
126 private VendorSoftwareProductInfoDao vspInfoDaoMock;
128 private ManualVspToscaManager manualVspToscaManager;
130 private DeploymentFlavorDao deploymentFlavorDaoMock;
133 private VendorSoftwareProductManagerImpl vendorSoftwareProductManager;
135 private OrchestrationTemplateCandidateManager orchestrationTemplateCandidateManagerMock;
137 private ComponentDependencyModelDao componentDependencyModelDao;
138 private OrchestrationTemplateCandidateManager candidateManager;
139 private MonitoringUploadsManager monitoringUploadsManager;
142 private ArgumentCaptor<ActivityLogEntity> activityLogEntityArg;
146 MockitoAnnotations.openMocks(this);
151 vendorSoftwareProductManager = null;
155 void testCreatePackageEtsiVNF() throws IOException {
157 final InputStream metadataInput = getClass()
158 .getResourceAsStream("/vspmanager.csar/metadata/ValidETSItosca.meta");
159 final InputStream manifestInput = getClass()
160 .getResourceAsStream("/vspmanager.csar/manifest/ValidNonManoTosca.mf")) {
162 final FileContentHandler handler = new FileContentHandler();
163 final byte[] metadataInputBytes = IOUtils.toByteArray(metadataInput);
164 handler.addFile(TOSCA_META_PATH_FILE_NAME, metadataInputBytes);
165 handler.addFile(TOSCA_META_ORIG_PATH_FILE_NAME, metadataInputBytes);
166 handler.addFile(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME, IOUtils.toByteArray(manifestInput));
167 final ToscaServiceModel toscaMetadata = new ToscaServiceModel(handler, new HashMap<>(), "");
168 when(enrichedServiceModelDaoMock.getServiceModel(any(), any())).thenReturn(toscaMetadata);
169 final VspDetails vsp =
170 createVspDetails("0", new Version(), "Vsp_PNF", "Test-vsp-pnf", "vendorName", "esy", "icon",
171 "category", "subCategory", "123", null);
172 //want to avoid triggering populateVersionsForVlm method
173 vsp.setVlmVersion(null);
175 when(vspInfoDaoMock.get(any())).thenReturn(vsp);
176 when(licenseArtifactsServiceMock.createLicenseArtifacts(any(), any(), any(), any()))
177 .thenReturn(new FileContentHandler());
178 final PackageInfo packageInfo = vendorSoftwareProductManager.createPackage("0", new Version());
179 assertEquals(packageInfo.getResourceType(), ResourceTypeEnum.VF.name());
184 void testCreatePackageEtsiNoManifest() throws IOException {
185 try (InputStream metadataInput = getClass().getResourceAsStream("/vspmanager.csar/metadata/ValidETSItosca.meta")) {
186 FileContentHandler handler = new FileContentHandler();
187 handler.addFile(TOSCA_META_PATH_FILE_NAME, IOUtils.toByteArray(metadataInput));
188 ToscaServiceModel toscaMetadata = new ToscaServiceModel(handler, new HashMap<>(), "");
189 when(enrichedServiceModelDaoMock.getServiceModel(any(), any())).thenReturn(toscaMetadata);
191 createVspDetails("0", new Version(), "Vsp_PNF", "Test-vsp-pnf", "vendorName", "esy", "icon",
192 "category", "subCategory", "123", null);
193 //want to avoid triggering populateVersionsForVlm method
194 vsp.setVlmVersion(null);
196 when(vspInfoDaoMock.get(any())).thenReturn(vsp);
197 when(licenseArtifactsServiceMock.createLicenseArtifacts(any(), any(), any(), any())).thenReturn(new FileContentHandler());
198 assertThrows(IOException.class, () -> vendorSoftwareProductManager.createPackage("0", new Version()));
203 void testCreatePackageEtsiPnfWithoutNonMano() throws IOException {
205 final InputStream metadataInput = getClass()
206 .getResourceAsStream("/vspmanager.csar/metadata/ValidETSItosca.meta");
207 final InputStream manifestInput = getClass()
208 .getResourceAsStream("/vspmanager.csar/manifest/ValidNonManoToscaPnfWithoutNonMano.mf")) {
210 final FileContentHandler handler = new FileContentHandler();
211 final byte[] metadataInputBytes = IOUtils.toByteArray(metadataInput);
212 handler.addFile(TOSCA_META_ORIG_PATH_FILE_NAME, metadataInputBytes);
213 handler.addFile(TOSCA_META_PATH_FILE_NAME, metadataInputBytes);
214 handler.addFile(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME, IOUtils.toByteArray(manifestInput));
215 final ToscaServiceModel toscaMetadata = new ToscaServiceModel(handler, new HashMap<>(), "");
216 when(enrichedServiceModelDaoMock.getServiceModel(any(), any())).thenReturn(toscaMetadata);
217 final VspDetails vsp =
218 createVspDetails("0", new Version(), "Vsp_PNF", "Test-vsp-pnf", "vendorName", "esy", "icon",
219 "category", "subCategory", "123", null);
220 //want to avoid triggering populateVersionsForVlm method
221 vsp.setVlmVersion(null);
223 when(vspInfoDaoMock.get(any())).thenReturn(vsp);
224 when(licenseArtifactsServiceMock.createLicenseArtifacts(any(), any(), any(), any()))
225 .thenReturn(new FileContentHandler());
226 final PackageInfo packageInfo = vendorSoftwareProductManager.createPackage("0", new Version());
227 assertEquals(packageInfo.getResourceType(), ResourceTypeEnum.PNF.name());
232 void testCreatePackageEtsiPnfWithNonManoArtifacts() throws IOException {
234 final InputStream metadataInput = getClass()
235 .getResourceAsStream("/vspmanager.csar/metadata/ValidETSItosca.meta");
236 final InputStream manifestInput = getClass()
237 .getResourceAsStream("/vspmanager.csar/manifest/ValidNonManoToscaPNFWithNonMano.mf");
238 final InputStream mainServiceTemplateYamlFile = getClass()
239 .getResourceAsStream("/vspmanager.csar/descriptor/MainServiceTemplate.yaml")) {
241 final FileContentHandler handler = new FileContentHandler();
242 handler.addFile(TOSCA_META_ORIG_PATH_FILE_NAME, IOUtils.toByteArray(metadataInput));
243 handler.addFile(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME, IOUtils.toByteArray(manifestInput));
244 handler.addFile("Deployment/ANOTHER/authorized_keys", "".getBytes());
246 final ServiceTemplate mainServiceTemplate = new YamlUtil()
247 .yamlToObject(mainServiceTemplateYamlFile, ServiceTemplate.class);
248 final String mainServiceTemplateName = "MainServiceTemplate.yaml";
249 final HashMap<String, ServiceTemplate> serviceTemplateMap = new HashMap<>();
250 serviceTemplateMap.put(mainServiceTemplateName, mainServiceTemplate);
252 final ToscaServiceModel toscaMetadata = new ToscaServiceModel(handler, serviceTemplateMap,
253 mainServiceTemplateName);
254 when(enrichedServiceModelDaoMock.getServiceModel(any(), any())).thenReturn(toscaMetadata);
255 final VspDetails vsp =
256 createVspDetails("0", new Version(), "Vsp_PNF", "Test-vsp-pnf", "vendorName", "esy", "icon",
257 "category", "subCategory", "123", null);
258 //want to avoid triggering populateVersionsForVlm method
259 vsp.setVlmVersion(null);
261 when(vspInfoDaoMock.get(any())).thenReturn(vsp);
262 when(licenseArtifactsServiceMock.createLicenseArtifacts(any(), any(), any(), any()))
263 .thenReturn(new FileContentHandler());
264 final PackageInfo packageInfo = vendorSoftwareProductManager.createPackage("0", new Version());
265 assertThat("PackageInfo vendor release should be based on the manifest compatible_specification_versions highest version",
266 packageInfo.getVendorRelease(), equalTo("3.3.1"));
267 System.out.println(packageInfo.getVendorRelease());
268 assertThat("Package Info should contain resource type", packageInfo.getResourceType(),
269 equalTo(ResourceTypeEnum.PNF.name()));
270 assertThat("Should not contain moved artifact", toscaMetadata.getArtifactFiles().getFileList(),
271 not(hasItem("Deployment/ANOTHER/authorized_keys")));
272 assertThat("Should contain moved artifact", toscaMetadata.getArtifactFiles().getFileList(),
273 hasItem("Informational/OTHER/authorized_keys"));
274 final String serviceTemplateAsYaml = new YamlUtil().objectToYaml(toscaMetadata.getServiceTemplates());
275 assertThat("Descriptor should not contain reference to file", serviceTemplateAsYaml,
276 not(containsString("Artifacts/Deployment/ANOTHER/authorized_keys")));
277 assertThat("Descriptor should contain reference to file", serviceTemplateAsYaml,
278 containsString("Artifacts/Informational/OTHER/authorized_keys"));
285 .when(vendorSoftwareProductManager).getVspQuestionnaireSchema(nullable(SchemaTemplateInput.class));
287 VspDetails vspToCreate =
288 createVspDetails(null, null, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
289 "category", "subCategory", "123", null);
291 VspDetails vsp = vendorSoftwareProductManager.createVsp(vspToCreate);
294 vspToCreate.setId(vsp.getId());
295 vspToCreate.setVersion(VERSION01);
296 assertVspsEquals(vsp, vspToCreate);
300 void testUpdateWithExistingName_negative() {
301 VersionInfo versionInfo = new VersionInfo();
302 versionInfo.setActiveVersion(VERSION01);
303 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
304 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
305 VersionableEntityAction.Write);
307 VspDetails existingVsp =
308 createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-existingVsp", "vendorName", "vlm1Id",
309 "icon", "category", "subCategory", "123", null);
310 VspDetails updatedVsp =
311 createVspDetails(VSP_ID, VERSION01, "Vsp1_updated", "Test-existingVsp", "vendorName",
312 "vlm1Id", "icon", "category", "subCategory", "123", null);
313 doReturn(existingVsp).when(vspInfoDaoMock)
314 .get(any(VspDetails.class));
315 doThrow(new CoreException(
316 new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION).build()))
317 .when(vendorSoftwareProductManager)
318 .updateUniqueName(existingVsp.getName(), updatedVsp.getName());
320 assertThrows(CoreException.class, () -> vendorSoftwareProductManager.updateVsp(updatedVsp));
325 VersionInfo versionInfo = new VersionInfo();
326 versionInfo.setActiveVersion(VERSION01);
327 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
328 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
329 VersionableEntityAction.Write);
330 VspDetails existingVsp =
331 createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
333 "subCategory", "456", null);
334 VspDetails updatedVsp =
335 createVspDetails(VSP_ID, VERSION01, "VSP1_updated", null, "vendorName", "vlm1Id", "icon",
337 "subCategory", "456", null);
338 doReturn(existingVsp).when(vspInfoDaoMock)
339 .get(any(VspDetails.class));
340 doNothing().when(vendorSoftwareProductManager)
341 .updateUniqueName(existingVsp.getName(), updatedVsp.getName());
343 vendorSoftwareProductManager.updateVsp(updatedVsp);
345 verify(vspInfoDaoMock).update(updatedVsp);
349 void testUpdateRemoveFG() {
350 VersionInfo versionInfo = new VersionInfo();
351 versionInfo.setActiveVersion(VERSION01);
352 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
353 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
354 VersionableEntityAction.Write);
355 List<String> fgs = new ArrayList<>();
358 VspDetails existingVsp =
359 createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
361 "subCategory", "456", fgs);
363 List<String> updFgs = new ArrayList<>();
364 VspDetails updatedVsp =
365 createVspDetails(VSP_ID, VERSION01, "VSP1_updated", null, "vendorName", "vlm1Id", "icon",
367 "subCategory", "456", updFgs);
368 doReturn(existingVsp).when(vspInfoDaoMock)
369 .get(any(VspDetails.class));
370 doNothing().when(vendorSoftwareProductManager)
371 .updateUniqueName(existingVsp.getName(), updatedVsp.getName());
373 DeploymentFlavorEntity dfEntity = new DeploymentFlavorEntity(VSP_ID, VERSION01, "DF_ID");
374 DeploymentFlavor flavor = new DeploymentFlavor();
375 flavor.setFeatureGroupId("fg1");
376 dfEntity.setDeploymentFlavorCompositionData(flavor);
378 List<DeploymentFlavorEntity> dfList = new ArrayList<>();
379 dfList.add(dfEntity);
381 doReturn(dfList).when(deploymentFlavorDaoMock).list(any(DeploymentFlavorEntity.class));
383 vendorSoftwareProductManager.updateVsp(updatedVsp);
385 verify(deploymentFlavorDaoMock).update(dfEntity);
387 assertNull(dfEntity.getDeploymentFlavorCompositionData().getFeatureGroupId());
392 void testGetNonExistingVersion_negative() {
393 var notExistVersion = new Version("43, 8");
394 doReturn(null).when(vspInfoDaoMock).get(any(VspDetails.class));
395 assertThrows(CoreException.class, () -> vendorSoftwareProductManager.getVsp(VSP_ID, notExistVersion));
399 void testGetCheckedOutVersion() {
400 VersionInfo versionInfo = new VersionInfo();
401 versionInfo.setActiveVersion(VERSION01);
402 versionInfo.setStatus(VersionStatus.Locked);
403 versionInfo.setLockingUser(USER1);
404 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
405 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
406 VersionableEntityAction.Read);
408 VspDetails existingVsp =
409 createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
411 "subCategory", "456", null);
412 doReturn(existingVsp).when(vspInfoDaoMock).get(any(VspDetails.class));
414 VspDetails actualVsp =
415 vendorSoftwareProductManager.getVsp(VSP_ID, VERSION01);
417 assertVspsEquals(actualVsp, existingVsp);
421 void testGetOldVersion() {
422 VersionInfo versionInfo = new VersionInfo();
423 versionInfo.setActiveVersion(new Version("0, 2"));
424 versionInfo.setViewableVersions(Arrays.asList(VERSION01, new Version("0, 2")));
425 versionInfo.setStatus(VersionStatus.Locked);
426 versionInfo.setLockingUser(USER2);
427 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
428 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
429 VersionableEntityAction.Read);
431 VspDetails existingVsp =
432 createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
434 "subCategory", "456", null);
435 doReturn(existingVsp)
436 .when(vspInfoDaoMock).get(any(VspDetails.class));
438 VspDetails actualVsp =
439 vendorSoftwareProductManager.getVsp(VSP_ID, VERSION01);
441 VspDetails expectedVsp =
443 .get(new VspDetails(VSP_ID, VERSION01));
444 assertVspsEquals(actualVsp, expectedVsp);
448 void testCreatePackage() throws IOException {
449 VersionInfo versionInfo = new VersionInfo();
450 versionInfo.setActiveVersion(VERSION10);
451 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
452 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
453 VersionableEntityAction.Read);
455 doReturn(new ToscaServiceModel(new FileContentHandler(), new HashMap<>(), "")).when
456 (enrichedServiceModelDaoMock).getServiceModel(VSP_ID, VERSION10);
457 doNothing().when(vendorSoftwareProductManager).populateVersionsForVlm(anyString(), any(Version.class));
458 VspDetails vsp = new VspDetails(VSP_ID, VERSION10);
459 vsp.setVendorId("vendorId");
460 vsp.setVlmVersion(VERSION10);
461 vsp.setFeatureGroups(Arrays.asList("fg1", "fg2"));
462 vsp.setModelIdList(List.of("aModel"));
463 doReturn(vsp).when(vspInfoDaoMock).get(any(VspDetails.class));
465 doReturn(new FileContentHandler()).when(licenseArtifactsServiceMock)
466 .createLicenseArtifacts(VSP_ID, vsp.getVendorId(), VERSION10, vsp.getFeatureGroups()
469 PackageInfo packageInfo = vendorSoftwareProductManager.createPackage(VSP_ID, VERSION10);
470 assertNotNull(packageInfo.getVspId());
471 assertEquals("1.0", packageInfo.getVendorRelease());
475 void testValidateWithCandidateDataNotProcessed() throws IOException {
477 createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
478 "category", "subCategory", "licenseAgreementId",
479 Collections.singletonList("featureGroupId"));
480 vsp.setOnboardingMethod("NetworkPackage");
481 doReturn(vsp).when(vspInfoDaoMock).get(any(VspDetails.class));
483 OrchestrationTemplateCandidateData orchestrationTemplateCandidateData = new
484 OrchestrationTemplateCandidateData();
485 orchestrationTemplateCandidateData.setFileSuffix("zip");
486 orchestrationTemplateCandidateData.setFilesDataStructure("testdata");
487 orchestrationTemplateCandidateData.setValidationData("");
488 doReturn(Optional.of(orchestrationTemplateCandidateData))
489 .when(orchestrationTemplateCandidateManagerMock)
490 .getInfo(VSP_ID, VERSION01);
491 ValidationResponse validationResponse =
492 vendorSoftwareProductManager.validate(vsp);
493 assertNotNull(validationResponse);
494 assertFalse(validationResponse.isValid());
495 assertNotNull(validationResponse.getVspErrors());
496 assertEquals(1, validationResponse.getVspErrors().size());
501 void testValidateWithCandidateProcessedIsInvalid() throws IOException {
502 VspDetails vsp = createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-VSP", "vendorName",
503 "vl1Id", "icond", "category", "subcategory", "licenseAgreementId", Collections
504 .singletonList("featureGroupId"));
505 vsp.setOnboardingMethod("NetworkPackage");
506 doReturn(vsp).when(vspInfoDaoMock).get(any(VspDetails.class));
508 OrchestrationTemplateCandidateData orchestrationTemplateCandidateData = new
509 OrchestrationTemplateCandidateData();
510 orchestrationTemplateCandidateData.setFileSuffix("zip");
511 orchestrationTemplateCandidateData.setValidationData("Invalid processed data");
512 doReturn(Optional.of(orchestrationTemplateCandidateData))
513 .when(orchestrationTemplateCandidateManagerMock)
514 .getInfo(VSP_ID, VERSION01);
515 ValidationResponse validationResponse =
516 vendorSoftwareProductManager.validate(vsp);
517 assertNotNull(validationResponse);
518 assertFalse(validationResponse.isValid());
519 assertNotNull(validationResponse.getVspErrors());
520 assertEquals(1, validationResponse.getVspErrors().size());
523 private static VspDetails createVspDetails(String id, Version version, String name, String desc,
524 String vendorName, String vlm, String icon,
525 String category, String subCategory,
526 String licenseAgreement, List<String> featureGroups) {
527 VspDetails vspDetails = new VspDetails(id, version);
528 vspDetails.setName(name);
529 vspDetails.setDescription(desc);
530 vspDetails.setIcon(icon);
531 vspDetails.setCategory(category);
532 vspDetails.setSubCategory(subCategory);
533 vspDetails.setVendorName(vendorName);
534 vspDetails.setVendorId(vlm);
535 vspDetails.setVlmVersion(new Version("1, 0"));
536 vspDetails.setLicenseAgreement(licenseAgreement);
537 vspDetails.setFeatureGroups(featureGroups);
538 vspDetails.setOnboardingMethod("HEAT");
542 private static void assertVspsEquals(VspDetails actual, VspDetails expected) {
543 assertEquals(actual.getId(), expected.getId());
544 assertEquals(actual.getVersion(), expected.getVersion());
545 assertEquals(actual.getName(), expected.getName());
546 assertEquals(actual.getDescription(), expected.getDescription());
547 assertEquals(actual.getIcon(), expected.getIcon());
548 assertEquals(actual.getCategory(), expected.getCategory());
549 assertEquals(actual.getSubCategory(), expected.getSubCategory());
550 assertEquals(actual.getVendorName(), expected.getVendorName());
551 assertEquals(actual.getVendorId(), expected.getVendorId());
552 assertEquals(actual.getLicenseAgreement(), expected.getLicenseAgreement());
553 assertEquals(actual.getFeatureGroups(), expected.getFeatureGroups());