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