2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.vendorsoftwareproduct.impl;
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.healing.api.HealingManager;
43 import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
44 import org.openecomp.sdc.tosca.datatypes.model.CapabilityDefinition;
45 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
46 import org.openecomp.sdc.vendorlicense.licenseartifacts.VendorLicenseArtifactsService;
47 import org.openecomp.sdc.vendorsoftwareproduct.ManualVspToscaManager;
48 import org.openecomp.sdc.vendorsoftwareproduct.MonitoringUploadsManager;
49 import org.openecomp.sdc.vendorsoftwareproduct.OrchestrationTemplateCandidateManager;
50 import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants;
51 import org.openecomp.sdc.vendorsoftwareproduct.dao.DeploymentFlavorDao;
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.DeploymentFlavorEntity;
57 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.PackageInfo;
58 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.UploadDataEntity;
59 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
60 import org.openecomp.sdc.vendorsoftwareproduct.impl.mock.EnrichmentManagerFactoryImpl;
61 import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.InformationArtifactGenerator;
62 import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager;
63 import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
64 import org.openecomp.sdc.vendorsoftwareproduct.types.ValidationResponse;
65 import org.openecomp.sdc.vendorsoftwareproduct.types.VersionedVendorSoftwareProductInfo;
66 import org.openecomp.sdc.vendorsoftwareproduct.types.composition.DeploymentFlavor;
67 import org.openecomp.sdc.versioning.VersioningManager;
68 import org.openecomp.sdc.versioning.dao.types.Version;
69 import org.openecomp.sdc.versioning.dao.types.VersionStatus;
70 import org.openecomp.sdc.versioning.errors.EditOnEntityLockedByOtherErrorBuilder;
71 import org.openecomp.sdc.versioning.errors.EntityNotExistErrorBuilder;
72 import org.openecomp.sdc.versioning.types.VersionInfo;
73 import org.openecomp.sdc.versioning.types.VersionableEntityAction;
74 import org.testng.Assert;
75 import org.testng.annotations.BeforeMethod;
76 import org.testng.annotations.Test;
79 import java.io.FileInputStream;
80 import java.io.IOException;
81 import java.io.InputStream;
83 import java.nio.ByteBuffer;
84 import java.util.ArrayList;
85 import java.util.Arrays;
86 import java.util.Collections;
87 import java.util.HashMap;
88 import java.util.List;
90 import java.util.zip.ZipEntry;
91 import java.util.zip.ZipInputStream;
93 import static org.mockito.Matchers.any;
94 import static org.mockito.Matchers.anyObject;
95 import static org.mockito.Matchers.eq;
96 import static org.mockito.Mockito.doNothing;
97 import static org.mockito.Mockito.doReturn;
98 import static org.mockito.Mockito.doThrow;
99 import static org.mockito.Mockito.never;
100 import static org.mockito.Mockito.verify;
103 public class VendorSoftwareProductManagerImplTest {
104 private static final String INVALID_VERSION_MSG = "Invalid requested version.";
106 private static String VSP_ID = "vspId";
107 private static String VERSION_ID = "versionId";
108 public static final Version VERSION01 = new Version(0, 1);
109 private static final Version VERSION10 = new Version(1, 0);
110 private static final String USER1 = "vspTestUser1";
111 private static final String USER2 = "vspTestUser2";
112 private static final String USER3 = "vspTestUser3";
113 private static String id006 = null;
114 private static String id007 = null;
117 private VersioningManager versioningManagerMock;
119 private VendorSoftwareProductDao vendorSoftwareProductDaoMock; // todo get rid of
121 private OrchestrationTemplateDao orchestrationTemplateDataDaoMock;
123 private VendorLicenseFacade vendorLicenseFacadeMock;
125 private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDaoMock;
127 private EnrichedServiceModelDao<ToscaServiceModel, ServiceElement> enrichedServiceModelDaoMock;
129 private HealingManager healingManagerMock;
131 private VendorLicenseArtifactsService licenseArtifactsServiceMock;
133 private CompositionEntityDataManager compositionEntityDataManagerMock;
135 private InformationArtifactGenerator informationArtifactGeneratorMock;
137 private ActivityLogManager activityLogManagerMock;
139 private PackageInfoDao packageInfoDao;
141 private VendorSoftwareProductInfoDao vspInfoDaoMock;
143 private ManualVspToscaManager manualVspToscaManager;
145 private DeploymentFlavorDao deploymentFlavorDaoMock;
150 private VendorSoftwareProductManagerImpl vendorSoftwareProductManager;
152 private OrchestrationTemplateCandidateManager candidateManager;
153 private MonitoringUploadsManager monitoringUploadsManager;
156 private ArgumentCaptor<ActivityLogEntity> activityLogEntityArg;
159 public void setUp() throws Exception {
160 MockitoAnnotations.initMocks(this);
164 public void testListWhenNone() {
165 doReturn(new HashMap<>()).when(versioningManagerMock).listEntitiesVersionInfo
166 (VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, USER1,
167 VersionableEntityAction.Read);
168 List<VersionedVendorSoftwareProductInfo> vsps =
169 vendorSoftwareProductManager.listVsps(null, USER1);
170 Assert.assertEquals(vsps.size(), 0);
174 public void testList() {
175 String vsp1id = "vsp1_id";
176 String vsp2id = "vsp2_id";
177 Map<String, VersionInfo> vspsTobeReturned = new HashMap<>();
179 VersionInfo versionInfo1 = new VersionInfo();
180 versionInfo1.setActiveVersion(VERSION01);
181 vspsTobeReturned.put(vsp1id, versionInfo1);
183 VersionInfo versionInfo2 = new VersionInfo();
184 versionInfo2.setActiveVersion(VERSION10);
185 vspsTobeReturned.put(vsp2id, versionInfo2);
187 doReturn(vspsTobeReturned).when(versioningManagerMock).listEntitiesVersionInfo
188 (VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, USER1,
189 VersionableEntityAction.Read);
191 VspDetails vsp1 = new VspDetails(vsp1id, VERSION01);
192 vsp1.setWritetimeMicroSeconds(8L);
193 doReturn(vsp1).when(vspInfoDaoMock)
194 .get(any(VspDetails.class));
196 List<VersionedVendorSoftwareProductInfo> vsps =
197 vendorSoftwareProductManager.listVsps(null, USER1);
198 Assert.assertEquals(vsps.size(), 2);
202 public void testListFinalsWhenNone() {
203 String vsp1id = "vsp1_id";
204 String vsp2id = "vsp2_id";
205 Map<String, VersionInfo> vspsTobeReturned = new HashMap<>();
207 VersionInfo versionInfo1 = new VersionInfo();
208 versionInfo1.setActiveVersion(VERSION01);
209 vspsTobeReturned.put(vsp1id, versionInfo1);
211 VersionInfo versionInfo2 = new VersionInfo();
212 versionInfo2.setActiveVersion(VERSION10);
213 vspsTobeReturned.put(vsp2id, versionInfo2);
215 doReturn(vspsTobeReturned).when(versioningManagerMock).listEntitiesVersionInfo
216 (VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, USER1,
217 VersionableEntityAction.Read);
219 List<VersionedVendorSoftwareProductInfo> vsps =
220 vendorSoftwareProductManager.listVsps(VersionStatus.Final.name(), USER1);
221 Assert.assertEquals(vsps.size(), 0);
225 public void testListFinals() {
226 String vsp1id = "vsp1_id";
227 String vsp2id = "vsp2_id";
228 Map<String, VersionInfo> vspsTobeReturned = new HashMap<>();
230 VersionInfo versionInfo1 = new VersionInfo();
231 versionInfo1.setActiveVersion(VERSION01);
232 vspsTobeReturned.put(vsp1id, versionInfo1);
234 VersionInfo versionInfo2 = new VersionInfo();
235 versionInfo2.setActiveVersion(new Version(1, 3));
236 versionInfo2.setLatestFinalVersion(VERSION10);
237 vspsTobeReturned.put(vsp2id, versionInfo2);
239 doReturn(vspsTobeReturned).when(versioningManagerMock).listEntitiesVersionInfo
240 (VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, USER1,
241 VersionableEntityAction.Read);
243 VspDetails vsp2 = new VspDetails(vsp2id, VERSION10);
244 vsp2.setWritetimeMicroSeconds(8L);
245 doReturn(vsp2).when(vspInfoDaoMock)
246 .get(any(VspDetails.class));
248 List<VersionedVendorSoftwareProductInfo> vsps =
249 vendorSoftwareProductManager.listVsps(VersionStatus.Final.name(), USER1);
250 Assert.assertEquals(vsps.size(), 1);
253 @Test(expectedExceptions = CoreException.class)
254 public void testCreateWithExistingName_negative() {
255 doThrow(new CoreException(
256 new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION).build()))
257 .when(vendorSoftwareProductManager).validateUniqueName("Vsp1");
258 VspDetails expectedVsp =
259 createVspDetails(null, null, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
260 "category", "subCategory", "123", null);
262 vendorSoftwareProductManager.createVsp(expectedVsp, USER1);
266 public void testCreate() {
267 doNothing().when(vendorSoftwareProductManager).validateUniqueName("Vsp1");
268 doNothing().when(vendorSoftwareProductManager).createUniqueName("Vsp1");
269 doReturn(VERSION01).when(versioningManagerMock).create(anyObject(), anyObject(), anyObject());
271 .when(vendorSoftwareProductManager).getVspQuestionnaireSchema(anyObject());
273 VspDetails vspToCreate =
274 createVspDetails(null, null, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
275 "category", "subCategory", "123", null);
277 VspDetails vsp = vendorSoftwareProductManager.createVsp(vspToCreate, USER1);
279 Assert.assertNotNull(vsp);
280 vspToCreate.setId(vsp.getId());
281 vspToCreate.setVersion(VERSION01);
282 assertVspsEquals(vsp, vspToCreate);
283 verify(activityLogManagerMock).addActionLog(activityLogEntityArg.capture(), eq(USER1));
284 ActivityLogEntity activityLogEntity = activityLogEntityArg.getValue();
285 Assert.assertEquals(activityLogEntity.getVersionId(), String.valueOf(VERSION01.getMajor() + 1));
286 Assert.assertTrue(activityLogEntity.isSuccess());
289 @Test(expectedExceptions = CoreException.class)
290 public void testUpdateWithExistingName_negative() {
291 VersionInfo versionInfo = new VersionInfo();
292 versionInfo.setActiveVersion(VERSION01);
293 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
294 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
295 VersionableEntityAction.Write);
297 VspDetails existingVsp =
298 createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-existingVsp", "vendorName", "vlm1Id",
299 "icon", "category", "subCategory", "123", null);
300 VspDetails updatedVsp =
301 createVspDetails(VSP_ID, VERSION01, "Vsp1_updated", "Test-existingVsp", "vendorName",
302 "vlm1Id", "icon", "category", "subCategory", "123", null);
303 doReturn(existingVsp).when(vspInfoDaoMock)
304 .get(any(VspDetails.class));
305 doThrow(new CoreException(
306 new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION).build()))
307 .when(vendorSoftwareProductManager)
308 .updateUniqueName(existingVsp.getName(), updatedVsp.getName());
310 vendorSoftwareProductManager.updateVsp(updatedVsp, USER1);
314 public void testUpdate() {
315 VersionInfo versionInfo = new VersionInfo();
316 versionInfo.setActiveVersion(VERSION01);
317 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
318 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
319 VersionableEntityAction.Write);
320 VspDetails existingVsp =
321 createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
323 "subCategory", "456", null);
324 VspDetails updatedVsp =
325 createVspDetails(VSP_ID, VERSION01, "VSP1_updated", null, "vendorName", "vlm1Id", "icon",
327 "subCategory", "456", null);
328 existingVsp.setWritetimeMicroSeconds(8L);
329 doReturn(existingVsp).when(vspInfoDaoMock)
330 .get(any(VspDetails.class));
331 doNothing().when(vendorSoftwareProductManager)
332 .updateUniqueName(existingVsp.getName(), updatedVsp.getName());
334 vendorSoftwareProductManager.updateVsp(updatedVsp, USER1);
336 verify(vspInfoDaoMock).update(updatedVsp);
340 public void testUpdateRemoveFG() {
341 VersionInfo versionInfo = new VersionInfo();
342 versionInfo.setActiveVersion(VERSION01);
343 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
344 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
345 VersionableEntityAction.Write);
346 List<String> fgs = new ArrayList<String>();
347 fgs.add("fg1"); fgs.add("fg2");
348 VspDetails existingVsp =
349 createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
351 "subCategory", "456", fgs);
353 List<String> updFgs = new ArrayList<String>();
355 VspDetails updatedVsp =
356 createVspDetails(VSP_ID, VERSION01, "VSP1_updated", null, "vendorName", "vlm1Id", "icon",
358 "subCategory", "456", updFgs);
359 existingVsp.setWritetimeMicroSeconds(8L);
360 doReturn(existingVsp).when(vspInfoDaoMock)
361 .get(any(VspDetails.class));
362 doNothing().when(vendorSoftwareProductManager)
363 .updateUniqueName(existingVsp.getName(), updatedVsp.getName());
365 DeploymentFlavorEntity dfEntity = new DeploymentFlavorEntity(VSP_ID,VERSION01,"DF_ID");
366 DeploymentFlavor flavor = new DeploymentFlavor();
367 flavor.setFeatureGroupId("fg1");
368 dfEntity.setDeploymentFlavorCompositionData(flavor);
370 List<DeploymentFlavorEntity> dfList = new ArrayList<DeploymentFlavorEntity>();
371 dfList.add(dfEntity);
373 doReturn(dfList).when(deploymentFlavorDaoMock).list(anyObject());
375 vendorSoftwareProductManager.updateVsp(updatedVsp, USER1);
377 verify(vendorSoftwareProductDaoMock).updateDeploymentFlavor(dfEntity);
379 Assert.assertNull(dfEntity.getDeploymentFlavorCompositionData().getFeatureGroupId());
383 @Test(expectedExceptions = CoreException.class)
384 public void testGetNonExistingVersion_negative() {
385 Version notExistversion = new Version(43, 8);
386 doReturn(null).when(vspInfoDaoMock).get(any(VspDetails.class));
387 vendorSoftwareProductManager.getVsp(VSP_ID, notExistversion, USER1);
391 public void testGetCheckedOutVersion() {
392 VersionInfo versionInfo = new VersionInfo();
393 versionInfo.setActiveVersion(VERSION01);
394 versionInfo.setStatus(VersionStatus.Locked);
395 versionInfo.setLockingUser(USER1);
396 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
397 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
398 VersionableEntityAction.Read);
400 VspDetails existingVsp =
401 createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
403 "subCategory", "456", null);
404 existingVsp.setWritetimeMicroSeconds(8L);
405 doReturn(existingVsp).when(vspInfoDaoMock).get(any(VspDetails.class));
407 VspDetails actualVsp =
408 vendorSoftwareProductManager.getVsp(VSP_ID, VERSION01, USER1);
410 assertVspsEquals(actualVsp, existingVsp);
414 public void testGetOldVersion() {
415 VersionInfo versionInfo = new VersionInfo();
416 versionInfo.setActiveVersion(new Version(0, 2));
417 versionInfo.setViewableVersions(Arrays.asList(VERSION01, new Version(0, 2)));
418 versionInfo.setStatus(VersionStatus.Locked);
419 versionInfo.setLockingUser(USER2);
420 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
421 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
422 VersionableEntityAction.Read);
424 VspDetails existingVsp =
425 createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
427 "subCategory", "456", null);
428 existingVsp.setWritetimeMicroSeconds(8L);
429 doReturn(existingVsp)
430 .when(vspInfoDaoMock).get(any(VspDetails.class));
432 VspDetails actualVsp =
433 vendorSoftwareProductManager.getVsp(VSP_ID, VERSION01, USER1);
435 VspDetails expectedVsp =
437 .get(new VspDetails(VSP_ID, VERSION01));
438 assertVspsEquals(actualVsp, expectedVsp);
442 public void testCheckin() {
443 doReturn(VERSION01).when(versioningManagerMock)
444 .checkin(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
446 Version version = vendorSoftwareProductManager.checkin(VSP_ID, USER1);
448 Assert.assertEquals(version, VERSION01);
449 verify(versioningManagerMock)
450 .checkin(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
452 verify(activityLogManagerMock).addActionLog(activityLogEntityArg.capture(), eq(USER1));
453 ActivityLogEntity activityLogEntity = activityLogEntityArg.getValue();
454 Assert.assertEquals(activityLogEntity.getVersionId(), String.valueOf(VERSION01.getMajor() + 1));
455 Assert.assertTrue(activityLogEntity.isSuccess());
459 public void testCheckout() {
460 doReturn(VERSION01).when(versioningManagerMock)
461 .checkout(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
463 Version version = vendorSoftwareProductManager.checkout(VSP_ID, USER1);
465 Assert.assertEquals(version, VERSION01);
466 verify(versioningManagerMock)
467 .checkout(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
470 verify(activityLogManagerMock).addActionLog(activityLogEntityArg.capture(), eq(USER1));
471 ActivityLogEntity activityLogEntity = activityLogEntityArg.getValue();
472 Assert.assertEquals(activityLogEntity.getVersionId(), String.valueOf(VERSION01.getMajor() + 1));
473 Assert.assertTrue(activityLogEntity.isSuccess());
478 public void testUndoCheckout() {
479 Version existingVersion = new Version(0, 2);
480 VersionInfo versionInfo = new VersionInfo();
481 versionInfo.setActiveVersion(existingVersion);
482 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
483 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE,
484 VSP_ID, USER1, VersionableEntityAction.Read);
486 doReturn(VERSION01).when(versioningManagerMock).undoCheckout(VendorSoftwareProductConstants
487 .VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1);
489 VspDetails vsp = new VspDetails(VSP_ID, existingVersion);
490 vsp.setName("ExistingName");
491 doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
492 doNothing().when(vendorSoftwareProductManager).updateUniqueName(vsp.getName(), vsp.getName());
494 Version undoCheckoutVersion = vendorSoftwareProductManager.undoCheckout(VSP_ID, USER1);
496 Assert.assertEquals(undoCheckoutVersion, VERSION01);
501 public void testSubmitWithMissingData() throws IOException {
502 VersionInfo versionInfo = new VersionInfo();
503 versionInfo.setActiveVersion(VERSION01);
505 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
506 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE,
507 VSP_ID, USER1, VersionableEntityAction.Read);
509 VspDetails vsp = new VspDetails(VSP_ID, VERSION01);
510 vsp.setOnboardingMethod("Manual");
511 doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
513 VspQuestionnaireEntity vspQuestionnaire = new VspQuestionnaireEntity(VSP_ID, VERSION01);
514 vspQuestionnaire.setQuestionnaireData("{}");
515 doReturn(vspQuestionnaire).when(vspInfoDaoMock).getQuestionnaire(VSP_ID, VERSION01);
517 ComponentEntity comp1 = new ComponentEntity(VSP_ID, VERSION01, "comp1");
518 comp1.setQuestionnaireData("{}");
519 doReturn(Collections.singleton(comp1)).when(vendorSoftwareProductDaoMock)
520 .listComponentsCompositionAndQuestionnaire(VSP_ID, VERSION01);
522 NicEntity nic1 = new NicEntity(VSP_ID, VERSION01, "comp1", "nic1");
523 nic1.setQuestionnaireData("{}");
524 doReturn(Collections.singleton(nic1))
525 .when(vendorSoftwareProductDaoMock).listNicsByVsp(VSP_ID, VERSION01);
527 ValidationResponse validationResponse = vendorSoftwareProductManager.submit(VSP_ID, USER1);
528 Assert.assertNotNull(validationResponse);
529 Assert.assertFalse(validationResponse.isValid());
530 List<String> errorIds = validationResponse.getVspErrors().stream().map(ErrorCode::id).distinct()
531 .collect(Collectors.toList());
532 Assert.assertTrue(errorIds.contains(ValidationErrorBuilder.FIELD_VALIDATION_ERROR_ERR_ID));
533 Assert.assertTrue(errorIds.contains(VendorSoftwareProductErrorCodes.VSP_INVALID));
535 verify(versioningManagerMock, never())
536 .submit(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
538 verify(activityLogManagerMock, never()).addActionLog(any(ActivityLogEntity.class), eq(USER1));
543 // TODO: 3/15/2017 fix and enable
545 public void testSubmitWithInvalidLicensingData() throws IOException {
546 VersionInfo versionInfo = new VersionInfo();
547 versionInfo.setActiveVersion(VERSION01);
548 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
549 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE,
550 VSP_ID, USER1, VersionableEntityAction.Read);
553 createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
554 "category", "subCategory", "licenseAgreementId",
555 Collections.singletonList("featureGroupId"));
556 doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
557 UploadDataEntity uploadData = new UploadDataEntity(VSP_ID, VERSION01);
558 uploadData.setContentData(
559 ByteBuffer.wrap(FileUtils.toByteArray(getFileInputStream("/emptyComposition"))));
560 doReturn(uploadData).when(orchestrationTemplateDataDaoMock)
561 .getOrchestrationTemplate(anyObject(), anyObject());
562 doReturn(new ToscaServiceModel(new FileContentHandler(), new HashMap<>(),
563 "MainServiceTemplate.yaml"))
564 .when(serviceModelDaoMock).getServiceModel(VSP_ID, VERSION01);
566 ValidationResponse validationResponse = vendorSoftwareProductManager.submit(VSP_ID, USER1);
567 Assert.assertNotNull(validationResponse);
568 Assert.assertFalse(validationResponse.isValid());
569 Assert.assertNull(validationResponse.getVspErrors());
570 Assert.assertEquals(validationResponse.getLicensingDataErrors(), 1);
572 verify(versioningManagerMock, never())
573 .submit(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
577 verify(activityLogManagerMock, never()).addActionLog(any(ActivityLogEntity.class), eq(USER1));
580 // TODO: 3/15/2017 fix and enable
582 public void testSubmit() throws IOException {
583 mockVersioning(VersionableEntityAction.Read);
585 EnrichmentManagerFactory.getInstance();
587 .registerFactory(EnrichmentManagerFactory.class, EnrichmentManagerFactoryImpl.class);
590 createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
591 "category", "subCategory", "123", Collections.singletonList("fg1"));
592 doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
593 UploadDataEntity uploadData = new UploadDataEntity(VSP_ID, VERSION01);
594 uploadData.setContentData(
595 ByteBuffer.wrap(FileUtils.toByteArray(getFileInputStream("/emptyComposition"))));
596 doReturn(uploadData).when(orchestrationTemplateDataDaoMock)
597 .getOrchestrationTemplate(anyObject(), anyObject());
598 doReturn(new ToscaServiceModel(new FileContentHandler(), new HashMap<>(),
599 "MainServiceTemplate.yaml"))
600 .when(serviceModelDaoMock).getServiceModel(VSP_ID, VERSION01);
602 ValidationResponse validationResponse = vendorSoftwareProductManager.submit(VSP_ID, USER1);
603 Assert.assertTrue(validationResponse.isValid());
605 /* Assert.assertEquals(vsp2.getVersionInfo().getActiveVersion(), VERSION10);
606 Assert.assertEquals(vsp2.getVersionInfo().getStatus(), VersionStatus.Final);
607 Assert.assertNull(vsp2.getVersionInfo().getLockingUser());*/
609 verify(versioningManagerMock)
610 .submit(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
612 verify(activityLogManagerMock).addActionLog(activityLogEntityArg.capture(), eq(USER1));
613 ActivityLogEntity activityLogEntity = activityLogEntityArg.getValue();
614 Assert.assertEquals(activityLogEntity.getVersionId(), String.valueOf(VERSION10.getMajor()));
615 Assert.assertTrue(activityLogEntity.isSuccess());
618 @Test(expectedExceptions = CoreException.class)
619 public void testCreatePackageOnNonFinalVersion_negative() throws IOException {
620 vendorSoftwareProductManager.createPackage(VSP_ID, VERSION01, USER1);
624 public void testCreatePackage() throws IOException {
625 /*VspDetails vspDetailsMock = new VspDetails("vspId", new Version(1, 0));
626 doReturn(vspDetailsMock).when(vspInfoDaoMock).get(anyObject());*/
627 VersionInfo versionInfo = new VersionInfo();
628 versionInfo.setActiveVersion(VERSION10);
629 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
630 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
631 VersionableEntityAction.Read);
633 doReturn(new ToscaServiceModel(new FileContentHandler(), new HashMap<>(), "")).when
634 (enrichedServiceModelDaoMock).getServiceModel(VSP_ID, VERSION10);
636 VspDetails vsp = new VspDetails(VSP_ID, VERSION10);
637 vsp.setVendorId("vendorId");
638 vsp.setVlmVersion(VERSION10);
639 vsp.setFeatureGroups(Arrays.asList("fg1", "fg2"));
640 doReturn(vsp).when(vspInfoDaoMock).get(any(VspDetails.class));
642 doReturn(new FileContentHandler()).when(licenseArtifactsServiceMock)
643 .createLicenseArtifacts(VSP_ID, vsp.getVendorId(), VERSION10, vsp.getFeatureGroups(),
646 PackageInfo packageInfo = vendorSoftwareProductManager.createPackage(VSP_ID, VERSION10, USER1);
647 Assert.assertNotNull(packageInfo.getVspId());
650 // TODO: 3/15/2017 fix and enable
651 //@Test(dependsOnMethods = {"testListFinals"})
652 public void testUploadFileMissingFile() {
653 InputStream zis = getFileInputStream("/vspmanager/zips/missingYml.zip");
655 UploadFileResponse uploadFileResponse =
656 candidateManager.upload(VSP_ID, VERSION01, zis, USER1, "zip", "missingYml");
658 Assert.assertEquals(uploadFileResponse.getErrors().size(), 0);
661 // TODO: 3/15/2017 fix and enable
662 //@Test(dependsOnMethods = {"testUploadFileMissingFile"})
663 public void testUploadNotZipFile() throws IOException {
664 URL url = this.getClass().getResource("/notZipFile");
668 .upload(VSP_ID, VERSION01,
669 url.openStream(), USER1, "zip", "notZipFile");
670 candidateManager.process(VSP_ID, VERSION01, USER1);
671 } catch (Exception ce) {
672 Assert.assertEquals(ce.getMessage(), Messages.CREATE_MANIFEST_FROM_ZIP.getErrorMessage());
675 verify(activityLogManagerMock, never()).addActionLog(any(ActivityLogEntity.class), eq(USER1));
679 private List<String> getWantedFileNamesFromCsar(String pathInCsar)
681 File translatedFile = vendorSoftwareProductManager.getTranslatedFile(VSP_ID, VERSION10, USER1);
683 return getFileNamesFromFolderInCsar(translatedFile,
687 private List<String> getFileNamesFromFolderInCsar(File csar, String folderName)
689 List<String> fileNames = new ArrayList<>();
691 ZipInputStream zip = new ZipInputStream(new FileInputStream(csar));
694 while ((ze = zip.getNextEntry()) != null) {
695 String name = ze.getName();
696 if (name.contains(folderName)) {
704 private void createPackageFromUpload(String vspId, String user, String filePath)
706 uploadFileAndProcess(vspId, user, filePath);
707 checkinSubmitCreatePackage(vspId, user);
710 private void uploadFileAndProcess(String vspId, String user, String filePath) {
711 vendorSoftwareProductManager.checkout(vspId, user);
712 candidateManager.upload(vspId, VERSION01, getFileInputStream(filePath), user, "zip", "file");
713 candidateManager.process(vspId, VERSION01, user);
716 private void checkinSubmitCreatePackage(String vspId, String user) throws IOException {
717 vendorSoftwareProductManager.checkin(vspId, user);
718 ValidationResponse submitResponse = vendorSoftwareProductManager.submit(vspId, user);
719 Assert.assertTrue(submitResponse.isValid());
720 vendorSoftwareProductManager.createPackage(vspId, VERSION10, user);
723 // TODO: 3/15/2017 fix and enable
726 public void testUpdatedVSPShouldBeInBeginningOfList() {
727 vendorSoftwareProductManager.updateVsp(new VspDetails(), USER3);
728 assertVSPInWantedLocationInVSPList(id006, 0, USER3);
730 InputStream zis = getFileInputStream("/vspmanager/zips/fullComposition.zip");
731 candidateManager.upload(id007, VERSION01, zis, USER3);
732 candidateManager.process(id007, VERSION01, USER3);
733 assertVSPInWantedLocationInVSPList(id007, 0, USER3);
736 @Test(dependsOnMethods = {"testUpdatedVSPShouldBeInBeginningOfList"})
737 public void testVSPInBeginningOfListAfterCheckin() {
738 vendorSoftwareProductManager.checkin(id006, USER3);
739 assertVSPInWantedLocationInVSPList(id006, 0, USER3);
741 vendorSoftwareProductManager.checkin(id007, USER3);
742 assertVSPInWantedLocationInVSPList(id007, 0, USER3);
745 @Test(dependsOnMethods = {"testVSPInBeginningOfListAfterCheckin"})
746 public void testVSPInBeginningOfListAfterCheckout() {
747 vendorSoftwareProductManager.checkout(id006, USER3);
748 assertVSPInWantedLocationInVSPList(id006, 0, USER3);
751 @Test(dependsOnMethods = {"testVSPInBeginningOfListAfterCheckout"})
752 public void testVSPInBeginningOfListAfterUndoCheckout() {
753 vendorSoftwareProductManager.checkout(id007, USER3);
754 assertVSPInWantedLocationInVSPList(id007, 0, USER3);
756 vendorSoftwareProductManager.undoCheckout(id006, USER3);
757 assertVSPInWantedLocationInVSPList(id006, 0, USER3);
760 @Test(dependsOnMethods = {"testVSPInBeginningOfListAfterUndoCheckout"})
761 public void testVSPInBeginningOfListAfterSubmit() throws IOException {
762 vendorSoftwareProductManager.checkin(id007, USER3);
763 vendorSoftwareProductManager.submit(id007, USER3);
765 assertVSPInWantedLocationInVSPList(id007, 0, USER3);
769 private void testLegalUpload(String vspId, Version version, InputStream upload, String user) {
770 candidateManager.upload(vspId, VERSION01, upload, USER1, "zip", "file");
771 candidateManager.process(vspId, VERSION01, user);
773 UploadDataEntity uploadData =
774 orchestrationTemplateDataDaoMock.getOrchestrationTemplate(vspId, version);
775 Assert.assertNotNull(uploadData);
778 private void addCapability(String entryValueKey, Map<String, CapabilityDefinition> capabilities,
779 String key, CapabilityDefinition value) {
781 capabilities.put(entryValueKey + "_" + key, value);
784 public InputStream getFileInputStream(String fileName) {
785 URL url = this.getClass().getResource(fileName);
787 return url.openStream();
788 } catch (IOException exception) {
789 exception.printStackTrace();
794 private void assertVSPInWantedLocationInVSPList(String vspId, int location, String user) {
795 List<VersionedVendorSoftwareProductInfo> vspList =
796 vendorSoftwareProductManager.listVsps(null, user);
797 Assert.assertEquals(vspList.get(location).getVspDetails().getId(), vspId);
801 static VspDetails createVspDetails(String id, Version version, String name, String desc,
802 String vendorName, String vlm, String icon,
803 String category, String subCategory,
804 String licenseAgreement, List<String> featureGroups) {
805 VspDetails vspDetails = new VspDetails(id, version);
806 vspDetails.setName(name);
807 vspDetails.setDescription(desc);
808 vspDetails.setIcon(icon);
809 vspDetails.setCategory(category);
810 vspDetails.setSubCategory(subCategory);
811 vspDetails.setVendorName(vendorName);
812 vspDetails.setVendorId(vlm);
813 vspDetails.setVlmVersion(new Version(1, 0));
814 vspDetails.setLicenseAgreement(licenseAgreement);
815 vspDetails.setFeatureGroups(featureGroups);
816 vspDetails.setOnboardingMethod("HEAT");
820 static void assertVspsEquals(VspDetails actual, VspDetails expected) {
821 Assert.assertEquals(actual.getId(), expected.getId());
822 Assert.assertEquals(actual.getVersion(), expected.getVersion());
823 Assert.assertEquals(actual.getName(), expected.getName());
824 Assert.assertEquals(actual.getDescription(), expected.getDescription());
825 Assert.assertEquals(actual.getIcon(), expected.getIcon());
826 Assert.assertEquals(actual.getCategory(), expected.getCategory());
827 Assert.assertEquals(actual.getSubCategory(), expected.getSubCategory());
828 Assert.assertEquals(actual.getVendorName(), expected.getVendorName());
829 Assert.assertEquals(actual.getVendorId(), expected.getVendorId());
830 Assert.assertEquals(actual.getLicenseAgreement(), expected.getLicenseAgreement());
831 Assert.assertEquals(actual.getFeatureGroups(), expected.getFeatureGroups());
834 // todo ********************** move to common **************************************
836 private void mockVersioning(VersionableEntityAction action) {
837 VersionInfo versionInfo = new VersionInfo();
838 versionInfo.setActiveVersion(VERSION01);
839 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
840 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1,
844 private void mockVersioningEntityNotExist(VersionableEntityAction action, String vspId) {
845 doThrow(new CoreException(new EntityNotExistErrorBuilder(
846 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, vspId).build()))
847 .when(versioningManagerMock).getEntityVersionInfo(
848 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, vspId, USER1,
852 private void MockVersioningEntityLocked(VersionableEntityAction action) {
853 doThrow(new CoreException(new EditOnEntityLockedByOtherErrorBuilder(
854 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1)
856 .when(versioningManagerMock).getEntityVersionInfo(
857 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER2,