fb1ab0306eff65df902883c7fff8e1289a96005f
[sdc.git] /
1 /*
2  * Copyright © 2016-2018 European Support Limited
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.openecomp.sdc.vendorsoftwareproduct.impl;
18
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.CSARConstants.TOSCA_META_PATH_FILE_NAME;
36
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;
93
94
95 public class VendorSoftwareProductManagerImplTest {
96
97   private static final String VSP_ID = "vspId";
98   private static final Version VERSION01 = new Version("0, 1");
99   private static final Version VERSION10 = new Version("1, 0");
100   private static final String USER1 = "vspTestUser1";
101   private static final String USER2 = "vspTestUser2";
102
103   @Mock
104   private ActionVersioningManager versioningManagerMock;
105   @Mock
106   private OrchestrationTemplateDao orchestrationTemplateDataDaoMock;
107   @Mock
108   private VendorLicenseFacade vendorLicenseFacadeMock;
109   @Mock
110   private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDaoMock;
111   @Mock
112   private EnrichedServiceModelDao<ToscaServiceModel, ServiceElement> enrichedServiceModelDaoMock;
113   @Mock
114   private HealingManager healingManagerMock;
115   @Mock
116   private VendorLicenseArtifactsService licenseArtifactsServiceMock;
117   @Mock
118   private CompositionEntityDataManager compositionEntityDataManagerMock;
119   @Mock
120   private InformationArtifactGenerator informationArtifactGeneratorMock;
121   @Mock
122   private PackageInfoDao packageInfoDao;
123   @Mock
124   private VendorSoftwareProductInfoDao vspInfoDaoMock;
125   @Mock
126   private ManualVspToscaManager manualVspToscaManager;
127   @Mock
128   private DeploymentFlavorDao deploymentFlavorDaoMock;
129   @Spy
130   @InjectMocks
131   private VendorSoftwareProductManagerImpl vendorSoftwareProductManager;
132   @Mock
133   private OrchestrationTemplateCandidateManager orchestrationTemplateCandidateManagerMock;
134   @Mock
135   private ComponentDependencyModelDao componentDependencyModelDao;
136   private OrchestrationTemplateCandidateManager candidateManager;
137   private MonitoringUploadsManager monitoringUploadsManager;
138
139   @Captor
140   private ArgumentCaptor<ActivityLogEntity> activityLogEntityArg;
141
142   @Before
143   public void setUp() {
144     MockitoAnnotations.initMocks(this);
145   }
146
147   @After
148   public void tearDown() {
149     vendorSoftwareProductManager = null;
150   }
151
152     @Test
153     public void testCreatePackageEtsiVNF() throws IOException {
154         try (
155             final InputStream metadataInput = getClass()
156                 .getResourceAsStream("/vspmanager.csar/metadata/ValidETSItosca.meta");
157             final InputStream manifestInput = getClass()
158                 .getResourceAsStream("/vspmanager.csar/manifest/ValidNonManoTosca.mf")) {
159
160             final FileContentHandler handler = new FileContentHandler();
161             final byte[] metadataInputBytes = IOUtils.toByteArray(metadataInput);
162             handler.addFile(TOSCA_META_PATH_FILE_NAME, metadataInputBytes);
163             handler.addFile(TOSCA_META_ORIG_PATH_FILE_NAME, metadataInputBytes);
164             handler.addFile(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME, IOUtils.toByteArray(manifestInput));
165             final ToscaServiceModel toscaMetadata = new ToscaServiceModel(handler, new HashMap<>(), "");
166             when(enrichedServiceModelDaoMock.getServiceModel(any(), any())).thenReturn(toscaMetadata);
167             final VspDetails vsp =
168                 createVspDetails("0", new Version(), "Vsp_PNF", "Test-vsp-pnf", "vendorName", "esy", "icon",
169                     "category", "subCategory", "123", null);
170             //want to avoid triggering populateVersionsForVlm method
171             vsp.setVlmVersion(null);
172
173             when(vspInfoDaoMock.get(any())).thenReturn(vsp);
174             when(licenseArtifactsServiceMock.createLicenseArtifacts(any(), any(), any(), any()))
175                 .thenReturn(new FileContentHandler());
176             final PackageInfo packageInfo = vendorSoftwareProductManager.createPackage("0", new Version());
177             assertEquals(packageInfo.getResourceType(), ResourceTypeEnum.VF.name());
178         }
179     }
180
181   @Test(expected = IOException.class)
182   public void testCreatePackageEtsiNoManifest() throws IOException {
183     try(InputStream metadataInput = getClass().getResourceAsStream("/vspmanager.csar/metadata/ValidETSItosca.meta"))
184     {
185       FileContentHandler handler = new FileContentHandler();
186       handler.addFile(TOSCA_META_PATH_FILE_NAME, IOUtils.toByteArray(metadataInput));
187       ToscaServiceModel toscaMetadata = new ToscaServiceModel(handler, new HashMap<>(), "");
188       when(enrichedServiceModelDaoMock.getServiceModel(any(), any())).thenReturn(toscaMetadata );
189       VspDetails vsp =
190               createVspDetails("0", new Version(), "Vsp_PNF", "Test-vsp-pnf", "vendorName", "esy", "icon",
191                       "category", "subCategory", "123", null);
192       //want to avoid triggering populateVersionsForVlm method
193       vsp.setVlmVersion(null);
194
195       when(vspInfoDaoMock.get(any())).thenReturn(vsp);
196       when(licenseArtifactsServiceMock.createLicenseArtifacts(any(),any(), any(), any())).thenReturn(new FileContentHandler());
197       vendorSoftwareProductManager.createPackage("0", new Version());
198       fail();
199     }
200   }
201
202     @Test
203     public void testCreatePackageEtsiPnfWithoutNonMano() throws IOException {
204         try (
205             final InputStream metadataInput = getClass()
206                 .getResourceAsStream("/vspmanager.csar/metadata/ValidETSItosca.meta");
207             final InputStream manifestInput = getClass()
208                 .getResourceAsStream("/vspmanager.csar/manifest/ValidNonManoToscaPnfWithoutNonMano.mf")) {
209
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);
222
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());
228         }
229     }
230
231     @Test
232     public void testCreatePackageEtsiPnfWithNonManoArtifacts() throws IOException {
233         try (
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")) {
240
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());
245
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);
251
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);
260
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("Package Info should contain resource type", packageInfo.getResourceType(),
266                 equalTo(ResourceTypeEnum.PNF.name()));
267             assertThat("Should not contain moved artifact", toscaMetadata.getArtifactFiles().getFileList(),
268                 not(hasItem("Deployment/ANOTHER/authorized_keys")));
269             assertThat("Should contain moved artifact", toscaMetadata.getArtifactFiles().getFileList(),
270                 hasItem("Informational/OTHER/authorized_keys"));
271             final String serviceTemplateAsYaml = new YamlUtil().objectToYaml(toscaMetadata.getServiceTemplates());
272             assertThat("Descriptor should not contain reference to file", serviceTemplateAsYaml,
273                 not(containsString("Artifacts/Deployment/ANOTHER/authorized_keys")));
274             assertThat("Descriptor should contain reference to file", serviceTemplateAsYaml,
275                 containsString("Artifacts/Informational/OTHER/authorized_keys"));
276         }
277     }
278
279   @Test
280   public void testCreate() {
281     //doReturn(VERSION01).when(versioningManagerMock).create(anyObject(), anyObject(), anyObject());
282     doReturn("{}")
283         .when(vendorSoftwareProductManager).getVspQuestionnaireSchema(anyObject());
284
285     VspDetails vspToCreate =
286         createVspDetails(null, null, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
287             "category", "subCategory", "123", null);
288
289     VspDetails vsp = vendorSoftwareProductManager.createVsp(vspToCreate);
290
291     Assert.assertNotNull(vsp);
292     vspToCreate.setId(vsp.getId());
293     vspToCreate.setVersion(VERSION01);
294     assertVspsEquals(vsp, vspToCreate);
295   }
296
297   @Test(expected = CoreException.class)
298   public void testUpdateWithExistingName_negative() {
299     VersionInfo versionInfo = new VersionInfo();
300     versionInfo.setActiveVersion(VERSION01);
301     doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
302         VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
303         VersionableEntityAction.Write);
304
305     VspDetails existingVsp =
306         createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-existingVsp", "vendorName", "vlm1Id",
307             "icon", "category", "subCategory", "123", null);
308     VspDetails updatedVsp =
309         createVspDetails(VSP_ID, VERSION01, "Vsp1_updated", "Test-existingVsp", "vendorName",
310             "vlm1Id", "icon", "category", "subCategory", "123", null);
311     doReturn(existingVsp).when(vspInfoDaoMock)
312         .get(any(VspDetails.class));
313     doThrow(new CoreException(
314         new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION).build()))
315         .when(vendorSoftwareProductManager)
316         .updateUniqueName(existingVsp.getName(), updatedVsp.getName());
317
318     vendorSoftwareProductManager.updateVsp(updatedVsp);
319   }
320
321   @Test
322   public void testUpdate() {
323     VersionInfo versionInfo = new VersionInfo();
324     versionInfo.setActiveVersion(VERSION01);
325     doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
326         VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
327         VersionableEntityAction.Write);
328     VspDetails existingVsp =
329         createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
330             "category",
331             "subCategory", "456", null);
332     VspDetails updatedVsp =
333         createVspDetails(VSP_ID, VERSION01, "VSP1_updated", null, "vendorName", "vlm1Id", "icon",
334             "category_updated",
335             "subCategory", "456", null);
336     doReturn(existingVsp).when(vspInfoDaoMock)
337         .get(any(VspDetails.class));
338     doNothing().when(vendorSoftwareProductManager)
339         .updateUniqueName(existingVsp.getName(), updatedVsp.getName());
340
341     vendorSoftwareProductManager.updateVsp(updatedVsp);
342
343     verify(vspInfoDaoMock).update(updatedVsp);
344   }
345
346   @Test
347   public void testUpdateRemoveFG() {
348     VersionInfo versionInfo = new VersionInfo();
349     versionInfo.setActiveVersion(VERSION01);
350     doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
351         VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
352         VersionableEntityAction.Write);
353     List<String> fgs = new ArrayList<>();
354     fgs.add("fg1");
355     fgs.add("fg2");
356     VspDetails existingVsp =
357         createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
358             "category",
359             "subCategory", "456", fgs);
360
361     List<String> updFgs = new ArrayList<>();
362     //updFgs.add("fg2");
363     VspDetails updatedVsp =
364         createVspDetails(VSP_ID, VERSION01, "VSP1_updated", null, "vendorName", "vlm1Id", "icon",
365             "category_updated",
366             "subCategory", "456", updFgs);
367     doReturn(existingVsp).when(vspInfoDaoMock)
368         .get(any(VspDetails.class));
369     doNothing().when(vendorSoftwareProductManager)
370         .updateUniqueName(existingVsp.getName(), updatedVsp.getName());
371
372     DeploymentFlavorEntity dfEntity = new DeploymentFlavorEntity(VSP_ID, VERSION01, "DF_ID");
373     DeploymentFlavor flavor = new DeploymentFlavor();
374     flavor.setFeatureGroupId("fg1");
375     dfEntity.setDeploymentFlavorCompositionData(flavor);
376
377     List<DeploymentFlavorEntity> dfList = new ArrayList<>();
378     dfList.add(dfEntity);
379
380     doReturn(dfList).when(deploymentFlavorDaoMock).list(anyObject());
381
382     vendorSoftwareProductManager.updateVsp(updatedVsp);
383
384     verify(deploymentFlavorDaoMock).update(dfEntity);
385
386     Assert.assertNull(dfEntity.getDeploymentFlavorCompositionData().getFeatureGroupId());
387
388   }
389
390   @Test(expected = CoreException.class)
391   public void testGetNonExistingVersion_negative() {
392     Version notExistversion = new Version("43, 8");
393     doReturn(null).when(vspInfoDaoMock).get(any(VspDetails.class));
394     vendorSoftwareProductManager.getVsp(VSP_ID, notExistversion);
395   }
396
397   @Test
398   public void testGetCheckedOutVersion() {
399     VersionInfo versionInfo = new VersionInfo();
400     versionInfo.setActiveVersion(VERSION01);
401     versionInfo.setStatus(VersionStatus.Locked);
402     versionInfo.setLockingUser(USER1);
403     doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
404         VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
405         VersionableEntityAction.Read);
406
407     VspDetails existingVsp =
408         createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
409             "category",
410             "subCategory", "456", null);
411     doReturn(existingVsp).when(vspInfoDaoMock).get(any(VspDetails.class));
412
413     VspDetails actualVsp =
414         vendorSoftwareProductManager.getVsp(VSP_ID, VERSION01);
415
416     assertVspsEquals(actualVsp, existingVsp);
417   }
418
419   @Test
420   public void testGetOldVersion() {
421     VersionInfo versionInfo = new VersionInfo();
422     versionInfo.setActiveVersion(new Version("0, 2"));
423     versionInfo.setViewableVersions(Arrays.asList(VERSION01, new Version("0, 2")));
424     versionInfo.setStatus(VersionStatus.Locked);
425     versionInfo.setLockingUser(USER2);
426     doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
427         VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
428         VersionableEntityAction.Read);
429
430     VspDetails existingVsp =
431         createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
432             "category",
433             "subCategory", "456", null);
434     doReturn(existingVsp)
435         .when(vspInfoDaoMock).get(any(VspDetails.class));
436
437     VspDetails actualVsp =
438         vendorSoftwareProductManager.getVsp(VSP_ID, VERSION01);
439
440     VspDetails expectedVsp =
441         vspInfoDaoMock
442             .get(new VspDetails(VSP_ID, VERSION01));
443     assertVspsEquals(actualVsp, expectedVsp);
444   }
445
446   @Test
447   public void testCreatePackage() throws IOException {
448     /*VspDetails vspDetailsMock = new VspDetails("vspId", new Version(1, 0));
449     doReturn(vspDetailsMock).when(vspInfoDaoMock).get(anyObject());*/
450     VersionInfo versionInfo = new VersionInfo();
451     versionInfo.setActiveVersion(VERSION10);
452     doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
453         VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
454         VersionableEntityAction.Read);
455
456     doReturn(new ToscaServiceModel(new FileContentHandler(), new HashMap<>(), "")).when
457         (enrichedServiceModelDaoMock).getServiceModel(VSP_ID, VERSION10);
458     doNothing().when(vendorSoftwareProductManager).populateVersionsForVlm(anyObject(), anyObject());
459     VspDetails vsp = new VspDetails(VSP_ID, VERSION10);
460     vsp.setVendorId("vendorId");
461     vsp.setVlmVersion(VERSION10);
462     vsp.setFeatureGroups(Arrays.asList("fg1", "fg2"));
463     doReturn(vsp).when(vspInfoDaoMock).get(any(VspDetails.class));
464
465     doReturn(new FileContentHandler()).when(licenseArtifactsServiceMock)
466         .createLicenseArtifacts(VSP_ID, vsp.getVendorId(), VERSION10, vsp.getFeatureGroups()
467         );
468
469     PackageInfo packageInfo = vendorSoftwareProductManager.createPackage(VSP_ID, VERSION10);
470     Assert.assertNotNull(packageInfo.getVspId());
471   }
472
473   @Test
474   public void testValidateWithCandidateDataNotProcessed() throws IOException {
475     VspDetails vsp =
476         createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
477             "category", "subCategory", "licenseAgreementId",
478             Collections.singletonList("featureGroupId"));
479     vsp.setOnboardingMethod("NetworkPackage");
480     doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
481
482     OrchestrationTemplateCandidateData orchestrationTemplateCandidateData = new
483         OrchestrationTemplateCandidateData();
484     orchestrationTemplateCandidateData.setFileSuffix("zip");
485     orchestrationTemplateCandidateData.setFilesDataStructure("testdata");
486     orchestrationTemplateCandidateData.setValidationData("");
487     doReturn(Optional.of(orchestrationTemplateCandidateData))
488         .when(orchestrationTemplateCandidateManagerMock)
489         .getInfo(VSP_ID, VERSION01);
490     ValidationResponse validationResponse =
491         vendorSoftwareProductManager.validate(vsp);
492     Assert.assertNotNull(validationResponse);
493     Assert.assertFalse(validationResponse.isValid());
494     Assert.assertNotNull(validationResponse.getVspErrors());
495     Assert.assertEquals(validationResponse.getVspErrors().size(), 1);
496
497   }
498
499   @Test
500   public void testValidateWithCandidateProcessedIsInvalid() throws IOException {
501     VspDetails vsp = createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-VSP", "vendorName",
502         "vl1Id", "icond", "category", "subcategory", "licenseAgreementId", Collections
503             .singletonList("featureGroupId"));
504     vsp.setOnboardingMethod("NetworkPackage");
505     doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
506
507     OrchestrationTemplateCandidateData orchestrationTemplateCandidateData = new
508         OrchestrationTemplateCandidateData();
509     orchestrationTemplateCandidateData.setFileSuffix("zip");
510     orchestrationTemplateCandidateData.setValidationData("Invalid processed data");
511     doReturn(Optional.of(orchestrationTemplateCandidateData))
512         .when(orchestrationTemplateCandidateManagerMock)
513         .getInfo(VSP_ID, VERSION01);
514     ValidationResponse validationResponse =
515         vendorSoftwareProductManager.validate(vsp);
516     Assert.assertNotNull(validationResponse);
517     Assert.assertFalse(validationResponse.isValid());
518     Assert.assertNotNull(validationResponse.getVspErrors());
519     Assert.assertEquals(validationResponse.getVspErrors().size(), 1);
520   }
521
522   private static VspDetails createVspDetails(String id, Version version, String name, String desc,
523                                      String vendorName, String vlm, String icon,
524                                      String category, String subCategory,
525                                      String licenseAgreement, List<String> featureGroups) {
526     VspDetails vspDetails = new VspDetails(id, version);
527     vspDetails.setName(name);
528     vspDetails.setDescription(desc);
529     vspDetails.setIcon(icon);
530     vspDetails.setCategory(category);
531     vspDetails.setSubCategory(subCategory);
532     vspDetails.setVendorName(vendorName);
533     vspDetails.setVendorId(vlm);
534     vspDetails.setVlmVersion(new Version("1, 0"));
535     vspDetails.setLicenseAgreement(licenseAgreement);
536     vspDetails.setFeatureGroups(featureGroups);
537     vspDetails.setOnboardingMethod("HEAT");
538     return vspDetails;
539   }
540
541   private static void assertVspsEquals(VspDetails actual, VspDetails expected) {
542     Assert.assertEquals(actual.getId(), expected.getId());
543     Assert.assertEquals(actual.getVersion(), expected.getVersion());
544     Assert.assertEquals(actual.getName(), expected.getName());
545     Assert.assertEquals(actual.getDescription(), expected.getDescription());
546     Assert.assertEquals(actual.getIcon(), expected.getIcon());
547     Assert.assertEquals(actual.getCategory(), expected.getCategory());
548     Assert.assertEquals(actual.getSubCategory(), expected.getSubCategory());
549     Assert.assertEquals(actual.getVendorName(), expected.getVendorName());
550     Assert.assertEquals(actual.getVendorId(), expected.getVendorId());
551     Assert.assertEquals(actual.getLicenseAgreement(), expected.getLicenseAgreement());
552     Assert.assertEquals(actual.getFeatureGroups(), expected.getFeatureGroups());
553   }
554
555 }