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.Matchers.equalTo;
21 import static org.hamcrest.Matchers.hasItem;
22 import static org.hamcrest.Matchers.not;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertThat;
25 import static org.junit.Assert.fail;
26 import static org.mockito.ArgumentMatchers.any;
27 import static org.mockito.ArgumentMatchers.anyObject;
28 import static org.mockito.Mockito.doNothing;
29 import static org.mockito.Mockito.doReturn;
30 import static org.mockito.Mockito.doThrow;
31 import static org.mockito.Mockito.verify;
32 import static org.mockito.Mockito.when;
33 import static org.openecomp.sdc.tosca.csar.CSARConstants.MAIN_SERVICE_TEMPLATE_MF_FILE_NAME;
34 import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_ORIG_PATH_FILE_NAME;
35 import static org.openecomp.sdc.tosca.csar.ToscaMetaEntry.TOSCA_META_PATH_FILE_NAME;
37 import java.io.IOException;
38 import java.io.InputStream;
39 import java.util.ArrayList;
40 import java.util.Arrays;
41 import java.util.Collections;
42 import java.util.HashMap;
43 import java.util.List;
44 import java.util.Optional;
45 import org.apache.commons.io.IOUtils;
46 import org.junit.After;
47 import org.junit.Assert;
48 import org.junit.Before;
49 import org.junit.Test;
50 import org.mockito.ArgumentCaptor;
51 import org.mockito.Captor;
52 import org.mockito.InjectMocks;
53 import org.mockito.Mock;
54 import org.mockito.MockitoAnnotations;
55 import org.mockito.Spy;
56 import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
57 import org.onap.sdc.tosca.services.YamlUtil;
58 import org.openecomp.core.model.dao.EnrichedServiceModelDao;
59 import org.openecomp.core.model.dao.ServiceModelDao;
60 import org.openecomp.core.model.types.ServiceElement;
61 import org.openecomp.core.utilities.file.FileContentHandler;
62 import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity;
63 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
64 import org.openecomp.sdc.common.errors.CoreException;
65 import org.openecomp.sdc.common.errors.ErrorCategory;
66 import org.openecomp.sdc.common.errors.ErrorCode;
67 import org.openecomp.sdc.healing.api.HealingManager;
68 import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
69 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
70 import org.openecomp.sdc.vendorlicense.licenseartifacts.VendorLicenseArtifactsService;
71 import org.openecomp.sdc.vendorsoftwareproduct.CompositionEntityDataManager;
72 import org.openecomp.sdc.vendorsoftwareproduct.ManualVspToscaManager;
73 import org.openecomp.sdc.vendorsoftwareproduct.MonitoringUploadsManager;
74 import org.openecomp.sdc.vendorsoftwareproduct.OrchestrationTemplateCandidateManager;
75 import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants;
76 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDependencyModelDao;
77 import org.openecomp.sdc.vendorsoftwareproduct.dao.DeploymentFlavorDao;
78 import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao;
79 import org.openecomp.sdc.vendorsoftwareproduct.dao.PackageInfoDao;
80 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao;
81 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.DeploymentFlavorEntity;
82 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData;
83 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.PackageInfo;
84 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
85 import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.InformationArtifactGenerator;
86 import org.openecomp.sdc.vendorsoftwareproduct.types.ValidationResponse;
87 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.DeploymentFlavor;
88 import org.openecomp.sdc.versioning.ActionVersioningManager;
89 import org.openecomp.sdc.versioning.dao.types.Version;
90 import org.openecomp.sdc.versioning.dao.types.VersionStatus;
91 import org.openecomp.sdc.versioning.types.VersionInfo;
92 import org.openecomp.sdc.versioning.types.VersionableEntityAction;
94 //import static org.openecomp.sdc.tosca.csar.CSARConstants.TOSCA_META_PATH_FILE_NAME;
97 public 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, ServiceElement> serviceModelDaoMock;
114 private EnrichedServiceModelDao<ToscaServiceModel, ServiceElement> 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;
145 public void setUp() {
146 MockitoAnnotations.initMocks(this);
150 public void tearDown() {
151 vendorSoftwareProductManager = null;
155 public 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.getName(), 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());
183 @Test(expected = IOException.class)
184 public void testCreatePackageEtsiNoManifest() throws IOException {
185 try(InputStream metadataInput = getClass().getResourceAsStream("/vspmanager.csar/metadata/ValidETSItosca.meta"))
187 FileContentHandler handler = new FileContentHandler();
188 handler.addFile(TOSCA_META_PATH_FILE_NAME.getName(), IOUtils.toByteArray(metadataInput));
189 ToscaServiceModel toscaMetadata = new ToscaServiceModel(handler, new HashMap<>(), "");
190 when(enrichedServiceModelDaoMock.getServiceModel(any(), any())).thenReturn(toscaMetadata );
192 createVspDetails("0", new Version(), "Vsp_PNF", "Test-vsp-pnf", "vendorName", "esy", "icon",
193 "category", "subCategory", "123", null);
194 //want to avoid triggering populateVersionsForVlm method
195 vsp.setVlmVersion(null);
197 when(vspInfoDaoMock.get(any())).thenReturn(vsp);
198 when(licenseArtifactsServiceMock.createLicenseArtifacts(any(),any(), any(), any())).thenReturn(new FileContentHandler());
199 vendorSoftwareProductManager.createPackage("0", new Version());
205 public void testCreatePackageEtsiPnfWithoutNonMano() throws IOException {
207 final InputStream metadataInput = getClass()
208 .getResourceAsStream("/vspmanager.csar/metadata/ValidETSItosca.meta");
209 final InputStream manifestInput = getClass()
210 .getResourceAsStream("/vspmanager.csar/manifest/ValidNonManoToscaPnfWithoutNonMano.mf")) {
212 final FileContentHandler handler = new FileContentHandler();
213 final byte[] metadataInputBytes = IOUtils.toByteArray(metadataInput);
214 handler.addFile(TOSCA_META_ORIG_PATH_FILE_NAME, metadataInputBytes);
215 handler.addFile(TOSCA_META_PATH_FILE_NAME.getName(), metadataInputBytes);
216 handler.addFile(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME, IOUtils.toByteArray(manifestInput));
217 final ToscaServiceModel toscaMetadata = new ToscaServiceModel(handler, new HashMap<>(), "");
218 when(enrichedServiceModelDaoMock.getServiceModel(any(), any())).thenReturn(toscaMetadata);
219 final VspDetails vsp =
220 createVspDetails("0", new Version(), "Vsp_PNF", "Test-vsp-pnf", "vendorName", "esy", "icon",
221 "category", "subCategory", "123", null);
222 //want to avoid triggering populateVersionsForVlm method
223 vsp.setVlmVersion(null);
225 when(vspInfoDaoMock.get(any())).thenReturn(vsp);
226 when(licenseArtifactsServiceMock.createLicenseArtifacts(any(), any(), any(), any()))
227 .thenReturn(new FileContentHandler());
228 final PackageInfo packageInfo = vendorSoftwareProductManager.createPackage("0", new Version());
229 assertEquals(packageInfo.getResourceType(), ResourceTypeEnum.PNF.name());
234 public void testCreatePackageEtsiPnfWithNonManoArtifacts() throws IOException {
236 final InputStream metadataInput = getClass()
237 .getResourceAsStream("/vspmanager.csar/metadata/ValidETSItosca.meta");
238 final InputStream manifestInput = getClass()
239 .getResourceAsStream("/vspmanager.csar/manifest/ValidNonManoToscaPNFWithNonMano.mf");
240 final InputStream mainServiceTemplateYamlFile = getClass()
241 .getResourceAsStream("/vspmanager.csar/descriptor/MainServiceTemplate.yaml")) {
243 final FileContentHandler handler = new FileContentHandler();
244 handler.addFile(TOSCA_META_ORIG_PATH_FILE_NAME, IOUtils.toByteArray(metadataInput));
245 handler.addFile(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME, IOUtils.toByteArray(manifestInput));
246 handler.addFile("Deployment/ANOTHER/authorized_keys", "".getBytes());
248 final ServiceTemplate mainServiceTemplate = new YamlUtil()
249 .yamlToObject(mainServiceTemplateYamlFile, ServiceTemplate.class);
250 final String mainServiceTemplateName = "MainServiceTemplate.yaml";
251 final HashMap<String, ServiceTemplate> serviceTemplateMap = new HashMap<>();
252 serviceTemplateMap.put(mainServiceTemplateName, mainServiceTemplate);
254 final ToscaServiceModel toscaMetadata = new ToscaServiceModel(handler, serviceTemplateMap,
255 mainServiceTemplateName);
256 when(enrichedServiceModelDaoMock.getServiceModel(any(), any())).thenReturn(toscaMetadata);
257 final VspDetails vsp =
258 createVspDetails("0", new Version(), "Vsp_PNF", "Test-vsp-pnf", "vendorName", "esy", "icon",
259 "category", "subCategory", "123", null);
260 //want to avoid triggering populateVersionsForVlm method
261 vsp.setVlmVersion(null);
263 when(vspInfoDaoMock.get(any())).thenReturn(vsp);
264 when(licenseArtifactsServiceMock.createLicenseArtifacts(any(), any(), any(), any()))
265 .thenReturn(new FileContentHandler());
266 final PackageInfo packageInfo = vendorSoftwareProductManager.createPackage("0", new Version());
267 assertThat("Package Info should contain resource type", packageInfo.getResourceType(),
268 equalTo(ResourceTypeEnum.PNF.name()));
269 assertThat("Should not contain moved artifact", toscaMetadata.getArtifactFiles().getFileList(),
270 not(hasItem("Deployment/ANOTHER/authorized_keys")));
271 assertThat("Should contain moved artifact", toscaMetadata.getArtifactFiles().getFileList(),
272 hasItem("Informational/OTHER/authorized_keys"));
273 final String serviceTemplateAsYaml = new YamlUtil().objectToYaml(toscaMetadata.getServiceTemplates());
274 assertThat("Descriptor should not contain reference to file", serviceTemplateAsYaml,
275 not(containsString("Artifacts/Deployment/ANOTHER/authorized_keys")));
276 assertThat("Descriptor should contain reference to file", serviceTemplateAsYaml,
277 containsString("Artifacts/Informational/OTHER/authorized_keys"));
282 public void testCreate() {
283 //doReturn(VERSION01).when(versioningManagerMock).create(anyObject(), anyObject(), anyObject());
285 .when(vendorSoftwareProductManager).getVspQuestionnaireSchema(anyObject());
287 VspDetails vspToCreate =
288 createVspDetails(null, null, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
289 "category", "subCategory", "123", null);
291 VspDetails vsp = vendorSoftwareProductManager.createVsp(vspToCreate);
293 Assert.assertNotNull(vsp);
294 vspToCreate.setId(vsp.getId());
295 vspToCreate.setVersion(VERSION01);
296 assertVspsEquals(vsp, vspToCreate);
299 @Test(expected = CoreException.class)
300 public 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 vendorSoftwareProductManager.updateVsp(updatedVsp);
324 public void testUpdate() {
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 public 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<>();
365 VspDetails updatedVsp =
366 createVspDetails(VSP_ID, VERSION01, "VSP1_updated", null, "vendorName", "vlm1Id", "icon",
368 "subCategory", "456", updFgs);
369 doReturn(existingVsp).when(vspInfoDaoMock)
370 .get(any(VspDetails.class));
371 doNothing().when(vendorSoftwareProductManager)
372 .updateUniqueName(existingVsp.getName(), updatedVsp.getName());
374 DeploymentFlavorEntity dfEntity = new DeploymentFlavorEntity(VSP_ID, VERSION01, "DF_ID");
375 DeploymentFlavor flavor = new DeploymentFlavor();
376 flavor.setFeatureGroupId("fg1");
377 dfEntity.setDeploymentFlavorCompositionData(flavor);
379 List<DeploymentFlavorEntity> dfList = new ArrayList<>();
380 dfList.add(dfEntity);
382 doReturn(dfList).when(deploymentFlavorDaoMock).list(anyObject());
384 vendorSoftwareProductManager.updateVsp(updatedVsp);
386 verify(deploymentFlavorDaoMock).update(dfEntity);
388 Assert.assertNull(dfEntity.getDeploymentFlavorCompositionData().getFeatureGroupId());
392 @Test(expected = CoreException.class)
393 public void testGetNonExistingVersion_negative() {
394 Version notExistversion = new Version("43, 8");
395 doReturn(null).when(vspInfoDaoMock).get(any(VspDetails.class));
396 vendorSoftwareProductManager.getVsp(VSP_ID, notExistversion);
400 public void testGetCheckedOutVersion() {
401 VersionInfo versionInfo = new VersionInfo();
402 versionInfo.setActiveVersion(VERSION01);
403 versionInfo.setStatus(VersionStatus.Locked);
404 versionInfo.setLockingUser(USER1);
405 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
406 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
407 VersionableEntityAction.Read);
409 VspDetails existingVsp =
410 createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
412 "subCategory", "456", null);
413 doReturn(existingVsp).when(vspInfoDaoMock).get(any(VspDetails.class));
415 VspDetails actualVsp =
416 vendorSoftwareProductManager.getVsp(VSP_ID, VERSION01);
418 assertVspsEquals(actualVsp, existingVsp);
422 public void testGetOldVersion() {
423 VersionInfo versionInfo = new VersionInfo();
424 versionInfo.setActiveVersion(new Version("0, 2"));
425 versionInfo.setViewableVersions(Arrays.asList(VERSION01, new Version("0, 2")));
426 versionInfo.setStatus(VersionStatus.Locked);
427 versionInfo.setLockingUser(USER2);
428 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
429 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
430 VersionableEntityAction.Read);
432 VspDetails existingVsp =
433 createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
435 "subCategory", "456", null);
436 doReturn(existingVsp)
437 .when(vspInfoDaoMock).get(any(VspDetails.class));
439 VspDetails actualVsp =
440 vendorSoftwareProductManager.getVsp(VSP_ID, VERSION01);
442 VspDetails expectedVsp =
444 .get(new VspDetails(VSP_ID, VERSION01));
445 assertVspsEquals(actualVsp, expectedVsp);
449 public void testCreatePackage() throws IOException {
450 /*VspDetails vspDetailsMock = new VspDetails("vspId", new Version(1, 0));
451 doReturn(vspDetailsMock).when(vspInfoDaoMock).get(anyObject());*/
452 VersionInfo versionInfo = new VersionInfo();
453 versionInfo.setActiveVersion(VERSION10);
454 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
455 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
456 VersionableEntityAction.Read);
458 doReturn(new ToscaServiceModel(new FileContentHandler(), new HashMap<>(), "")).when
459 (enrichedServiceModelDaoMock).getServiceModel(VSP_ID, VERSION10);
460 doNothing().when(vendorSoftwareProductManager).populateVersionsForVlm(anyObject(), anyObject());
461 VspDetails vsp = new VspDetails(VSP_ID, VERSION10);
462 vsp.setVendorId("vendorId");
463 vsp.setVlmVersion(VERSION10);
464 vsp.setFeatureGroups(Arrays.asList("fg1", "fg2"));
465 doReturn(vsp).when(vspInfoDaoMock).get(any(VspDetails.class));
467 doReturn(new FileContentHandler()).when(licenseArtifactsServiceMock)
468 .createLicenseArtifacts(VSP_ID, vsp.getVendorId(), VERSION10, vsp.getFeatureGroups()
471 PackageInfo packageInfo = vendorSoftwareProductManager.createPackage(VSP_ID, VERSION10);
472 Assert.assertNotNull(packageInfo.getVspId());
476 public void testValidateWithCandidateDataNotProcessed() throws IOException {
478 createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
479 "category", "subCategory", "licenseAgreementId",
480 Collections.singletonList("featureGroupId"));
481 vsp.setOnboardingMethod("NetworkPackage");
482 doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
484 OrchestrationTemplateCandidateData orchestrationTemplateCandidateData = new
485 OrchestrationTemplateCandidateData();
486 orchestrationTemplateCandidateData.setFileSuffix("zip");
487 orchestrationTemplateCandidateData.setFilesDataStructure("testdata");
488 orchestrationTemplateCandidateData.setValidationData("");
489 doReturn(Optional.of(orchestrationTemplateCandidateData))
490 .when(orchestrationTemplateCandidateManagerMock)
491 .getInfo(VSP_ID, VERSION01);
492 ValidationResponse validationResponse =
493 vendorSoftwareProductManager.validate(vsp);
494 Assert.assertNotNull(validationResponse);
495 Assert.assertFalse(validationResponse.isValid());
496 Assert.assertNotNull(validationResponse.getVspErrors());
497 Assert.assertEquals(1, validationResponse.getVspErrors().size());
502 public void testValidateWithCandidateProcessedIsInvalid() throws IOException {
503 VspDetails vsp = createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-VSP", "vendorName",
504 "vl1Id", "icond", "category", "subcategory", "licenseAgreementId", Collections
505 .singletonList("featureGroupId"));
506 vsp.setOnboardingMethod("NetworkPackage");
507 doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
509 OrchestrationTemplateCandidateData orchestrationTemplateCandidateData = new
510 OrchestrationTemplateCandidateData();
511 orchestrationTemplateCandidateData.setFileSuffix("zip");
512 orchestrationTemplateCandidateData.setValidationData("Invalid processed data");
513 doReturn(Optional.of(orchestrationTemplateCandidateData))
514 .when(orchestrationTemplateCandidateManagerMock)
515 .getInfo(VSP_ID, VERSION01);
516 ValidationResponse validationResponse =
517 vendorSoftwareProductManager.validate(vsp);
518 Assert.assertNotNull(validationResponse);
519 Assert.assertFalse(validationResponse.isValid());
520 Assert.assertNotNull(validationResponse.getVspErrors());
521 Assert.assertEquals(1, validationResponse.getVspErrors().size());
524 private static VspDetails createVspDetails(String id, Version version, String name, String desc,
525 String vendorName, String vlm, String icon,
526 String category, String subCategory,
527 String licenseAgreement, List<String> featureGroups) {
528 VspDetails vspDetails = new VspDetails(id, version);
529 vspDetails.setName(name);
530 vspDetails.setDescription(desc);
531 vspDetails.setIcon(icon);
532 vspDetails.setCategory(category);
533 vspDetails.setSubCategory(subCategory);
534 vspDetails.setVendorName(vendorName);
535 vspDetails.setVendorId(vlm);
536 vspDetails.setVlmVersion(new Version("1, 0"));
537 vspDetails.setLicenseAgreement(licenseAgreement);
538 vspDetails.setFeatureGroups(featureGroups);
539 vspDetails.setOnboardingMethod("HEAT");
543 private static void assertVspsEquals(VspDetails actual, VspDetails expected) {
544 Assert.assertEquals(actual.getId(), expected.getId());
545 Assert.assertEquals(actual.getVersion(), expected.getVersion());
546 Assert.assertEquals(actual.getName(), expected.getName());
547 Assert.assertEquals(actual.getDescription(), expected.getDescription());
548 Assert.assertEquals(actual.getIcon(), expected.getIcon());
549 Assert.assertEquals(actual.getCategory(), expected.getCategory());
550 Assert.assertEquals(actual.getSubCategory(), expected.getSubCategory());
551 Assert.assertEquals(actual.getVendorName(), expected.getVendorName());
552 Assert.assertEquals(actual.getVendorId(), expected.getVendorId());
553 Assert.assertEquals(actual.getLicenseAgreement(), expected.getLicenseAgreement());
554 Assert.assertEquals(actual.getFeatureGroups(), expected.getFeatureGroups());