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.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;
83 import java.io.FileInputStream;
84 import java.io.IOException;
85 import java.io.InputStream;
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;
94 import java.util.stream.Collectors;
95 import java.util.zip.ZipEntry;
96 import java.util.zip.ZipInputStream;
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;
109 * Created by TALIO on 4/23/2016
111 public class VendorSoftwareProductManagerImplTest {
112 private static final String INVALID_VERSION_MSG = "Invalid requested version.";
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;
125 private VersioningManager versioningManagerMock;
127 private VendorSoftwareProductDao vendorSoftwareProductDaoMock; // todo get rid of
129 private OrchestrationTemplateDao orchestrationTemplateDataDaoMock;
131 private VendorLicenseFacade vendorLicenseFacadeMock;
133 private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDaoMock;
135 private EnrichedServiceModelDao<ToscaServiceModel, ServiceElement> enrichedServiceModelDaoMock;
137 private HealingManager healingManagerMock;
139 private VendorLicenseArtifactsService licenseArtifactsServiceMock;
141 private CompositionEntityDataManager compositionEntityDataManagerMock;
143 private InformationArtifactGenerator informationArtifactGeneratorMock;
145 private ActivityLogManager activityLogManagerMock;
147 private PackageInfoDao packageInfoDao;
149 private VendorSoftwareProductInfoDao vspInfoDaoMock;
154 private VendorSoftwareProductManagerImpl vendorSoftwareProductManager;
156 private OrchestrationTemplateCandidateManager candidateManager;
157 private MibManager mibManager;
160 private ArgumentCaptor<ActivityLogEntity> activityLogEntityArg;
163 public void setUp() throws Exception {
164 MockitoAnnotations.initMocks(this);
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);
178 public void testList() {
179 String vsp1id = "vsp1_id";
180 String vsp2id = "vsp2_id";
181 Map<String, VersionInfo> vspsTobeReturned = new HashMap<>();
183 VersionInfo versionInfo1 = new VersionInfo();
184 versionInfo1.setActiveVersion(VERSION01);
185 vspsTobeReturned.put(vsp1id, versionInfo1);
187 VersionInfo versionInfo2 = new VersionInfo();
188 versionInfo2.setActiveVersion(VERSION10);
189 vspsTobeReturned.put(vsp2id, versionInfo2);
191 doReturn(vspsTobeReturned).when(versioningManagerMock).listEntitiesVersionInfo
192 (VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, USER1,
193 VersionableEntityAction.Read);
195 VspDetails vsp1 = new VspDetails(vsp1id, VERSION01);
196 vsp1.setWritetimeMicroSeconds(8L);
197 doReturn(vsp1).when(vspInfoDaoMock)
198 .get(any(VspDetails.class));
200 List<VersionedVendorSoftwareProductInfo> vsps =
201 vendorSoftwareProductManager.listVsps(null, USER1);
202 Assert.assertEquals(vsps.size(), 2);
206 public void testListFinalsWhenNone() {
207 String vsp1id = "vsp1_id";
208 String vsp2id = "vsp2_id";
209 Map<String, VersionInfo> vspsTobeReturned = new HashMap<>();
211 VersionInfo versionInfo1 = new VersionInfo();
212 versionInfo1.setActiveVersion(VERSION01);
213 vspsTobeReturned.put(vsp1id, versionInfo1);
215 VersionInfo versionInfo2 = new VersionInfo();
216 versionInfo2.setActiveVersion(VERSION10);
217 vspsTobeReturned.put(vsp2id, versionInfo2);
219 doReturn(vspsTobeReturned).when(versioningManagerMock).listEntitiesVersionInfo
220 (VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, USER1,
221 VersionableEntityAction.Read);
223 List<VersionedVendorSoftwareProductInfo> vsps =
224 vendorSoftwareProductManager.listVsps(VersionStatus.Final.name(), USER1);
225 Assert.assertEquals(vsps.size(), 0);
229 public void testListFinals() {
230 String vsp1id = "vsp1_id";
231 String vsp2id = "vsp2_id";
232 Map<String, VersionInfo> vspsTobeReturned = new HashMap<>();
234 VersionInfo versionInfo1 = new VersionInfo();
235 versionInfo1.setActiveVersion(VERSION01);
236 vspsTobeReturned.put(vsp1id, versionInfo1);
238 VersionInfo versionInfo2 = new VersionInfo();
239 versionInfo2.setActiveVersion(new Version(1, 3));
240 versionInfo2.setLatestFinalVersion(VERSION10);
241 vspsTobeReturned.put(vsp2id, versionInfo2);
243 doReturn(vspsTobeReturned).when(versioningManagerMock).listEntitiesVersionInfo
244 (VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, USER1,
245 VersionableEntityAction.Read);
247 VspDetails vsp2 = new VspDetails(vsp2id, VERSION10);
248 vsp2.setWritetimeMicroSeconds(8L);
249 doReturn(vsp2).when(vspInfoDaoMock)
250 .get(any(VspDetails.class));
252 List<VersionedVendorSoftwareProductInfo> vsps =
253 vendorSoftwareProductManager.listVsps(VersionStatus.Final.name(), USER1);
254 Assert.assertEquals(vsps.size(), 1);
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);
266 vendorSoftwareProductManager.createVsp(expectedVsp, USER1);
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());
275 .when(vendorSoftwareProductManager).getVspQuestionnaireSchema(anyObject());
277 VspDetails vspToCreate =
278 createVspDetails(null, null, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon",
279 "category", "subCategory", "123", null);
281 VspDetails vsp = vendorSoftwareProductManager.createVsp(vspToCreate, USER1);
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());
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);
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());
314 vendorSoftwareProductManager.updateVsp(updatedVsp, USER1);
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",
327 "subCategory", "456", null);
328 VspDetails updatedVsp =
329 createVspDetails(VSP_ID, VERSION01, "VSP1_updated", null, "vendorName", "vlm1Id", "icon",
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());
338 vendorSoftwareProductManager.updateVsp(updatedVsp, USER1);
340 verify(vspInfoDaoMock).update(updatedVsp);
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);
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);
360 VspDetails existingVsp =
361 createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
363 "subCategory", "456", null);
364 existingVsp.setWritetimeMicroSeconds(8L);
365 doReturn(existingVsp).when(vspInfoDaoMock).get(any(VspDetails.class));
367 VspDetails actualVsp =
368 vendorSoftwareProductManager.getVsp(VSP_ID, VERSION01, USER1);
370 assertVspsEquals(actualVsp, existingVsp);
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);
384 VspDetails existingVsp =
385 createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon",
387 "subCategory", "456", null);
388 existingVsp.setWritetimeMicroSeconds(8L);
389 doReturn(existingVsp)
390 .when(vspInfoDaoMock).get(any(VspDetails.class));
392 VspDetails actualVsp =
393 vendorSoftwareProductManager.getVsp(VSP_ID, VERSION01, USER1);
395 VspDetails expectedVsp =
397 .get(new VspDetails(VSP_ID, VERSION01));
398 assertVspsEquals(actualVsp, expectedVsp);
402 public void testCheckin() {
403 doReturn(VERSION01).when(versioningManagerMock)
404 .checkin(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
406 Version version = vendorSoftwareProductManager.checkin(VSP_ID, USER1);
408 Assert.assertEquals(version, VERSION01);
409 verify(versioningManagerMock)
410 .checkin(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
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());
419 public void testCheckout() {
420 doReturn(VERSION01).when(versioningManagerMock)
421 .checkout(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
423 Version version = vendorSoftwareProductManager.checkout(VSP_ID, USER1);
425 Assert.assertEquals(version, VERSION01);
426 verify(versioningManagerMock)
427 .checkout(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
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());
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);
446 doReturn(VERSION01).when(versioningManagerMock).undoCheckout(VendorSoftwareProductConstants
447 .VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1);
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());
454 Version undoCheckoutVersion = vendorSoftwareProductManager.undoCheckout(VSP_ID, USER1);
456 Assert.assertEquals(undoCheckoutVersion, VERSION01);
461 public void testSubmitWithMissingData() throws IOException {
462 VersionInfo versionInfo = new VersionInfo();
463 versionInfo.setActiveVersion(VERSION01);
465 doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo(
466 VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE,
467 VSP_ID, USER1, VersionableEntityAction.Read);
469 VspDetails vsp = new VspDetails(VSP_ID, VERSION01);
470 doReturn(vsp).when(vspInfoDaoMock).get(anyObject());
472 VspQuestionnaireEntity vspQuestionnaire = new VspQuestionnaireEntity(VSP_ID, VERSION01);
473 vspQuestionnaire.setQuestionnaireData("{}");
474 doReturn(vspQuestionnaire).when(vspInfoDaoMock).getQuestionnaire(VSP_ID, VERSION01);
476 ComponentEntity comp1 = new ComponentEntity(VSP_ID, VERSION01, "comp1");
477 comp1.setQuestionnaireData("{}");
478 doReturn(Collections.singleton(comp1)).when(vendorSoftwareProductDaoMock)
479 .listComponentsCompositionAndQuestionnaire(VSP_ID, VERSION01);
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);
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));
494 verify(versioningManagerMock, never())
495 .submit(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
497 verify(activityLogManagerMock, never()).addActionLog(any(ActivityLogEntity.class), eq(USER1));
500 // TODO: 3/15/2017 fix and enable
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);
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);
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);
529 verify(versioningManagerMock, never())
530 .submit(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
534 verify(activityLogManagerMock, never()).addActionLog(any(ActivityLogEntity.class), eq(USER1));
537 // TODO: 3/15/2017 fix and enable
539 public void testSubmit() throws IOException {
540 mockVersioning(VersionableEntityAction.Read);
542 EnrichmentManagerFactory.getInstance();
544 .registerFactory(EnrichmentManagerFactory.class, EnrichmentManagerFactoryImpl.class);
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);
559 ValidationResponse validationResponse = vendorSoftwareProductManager.submit(VSP_ID, USER1);
560 Assert.assertTrue(validationResponse.isValid());
562 /* Assert.assertEquals(vsp2.getVersionInfo().getActiveVersion(), VERSION10);
563 Assert.assertEquals(vsp2.getVersionInfo().getStatus(), VersionStatus.Final);
564 Assert.assertNull(vsp2.getVersionInfo().getLockingUser());*/
566 verify(versioningManagerMock)
567 .submit(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID,
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());
575 @Test(expectedExceptions = CoreException.class)
576 public void testCreatePackageOnNonFinalVersion_negative() throws IOException {
577 vendorSoftwareProductManager.createPackage(VSP_ID, VERSION01, USER1);
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);
590 doReturn(new ToscaServiceModel(new FileContentHandler(), new HashMap<>(), "")).when
591 (enrichedServiceModelDaoMock).getServiceModel(VSP_ID, VERSION10);
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));
599 doReturn(new FileContentHandler()).when(licenseArtifactsServiceMock)
600 .createLicenseArtifacts(VSP_ID, vsp.getVendorId(), VERSION10, vsp.getFeatureGroups(),
603 PackageInfo packageInfo = vendorSoftwareProductManager.createPackage(VSP_ID, VERSION10, USER1);
604 Assert.assertNotNull(packageInfo.getVspId());
607 // TODO: 3/15/2017 fix and enable
608 //@Test(dependsOnMethods = {"testListFinals"})
609 public void testUploadFileMissingFile() {
610 InputStream zis = getFileInputStream("/vspmanager/zips/missingYml.zip");
612 UploadFileResponse uploadFileResponse =
613 candidateManager.upload(VSP_ID, VERSION01, zis, USER1);
615 Assert.assertEquals(uploadFileResponse.getErrors().size(), 0);
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");
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());
632 verify(activityLogManagerMock, never()).addActionLog(any(ActivityLogEntity.class), eq(USER1));
636 public void testEnrichModelInSubmit() {
638 .deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME,
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();
646 InputStream zis = getFileInputStream("/vspmanager/zips/fullComposition.zip");
647 candidateManager.upload(id, VERSION01, zis, USER1);
648 OrchestrationTemplateActionResponse uploadFileResponse =
649 candidateManager.process(id, VERSION01, USER1);
652 vendorSoftwareProductManager.checkin(id, USER1);
655 ValidationResponse result = vendorSoftwareProductManager.submit(id, USER1);
656 } catch (IOException exception) {
659 VersionedVendorSoftwareProductInfo details =
660 vendorSoftwareProductManager.getVsp(id, null, USER1);
661 Collection<ComponentEntity> components =vendorSoftwareProductManager
662 .listComponents(id, details.getVersionInfo().getActiveVersion(), USER1);
664 ToscaServiceModel model =
665 (ToscaServiceModel) EnrichedServiceModelDaoFactory.getInstance().createInterface()
666 .getServiceModel(id, details.getVersionInfo().getActiveVersion());
668 Map<String, CapabilityDefinition> capabilities = new HashMap<>();
669 for (ComponentEntity component : components) {
670 model.getServiceTemplates().
673 filter(entryValue -> entryValue.getValue() != null &&
674 entryValue.getValue().getNode_types() != null &&
675 entryValue.getValue().
677 containsKey(component.getComponentCompositionData().getName())).
678 forEach(entryValue -> entryValue.getValue().getNode_types().
681 filter(type -> MapUtils.isNotEmpty(type.getCapabilities())).
682 forEach(type -> type.getCapabilities().
684 forEach(entry -> addCapability(entryValue.getKey(), capabilities, entry.getKey(),
685 entry.getValue()))));
689 Assert.assertNotNull(capabilities);
692 @Test(dependsOnMethods = {"testCreatePackage"})
693 public void testEnrichedFilesDeletedOnNewUpload() throws IOException {
694 Version activeVersion;
696 createPackageFromUpload(VSP_ID, USER1, "/fullComposition");
697 activeVersion = vendorSoftwareProductManager.getVsp(VSP_ID, null, USER1).getVersionInfo()
700 List<ServiceArtifact> firstExternalArtifacts = enrichedServiceModelDaoMock
701 .getExternalArtifacts(VSP_ID, activeVersion);
702 ToscaServiceModel firstServiceModel = enrichedServiceModelDaoMock.getServiceModel(VSP_ID,
705 createPackageFromUpload(VSP_ID, USER1, "/emptyComposition");
706 activeVersion = vendorSoftwareProductManager.getVsp(VSP_ID, null, USER1).getVersionInfo()
709 List<ServiceArtifact> secondExternalArtifacts = enrichedServiceModelDaoMock
710 .getExternalArtifacts(VSP_ID, activeVersion);
711 ToscaServiceModel secondServiceModel = enrichedServiceModelDaoMock.getServiceModel(VSP_ID,
714 Assert.assertNotEquals(firstExternalArtifacts, secondExternalArtifacts);
715 Assert.assertNotEquals(firstServiceModel, secondServiceModel);
719 @Test(dependsOnMethods = {"testMibsDeletedInCsar"})
720 public void testServiceTemplatesAreDeletedInCsarOnNewUpload() throws IOException {
721 String nestedPath = "Definitions" + File.separator + "nested";
723 uploadFileAndProcess(VSP_ID, USER1, "/vspmanager/zips/fullCompositionNested.zip");
724 checkinSubmitCreatePackage(VSP_ID, USER1);
725 List<String> nestedFileNamesServiceTemplates =
726 getWantedFileNamesFromCsar(nestedPath);
728 uploadFileAndProcess(VSP_ID, USER1, "/vspmanager/zips/fullComposition.zip");
729 checkinSubmitCreatePackage(VSP_ID, USER1);
730 List<String> emptyNestedNamesList = getWantedFileNamesFromCsar(nestedPath);
732 Assert.assertEquals(emptyNestedNamesList.size(), 0);
733 Assert.assertNotEquals(emptyNestedNamesList.size(), nestedFileNamesServiceTemplates.size());
736 private List<String> getWantedFileNamesFromCsar(String pathInCsar)
738 File translatedFile = vendorSoftwareProductManager.getTranslatedFile(VSP_ID, VERSION10, USER1);
740 return getFileNamesFromFolderInCsar(translatedFile,
744 private List<String> getFileNamesFromFolderInCsar(File csar, String folderName)
746 List<String> fileNames = new ArrayList<>();
748 ZipInputStream zip = new ZipInputStream(new FileInputStream(csar));
751 while ((ze = zip.getNextEntry()) != null) {
752 String name = ze.getName();
753 if (name.contains(folderName)) {
761 private Pair<String, String> uploadMib(String vspId, String user, String filePath,
763 List<ComponentEntity> componentEntities = null;
764 //(List<ComponentEntity>) vendorSoftwareProductManager.listComponents(vspId, null, user);
765 mibManager.upload(getFileInputStream(filePath),
767 VERSION01, componentEntities.get(0).getId(), ArtifactType.SNMP_POLL, user);
768 //TODO: add validate of addActionLog() func call
770 return new ImmutablePair<>(componentEntities.get(0).getId(),
771 componentEntities.get(0).getComponentCompositionData()
775 private void createPackageFromUpload(String vspId, String user, String filePath)
777 uploadFileAndProcess(vspId, user, filePath);
778 checkinSubmitCreatePackage(vspId, user);
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);
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);
794 // TODO: 3/15/2017 fix and enable
797 public void testUpdatedVSPShouldBeInBeginningOfList() {
798 vendorSoftwareProductManager.updateVsp(new VspDetails(), USER3);
799 assertVSPInWantedLocationInVSPList(id006, 0, USER3);
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);
807 @Test(dependsOnMethods = {"testUpdatedVSPShouldBeInBeginningOfList"})
808 public void testVSPInBeginningOfListAfterCheckin() {
809 vendorSoftwareProductManager.checkin(id006, USER3);
810 assertVSPInWantedLocationInVSPList(id006, 0, USER3);
812 vendorSoftwareProductManager.checkin(id007, USER3);
813 assertVSPInWantedLocationInVSPList(id007, 0, USER3);
816 @Test(dependsOnMethods = {"testVSPInBeginningOfListAfterCheckin"})
817 public void testVSPInBeginningOfListAfterCheckout() {
818 vendorSoftwareProductManager.checkout(id006, USER3);
819 assertVSPInWantedLocationInVSPList(id006, 0, USER3);
822 @Test(dependsOnMethods = {"testVSPInBeginningOfListAfterCheckout"})
823 public void testVSPInBeginningOfListAfterUndoCheckout() {
824 vendorSoftwareProductManager.checkout(id007, USER3);
825 assertVSPInWantedLocationInVSPList(id007, 0, USER3);
827 vendorSoftwareProductManager.undoCheckout(id006, USER3);
828 assertVSPInWantedLocationInVSPList(id006, 0, USER3);
831 @Test(dependsOnMethods = {"testVSPInBeginningOfListAfterUndoCheckout"})
832 public void testVSPInBeginningOfListAfterSubmit() throws IOException {
833 vendorSoftwareProductManager.checkin(id007, USER3);
834 vendorSoftwareProductManager.submit(id007, USER3);
836 assertVSPInWantedLocationInVSPList(id007, 0, USER3);
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);
844 UploadDataEntity uploadData =
845 orchestrationTemplateDataDaoMock.getOrchestrationTemplate(vspId, version);
846 Assert.assertNotNull(uploadData);
849 private void addCapability(String entryValueKey, Map<String, CapabilityDefinition> capabilities,
850 String key, CapabilityDefinition value) {
852 capabilities.put(entryValueKey + "_" + key, value);
855 public InputStream getFileInputStream(String fileName) {
856 URL url = this.getClass().getResource(fileName);
858 return url.openStream();
859 } catch (IOException exception) {
860 exception.printStackTrace();
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);
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;
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;
887 // Assert.assertTrue(isInfoArtifactInZip);
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);
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,