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