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.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;
81 import java.io.FileInputStream;
82 import java.io.IOException;
83 import java.io.InputStream;
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;
92 import java.util.stream.Collectors;
93 import java.util.zip.ZipEntry;
94 import java.util.zip.ZipInputStream;
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;
106 public class VendorSoftwareProductManagerImplTest {
107 private static final String INVALID_VERSION_MSG = "Invalid requested version.";
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;
120 private VersioningManager versioningManagerMock;
122 private VendorSoftwareProductDao vendorSoftwareProductDaoMock; // todo get rid of
124 private OrchestrationTemplateDao orchestrationTemplateDataDaoMock;
126 private VendorLicenseFacade vendorLicenseFacadeMock;
128 private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDaoMock;
130 private EnrichedServiceModelDao<ToscaServiceModel, ServiceElement> enrichedServiceModelDaoMock;
132 private HealingManager healingManagerMock;
134 private VendorLicenseArtifactsService licenseArtifactsServiceMock;
136 private CompositionEntityDataManager compositionEntityDataManagerMock;
138 private InformationArtifactGenerator informationArtifactGeneratorMock;
140 private ActivityLogManager activityLogManagerMock;
142 private PackageInfoDao packageInfoDao;
144 private VendorSoftwareProductInfoDao vspInfoDaoMock;
146 private ManualVspToscaManager manualVspToscaManager;
151 private VendorSoftwareProductManagerImpl vendorSoftwareProductManager;
153 private OrchestrationTemplateCandidateManager candidateManager;
154 private MonitoringUploadsManager monitoringUploadsManager;
157 private ArgumentCaptor<ActivityLogEntity> activityLogEntityArg;
160 public void setUp() throws Exception {
161 MockitoAnnotations.initMocks(this);
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);
175 public void testList() {
176 String vsp1id = "vsp1_id";
177 String vsp2id = "vsp2_id";
178 Map<String, VersionInfo> vspsTobeReturned = new HashMap<>();
180 VersionInfo versionInfo1 = new VersionInfo();
181 versionInfo1.setActiveVersion(VERSION01);
182 vspsTobeReturned.put(vsp1id, versionInfo1);
184 VersionInfo versionInfo2 = new VersionInfo();
185 versionInfo2.setActiveVersion(VERSION10);
186 vspsTobeReturned.put(vsp2id, versionInfo2);
188 doReturn(vspsTobeReturned).when(versioningManagerMock).listEntitiesVersionInfo
189 (VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, USER1,
190 VersionableEntityAction.Read);
192 VspDetails vsp1 = new VspDetails(vsp1id, VERSION01);
193 vsp1.setWritetimeMicroSeconds(8L);
194 doReturn(vsp1).when(vspInfoDaoMock)
195 .get(any(VspDetails.class));
197 List<VersionedVendorSoftwareProductInfo> vsps =
198 vendorSoftwareProductManager.listVsps(null, USER1);
199 Assert.assertEquals(vsps.size(), 2);
203 public void testListFinalsWhenNone() {
204 String vsp1id = "vsp1_id";
205 String vsp2id = "vsp2_id";
206 Map<String, VersionInfo> vspsTobeReturned = new HashMap<>();
208 VersionInfo versionInfo1 = new VersionInfo();
209 versionInfo1.setActiveVersion(VERSION01);
210 vspsTobeReturned.put(vsp1id, versionInfo1);
212 VersionInfo versionInfo2 = new VersionInfo();
213 versionInfo2.setActiveVersion(VERSION10);
214 vspsTobeReturned.put(vsp2id, versionInfo2);
216 doReturn(vspsTobeReturned).when(versioningManagerMock).listEntitiesVersionInfo
217 (VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, USER1,
218 VersionableEntityAction.Read);
220 List<VersionedVendorSoftwareProductInfo> vsps =
221 vendorSoftwareProductManager.listVsps(VersionStatus.Final.name(), USER1);
222 Assert.assertEquals(vsps.size(), 0);
226 public void testListFinals() {
227 String vsp1id = "vsp1_id";
228 String vsp2id = "vsp2_id";
229 Map<String, VersionInfo> vspsTobeReturned = new HashMap<>();
231 VersionInfo versionInfo1 = new VersionInfo();
232 versionInfo1.setActiveVersion(VERSION01);
233 vspsTobeReturned.put(vsp1id, versionInfo1);
235 VersionInfo versionInfo2 = new VersionInfo();
236 versionInfo2.setActiveVersion(new Version(1, 3));
237 versionInfo2.setLatestFinalVersion(VERSION10);
238 vspsTobeReturned.put(vsp2id, versionInfo2);
240 doReturn(vspsTobeReturned).when(versioningManagerMock).listEntitiesVersionInfo
241 (VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, USER1,
242 VersionableEntityAction.Read);
244 VspDetails vsp2 = new VspDetails(vsp2id, VERSION10);
245 vsp2.setWritetimeMicroSeconds(8L);
246 doReturn(vsp2).when(vspInfoDaoMock)
247 .get(any(VspDetails.class));
249 List<VersionedVendorSoftwareProductInfo> vsps =
250 vendorSoftwareProductManager.listVsps(VersionStatus.Final.name(), USER1);
251 Assert.assertEquals(vsps.size(), 1);
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);
263 vendorSoftwareProductManager.createVsp(expectedVsp, USER1);
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());
272 .when(vendorSoftwareProductManager).getVspQuestionnaireSchema(anyObject());
274 VspDetails vspToCreate =
275 createVspDetails(null, null, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
276 "category", "subCategory", "123", null);
278 VspDetails vsp = vendorSoftwareProductManager.createVsp(vspToCreate, USER1);
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());
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);
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());
311 vendorSoftwareProductManager.updateVsp(updatedVsp, USER1);
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",
324 "subCategory", "456", null);
325 VspDetails updatedVsp =
326 createVspDetails(VSP_ID, VERSION01, "VSP1_updated", null, "vendorName", "vlm1Id", "icon",
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());
335 vendorSoftwareProductManager.updateVsp(updatedVsp, USER1);
337 verify(vspInfoDaoMock).update(updatedVsp);
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);
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);
357 VspDetails existingVsp =
358 createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
360 "subCategory", "456", null);
361 existingVsp.setWritetimeMicroSeconds(8L);
362 doReturn(existingVsp).when(vspInfoDaoMock).get(any(VspDetails.class));
364 VspDetails actualVsp =
365 vendorSoftwareProductManager.getVsp(VSP_ID, VERSION01, USER1);
367 assertVspsEquals(actualVsp, existingVsp);
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);
381 VspDetails existingVsp =
382 createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
384 "subCategory", "456", null);
385 existingVsp.setWritetimeMicroSeconds(8L);
386 doReturn(existingVsp)
387 .when(vspInfoDaoMock).get(any(VspDetails.class));
389 VspDetails actualVsp =
390 vendorSoftwareProductManager.getVsp(VSP_ID, VERSION01, USER1);
392 VspDetails expectedVsp =
394 .get(new VspDetails(VSP_ID, VERSION01));
395 assertVspsEquals(actualVsp, expectedVsp);
399 public void testCheckin() {
400 doReturn(VERSION01).when(versioningManagerMock)
401 .checkin(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
403 Version version = vendorSoftwareProductManager.checkin(VSP_ID, USER1);
405 Assert.assertEquals(version, VERSION01);
406 verify(versioningManagerMock)
407 .checkin(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
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());
416 public void testCheckout() {
417 doReturn(VERSION01).when(versioningManagerMock)
418 .checkout(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
420 Version version = vendorSoftwareProductManager.checkout(VSP_ID, USER1);
422 Assert.assertEquals(version, VERSION01);
423 verify(versioningManagerMock)
424 .checkout(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
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());
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);
443 doReturn(VERSION01).when(versioningManagerMock).undoCheckout(VendorSoftwareProductConstants
444 .VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1);
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());
451 Version undoCheckoutVersion = vendorSoftwareProductManager.undoCheckout(VSP_ID, USER1);
453 Assert.assertEquals(undoCheckoutVersion, VERSION01);
458 public void testSubmitWithMissingData() throws IOException {
459 VersionInfo versionInfo = new VersionInfo();
460 versionInfo.setActiveVersion(VERSION01);
462 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
463 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE,
464 VSP_ID, USER1, VersionableEntityAction.Read);
466 VspDetails vsp = new VspDetails(VSP_ID, VERSION01);
467 vsp.setOnboardingMethod("Manual");
468 doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
470 VspQuestionnaireEntity vspQuestionnaire = new VspQuestionnaireEntity(VSP_ID, VERSION01);
471 vspQuestionnaire.setQuestionnaireData("{}");
472 doReturn(vspQuestionnaire).when(vspInfoDaoMock).getQuestionnaire(VSP_ID, VERSION01);
474 ComponentEntity comp1 = new ComponentEntity(VSP_ID, VERSION01, "comp1");
475 comp1.setQuestionnaireData("{}");
476 doReturn(Collections.singleton(comp1)).when(vendorSoftwareProductDaoMock)
477 .listComponentsCompositionAndQuestionnaire(VSP_ID, VERSION01);
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);
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));
492 verify(versioningManagerMock, never())
493 .submit(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
495 verify(activityLogManagerMock, never()).addActionLog(any(ActivityLogEntity.class), eq(USER1));
498 // TODO: 3/15/2017 fix and enable
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);
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);
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);
527 verify(versioningManagerMock, never())
528 .submit(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
532 verify(activityLogManagerMock, never()).addActionLog(any(ActivityLogEntity.class), eq(USER1));
535 // TODO: 3/15/2017 fix and enable
537 public void testSubmit() throws IOException {
538 mockVersioning(VersionableEntityAction.Read);
540 EnrichmentManagerFactory.getInstance();
542 .registerFactory(EnrichmentManagerFactory.class, EnrichmentManagerFactoryImpl.class);
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);
557 ValidationResponse validationResponse = vendorSoftwareProductManager.submit(VSP_ID, USER1);
558 Assert.assertTrue(validationResponse.isValid());
560 /* Assert.assertEquals(vsp2.getVersionInfo().getActiveVersion(), VERSION10);
561 Assert.assertEquals(vsp2.getVersionInfo().getStatus(), VersionStatus.Final);
562 Assert.assertNull(vsp2.getVersionInfo().getLockingUser());*/
564 verify(versioningManagerMock)
565 .submit(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
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());
573 @Test(expectedExceptions = CoreException.class)
574 public void testCreatePackageOnNonFinalVersion_negative() throws IOException {
575 vendorSoftwareProductManager.createPackage(VSP_ID, VERSION01, USER1);
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);
588 doReturn(new ToscaServiceModel(new FileContentHandler(), new HashMap<>(), "")).when
589 (enrichedServiceModelDaoMock).getServiceModel(VSP_ID, VERSION10);
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));
597 doReturn(new FileContentHandler()).when(licenseArtifactsServiceMock)
598 .createLicenseArtifacts(VSP_ID, vsp.getVendorId(), VERSION10, vsp.getFeatureGroups(),
601 PackageInfo packageInfo = vendorSoftwareProductManager.createPackage(VSP_ID, VERSION10, USER1);
602 Assert.assertNotNull(packageInfo.getVspId());
605 // TODO: 3/15/2017 fix and enable
606 //@Test(dependsOnMethods = {"testListFinals"})
607 public void testUploadFileMissingFile() {
608 InputStream zis = getFileInputStream("/vspmanager/zips/missingYml.zip");
610 UploadFileResponse uploadFileResponse =
611 candidateManager.upload(VSP_ID, VERSION01, zis, USER1);
613 Assert.assertEquals(uploadFileResponse.getErrors().size(), 0);
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");
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());
630 verify(activityLogManagerMock, never()).addActionLog(any(ActivityLogEntity.class), eq(USER1));
634 public void testEnrichModelInSubmit() {
636 .deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME,
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();
644 InputStream zis = getFileInputStream("/vspmanager/zips/fullComposition.zip");
645 candidateManager.upload(id, VERSION01, zis, USER1);
646 OrchestrationTemplateActionResponse uploadFileResponse =
647 candidateManager.process(id, VERSION01, USER1);
650 vendorSoftwareProductManager.checkin(id, USER1);
653 ValidationResponse result = vendorSoftwareProductManager.submit(id, USER1);
654 } catch (IOException exception) {
657 VersionedVendorSoftwareProductInfo details =
658 vendorSoftwareProductManager.getVsp(id, null, USER1);
659 Collection<ComponentEntity> components =vendorSoftwareProductManager
660 .listComponents(id, details.getVersionInfo().getActiveVersion(), USER1);
662 ToscaServiceModel model =
663 (ToscaServiceModel) EnrichedServiceModelDaoFactory.getInstance().createInterface()
664 .getServiceModel(id, details.getVersionInfo().getActiveVersion());
666 Map<String, CapabilityDefinition> capabilities = new HashMap<>();
667 for (ComponentEntity component : components) {
668 model.getServiceTemplates().
671 filter(entryValue -> entryValue.getValue() != null &&
672 entryValue.getValue().getNode_types() != null &&
673 entryValue.getValue().
675 containsKey(component.getComponentCompositionData().getName())).
676 forEach(entryValue -> entryValue.getValue().getNode_types().
679 filter(type -> MapUtils.isNotEmpty(type.getCapabilities())).
680 forEach(type -> type.getCapabilities().
682 forEach(entry -> addCapability(entryValue.getKey(), capabilities, entry.getKey(),
683 entry.getValue()))));
687 Assert.assertNotNull(capabilities);
690 @Test(dependsOnMethods = {"testCreatePackage"})
691 public void testEnrichedFilesDeletedOnNewUpload() throws IOException {
692 Version activeVersion;
694 createPackageFromUpload(VSP_ID, USER1, "/fullComposition");
695 activeVersion = vendorSoftwareProductManager.getVsp(VSP_ID, null, USER1).getVersionInfo()
698 List<ServiceArtifact> firstExternalArtifacts = enrichedServiceModelDaoMock
699 .getExternalArtifacts(VSP_ID, activeVersion);
700 ToscaServiceModel firstServiceModel = enrichedServiceModelDaoMock.getServiceModel(VSP_ID,
703 createPackageFromUpload(VSP_ID, USER1, "/emptyComposition");
704 activeVersion = vendorSoftwareProductManager.getVsp(VSP_ID, null, USER1).getVersionInfo()
707 List<ServiceArtifact> secondExternalArtifacts = enrichedServiceModelDaoMock
708 .getExternalArtifacts(VSP_ID, activeVersion);
709 ToscaServiceModel secondServiceModel = enrichedServiceModelDaoMock.getServiceModel(VSP_ID,
712 Assert.assertNotEquals(firstExternalArtifacts, secondExternalArtifacts);
713 Assert.assertNotEquals(firstServiceModel, secondServiceModel);
717 @Test(dependsOnMethods = {"testMibsDeletedInCsar"})
718 public void testServiceTemplatesAreDeletedInCsarOnNewUpload() throws IOException {
719 String nestedPath = "Definitions" + File.separator + "nested";
721 uploadFileAndProcess(VSP_ID, USER1, "/vspmanager/zips/fullCompositionNested.zip");
722 checkinSubmitCreatePackage(VSP_ID, USER1);
723 List<String> nestedFileNamesServiceTemplates =
724 getWantedFileNamesFromCsar(nestedPath);
726 uploadFileAndProcess(VSP_ID, USER1, "/vspmanager/zips/fullComposition.zip");
727 checkinSubmitCreatePackage(VSP_ID, USER1);
728 List<String> emptyNestedNamesList = getWantedFileNamesFromCsar(nestedPath);
730 Assert.assertEquals(emptyNestedNamesList.size(), 0);
731 Assert.assertNotEquals(emptyNestedNamesList.size(), nestedFileNamesServiceTemplates.size());
734 private List<String> getWantedFileNamesFromCsar(String pathInCsar)
736 File translatedFile = vendorSoftwareProductManager.getTranslatedFile(VSP_ID, VERSION10, USER1);
738 return getFileNamesFromFolderInCsar(translatedFile,
742 private List<String> getFileNamesFromFolderInCsar(File csar, String folderName)
744 List<String> fileNames = new ArrayList<>();
746 ZipInputStream zip = new ZipInputStream(new FileInputStream(csar));
749 while ((ze = zip.getNextEntry()) != null) {
750 String name = ze.getName();
751 if (name.contains(folderName)) {
759 //Disabled for sonar null pointer issue for componentEntities
760 private Pair<String, String> uploadMib(String vspId, String user, String filePath,
762 List<ComponentEntity> componentEntities = null;
763 //(List<ComponentEntity>) vendorSoftwareProductManager.listComponents(vspId, null, user);
764 monitoringUploadsManager.upload(getFileInputStream(filePath),
766 VERSION01, componentEntities.get(0).getId(), MonitoringUploadType.SNMP_POLL, user);
767 //TODO: add validate of addActionLog() func call
769 return new ImmutablePair<>(componentEntities.get(0).getId(),
770 componentEntities.get(0).getComponentCompositionData()
774 private void createPackageFromUpload(String vspId, String user, String filePath)
776 uploadFileAndProcess(vspId, user, filePath);
777 checkinSubmitCreatePackage(vspId, user);
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);
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);
793 // TODO: 3/15/2017 fix and enable
796 public void testUpdatedVSPShouldBeInBeginningOfList() {
797 vendorSoftwareProductManager.updateVsp(new VspDetails(), USER3);
798 assertVSPInWantedLocationInVSPList(id006, 0, USER3);
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);
806 @Test(dependsOnMethods = {"testUpdatedVSPShouldBeInBeginningOfList"})
807 public void testVSPInBeginningOfListAfterCheckin() {
808 vendorSoftwareProductManager.checkin(id006, USER3);
809 assertVSPInWantedLocationInVSPList(id006, 0, USER3);
811 vendorSoftwareProductManager.checkin(id007, USER3);
812 assertVSPInWantedLocationInVSPList(id007, 0, USER3);
815 @Test(dependsOnMethods = {"testVSPInBeginningOfListAfterCheckin"})
816 public void testVSPInBeginningOfListAfterCheckout() {
817 vendorSoftwareProductManager.checkout(id006, USER3);
818 assertVSPInWantedLocationInVSPList(id006, 0, USER3);
821 @Test(dependsOnMethods = {"testVSPInBeginningOfListAfterCheckout"})
822 public void testVSPInBeginningOfListAfterUndoCheckout() {
823 vendorSoftwareProductManager.checkout(id007, USER3);
824 assertVSPInWantedLocationInVSPList(id007, 0, USER3);
826 vendorSoftwareProductManager.undoCheckout(id006, USER3);
827 assertVSPInWantedLocationInVSPList(id006, 0, USER3);
830 @Test(dependsOnMethods = {"testVSPInBeginningOfListAfterUndoCheckout"})
831 public void testVSPInBeginningOfListAfterSubmit() throws IOException {
832 vendorSoftwareProductManager.checkin(id007, USER3);
833 vendorSoftwareProductManager.submit(id007, USER3);
835 assertVSPInWantedLocationInVSPList(id007, 0, USER3);
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);
843 UploadDataEntity uploadData =
844 orchestrationTemplateDataDaoMock.getOrchestrationTemplate(vspId, version);
845 Assert.assertNotNull(uploadData);
848 private void addCapability(String entryValueKey, Map<String, CapabilityDefinition> capabilities,
849 String key, CapabilityDefinition value) {
851 capabilities.put(entryValueKey + "_" + key, value);
854 public InputStream getFileInputStream(String fileName) {
855 URL url = this.getClass().getResource(fileName);
857 return url.openStream();
858 } catch (IOException exception) {
859 exception.printStackTrace();
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);
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;
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;
886 // Assert.assertTrue(isInfoArtifactInZip);
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");
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());
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);
927 // id005 = createdVsp.getId();
928 // Assert.assertNotNull(id005);
929 // Assert.assertNotNull(createdVsp.getVersion());
931 // try (InputStream zipInputStream = new ZipFileUtils().getZipInputStream("/legalUploadWithWarning")) {
933 // UploadFileResponse uploadFileResponse = vendorSoftwareProductManager.upload(id005, zipInputStream, USER1);
934 // vendorSoftwareProductManager.process(id005, USER1);
935 // Optional<File> fileCandidate = vendorSoftwareProductManager.get(id005, USER1);
937 // File latestHeatPackage = fileCandidate.get();
939 // zipInputStream.reset();
940 // byte[] uploaded = IOUtils.toByteArray(zipInputStream);
942 // Optional<FileContentHandler> zipContentMap = vendorSoftwareProductManager.getZipContentMap(uploadFileResponse, uploaded);
943 // FileContentHandler fileContentHandler = new FileContentHandler();
944 // if(zipContentMap.isPresent()){
945 // fileContentHandler = zipContentMap.get();
948 // uploaded = IOUtils.toByteArray(fileContentHandler.getFiles().values());
950 // byte[] downloaded;
951 // try (BufferedInputStream fileStream = new BufferedInputStream(new FileInputStream(latestHeatPackage))) {
952 // downloaded = IOUtils.toByteArray(fileStream);
955 // Assert.assertTrue(Arrays.equals(uploaded, downloaded));
959 // todo ********************** move to common **************************************
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,
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,
977 private void MockVersioningEntityLocked(VersionableEntityAction action) {
978 doThrow(new CoreException(new EditOnEntityLockedByOtherErrorBuilder(
979 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1)
981 .when(versioningManagerMock).getEntityVersionInfo(
982 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER2,