2fc4385563611e343cce25f074c5e2565a1082b2
[sdc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.vendorsoftwareproduct.impl;
22
23 import org.mockito.ArgumentCaptor;
24 import org.mockito.Captor;
25 import org.mockito.InjectMocks;
26 import org.mockito.Mock;
27 import org.mockito.MockitoAnnotations;
28 import org.mockito.Spy;
29 import org.openecomp.core.enrichment.factory.EnrichmentManagerFactory;
30 import org.openecomp.core.factory.impl.AbstractFactoryBase;
31 import org.openecomp.core.model.dao.EnrichedServiceModelDao;
32 import org.openecomp.core.model.dao.ServiceModelDao;
33 import org.openecomp.core.model.types.ServiceElement;
34 import org.openecomp.core.utilities.file.FileContentHandler;
35 import org.openecomp.core.utilities.file.FileUtils;
36 import org.openecomp.sdc.activityLog.ActivityLogManager;
37 import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity;
38 import org.openecomp.sdc.common.errors.CoreException;
39 import org.openecomp.sdc.common.errors.ErrorCategory;
40 import org.openecomp.sdc.common.errors.ErrorCode;
41 import org.openecomp.sdc.common.errors.Messages;
42 import org.openecomp.sdc.common.errors.ValidationErrorBuilder;
43 import org.openecomp.sdc.healing.api.HealingManager;
44 import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
45 import org.openecomp.sdc.tosca.datatypes.model.CapabilityDefinition;
46 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
47 import org.openecomp.sdc.vendorlicense.licenseartifacts.VendorLicenseArtifactsService;
48 import org.openecomp.sdc.vendorsoftwareproduct.ManualVspToscaManager;
49 import org.openecomp.sdc.vendorsoftwareproduct.MonitoringUploadsManager;
50 import org.openecomp.sdc.vendorsoftwareproduct.OrchestrationTemplateCandidateManager;
51 import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants;
52 import org.openecomp.sdc.vendorsoftwareproduct.dao.DeploymentFlavorDao;
53 import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao;
54 import org.openecomp.sdc.vendorsoftwareproduct.dao.PackageInfoDao;
55 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao;
56 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao;
57 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity;
58 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.DeploymentFlavorEntity;
59 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity;
60 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.PackageInfo;
61 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.UploadDataEntity;
62 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
63 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspQuestionnaireEntity;
64 import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes;
65 import org.openecomp.sdc.vendorsoftwareproduct.impl.mock.EnrichmentManagerFactoryImpl;
66 import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.InformationArtifactGenerator;
67 import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager;
68 import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
69 import org.openecomp.sdc.vendorsoftwareproduct.types.ValidationResponse;
70 import org.openecomp.sdc.vendorsoftwareproduct.types.VersionedVendorSoftwareProductInfo;
71 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.DeploymentFlavor;
72 import org.openecomp.sdc.versioning.VersioningManager;
73 import org.openecomp.sdc.versioning.dao.types.Version;
74 import org.openecomp.sdc.versioning.dao.types.VersionStatus;
75 import org.openecomp.sdc.versioning.errors.EditOnEntityLockedByOtherErrorBuilder;
76 import org.openecomp.sdc.versioning.errors.EntityNotExistErrorBuilder;
77 import org.openecomp.sdc.versioning.types.VersionInfo;
78 import org.openecomp.sdc.versioning.types.VersionableEntityAction;
79 import org.testng.Assert;
80 import org.testng.annotations.BeforeMethod;
81 import org.testng.annotations.Test;
82
83 import java.io.File;
84 import java.io.FileInputStream;
85 import java.io.IOException;
86 import java.io.InputStream;
87 import java.net.URL;
88 import java.nio.ByteBuffer;
89 import java.util.ArrayList;
90 import java.util.Arrays;
91 import java.util.Collections;
92 import java.util.HashMap;
93 import java.util.List;
94 import java.util.Map;
95 import java.util.stream.Collectors;
96 import java.util.zip.ZipEntry;
97 import java.util.zip.ZipInputStream;
98
99 import static org.mockito.Matchers.any;
100 import static org.mockito.Matchers.anyObject;
101 import static org.mockito.Matchers.eq;
102 import static org.mockito.Mockito.doNothing;
103 import static org.mockito.Mockito.doReturn;
104 import static org.mockito.Mockito.doThrow;
105 import static org.mockito.Mockito.never;
106 import static org.mockito.Mockito.verify;
107
108
109 public class VendorSoftwareProductManagerImplTest {
110   private static final String INVALID_VERSION_MSG = "Invalid requested version.";
111
112   private static String VSP_ID = "vspId";
113   private static String VERSION_ID = "versionId";
114   public static final Version VERSION01 = new Version(0, 1);
115   private static final Version VERSION10 = new Version(1, 0);
116   private static final String USER1 = "vspTestUser1";
117   private static final String USER2 = "vspTestUser2";
118   private static final String USER3 = "vspTestUser3";
119   private static String id006 = null;
120   private static String id007 = null;
121
122   @Mock
123   private VersioningManager versioningManagerMock;
124   @Mock
125   private VendorSoftwareProductDao vendorSoftwareProductDaoMock; // todo get rid of
126   @Mock
127   private OrchestrationTemplateDao orchestrationTemplateDataDaoMock;
128   @Mock
129   private VendorLicenseFacade vendorLicenseFacadeMock;
130   @Mock
131   private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDaoMock;
132   @Mock
133   private EnrichedServiceModelDao<ToscaServiceModel, ServiceElement> enrichedServiceModelDaoMock;
134   @Mock
135   private HealingManager healingManagerMock;
136   @Mock
137   private VendorLicenseArtifactsService licenseArtifactsServiceMock;
138   @Mock
139   private CompositionEntityDataManager compositionEntityDataManagerMock;
140   @Mock
141   private InformationArtifactGenerator informationArtifactGeneratorMock;
142   @Mock
143   private ActivityLogManager activityLogManagerMock;
144   @Mock
145   private PackageInfoDao packageInfoDao;
146   @Mock
147   private VendorSoftwareProductInfoDao vspInfoDaoMock;
148   @Mock
149   private ManualVspToscaManager manualVspToscaManager;
150   @Mock
151   private DeploymentFlavorDao deploymentFlavorDaoMock;
152
153
154   @Spy
155   @InjectMocks
156   private VendorSoftwareProductManagerImpl vendorSoftwareProductManager;
157
158   private OrchestrationTemplateCandidateManager candidateManager;
159   private MonitoringUploadsManager monitoringUploadsManager;
160
161   @Captor
162   private ArgumentCaptor<ActivityLogEntity> activityLogEntityArg;
163
164   @BeforeMethod
165   public void setUp() throws Exception {
166     MockitoAnnotations.initMocks(this);
167   }
168
169   @Test
170   public void testListWhenNone() {
171     doReturn(new HashMap<>()).when(versioningManagerMock).listEntitiesVersionInfo
172         (VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, USER1,
173             VersionableEntityAction.Read);
174     List<VersionedVendorSoftwareProductInfo> vsps =
175         vendorSoftwareProductManager.listVsps(null, USER1);
176     Assert.assertEquals(vsps.size(), 0);
177   }
178
179   @Test
180   public void testList() {
181     String vsp1id = "vsp1_id";
182     String vsp2id = "vsp2_id";
183     Map<String, VersionInfo> vspsTobeReturned = new HashMap<>();
184
185     VersionInfo versionInfo1 = new VersionInfo();
186     versionInfo1.setActiveVersion(VERSION01);
187     vspsTobeReturned.put(vsp1id, versionInfo1);
188
189     VersionInfo versionInfo2 = new VersionInfo();
190     versionInfo2.setActiveVersion(VERSION10);
191     vspsTobeReturned.put(vsp2id, versionInfo2);
192
193     doReturn(vspsTobeReturned).when(versioningManagerMock).listEntitiesVersionInfo
194         (VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, USER1,
195             VersionableEntityAction.Read);
196
197     VspDetails vsp1 = new VspDetails(vsp1id, VERSION01);
198     vsp1.setWritetimeMicroSeconds(8L);
199     doReturn(vsp1).when(vspInfoDaoMock)
200         .get(any(VspDetails.class));
201
202     List<VersionedVendorSoftwareProductInfo> vsps =
203         vendorSoftwareProductManager.listVsps(null, USER1);
204     Assert.assertEquals(vsps.size(), 2);
205   }
206
207   @Test
208   public void testListFinalsWhenNone() {
209     String vsp1id = "vsp1_id";
210     String vsp2id = "vsp2_id";
211     Map<String, VersionInfo> vspsTobeReturned = new HashMap<>();
212
213     VersionInfo versionInfo1 = new VersionInfo();
214     versionInfo1.setActiveVersion(VERSION01);
215     vspsTobeReturned.put(vsp1id, versionInfo1);
216
217     VersionInfo versionInfo2 = new VersionInfo();
218     versionInfo2.setActiveVersion(VERSION10);
219     vspsTobeReturned.put(vsp2id, versionInfo2);
220
221     doReturn(vspsTobeReturned).when(versioningManagerMock).listEntitiesVersionInfo
222         (VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, USER1,
223             VersionableEntityAction.Read);
224
225     List<VersionedVendorSoftwareProductInfo> vsps =
226         vendorSoftwareProductManager.listVsps(VersionStatus.Final.name(), USER1);
227     Assert.assertEquals(vsps.size(), 0);
228   }
229
230   @Test
231   public void testListFinals() {
232     String vsp1id = "vsp1_id";
233     String vsp2id = "vsp2_id";
234     Map<String, VersionInfo> vspsTobeReturned = new HashMap<>();
235
236     VersionInfo versionInfo1 = new VersionInfo();
237     versionInfo1.setActiveVersion(VERSION01);
238     vspsTobeReturned.put(vsp1id, versionInfo1);
239
240     VersionInfo versionInfo2 = new VersionInfo();
241     versionInfo2.setActiveVersion(new Version(1, 3));
242     versionInfo2.setLatestFinalVersion(VERSION10);
243     vspsTobeReturned.put(vsp2id, versionInfo2);
244
245     doReturn(vspsTobeReturned).when(versioningManagerMock).listEntitiesVersionInfo
246         (VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, USER1,
247             VersionableEntityAction.Read);
248
249     VspDetails vsp2 = new VspDetails(vsp2id, VERSION10);
250     vsp2.setWritetimeMicroSeconds(8L);
251     doReturn(vsp2).when(vspInfoDaoMock)
252         .get(any(VspDetails.class));
253
254     List<VersionedVendorSoftwareProductInfo> vsps =
255         vendorSoftwareProductManager.listVsps(VersionStatus.Final.name(), USER1);
256     Assert.assertEquals(vsps.size(), 1);
257   }
258
259   @Test(expectedExceptions = CoreException.class)
260   public void testCreateWithExistingName_negative() {
261     doThrow(new CoreException(
262         new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION).build()))
263         .when(vendorSoftwareProductManager).validateUniqueName("Vsp1");
264     VspDetails expectedVsp =
265         createVspDetails(null, null, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
266             "category", "subCategory", "123", null);
267
268     vendorSoftwareProductManager.createVsp(expectedVsp, USER1);
269   }
270
271   @Test
272   public void testCreate() {
273     doNothing().when(vendorSoftwareProductManager).validateUniqueName("Vsp1");
274     doNothing().when(vendorSoftwareProductManager).createUniqueName("Vsp1");
275     doReturn(VERSION01).when(versioningManagerMock).create(anyObject(), anyObject(), anyObject());
276     doReturn("{}")
277         .when(vendorSoftwareProductManager).getVspQuestionnaireSchema(anyObject());
278
279     VspDetails vspToCreate =
280         createVspDetails(null, null, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
281             "category", "subCategory", "123", null);
282
283     VspDetails vsp = vendorSoftwareProductManager.createVsp(vspToCreate, USER1);
284
285     Assert.assertNotNull(vsp);
286     vspToCreate.setId(vsp.getId());
287     vspToCreate.setVersion(VERSION01);
288     assertVspsEquals(vsp, vspToCreate);
289     verify(activityLogManagerMock).addActionLog(activityLogEntityArg.capture(), eq(USER1));
290     ActivityLogEntity activityLogEntity = activityLogEntityArg.getValue();
291     Assert.assertEquals(activityLogEntity.getVersionId(), String.valueOf(VERSION01.getMajor() + 1));
292     Assert.assertTrue(activityLogEntity.isSuccess());
293   }
294
295   @Test(expectedExceptions = CoreException.class)
296   public void testUpdateWithExistingName_negative() {
297     VersionInfo versionInfo = new VersionInfo();
298     versionInfo.setActiveVersion(VERSION01);
299     doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
300         VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
301         VersionableEntityAction.Write);
302
303     VspDetails existingVsp =
304         createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-existingVsp", "vendorName", "vlm1Id",
305             "icon", "category", "subCategory", "123", null);
306     VspDetails updatedVsp =
307         createVspDetails(VSP_ID, VERSION01, "Vsp1_updated", "Test-existingVsp", "vendorName",
308             "vlm1Id", "icon", "category", "subCategory", "123", null);
309     doReturn(existingVsp).when(vspInfoDaoMock)
310         .get(any(VspDetails.class));
311     doThrow(new CoreException(
312         new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION).build()))
313         .when(vendorSoftwareProductManager)
314         .updateUniqueName(existingVsp.getName(), updatedVsp.getName());
315
316     vendorSoftwareProductManager.updateVsp(updatedVsp, USER1);
317   }
318
319   @Test
320   public void testUpdate() {
321     VersionInfo versionInfo = new VersionInfo();
322     versionInfo.setActiveVersion(VERSION01);
323     doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
324         VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
325         VersionableEntityAction.Write);
326     VspDetails existingVsp =
327         createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
328             "category",
329             "subCategory", "456", null);
330     VspDetails updatedVsp =
331         createVspDetails(VSP_ID, VERSION01, "VSP1_updated", null, "vendorName", "vlm1Id", "icon",
332             "category_updated",
333             "subCategory", "456", null);
334     existingVsp.setWritetimeMicroSeconds(8L);
335     doReturn(existingVsp).when(vspInfoDaoMock)
336         .get(any(VspDetails.class));
337     doNothing().when(vendorSoftwareProductManager)
338         .updateUniqueName(existingVsp.getName(), updatedVsp.getName());
339
340     vendorSoftwareProductManager.updateVsp(updatedVsp, USER1);
341
342     verify(vspInfoDaoMock).update(updatedVsp);
343   }
344
345   @Test
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<String>();
353     fgs.add("fg1"); fgs.add("fg2");
354     VspDetails existingVsp =
355         createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
356             "category",
357             "subCategory", "456", fgs);
358
359     List<String> updFgs = new ArrayList<String>();
360     updFgs.add("fg2");
361     VspDetails updatedVsp =
362         createVspDetails(VSP_ID, VERSION01, "VSP1_updated", null, "vendorName", "vlm1Id", "icon",
363             "category_updated",
364             "subCategory", "456", updFgs);
365     existingVsp.setWritetimeMicroSeconds(8L);
366     doReturn(existingVsp).when(vspInfoDaoMock)
367         .get(any(VspDetails.class));
368     doNothing().when(vendorSoftwareProductManager)
369         .updateUniqueName(existingVsp.getName(), updatedVsp.getName());
370
371     DeploymentFlavorEntity dfEntity = new DeploymentFlavorEntity(VSP_ID,VERSION01,"DF_ID");
372     DeploymentFlavor flavor = new DeploymentFlavor();
373     flavor.setFeatureGroupId("fg1");
374     dfEntity.setDeploymentFlavorCompositionData(flavor);
375
376     List<DeploymentFlavorEntity> dfList = new ArrayList<DeploymentFlavorEntity>();
377     dfList.add(dfEntity);
378
379     doReturn(dfList).when(deploymentFlavorDaoMock).list(anyObject());
380
381     vendorSoftwareProductManager.updateVsp(updatedVsp, USER1);
382
383     verify(vendorSoftwareProductDaoMock).updateDeploymentFlavor(dfEntity);
384
385     Assert.assertNull(dfEntity.getDeploymentFlavorCompositionData().getFeatureGroupId());
386
387   }
388
389   @Test(expectedExceptions = 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, USER1);
394   }
395
396   @Test
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);
405
406     VspDetails existingVsp =
407         createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
408             "category",
409             "subCategory", "456", null);
410     existingVsp.setWritetimeMicroSeconds(8L);
411     doReturn(existingVsp).when(vspInfoDaoMock).get(any(VspDetails.class));
412
413     VspDetails actualVsp =
414         vendorSoftwareProductManager.getVsp(VSP_ID, VERSION01, USER1);
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     existingVsp.setWritetimeMicroSeconds(8L);
435     doReturn(existingVsp)
436         .when(vspInfoDaoMock).get(any(VspDetails.class));
437
438     VspDetails actualVsp =
439         vendorSoftwareProductManager.getVsp(VSP_ID, VERSION01, USER1);
440
441     VspDetails expectedVsp =
442         vspInfoDaoMock
443             .get(new VspDetails(VSP_ID, VERSION01));
444     assertVspsEquals(actualVsp, expectedVsp);
445   }
446
447   @Test
448   public void testCheckin() {
449     doReturn(VERSION01).when(versioningManagerMock)
450         .checkin(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
451             USER1, null);
452     Version version = vendorSoftwareProductManager.checkin(VSP_ID, USER1);
453
454     Assert.assertEquals(version, VERSION01);
455     verify(versioningManagerMock)
456         .checkin(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
457             USER1, null);
458     verify(activityLogManagerMock).addActionLog(activityLogEntityArg.capture(), eq(USER1));
459     ActivityLogEntity activityLogEntity = activityLogEntityArg.getValue();
460     Assert.assertEquals(activityLogEntity.getVersionId(), String.valueOf(VERSION01.getMajor() + 1));
461     Assert.assertTrue(activityLogEntity.isSuccess());
462   }
463
464   @Test
465   public void testCheckout() {
466     doReturn(VERSION01).when(versioningManagerMock)
467         .checkout(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
468             USER1);
469     Version version = vendorSoftwareProductManager.checkout(VSP_ID, USER1);
470
471     Assert.assertEquals(version, VERSION01);
472     verify(versioningManagerMock)
473         .checkout(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
474             USER1);
475
476     verify(activityLogManagerMock).addActionLog(activityLogEntityArg.capture(), eq(USER1));
477     ActivityLogEntity activityLogEntity = activityLogEntityArg.getValue();
478     Assert.assertEquals(activityLogEntity.getVersionId(), String.valueOf(VERSION01.getMajor() + 1));
479     Assert.assertTrue(activityLogEntity.isSuccess());
480   }
481
482
483   @Test
484   public void testUndoCheckout() {
485     Version existingVersion = new Version(0, 2);
486     VersionInfo versionInfo = new VersionInfo();
487     versionInfo.setActiveVersion(existingVersion);
488     doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
489         VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE,
490         VSP_ID, USER1, VersionableEntityAction.Read);
491
492     doReturn(VERSION01).when(versioningManagerMock).undoCheckout(VendorSoftwareProductConstants
493         .VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1);
494
495     VspDetails vsp = new VspDetails(VSP_ID, existingVersion);
496     vsp.setName("ExistingName");
497     doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
498     doNothing().when(vendorSoftwareProductManager).updateUniqueName(vsp.getName(), vsp.getName());
499
500     Version undoCheckoutVersion = vendorSoftwareProductManager.undoCheckout(VSP_ID, USER1);
501
502     Assert.assertEquals(undoCheckoutVersion, VERSION01);
503   }
504
505 /*
506   @Test
507   public void testSubmitWithMissingData() throws IOException {
508     VersionInfo versionInfo = new VersionInfo();
509     versionInfo.setActiveVersion(VERSION01);
510
511     doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
512         VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE,
513         VSP_ID, USER1, VersionableEntityAction.Read);
514
515     VspDetails vsp = new VspDetails(VSP_ID, VERSION01);
516     vsp.setOnboardingMethod("Manual");
517     doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
518
519     VspQuestionnaireEntity vspQuestionnaire = new VspQuestionnaireEntity(VSP_ID, VERSION01);
520     vspQuestionnaire.setQuestionnaireData("{}");
521     doReturn(vspQuestionnaire).when(vspInfoDaoMock).getQuestionnaire(VSP_ID, VERSION01);
522
523     ComponentEntity comp1 = new ComponentEntity(VSP_ID, VERSION01, "comp1");
524     comp1.setQuestionnaireData("{}");
525     doReturn(Collections.singleton(comp1)).when(vendorSoftwareProductDaoMock)
526         .listComponentsCompositionAndQuestionnaire(VSP_ID, VERSION01);
527
528     NicEntity nic1 = new NicEntity(VSP_ID, VERSION01, "comp1", "nic1");
529     nic1.setQuestionnaireData("{}");
530     doReturn(Collections.singleton(nic1))
531         .when(vendorSoftwareProductDaoMock).listNicsByVsp(VSP_ID, VERSION01);
532
533     ValidationResponse validationResponse = vendorSoftwareProductManager.submit(VSP_ID, USER1);
534     Assert.assertNotNull(validationResponse);
535     Assert.assertFalse(validationResponse.isValid());
536     List<String> errorIds = validationResponse.getVspErrors().stream().map(ErrorCode::id).distinct()
537         .collect(Collectors.toList());
538     Assert.assertTrue(errorIds.contains(ValidationErrorBuilder.FIELD_VALIDATION_ERROR_ERR_ID));
539     Assert.assertTrue(errorIds.contains(VendorSoftwareProductErrorCodes.VSP_INVALID));
540
541     verify(versioningManagerMock, never())
542         .submit(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
543             USER1, null);
544     verify(activityLogManagerMock, never()).addActionLog(any(ActivityLogEntity.class), eq(USER1));
545   }
546
547   */
548
549   // TODO: 3/15/2017 fix and enable
550   //@Test
551   public void testSubmitWithInvalidLicensingData() throws IOException {
552     VersionInfo versionInfo = new VersionInfo();
553     versionInfo.setActiveVersion(VERSION01);
554     doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
555         VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE,
556         VSP_ID, USER1, VersionableEntityAction.Read);
557
558     VspDetails vsp =
559         createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
560             "category", "subCategory", "licenseAgreementId",
561             Collections.singletonList("featureGroupId"));
562     doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
563     UploadDataEntity uploadData = new UploadDataEntity(VSP_ID, VERSION01);
564     uploadData.setContentData(
565         ByteBuffer.wrap(FileUtils.toByteArray(getFileInputStream("/emptyComposition"))));
566     doReturn(uploadData).when(orchestrationTemplateDataDaoMock)
567         .getOrchestrationTemplate(anyObject(), anyObject());
568     doReturn(new ToscaServiceModel(new FileContentHandler(), new HashMap<>(),
569         "MainServiceTemplate.yaml"))
570         .when(serviceModelDaoMock).getServiceModel(VSP_ID, VERSION01);
571
572     ValidationResponse validationResponse = vendorSoftwareProductManager.submit(VSP_ID, USER1);
573     Assert.assertNotNull(validationResponse);
574     Assert.assertFalse(validationResponse.isValid());
575     Assert.assertNull(validationResponse.getVspErrors());
576     Assert.assertEquals(validationResponse.getLicensingDataErrors(), 1);
577
578     verify(versioningManagerMock, never())
579         .submit(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
580             USER1, null);
581
582     //TODO - check..
583     verify(activityLogManagerMock, never()).addActionLog(any(ActivityLogEntity.class), eq(USER1));
584   }
585
586   // TODO: 3/15/2017 fix and enable
587   //@Test
588   public void testSubmit() throws IOException {
589     mockVersioning(VersionableEntityAction.Read);
590
591     EnrichmentManagerFactory.getInstance();
592     AbstractFactoryBase
593         .registerFactory(EnrichmentManagerFactory.class, EnrichmentManagerFactoryImpl.class);
594
595     VspDetails vsp =
596         createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
597             "category", "subCategory", "123", Collections.singletonList("fg1"));
598     doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
599     UploadDataEntity uploadData = new UploadDataEntity(VSP_ID, VERSION01);
600     uploadData.setContentData(
601         ByteBuffer.wrap(FileUtils.toByteArray(getFileInputStream("/emptyComposition"))));
602     doReturn(uploadData).when(orchestrationTemplateDataDaoMock)
603         .getOrchestrationTemplate(anyObject(), anyObject());
604     doReturn(new ToscaServiceModel(new FileContentHandler(), new HashMap<>(),
605         "MainServiceTemplate.yaml"))
606         .when(serviceModelDaoMock).getServiceModel(VSP_ID, VERSION01);
607
608     ValidationResponse validationResponse = vendorSoftwareProductManager.submit(VSP_ID, USER1);
609     Assert.assertTrue(validationResponse.isValid());
610
611 /*    Assert.assertEquals(vsp2.getVersionInfo().getActiveVersion(), VERSION10);
612     Assert.assertEquals(vsp2.getVersionInfo().getStatus(), VersionStatus.Final);
613     Assert.assertNull(vsp2.getVersionInfo().getLockingUser());*/
614
615     verify(versioningManagerMock)
616         .submit(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
617             USER1, null);
618     verify(activityLogManagerMock).addActionLog(activityLogEntityArg.capture(), eq(USER1));
619     ActivityLogEntity activityLogEntity = activityLogEntityArg.getValue();
620     Assert.assertEquals(activityLogEntity.getVersionId(), String.valueOf(VERSION10.getMajor()));
621     Assert.assertTrue(activityLogEntity.isSuccess());
622   }
623
624   @Test(expectedExceptions = CoreException.class)
625   public void testCreatePackageOnNonFinalVersion_negative() throws IOException {
626     vendorSoftwareProductManager.createPackage(VSP_ID, VERSION01, USER1);
627   }
628
629   @Test
630   public void testCreatePackage() throws IOException {
631     /*VspDetails vspDetailsMock = new VspDetails("vspId", new Version(1, 0));
632     doReturn(vspDetailsMock).when(vspInfoDaoMock).get(anyObject());*/
633     VersionInfo versionInfo = new VersionInfo();
634     versionInfo.setActiveVersion(VERSION10);
635     doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
636         VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
637         VersionableEntityAction.Read);
638
639     doReturn(new ToscaServiceModel(new FileContentHandler(), new HashMap<>(), "")).when
640         (enrichedServiceModelDaoMock).getServiceModel(VSP_ID, VERSION10);
641
642     VspDetails vsp = new VspDetails(VSP_ID, VERSION10);
643     vsp.setVendorId("vendorId");
644     vsp.setVlmVersion(VERSION10);
645     vsp.setFeatureGroups(Arrays.asList("fg1", "fg2"));
646     doReturn(vsp).when(vspInfoDaoMock).get(any(VspDetails.class));
647
648     doReturn(new FileContentHandler()).when(licenseArtifactsServiceMock)
649         .createLicenseArtifacts(VSP_ID, vsp.getVendorId(), VERSION10, vsp.getFeatureGroups(),
650             USER1);
651
652     PackageInfo packageInfo = vendorSoftwareProductManager.createPackage(VSP_ID, VERSION10, USER1);
653     Assert.assertNotNull(packageInfo.getVspId());
654   }
655
656   // TODO: 3/15/2017 fix and enable
657   //@Test(dependsOnMethods = {"testListFinals"})
658   public void testUploadFileMissingFile() {
659     InputStream zis = getFileInputStream("/vspmanager/zips/missingYml.zip");
660
661     UploadFileResponse uploadFileResponse =
662         candidateManager.upload(VSP_ID, VERSION01, zis, USER1);
663
664     Assert.assertEquals(uploadFileResponse.getErrors().size(), 0);
665   }
666
667   // TODO: 3/15/2017 fix and enable
668   //@Test(dependsOnMethods = {"testUploadFileMissingFile"})
669   public void testUploadNotZipFile() throws IOException {
670     URL url = this.getClass().getResource("/notZipFile");
671
672     try {
673       candidateManager
674           .upload(VSP_ID, VERSION01,
675               url.openStream(), USER1);
676       candidateManager.process(VSP_ID, VERSION01, USER1);
677     } catch (Exception ce) {
678       Assert.assertEquals(ce.getMessage(), Messages.CREATE_MANIFEST_FROM_ZIP.getErrorMessage());
679     }
680
681     verify(activityLogManagerMock, never()).addActionLog(any(ActivityLogEntity.class), eq(USER1));
682   }
683 /*
684   @Test
685   public void testEnrichModelInSubmit() {
686     UniqueValueUtil
687         .deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME,
688             "VSP_syb");
689     VspDetails vspDetails = vendorSoftwareProductManager.createVsp(
690         createVspDetails(null, null, "VSP_syb", "Test-vsp_syb", "vendorName", "vlm1Id", "icon",
691             "category", "subCategory", "456", null), USER1);
692     String id = vspDetails.getId();
693
694     //upload file
695     InputStream zis = getFileInputStream("/vspmanager/zips/fullComposition.zip");
696     candidateManager.upload(id, VERSION01, zis, USER1);
697     OrchestrationTemplateActionResponse uploadFileResponse =
698         candidateManager.process(id, VERSION01, USER1);
699
700     //check in
701     vendorSoftwareProductManager.checkin(id, USER1);
702     //submit
703     try {
704       ValidationResponse result = vendorSoftwareProductManager.submit(id, USER1);
705     } catch (IOException exception) {
706       Assert.fail();
707     }
708     VersionedVendorSoftwareProductInfo details =
709         vendorSoftwareProductManager.getVsp(id, null, USER1);
710     Collection<ComponentEntity> components =vendorSoftwareProductManager
711         .listComponents(id, details.getVersionInfo().getActiveVersion(), USER1);
712
713     ToscaServiceModel model =
714         (ToscaServiceModel) EnrichedServiceModelDaoFactory.getInstance().createInterface()
715             .getServiceModel(id, details.getVersionInfo().getActiveVersion());
716
717     Map<String, CapabilityDefinition> capabilities = new HashMap<>();
718     for (ComponentEntity component : components) {
719       model.getServiceTemplates().
720           entrySet().
721           stream().
722           filter(entryValue -> entryValue.getValue() != null &&
723               entryValue.getValue().getNode_types() != null &&
724               entryValue.getValue().
725                   getNode_types().
726                   containsKey(component.getComponentCompositionData().getName())).
727           forEach(entryValue -> entryValue.getValue().getNode_types().
728               values().
729               stream().
730               filter(type -> MapUtils.isNotEmpty(type.getCapabilities())).
731               forEach(type -> type.getCapabilities().
732                   entrySet().
733                   forEach(entry -> addCapability(entryValue.getKey(), capabilities, entry.getKey(),
734                       entry.getValue()))));
735
736     }
737
738     Assert.assertNotNull(capabilities);
739   }
740
741   @Test(dependsOnMethods = {"testCreatePackage"})
742   public void testEnrichedFilesDeletedOnNewUpload() throws IOException {
743     Version activeVersion;
744
745     createPackageFromUpload(VSP_ID, USER1, "/fullComposition");
746     activeVersion = vendorSoftwareProductManager.getVsp(VSP_ID, null, USER1).getVersionInfo()
747         .getActiveVersion();
748
749     List<ServiceArtifact> firstExternalArtifacts = enrichedServiceModelDaoMock
750         .getExternalArtifacts(VSP_ID, activeVersion);
751     ToscaServiceModel firstServiceModel = enrichedServiceModelDaoMock.getServiceModel(VSP_ID,
752         activeVersion);
753
754     createPackageFromUpload(VSP_ID, USER1, "/emptyComposition");
755     activeVersion = vendorSoftwareProductManager.getVsp(VSP_ID, null, USER1).getVersionInfo()
756         .getActiveVersion();
757
758     List<ServiceArtifact> secondExternalArtifacts = enrichedServiceModelDaoMock
759         .getExternalArtifacts(VSP_ID, activeVersion);
760     ToscaServiceModel secondServiceModel = enrichedServiceModelDaoMock.getServiceModel(VSP_ID,
761         activeVersion);
762
763     Assert.assertNotEquals(firstExternalArtifacts, secondExternalArtifacts);
764     Assert.assertNotEquals(firstServiceModel, secondServiceModel);
765
766   }
767
768   @Test(dependsOnMethods = {"testMibsDeletedInCsar"})
769   public void testServiceTemplatesAreDeletedInCsarOnNewUpload() throws IOException {
770     String nestedPath = "Definitions" + File.separator + "nested";
771
772     uploadFileAndProcess(VSP_ID, USER1, "/vspmanager/zips/fullCompositionNested.zip");
773     checkinSubmitCreatePackage(VSP_ID, USER1);
774     List<String> nestedFileNamesServiceTemplates =
775         getWantedFileNamesFromCsar(nestedPath);
776
777     uploadFileAndProcess(VSP_ID, USER1, "/vspmanager/zips/fullComposition.zip");
778     checkinSubmitCreatePackage(VSP_ID, USER1);
779     List<String> emptyNestedNamesList = getWantedFileNamesFromCsar(nestedPath);
780
781     Assert.assertEquals(emptyNestedNamesList.size(), 0);
782     Assert.assertNotEquals(emptyNestedNamesList.size(), nestedFileNamesServiceTemplates.size());
783   }*/
784
785   private List<String> getWantedFileNamesFromCsar(String pathInCsar)
786       throws IOException {
787     File translatedFile = vendorSoftwareProductManager.getTranslatedFile(VSP_ID, VERSION10, USER1);
788
789     return getFileNamesFromFolderInCsar(translatedFile,
790         pathInCsar);
791   }
792
793   private List<String> getFileNamesFromFolderInCsar(File csar, String folderName)
794       throws IOException {
795     List<String> fileNames = new ArrayList<>();
796
797     ZipInputStream zip = new ZipInputStream(new FileInputStream(csar));
798     ZipEntry ze;
799
800     while ((ze = zip.getNextEntry()) != null) {
801       String name = ze.getName();
802       if (name.contains(folderName)) {
803         fileNames.add(name);
804       }
805     }
806
807     return fileNames;
808   }
809   /*
810   //Disabled for sonar null pointer issue for componentEntities
811   private Pair<String, String> uploadMib(String vspId, String user, String filePath,
812                                          String fileName) {
813     List<ComponentEntity> componentEntities = null;
814     //(List<ComponentEntity>) vendorSoftwareProductManager.listComponents(vspId, null, user);
815     monitoringUploadsManager.upload(getFileInputStream(filePath),
816         fileName, vspId,
817         VERSION01, componentEntities.get(0).getId(), MonitoringUploadType.SNMP_POLL, user);
818     //TODO: add validate of addActionLog() func call
819
820     return new ImmutablePair<>(componentEntities.get(0).getId(),
821         componentEntities.get(0).getComponentCompositionData()
822             .getDisplayName());
823   }*/
824
825   private void createPackageFromUpload(String vspId, String user, String filePath)
826       throws IOException {
827     uploadFileAndProcess(vspId, user, filePath);
828     checkinSubmitCreatePackage(vspId, user);
829   }
830
831   private void uploadFileAndProcess(String vspId, String user, String filePath) {
832     vendorSoftwareProductManager.checkout(vspId, user);
833     candidateManager.upload(vspId, VERSION01, getFileInputStream(filePath), user);
834     candidateManager.process(vspId, VERSION01, user);
835   }
836
837   private void checkinSubmitCreatePackage(String vspId, String user) throws IOException {
838     vendorSoftwareProductManager.checkin(vspId, user);
839     ValidationResponse submitResponse = vendorSoftwareProductManager.submit(vspId, user);
840     Assert.assertTrue(submitResponse.isValid());
841     vendorSoftwareProductManager.createPackage(vspId, VERSION10, user);
842   }
843
844   // TODO: 3/15/2017 fix and enable
845 /*
846
847   public void testUpdatedVSPShouldBeInBeginningOfList() {
848     vendorSoftwareProductManager.updateVsp(new VspDetails(), USER3);
849     assertVSPInWantedLocationInVSPList(id006, 0, USER3);
850
851     InputStream zis = getFileInputStream("/vspmanager/zips/fullComposition.zip");
852     candidateManager.upload(id007, VERSION01, zis, USER3);
853     candidateManager.process(id007, VERSION01, USER3);
854     assertVSPInWantedLocationInVSPList(id007, 0, USER3);
855   }
856
857   @Test(dependsOnMethods = {"testUpdatedVSPShouldBeInBeginningOfList"})
858   public void testVSPInBeginningOfListAfterCheckin() {
859     vendorSoftwareProductManager.checkin(id006, USER3);
860     assertVSPInWantedLocationInVSPList(id006, 0, USER3);
861
862     vendorSoftwareProductManager.checkin(id007, USER3);
863     assertVSPInWantedLocationInVSPList(id007, 0, USER3);
864   }
865
866   @Test(dependsOnMethods = {"testVSPInBeginningOfListAfterCheckin"})
867   public void testVSPInBeginningOfListAfterCheckout() {
868     vendorSoftwareProductManager.checkout(id006, USER3);
869     assertVSPInWantedLocationInVSPList(id006, 0, USER3);
870   }
871
872   @Test(dependsOnMethods = {"testVSPInBeginningOfListAfterCheckout"})
873   public void testVSPInBeginningOfListAfterUndoCheckout() {
874     vendorSoftwareProductManager.checkout(id007, USER3);
875     assertVSPInWantedLocationInVSPList(id007, 0, USER3);
876
877     vendorSoftwareProductManager.undoCheckout(id006, USER3);
878     assertVSPInWantedLocationInVSPList(id006, 0, USER3);
879   }
880
881   @Test(dependsOnMethods = {"testVSPInBeginningOfListAfterUndoCheckout"})
882   public void testVSPInBeginningOfListAfterSubmit() throws IOException {
883     vendorSoftwareProductManager.checkin(id007, USER3);
884     vendorSoftwareProductManager.submit(id007, USER3);
885
886     assertVSPInWantedLocationInVSPList(id007, 0, USER3);
887   }
888 */
889
890   private void testLegalUpload(String vspId, Version version, InputStream upload, String user) {
891     candidateManager.upload(vspId, VERSION01, upload, USER1);
892     candidateManager.process(vspId, VERSION01, user);
893
894     UploadDataEntity uploadData =
895         orchestrationTemplateDataDaoMock.getOrchestrationTemplate(vspId, version);
896     Assert.assertNotNull(uploadData);
897   }
898
899   private void addCapability(String entryValueKey, Map<String, CapabilityDefinition> capabilities,
900                              String key, CapabilityDefinition value) {
901
902     capabilities.put(entryValueKey + "_" + key, value);
903   }
904
905   public InputStream getFileInputStream(String fileName) {
906     URL url = this.getClass().getResource(fileName);
907     try {
908       return url.openStream();
909     } catch (IOException exception) {
910       exception.printStackTrace();
911       return null;
912     }
913   }
914
915   private void assertVSPInWantedLocationInVSPList(String vspId, int location, String user) {
916     List<VersionedVendorSoftwareProductInfo> vspList =
917         vendorSoftwareProductManager.listVsps(null, user);
918     Assert.assertEquals(vspList.get(location).getVspDetails().getId(), vspId);
919   }
920
921
922   //  private void assertInfoArtifactIsInRightPathInCsar(String vspId, String zipFileName)
923 //      throws IOException {
924 //    ZipInputStream inputZipStream = new ZipInputStream(new FileInputStream(new File(zipFileName)));
925 //    boolean isInfoArtifactInZip = false;
926 //
927 //    ZipEntry zipEntry;
928 //    while ((zipEntry = inputZipStream.getNextEntry()) != null) {
929 //      String currentEntryName = zipEntry.getName();
930 //      if(currentEntryName.equals("Artifacts\\Informative\\Guide\\VSP_" +
931 //          vspId + "_Information.txt")){
932 //        isInfoArtifactInZip = true;
933 //        break;
934 //      }
935 //    }
936 //
937 //    Assert.assertTrue(isInfoArtifactInZip);
938 //  }
939   static VspDetails createVspDetails(String id, Version version, String name, String desc,
940                                      String vendorName, String vlm, String icon,
941                                      String category, String subCategory,
942                                      String licenseAgreement, List<String> featureGroups) {
943     VspDetails vspDetails = new VspDetails(id, version);
944     vspDetails.setName(name);
945     vspDetails.setDescription(desc);
946     vspDetails.setIcon(icon);
947     vspDetails.setCategory(category);
948     vspDetails.setSubCategory(subCategory);
949     vspDetails.setVendorName(vendorName);
950     vspDetails.setVendorId(vlm);
951     vspDetails.setVlmVersion(new Version(1, 0));
952     vspDetails.setLicenseAgreement(licenseAgreement);
953     vspDetails.setFeatureGroups(featureGroups);
954     vspDetails.setOnboardingMethod("HEAT");
955     return vspDetails;
956   }
957
958   static void assertVspsEquals(VspDetails actual, VspDetails expected) {
959     Assert.assertEquals(actual.getId(), expected.getId());
960     Assert.assertEquals(actual.getVersion(), expected.getVersion());
961     Assert.assertEquals(actual.getName(), expected.getName());
962     Assert.assertEquals(actual.getDescription(), expected.getDescription());
963     Assert.assertEquals(actual.getIcon(), expected.getIcon());
964     Assert.assertEquals(actual.getCategory(), expected.getCategory());
965     Assert.assertEquals(actual.getSubCategory(), expected.getSubCategory());
966     Assert.assertEquals(actual.getVendorName(), expected.getVendorName());
967     Assert.assertEquals(actual.getVendorId(), expected.getVendorId());
968     Assert.assertEquals(actual.getLicenseAgreement(), expected.getLicenseAgreement());
969     Assert.assertEquals(actual.getFeatureGroups(), expected.getFeatureGroups());
970   }
971
972
973 //    @Test
974 //    public void testDownloadFile() throws IOException {
975 //        VspDetails expectedVsp = VSPCommon.createVspDetails(null, null, String.format("VSP-test-%s", vlm1Id), "Test-vsp", "vendorName", "vlm1Id", "icon", "category", "subCategory", "123", null);
976 //        VspDetails createdVsp = vendorSoftwareProductManager.createVsp(expectedVsp, USER1);
977 //
978 //        id005 = createdVsp.getId();
979 //        Assert.assertNotNull(id005);
980 //        Assert.assertNotNull(createdVsp.getVersion());
981 //
982 //        try (InputStream zipInputStream = new ZipFileUtils().getZipInputStream("/legalUploadWithWarning")) {
983 //
984 //            UploadFileResponse uploadFileResponse = vendorSoftwareProductManager.upload(id005, zipInputStream, USER1);
985 //            vendorSoftwareProductManager.process(id005, USER1);
986 //            Optional<File> fileCandidate = vendorSoftwareProductManager.get(id005, USER1);
987 //
988 //            File latestHeatPackage = fileCandidate.get();
989 //
990 //            zipInputStream.reset();
991 //            byte[] uploaded = IOUtils.toByteArray(zipInputStream);
992 //
993 //            Optional<FileContentHandler> zipContentMap = vendorSoftwareProductManager.getZipContentMap(uploadFileResponse, uploaded);
994 //            FileContentHandler fileContentHandler = new FileContentHandler();
995 //            if(zipContentMap.isPresent()){
996 //                 fileContentHandler = zipContentMap.get();
997 //            }
998 //
999 //            uploaded = IOUtils.toByteArray(fileContentHandler.getFiles().values());
1000 //
1001 //            byte[] downloaded;
1002 //            try (BufferedInputStream fileStream = new BufferedInputStream(new FileInputStream(latestHeatPackage))) {
1003 //                downloaded = IOUtils.toByteArray(fileStream);
1004 //            }
1005 //
1006 //            Assert.assertTrue(Arrays.equals(uploaded, downloaded));
1007 //        }
1008 //    }
1009
1010   // todo ********************** move to common **************************************
1011
1012   private void mockVersioning(VersionableEntityAction action) {
1013     VersionInfo versionInfo = new VersionInfo();
1014     versionInfo.setActiveVersion(VERSION01);
1015     doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
1016         VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
1017         action);
1018   }
1019
1020   private void mockVersioningEntityNotExist(VersionableEntityAction action, String vspId) {
1021     doThrow(new CoreException(new EntityNotExistErrorBuilder(
1022         VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, vspId).build()))
1023         .when(versioningManagerMock).getEntityVersionInfo(
1024         VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, vspId, USER1,
1025         action);
1026   }
1027
1028   private void MockVersioningEntityLocked(VersionableEntityAction action) {
1029     doThrow(new CoreException(new EditOnEntityLockedByOtherErrorBuilder(
1030         VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1)
1031         .build()))
1032         .when(versioningManagerMock).getEntityVersionInfo(
1033         VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER2,
1034         action);
1035   }
1036 }