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.ToscaMetadataFileInfo.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 public class VendorSoftwareProductManagerImplTest {
96 private static final String VSP_ID = "vspId";
97 private static final Version VERSION01 = new Version("0, 1");
98 private static final Version VERSION10 = new Version("1, 0");
99 private static final String USER1 = "vspTestUser1";
100 private static final String USER2 = "vspTestUser2";
103 private ActionVersioningManager versioningManagerMock;
105 private OrchestrationTemplateDao orchestrationTemplateDataDaoMock;
107 private VendorLicenseFacade vendorLicenseFacadeMock;
109 private ServiceModelDao<ToscaServiceModel> serviceModelDaoMock;
111 private EnrichedServiceModelDao<ToscaServiceModel> enrichedServiceModelDaoMock;
113 private HealingManager healingManagerMock;
115 private VendorLicenseArtifactsService licenseArtifactsServiceMock;
117 private CompositionEntityDataManager compositionEntityDataManagerMock;
119 private InformationArtifactGenerator informationArtifactGeneratorMock;
121 private PackageInfoDao packageInfoDao;
123 private VendorSoftwareProductInfoDao vspInfoDaoMock;
125 private ManualVspToscaManager manualVspToscaManager;
127 private DeploymentFlavorDao deploymentFlavorDaoMock;
130 private VendorSoftwareProductManagerImpl vendorSoftwareProductManager;
132 private OrchestrationTemplateCandidateManager orchestrationTemplateCandidateManagerMock;
134 private ComponentDependencyModelDao componentDependencyModelDao;
135 private OrchestrationTemplateCandidateManager candidateManager;
136 private MonitoringUploadsManager monitoringUploadsManager;
139 private ArgumentCaptor<ActivityLogEntity> activityLogEntityArg;
142 public void setUp() {
143 MockitoAnnotations.initMocks(this);
147 public void tearDown() {
148 vendorSoftwareProductManager = null;
152 public void testCreatePackageEtsiVNF() throws IOException {
154 final InputStream metadataInput = getClass()
155 .getResourceAsStream("/vspmanager.csar/metadata/ValidETSItosca.meta");
156 final InputStream manifestInput = getClass()
157 .getResourceAsStream("/vspmanager.csar/manifest/ValidNonManoTosca.mf")) {
159 final FileContentHandler handler = new FileContentHandler();
160 final byte[] metadataInputBytes = IOUtils.toByteArray(metadataInput);
161 handler.addFile(TOSCA_META_PATH_FILE_NAME, metadataInputBytes);
162 handler.addFile(TOSCA_META_ORIG_PATH_FILE_NAME, metadataInputBytes);
163 handler.addFile(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME, IOUtils.toByteArray(manifestInput));
164 final ToscaServiceModel toscaMetadata = new ToscaServiceModel(handler, new HashMap<>(), "");
165 when(enrichedServiceModelDaoMock.getServiceModel(any(), any())).thenReturn(toscaMetadata);
166 final VspDetails vsp =
167 createVspDetails("0", new Version(), "Vsp_PNF", "Test-vsp-pnf", "vendorName", "esy", "icon",
168 "category", "subCategory", "123", null);
169 //want to avoid triggering populateVersionsForVlm method
170 vsp.setVlmVersion(null);
172 when(vspInfoDaoMock.get(any())).thenReturn(vsp);
173 when(licenseArtifactsServiceMock.createLicenseArtifacts(any(), any(), any(), any()))
174 .thenReturn(new FileContentHandler());
175 final PackageInfo packageInfo = vendorSoftwareProductManager.createPackage("0", new Version());
176 assertEquals(packageInfo.getResourceType(), ResourceTypeEnum.VF.name());
180 @Test(expected = IOException.class)
181 public void testCreatePackageEtsiNoManifest() throws IOException {
182 try(InputStream metadataInput = getClass().getResourceAsStream("/vspmanager.csar/metadata/ValidETSItosca.meta"))
184 FileContentHandler handler = new FileContentHandler();
185 handler.addFile(TOSCA_META_PATH_FILE_NAME, IOUtils.toByteArray(metadataInput));
186 ToscaServiceModel toscaMetadata = new ToscaServiceModel(handler, new HashMap<>(), "");
187 when(enrichedServiceModelDaoMock.getServiceModel(any(), any())).thenReturn(toscaMetadata );
189 createVspDetails("0", new Version(), "Vsp_PNF", "Test-vsp-pnf", "vendorName", "esy", "icon",
190 "category", "subCategory", "123", null);
191 //want to avoid triggering populateVersionsForVlm method
192 vsp.setVlmVersion(null);
194 when(vspInfoDaoMock.get(any())).thenReturn(vsp);
195 when(licenseArtifactsServiceMock.createLicenseArtifacts(any(),any(), any(), any())).thenReturn(new FileContentHandler());
196 vendorSoftwareProductManager.createPackage("0", new Version());
202 public void testCreatePackageEtsiPnfWithoutNonMano() throws IOException {
204 final InputStream metadataInput = getClass()
205 .getResourceAsStream("/vspmanager.csar/metadata/ValidETSItosca.meta");
206 final InputStream manifestInput = getClass()
207 .getResourceAsStream("/vspmanager.csar/manifest/ValidNonManoToscaPnfWithoutNonMano.mf")) {
209 final FileContentHandler handler = new FileContentHandler();
210 final byte[] metadataInputBytes = IOUtils.toByteArray(metadataInput);
211 handler.addFile(TOSCA_META_ORIG_PATH_FILE_NAME, metadataInputBytes);
212 handler.addFile(TOSCA_META_PATH_FILE_NAME, metadataInputBytes);
213 handler.addFile(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME, IOUtils.toByteArray(manifestInput));
214 final ToscaServiceModel toscaMetadata = new ToscaServiceModel(handler, new HashMap<>(), "");
215 when(enrichedServiceModelDaoMock.getServiceModel(any(), any())).thenReturn(toscaMetadata);
216 final VspDetails vsp =
217 createVspDetails("0", new Version(), "Vsp_PNF", "Test-vsp-pnf", "vendorName", "esy", "icon",
218 "category", "subCategory", "123", null);
219 //want to avoid triggering populateVersionsForVlm method
220 vsp.setVlmVersion(null);
222 when(vspInfoDaoMock.get(any())).thenReturn(vsp);
223 when(licenseArtifactsServiceMock.createLicenseArtifacts(any(), any(), any(), any()))
224 .thenReturn(new FileContentHandler());
225 final PackageInfo packageInfo = vendorSoftwareProductManager.createPackage("0", new Version());
226 assertEquals(packageInfo.getResourceType(), ResourceTypeEnum.PNF.name());
231 public void testCreatePackageEtsiPnfWithNonManoArtifacts() throws IOException {
233 final InputStream metadataInput = getClass()
234 .getResourceAsStream("/vspmanager.csar/metadata/ValidETSItosca.meta");
235 final InputStream manifestInput = getClass()
236 .getResourceAsStream("/vspmanager.csar/manifest/ValidNonManoToscaPNFWithNonMano.mf");
237 final InputStream mainServiceTemplateYamlFile = getClass()
238 .getResourceAsStream("/vspmanager.csar/descriptor/MainServiceTemplate.yaml")) {
240 final FileContentHandler handler = new FileContentHandler();
241 handler.addFile(TOSCA_META_ORIG_PATH_FILE_NAME, IOUtils.toByteArray(metadataInput));
242 handler.addFile(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME, IOUtils.toByteArray(manifestInput));
243 handler.addFile("Deployment/ANOTHER/authorized_keys", "".getBytes());
245 final ServiceTemplate mainServiceTemplate = new YamlUtil()
246 .yamlToObject(mainServiceTemplateYamlFile, ServiceTemplate.class);
247 final String mainServiceTemplateName = "MainServiceTemplate.yaml";
248 final HashMap<String, ServiceTemplate> serviceTemplateMap = new HashMap<>();
249 serviceTemplateMap.put(mainServiceTemplateName, mainServiceTemplate);
251 final ToscaServiceModel toscaMetadata = new ToscaServiceModel(handler, serviceTemplateMap,
252 mainServiceTemplateName);
253 when(enrichedServiceModelDaoMock.getServiceModel(any(), any())).thenReturn(toscaMetadata);
254 final VspDetails vsp =
255 createVspDetails("0", new Version(), "Vsp_PNF", "Test-vsp-pnf", "vendorName", "esy", "icon",
256 "category", "subCategory", "123", null);
257 //want to avoid triggering populateVersionsForVlm method
258 vsp.setVlmVersion(null);
260 when(vspInfoDaoMock.get(any())).thenReturn(vsp);
261 when(licenseArtifactsServiceMock.createLicenseArtifacts(any(), any(), any(), any()))
262 .thenReturn(new FileContentHandler());
263 final PackageInfo packageInfo = vendorSoftwareProductManager.createPackage("0", new Version());
264 assertThat("Package Info should contain resource type", packageInfo.getResourceType(),
265 equalTo(ResourceTypeEnum.PNF.name()));
266 assertThat("Should not contain moved artifact", toscaMetadata.getArtifactFiles().getFileList(),
267 not(hasItem("Deployment/ANOTHER/authorized_keys")));
268 assertThat("Should contain moved artifact", toscaMetadata.getArtifactFiles().getFileList(),
269 hasItem("Informational/OTHER/authorized_keys"));
270 final String serviceTemplateAsYaml = new YamlUtil().objectToYaml(toscaMetadata.getServiceTemplates());
271 assertThat("Descriptor should not contain reference to file", serviceTemplateAsYaml,
272 not(containsString("Artifacts/Deployment/ANOTHER/authorized_keys")));
273 assertThat("Descriptor should contain reference to file", serviceTemplateAsYaml,
274 containsString("Artifacts/Informational/OTHER/authorized_keys"));
279 public void testCreate() {
280 //doReturn(VERSION01).when(versioningManagerMock).create(anyObject(), anyObject(), anyObject());
282 .when(vendorSoftwareProductManager).getVspQuestionnaireSchema(anyObject());
284 VspDetails vspToCreate =
285 createVspDetails(null, null, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
286 "category", "subCategory", "123", null);
288 VspDetails vsp = vendorSoftwareProductManager.createVsp(vspToCreate);
290 Assert.assertNotNull(vsp);
291 vspToCreate.setId(vsp.getId());
292 vspToCreate.setVersion(VERSION01);
293 assertVspsEquals(vsp, vspToCreate);
296 @Test(expected = CoreException.class)
297 public void testUpdateWithExistingName_negative() {
298 VersionInfo versionInfo = new VersionInfo();
299 versionInfo.setActiveVersion(VERSION01);
300 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
301 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
302 VersionableEntityAction.Write);
304 VspDetails existingVsp =
305 createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-existingVsp", "vendorName", "vlm1Id",
306 "icon", "category", "subCategory", "123", null);
307 VspDetails updatedVsp =
308 createVspDetails(VSP_ID, VERSION01, "Vsp1_updated", "Test-existingVsp", "vendorName",
309 "vlm1Id", "icon", "category", "subCategory", "123", null);
310 doReturn(existingVsp).when(vspInfoDaoMock)
311 .get(any(VspDetails.class));
312 doThrow(new CoreException(
313 new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION).build()))
314 .when(vendorSoftwareProductManager)
315 .updateUniqueName(existingVsp.getName(), updatedVsp.getName());
317 vendorSoftwareProductManager.updateVsp(updatedVsp);
321 public void testUpdate() {
322 VersionInfo versionInfo = new VersionInfo();
323 versionInfo.setActiveVersion(VERSION01);
324 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
325 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
326 VersionableEntityAction.Write);
327 VspDetails existingVsp =
328 createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
330 "subCategory", "456", null);
331 VspDetails updatedVsp =
332 createVspDetails(VSP_ID, VERSION01, "VSP1_updated", null, "vendorName", "vlm1Id", "icon",
334 "subCategory", "456", null);
335 doReturn(existingVsp).when(vspInfoDaoMock)
336 .get(any(VspDetails.class));
337 doNothing().when(vendorSoftwareProductManager)
338 .updateUniqueName(existingVsp.getName(), updatedVsp.getName());
340 vendorSoftwareProductManager.updateVsp(updatedVsp);
342 verify(vspInfoDaoMock).update(updatedVsp);
346 public void testUpdateRemoveFG() {
347 VersionInfo versionInfo = new VersionInfo();
348 versionInfo.setActiveVersion(VERSION01);
349 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
350 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
351 VersionableEntityAction.Write);
352 List<String> fgs = new ArrayList<>();
355 VspDetails existingVsp =
356 createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
358 "subCategory", "456", fgs);
360 List<String> updFgs = new ArrayList<>();
362 VspDetails updatedVsp =
363 createVspDetails(VSP_ID, VERSION01, "VSP1_updated", null, "vendorName", "vlm1Id", "icon",
365 "subCategory", "456", updFgs);
366 doReturn(existingVsp).when(vspInfoDaoMock)
367 .get(any(VspDetails.class));
368 doNothing().when(vendorSoftwareProductManager)
369 .updateUniqueName(existingVsp.getName(), updatedVsp.getName());
371 DeploymentFlavorEntity dfEntity = new DeploymentFlavorEntity(VSP_ID, VERSION01, "DF_ID");
372 DeploymentFlavor flavor = new DeploymentFlavor();
373 flavor.setFeatureGroupId("fg1");
374 dfEntity.setDeploymentFlavorCompositionData(flavor);
376 List<DeploymentFlavorEntity> dfList = new ArrayList<>();
377 dfList.add(dfEntity);
379 doReturn(dfList).when(deploymentFlavorDaoMock).list(anyObject());
381 vendorSoftwareProductManager.updateVsp(updatedVsp);
383 verify(deploymentFlavorDaoMock).update(dfEntity);
385 Assert.assertNull(dfEntity.getDeploymentFlavorCompositionData().getFeatureGroupId());
389 @Test(expected = CoreException.class)
390 public void testGetNonExistingVersion_negative() {
391 Version notExistversion = new Version("43, 8");
392 doReturn(null).when(vspInfoDaoMock).get(any(VspDetails.class));
393 vendorSoftwareProductManager.getVsp(VSP_ID, notExistversion);
397 public void testGetCheckedOutVersion() {
398 VersionInfo versionInfo = new VersionInfo();
399 versionInfo.setActiveVersion(VERSION01);
400 versionInfo.setStatus(VersionStatus.Locked);
401 versionInfo.setLockingUser(USER1);
402 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
403 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
404 VersionableEntityAction.Read);
406 VspDetails existingVsp =
407 createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
409 "subCategory", "456", null);
410 doReturn(existingVsp).when(vspInfoDaoMock).get(any(VspDetails.class));
412 VspDetails actualVsp =
413 vendorSoftwareProductManager.getVsp(VSP_ID, VERSION01);
415 assertVspsEquals(actualVsp, existingVsp);
419 public void testGetOldVersion() {
420 VersionInfo versionInfo = new VersionInfo();
421 versionInfo.setActiveVersion(new Version("0, 2"));
422 versionInfo.setViewableVersions(Arrays.asList(VERSION01, new Version("0, 2")));
423 versionInfo.setStatus(VersionStatus.Locked);
424 versionInfo.setLockingUser(USER2);
425 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
426 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
427 VersionableEntityAction.Read);
429 VspDetails existingVsp =
430 createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
432 "subCategory", "456", null);
433 doReturn(existingVsp)
434 .when(vspInfoDaoMock).get(any(VspDetails.class));
436 VspDetails actualVsp =
437 vendorSoftwareProductManager.getVsp(VSP_ID, VERSION01);
439 VspDetails expectedVsp =
441 .get(new VspDetails(VSP_ID, VERSION01));
442 assertVspsEquals(actualVsp, expectedVsp);
446 public void testCreatePackage() throws IOException {
447 /*VspDetails vspDetailsMock = new VspDetails("vspId", new Version(1, 0));
448 doReturn(vspDetailsMock).when(vspInfoDaoMock).get(anyObject());*/
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(anyObject(), anyObject());
458 VspDetails vsp = new VspDetails(VSP_ID, VERSION10);
459 vsp.setVendorId("vendorId");
460 vsp.setVlmVersion(VERSION10);
461 vsp.setFeatureGroups(Arrays.asList("fg1", "fg2"));
462 doReturn(vsp).when(vspInfoDaoMock).get(any(VspDetails.class));
464 doReturn(new FileContentHandler()).when(licenseArtifactsServiceMock)
465 .createLicenseArtifacts(VSP_ID, vsp.getVendorId(), VERSION10, vsp.getFeatureGroups()
468 PackageInfo packageInfo = vendorSoftwareProductManager.createPackage(VSP_ID, VERSION10);
469 Assert.assertNotNull(packageInfo.getVspId());
473 public void testValidateWithCandidateDataNotProcessed() throws IOException {
475 createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
476 "category", "subCategory", "licenseAgreementId",
477 Collections.singletonList("featureGroupId"));
478 vsp.setOnboardingMethod("NetworkPackage");
479 doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
481 OrchestrationTemplateCandidateData orchestrationTemplateCandidateData = new
482 OrchestrationTemplateCandidateData();
483 orchestrationTemplateCandidateData.setFileSuffix("zip");
484 orchestrationTemplateCandidateData.setFilesDataStructure("testdata");
485 orchestrationTemplateCandidateData.setValidationData("");
486 doReturn(Optional.of(orchestrationTemplateCandidateData))
487 .when(orchestrationTemplateCandidateManagerMock)
488 .getInfo(VSP_ID, VERSION01);
489 ValidationResponse validationResponse =
490 vendorSoftwareProductManager.validate(vsp);
491 Assert.assertNotNull(validationResponse);
492 Assert.assertFalse(validationResponse.isValid());
493 Assert.assertNotNull(validationResponse.getVspErrors());
494 Assert.assertEquals(1, validationResponse.getVspErrors().size());
499 public void testValidateWithCandidateProcessedIsInvalid() throws IOException {
500 VspDetails vsp = createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-VSP", "vendorName",
501 "vl1Id", "icond", "category", "subcategory", "licenseAgreementId", Collections
502 .singletonList("featureGroupId"));
503 vsp.setOnboardingMethod("NetworkPackage");
504 doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
506 OrchestrationTemplateCandidateData orchestrationTemplateCandidateData = new
507 OrchestrationTemplateCandidateData();
508 orchestrationTemplateCandidateData.setFileSuffix("zip");
509 orchestrationTemplateCandidateData.setValidationData("Invalid processed data");
510 doReturn(Optional.of(orchestrationTemplateCandidateData))
511 .when(orchestrationTemplateCandidateManagerMock)
512 .getInfo(VSP_ID, VERSION01);
513 ValidationResponse validationResponse =
514 vendorSoftwareProductManager.validate(vsp);
515 Assert.assertNotNull(validationResponse);
516 Assert.assertFalse(validationResponse.isValid());
517 Assert.assertNotNull(validationResponse.getVspErrors());
518 Assert.assertEquals(1, validationResponse.getVspErrors().size());
521 private static VspDetails createVspDetails(String id, Version version, String name, String desc,
522 String vendorName, String vlm, String icon,
523 String category, String subCategory,
524 String licenseAgreement, List<String> featureGroups) {
525 VspDetails vspDetails = new VspDetails(id, version);
526 vspDetails.setName(name);
527 vspDetails.setDescription(desc);
528 vspDetails.setIcon(icon);
529 vspDetails.setCategory(category);
530 vspDetails.setSubCategory(subCategory);
531 vspDetails.setVendorName(vendorName);
532 vspDetails.setVendorId(vlm);
533 vspDetails.setVlmVersion(new Version("1, 0"));
534 vspDetails.setLicenseAgreement(licenseAgreement);
535 vspDetails.setFeatureGroups(featureGroups);
536 vspDetails.setOnboardingMethod("HEAT");
540 private static void assertVspsEquals(VspDetails actual, VspDetails expected) {
541 Assert.assertEquals(actual.getId(), expected.getId());
542 Assert.assertEquals(actual.getVersion(), expected.getVersion());
543 Assert.assertEquals(actual.getName(), expected.getName());
544 Assert.assertEquals(actual.getDescription(), expected.getDescription());
545 Assert.assertEquals(actual.getIcon(), expected.getIcon());
546 Assert.assertEquals(actual.getCategory(), expected.getCategory());
547 Assert.assertEquals(actual.getSubCategory(), expected.getSubCategory());
548 Assert.assertEquals(actual.getVendorName(), expected.getVendorName());
549 Assert.assertEquals(actual.getVendorId(), expected.getVendorId());
550 Assert.assertEquals(actual.getLicenseAgreement(), expected.getLicenseAgreement());
551 Assert.assertEquals(actual.getFeatureGroups(), expected.getFeatureGroups());