1 package org.openecomp.sdc.vendorsoftwareproduct;
3 import org.openecomp.sdc.common.errors.CoreException;
4 import org.openecomp.sdc.common.errors.ErrorCode;
5 import org.openecomp.sdc.common.errors.ValidationErrorBuilder;
6 import org.openecomp.sdc.common.utils.AsdcCommon;
7 import org.openecomp.sdc.heat.datatypes.structure.HeatStructureTree;
8 import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel;
9 import org.openecomp.sdc.tosca.datatypes.model.CapabilityDefinition;
10 import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity;
11 import org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity;
12 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
14 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory;
15 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.PackageInfo;
16 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.UploadDataEntity;
17 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
18 import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes;
19 import org.openecomp.sdc.vendorsoftwareproduct.impl.VendorSoftwareProductManagerImpl;
20 import org.openecomp.sdc.vendorsoftwareproduct.tree.UploadFileTest;
21 import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
22 import org.openecomp.sdc.vendorsoftwareproduct.types.ValidationResponse;
23 import org.openecomp.sdc.vendorsoftwareproduct.types.VersionedVendorSoftwareProductInfo;
24 import org.openecomp.sdc.versioning.dao.types.Version;
25 import org.openecomp.sdc.versioning.errors.VersioningErrorCodes;
26 import org.openecomp.core.model.dao.EnrichedServiceModelDaoFactory;
27 import org.openecomp.core.util.UniqueValueUtil;
28 import org.openecomp.core.utilities.CommonMethods;
29 import org.openecomp.core.validation.errors.Messages;
30 import org.apache.commons.collections4.MapUtils;
31 import org.apache.commons.io.IOUtils;
32 import org.testng.Assert;
33 import org.testng.annotations.BeforeTest;
34 import org.testng.annotations.Test;
39 import java.util.stream.Collectors;
41 public class VendorSoftwareProductManagerTest {
42 public static final Version VERSION01 = new Version(0, 1);
43 public static final Version VERSION10 = new Version(1, 0);
44 private static final String USER1 = "vspTestUser1";
45 private static final String USER2 = "vspTestUser2";
46 private static final String USER3 = "vspTestUser3";
47 public static String id001 = null;
48 public static String id002 = null;
49 public static String id003 = null;
50 public static String id004 = null;
51 public static String id005 = null;
52 public static String id006 = null;
53 public static String id007 = null;
54 public static Version activeVersion002 = null;
55 private static VendorSoftwareProductManager vendorSoftwareProductManager =
56 new VendorSoftwareProductManagerImpl();
57 private static org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao
58 vendorSoftwareProductDao =
59 VendorSoftwareProductDaoFactory.getInstance().createInterface();
60 private static VendorLicenseFacade vendorLicenseFacade =
61 org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacadeFactory.getInstance().createInterface();
62 private static String vlm1Id;
63 private static String licenseAgreementId;
64 private static String featureGroupId;
65 private static VspDetails vsp1;
66 private static VspDetails vsp2;
67 UploadFileTest ut = new UploadFileTest();
69 static void assertVspsEquals(VspDetails actual, VspDetails expected) {
70 Assert.assertEquals(actual.getId(), expected.getId());
71 Assert.assertEquals(actual.getVersion(), expected.getVersion());
72 Assert.assertEquals(actual.getName(), expected.getName());
73 Assert.assertEquals(actual.getDescription(), expected.getDescription());
74 Assert.assertEquals(actual.getIcon(), expected.getIcon());
75 Assert.assertEquals(actual.getCategory(), expected.getCategory());
76 Assert.assertEquals(actual.getSubCategory(), expected.getSubCategory());
77 Assert.assertEquals(actual.getVendorName(), expected.getVendorName());
78 Assert.assertEquals(actual.getVendorId(), expected.getVendorId());
79 Assert.assertEquals(actual.getLicenseAgreement(), expected.getLicenseAgreement());
80 Assert.assertEquals(actual.getFeatureGroups(), expected.getFeatureGroups());
86 .deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME,
89 .deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME,
92 .deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME,
95 .deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME,
98 .deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME,
101 .deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME,
106 private void createVlm() {
107 vlm1Id = vendorLicenseFacade.createVendorLicenseModel(VSPCommon
108 .createVendorLicenseModel("vlmName " + CommonMethods.nextUuId(), "vlm1Id desc", "icon1"),
111 String entitlementPoolId = vendorLicenseFacade
112 .createEntitlementPool(new EntitlementPoolEntity(vlm1Id, null, null), USER1).getId();
114 org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity
115 featureGroup = new org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity(vlm1Id, null, null);
116 featureGroup.getEntitlementPoolIds().add(entitlementPoolId);
117 featureGroupId = vendorLicenseFacade.createFeatureGroup(featureGroup, USER1).getId();
119 LicenseAgreementEntity licenseAgreement = new LicenseAgreementEntity(vlm1Id, null, null);
120 licenseAgreement.getFeatureGroupIds().add(featureGroupId);
122 vendorLicenseFacade.createLicenseAgreement(licenseAgreement, USER1).getId();
124 vendorLicenseFacade.checkin(vlm1Id, USER1);
125 vendorLicenseFacade.submit(vlm1Id, USER1);
129 public void testHeatSet() {
130 Set<HeatStructureTree> set = new HashSet<>();
131 HeatStructureTree heatStructureTree1 = new HeatStructureTree();
132 HeatStructureTree heatStructureTree2 = new HeatStructureTree();
134 heatStructureTree1.setFileName("file");
136 HeatStructureTree env = new HeatStructureTree();
137 env.setFileName("env");
138 heatStructureTree1.setEnv(env);
140 heatStructureTree2.setFileName("file");
141 heatStructureTree2.setEnv(env);
143 set.add(heatStructureTree1);
144 set.add(heatStructureTree2);
146 Assert.assertEquals(set.size(), 1);
149 @Test(dependsOnMethods = {"testHeatSet"})
150 public void testCreateVSP() {
151 VspDetails expectedVsp = VSPCommon
152 .createVspDetails(null, null, "VSP1", "Test-vsp", "vendorName", vlm1Id, "icon", "category",
153 "subCategory", "123", null);
155 VspDetails createdVsp = vendorSoftwareProductManager.createNewVsp(expectedVsp, USER1);
156 id001 = createdVsp.getId();
157 Assert.assertNotNull(id001);
158 Assert.assertNotNull(createdVsp.getVersion());
160 VspDetails actualVsp =
161 vendorSoftwareProductDao.getVendorSoftwareProductInfo(new VspDetails(id001, VERSION01));
162 expectedVsp.setId(id001);
163 expectedVsp.setVersion(VERSION01);
165 assertVspsEquals(actualVsp, expectedVsp);
166 Assert.assertNotNull(
167 vendorSoftwareProductManager.getVspQuestionnaire(id001, null, USER1).getData());
170 @Test(dependsOnMethods = {"testCreateVSP"})
171 public void testCreateWithExistingName_negative() {
173 VspDetails expectedVsp = VSPCommon
174 .createVspDetails(null, null, "Vsp1", "Test-vsp", "vendorName", vlm1Id, "icon",
175 "category", "subCategory", "123", null);
176 vendorSoftwareProductManager.createNewVsp(expectedVsp, USER1);
178 } catch (CoreException e) {
179 Assert.assertEquals(e.code().id(), UniqueValueUtil.UNIQUE_VALUE_VIOLATION);
183 @Test(dependsOnMethods = {"testCreateWithExistingName_negative"})
184 public void testGetVSPDetails() {
185 VersionedVendorSoftwareProductInfo actualVsp =
186 vendorSoftwareProductManager.getVspDetails(id001, null, USER1);
188 VspDetails expectedVsp =
189 vendorSoftwareProductDao.getVendorSoftwareProductInfo(new VspDetails(id001, VERSION01));
190 assertVspsEquals(actualVsp.getVspDetails(), expectedVsp);
191 Assert.assertEquals(actualVsp.getVersionInfo().getActiveVersion(), VERSION01);
192 Assert.assertEquals(actualVsp.getVersionInfo().getStatus(), org.openecomp.sdc.versioning.dao.types.VersionStatus.Locked);
193 Assert.assertEquals(actualVsp.getVersionInfo().getLockingUser(), USER1);
196 @Test(dependsOnMethods = {"testGetVSPDetails"})
197 public void testUpdateVSP() {
198 VspDetails expectedVsp = VSPCommon
199 .createVspDetails(id001, VERSION01, "VSP1", null, "vendorName", vlm1Id, "icon", "category",
200 "subCategory", "456", null);
201 vendorSoftwareProductManager.updateVsp(expectedVsp, USER1);
203 VspDetails actualVsp =
204 vendorSoftwareProductDao.getVendorSoftwareProductInfo(new VspDetails(id001, VERSION01));
206 assertVspsEquals(actualVsp, expectedVsp);
209 @Test(dependsOnMethods = {"testUpdateVSP"})
210 public void testGetVSPDetailsAfterUpdate() {
211 VersionedVendorSoftwareProductInfo vspDetails =
212 vendorSoftwareProductManager.getVspDetails(id001, null, USER1);
213 Assert.assertEquals(vspDetails.getVspDetails().getName(), "VSP1");
214 Assert.assertEquals(vspDetails.getVspDetails().getCategory(), "category");
215 Assert.assertEquals(vspDetails.getVspDetails().getSubCategory(), "subCategory");
216 Assert.assertEquals(vspDetails.getVspDetails().getVendorId(), vlm1Id);
217 Assert.assertEquals(vspDetails.getVersionInfo().getActiveVersion(), VERSION01);
218 Assert.assertEquals(vspDetails.getVersionInfo().getStatus(), org.openecomp.sdc.versioning.dao.types.VersionStatus.Locked);
219 Assert.assertEquals(vspDetails.getVersionInfo().getLockingUser(), USER1);
222 @Test(dependsOnMethods = {"testGetVSPDetailsAfterUpdate"})
223 public void testGetVSPList() {
224 String licenseAgreementId = "bla bla";
225 VspDetails vspDetails = vendorSoftwareProductManager.createNewVsp(VSPCommon
226 .createVspDetails(null, null, "VSP3", "Test-vsp", "vendorName", vlm1Id, "icon", "category",
227 "subCategory", licenseAgreementId, null), USER1);
228 id002 = vspDetails.getId();
229 vspDetails = vendorSoftwareProductManager.createNewVsp(VSPCommon
230 .createVspDetails(null, null, "VSP4", "Test-vsp", "vendorName", vlm1Id, "icon", "category",
231 "subCategory", licenseAgreementId, null), USER1);
232 id003 = vspDetails.getId();
234 List<VersionedVendorSoftwareProductInfo> vspDetailsList =
235 vendorSoftwareProductManager.getVspList(null, USER1);
237 for (VersionedVendorSoftwareProductInfo vsp : vspDetailsList) {
238 if (vsp.getVspDetails().getId().equals(id001) || vsp.getVspDetails().getId().equals(id002) ||
239 vsp.getVspDetails().getId().equals(id003)) {
244 Assert.assertEquals(foundCount, 3);
247 @Test(dependsOnMethods = {"testGetVSPList"})
248 // Unsupported operation for 1607 release.
249 /* public void testDeleteVSP() {
250 vendorSoftwareProductManager.deleteVsp(id001, USER1);
252 VspDetails vspDetails = vendorSoftwareProductDao.getVendorSoftwareProductInfo(new VspDetails(id001, VERSION01));
253 Assert.assertNull(vspDetails);
255 List<VersionedVendorSoftwareProductInfo> vspDetailsList = vendorSoftwareProductManager.getVspList(null, USER1);
256 boolean found001 = false;
257 for (VersionedVendorSoftwareProductInfo vsp : vspDetailsList) {
258 if (vsp.getVspDetails().getId().equals(id001)) {
263 Assert.assertFalse(found001);
267 @Test(dependsOnMethods = {"testDeleteVSP"})*/
268 public void testCheckin() {
269 vendorSoftwareProductManager.checkin(id002, USER1);
271 VersionedVendorSoftwareProductInfo vsp2 =
272 vendorSoftwareProductManager.getVspDetails(id002, null, USER1);
273 Assert.assertEquals(vsp2.getVersionInfo().getActiveVersion(), VERSION01);
274 Assert.assertEquals(vsp2.getVersionInfo().getStatus(), org.openecomp.sdc.versioning.dao.types.VersionStatus.Available);
275 Assert.assertNull(vsp2.getVersionInfo().getLockingUser());
278 @Test(dependsOnMethods = {"testCheckin"})
279 public void testCheckout() {
280 vendorSoftwareProductManager.checkout(id002, USER2);
282 VersionedVendorSoftwareProductInfo vsp2 =
283 vendorSoftwareProductManager.getVspDetails(id002, null, USER2);
284 Assert.assertEquals(vsp2.getVersionInfo().getActiveVersion(), new Version(0, 2));
285 Assert.assertEquals(vsp2.getVersionInfo().getStatus(), org.openecomp.sdc.versioning.dao.types.VersionStatus.Locked);
286 Assert.assertEquals(vsp2.getVersionInfo().getLockingUser(), USER2);
288 vsp2 = vendorSoftwareProductManager.getVspDetails(id002, null, USER1);
289 Assert.assertEquals(vsp2.getVersionInfo().getActiveVersion(), VERSION01);
290 Assert.assertEquals(vsp2.getVersionInfo().getStatus(), org.openecomp.sdc.versioning.dao.types.VersionStatus.Locked);
291 Assert.assertEquals(vsp2.getVersionInfo().getLockingUser(), USER2);
294 @Test(dependsOnMethods = {"testCheckout"})
295 public void testUndoCheckout() {
296 vendorSoftwareProductManager.undoCheckout(id002, USER2);
298 VersionedVendorSoftwareProductInfo vsp2 =
299 vendorSoftwareProductManager.getVspDetails(id002, null, USER2);
300 Assert.assertEquals(vsp2.getVersionInfo().getActiveVersion(), VERSION01);
301 Assert.assertEquals(vsp2.getVersionInfo().getStatus(), org.openecomp.sdc.versioning.dao.types.VersionStatus.Available);
302 Assert.assertNull(vsp2.getVersionInfo().getLockingUser());
305 @Test(dependsOnMethods = {"testUndoCheckout"})
306 public void testListFinalVspsWhenNone() {
307 List<VersionedVendorSoftwareProductInfo> vspDetailsList =
308 vendorSoftwareProductManager.getVspList(
309 org.openecomp.sdc.versioning.dao.types.VersionStatus.Final.name(), USER1);
310 int nonFinalFoundCount = 0;
311 for (VersionedVendorSoftwareProductInfo vsp : vspDetailsList) {
312 if (vsp.getVspDetails().getId().equals(id001) || vsp.getVspDetails().getId().equals(id002) ||
313 vsp.getVspDetails().getId().equals(id003)) {
314 nonFinalFoundCount++;
318 Assert.assertEquals(nonFinalFoundCount, 0);
321 @Test(dependsOnMethods = "testListFinalVspsWhenNone")
322 public void testSubmitWithoutLicencingData() throws IOException {
323 ValidationResponse validationResponse = vendorSoftwareProductManager.submit(id002, USER2);
324 Assert.assertNotNull(validationResponse);
325 Assert.assertFalse(validationResponse.isValid());
326 List<String> errorIds = validationResponse.getVspErrors().stream().map(ErrorCode::id).distinct()
327 .collect(Collectors.toList());
328 Assert.assertTrue(errorIds.contains(ValidationErrorBuilder.FIELD_VALIDATION_ERROR_ERR_ID));
329 Assert.assertTrue(errorIds.contains(VendorSoftwareProductErrorCodes.VSP_INVALID));
332 @Test(dependsOnMethods = {"testSubmitWithoutLicencingData"})
333 public void testSubmitWithoutUploadData() throws IOException {
334 vendorSoftwareProductManager.checkout(id002, USER2);
336 VspDetails updatedVsp2 =
337 vendorSoftwareProductManager.getVspDetails(id002, null, USER2).getVspDetails();
338 updatedVsp2.setFeatureGroups(new ArrayList<>());
339 updatedVsp2.getFeatureGroups().add(featureGroupId);
340 updatedVsp2.setLicenseAgreement(licenseAgreementId);
342 vendorSoftwareProductManager.updateVsp(updatedVsp2, USER2);
343 activeVersion002 = vendorSoftwareProductManager.checkin(id002, USER2);
345 ValidationResponse validationResponse = vendorSoftwareProductManager.submit(id002, USER2);
346 Assert.assertNotNull(validationResponse);
347 Assert.assertFalse(validationResponse.isValid());
348 Assert.assertTrue(validationResponse.getVspErrors().size() > 0);
351 @Test(dependsOnMethods = {"testSubmitWithoutUploadData"})
352 public void testUploadFile() throws IOException {
353 activeVersion002 = vendorSoftwareProductManager.checkout(id002, USER1);
354 testLegalUpload(id002, activeVersion002,
355 getFileInputStream("/vspmanager/zips/emptyComposition.zip"), USER1);
358 /* @Test(dependsOnMethods = {"testUploadFile"})
359 public void testUploadFile2() throws IOException {
360 testLegalUpload(id002, activeVersion002, ut.getZipInputStream("/legalUpload2"), USER1);
364 public void testDownloadFile() throws IOException {
365 VspDetails expectedVsp = VSPCommon
366 .createVspDetails(null, null, String.format("VSP-test-%s", vlm1Id), "Test-vsp",
367 "vendorName", vlm1Id, "icon", "category", "subCategory", "123", null);
368 VspDetails createdVsp = vendorSoftwareProductManager.createNewVsp(expectedVsp, USER1);
370 id005 = createdVsp.getId();
371 Assert.assertNotNull(id005);
372 Assert.assertNotNull(createdVsp.getVersion());
374 //InputStream zipInputStream = getFileInputStream("/legalUpload/zip/legalUpload.zip")
375 try (InputStream zipInputStream = ut.getZipInputStream("/legalUpload")) {
377 UploadFileResponse resp =
378 vendorSoftwareProductManager.uploadFile(id005, zipInputStream, USER1);
379 File latestHeatPackage = vendorSoftwareProductManager.getLatestHeatPackage(id005, USER1);
381 zipInputStream.reset();
382 byte[] uploaded = IOUtils.toByteArray(zipInputStream);
385 try (BufferedInputStream fileStream = new BufferedInputStream(
386 new FileInputStream(latestHeatPackage))) {
387 downloaded = IOUtils.toByteArray(fileStream);
390 Assert.assertTrue(Arrays.equals(uploaded, downloaded));
394 @Test(dependsOnMethods = {"testUploadFile"})
395 public void testUploadNotExistingFile() throws IOException {
396 URL url = this.getClass().getResource("notExist.zip");
397 testLegalUpload(id002, activeVersion002, url == null ? null : url.openStream(), USER1);
400 @Test(dependsOnMethods = {"testUploadFile"}, expectedExceptions = CoreException.class)
401 public void negativeTestCreatePackageBeforeSubmit() throws IOException {
402 vendorSoftwareProductManager.createPackage(id002, USER1);
405 @Test(dependsOnMethods = {"negativeTestCreatePackageBeforeSubmit"})
406 public void negativeTestGetVSPDetailsNonExistingVersion() {
408 vendorSoftwareProductManager.getVspDetails(id002, new Version(43, 8), USER1);
409 Assert.assertTrue(false);
410 } catch (CoreException e) {
411 Assert.assertEquals(e.code().id(), VersioningErrorCodes.REQUESTED_VERSION_INVALID);
415 @Test(dependsOnMethods = {"negativeTestCreatePackageBeforeSubmit"})
416 public void negativeTestGetVSPDetailsCheckoutByOtherVersion() {
418 vendorSoftwareProductManager.getVspDetails(id002, activeVersion002, USER2);
419 Assert.assertTrue(false);
420 } catch (CoreException e) {
421 Assert.assertEquals(e.code().id(), VersioningErrorCodes.REQUESTED_VERSION_INVALID);
425 @Test(dependsOnMethods = {"negativeTestCreatePackageBeforeSubmit"})
426 public void testGetVSPDetailsCandidateVersion() {
427 VersionedVendorSoftwareProductInfo actualVsp =
428 vendorSoftwareProductManager.getVspDetails(id002, new Version(0, 3), USER1);
430 VspDetails expectedVsp = vendorSoftwareProductDao
431 .getVendorSoftwareProductInfo(new VspDetails(id002, new Version(0, 3)));
432 assertVspsEquals(actualVsp.getVspDetails(), expectedVsp);
433 Assert.assertEquals(actualVsp.getVersionInfo().getActiveVersion(), new Version(0, 3));
434 Assert.assertEquals(actualVsp.getVersionInfo().getStatus(), org.openecomp.sdc.versioning.dao.types.VersionStatus.Locked);
435 Assert.assertEquals(actualVsp.getVersionInfo().getLockingUser(), USER1);
438 @Test(dependsOnMethods = {"negativeTestCreatePackageBeforeSubmit"})
439 public void testGetVSPDetailsOldVersion() {
440 VersionedVendorSoftwareProductInfo actualVsp =
441 vendorSoftwareProductManager.getVspDetails(id002, new Version(0, 1), USER2);
443 VspDetails expectedVsp = vendorSoftwareProductDao
444 .getVendorSoftwareProductInfo(new VspDetails(id002, new Version(0, 1)));
445 assertVspsEquals(actualVsp.getVspDetails(), expectedVsp);
446 Assert.assertEquals(actualVsp.getVersionInfo().getActiveVersion(), new Version(0, 2));
447 Assert.assertEquals(actualVsp.getVersionInfo().getStatus(), org.openecomp.sdc.versioning.dao.types.VersionStatus.Locked);
448 Assert.assertEquals(actualVsp.getVersionInfo().getLockingUser(), USER1);
451 @Test(dependsOnMethods = {"negativeTestGetVSPDetailsNonExistingVersion",
452 "negativeTestGetVSPDetailsCheckoutByOtherVersion", "testGetVSPDetailsCandidateVersion",
453 "testGetVSPDetailsOldVersion"})
454 public void testSubmit() throws IOException {
455 activeVersion002 = vendorSoftwareProductManager.checkin(id002, USER1);
456 ValidationResponse validationResponse = vendorSoftwareProductManager.submit(id002, USER1);
457 Assert.assertTrue(validationResponse.isValid());
459 VersionedVendorSoftwareProductInfo vsp2 =
460 vendorSoftwareProductManager.getVspDetails(id002, null, USER1);
461 Assert.assertEquals(vsp2.getVersionInfo().getActiveVersion(), VERSION10);
462 Assert.assertEquals(vsp2.getVersionInfo().getStatus(), org.openecomp.sdc.versioning.dao.types.VersionStatus.Final);
463 Assert.assertNull(vsp2.getVersionInfo().getLockingUser());
466 @Test(dependsOnMethods = {"testSubmit"})
467 public void testListFinalVspsWhenExist() {
468 List<VersionedVendorSoftwareProductInfo> vspDetailsList =
469 vendorSoftwareProductManager.getVspList(
470 org.openecomp.sdc.versioning.dao.types.VersionStatus.Final.name(), USER1);
471 int nonFinalFoundCount = 0;
472 boolean found002 = false;
473 for (VersionedVendorSoftwareProductInfo vsp : vspDetailsList) {
474 if (vsp.getVspDetails().getId().equals(id002)) {
477 if (vsp.getVspDetails().getId().equals(id001) || vsp.getVspDetails().getId().equals(id003)) {
478 nonFinalFoundCount++;
482 Assert.assertEquals(nonFinalFoundCount, 0);
483 Assert.assertTrue(found002);
486 @Test(dependsOnMethods = {"testSubmit"})
487 public void testCreatePackage() throws IOException {
488 PackageInfo packageInfo = vendorSoftwareProductManager.createPackage(id002, USER1);
489 Assert.assertNotNull(packageInfo.getVspId());
493 public void testUploadFileWithoutManifest() {
494 InputStream zis = getFileInputStream("/vspmanager/zips/withoutManifest.zip");
495 VspDetails vspDetails = vendorSoftwareProductManager.createNewVsp(VSPCommon
496 .createVspDetails(null, null, "VSP5", "Test-vsp", "vendorName", vlm1Id, "icon", "category",
497 "subCategory", "456", null), USER1);
498 id004 = vspDetails.getId();
500 UploadFileResponse uploadFileResponse =
501 vendorSoftwareProductManager.uploadFile(id004, zis, USER1);
503 Assert.assertNotNull(uploadFileResponse.getErrors());
504 Assert.assertEquals(uploadFileResponse.getErrors().size(), 1);
507 @Test(dependsOnMethods = {"testUploadFileWithoutManifest"})
508 public void testUploadFileMissingFile() {
509 InputStream zis = getFileInputStream("/vspmanager/zips/missingYml.zip");
511 UploadFileResponse uploadFileResponse =
512 vendorSoftwareProductManager.uploadFile(id004, zis, USER1);
514 Assert.assertEquals(uploadFileResponse.getErrors().size(), 3);
517 @Test(dependsOnMethods = {"testUploadFileMissingFile"})
518 public void testUploadNotZipFile() throws IOException {
519 URL url = this.getClass().getResource("/notZipFile");
520 UploadFileResponse uploadFileResponse =
521 vendorSoftwareProductManager.uploadFile(id004, url.openStream(), USER1);
523 Assert.assertNotNull(uploadFileResponse.getErrors());
525 uploadFileResponse.getErrors().get(AsdcCommon.UPLOAD_FILE).get(0).getMessage(),
526 Messages.INVALID_ZIP_FILE.getErrorMessage());
530 public void testEnrichModelInSubmit() {
532 .deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME,
534 VspDetails vspDetails = vendorSoftwareProductManager.createNewVsp(VSPCommon
535 .createVspDetails(null, null, "VSP_syb", "Test-vsp_syb", "vendorName", vlm1Id, "icon",
536 "category", "subCategory", "456", null), USER1);
537 String id = vspDetails.getId();
540 InputStream zis = getFileInputStream("/vspmanager/zips/fullComposition.zip");
541 UploadFileResponse uploadFileResponse = vendorSoftwareProductManager.uploadFile(id, zis, USER1);
544 vendorSoftwareProductManager.checkin(id, USER1);
547 ValidationResponse result = vendorSoftwareProductManager.submit(id, USER1);
548 } catch (IOException e) {
551 VersionedVendorSoftwareProductInfo details =
552 vendorSoftwareProductManager.getVspDetails(id, null, USER1);
553 Collection<org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity> components = vendorSoftwareProductManager
554 .listComponents(id, details.getVersionInfo().getActiveVersion(), USER1);
556 ToscaServiceModel model =
557 (ToscaServiceModel) EnrichedServiceModelDaoFactory.getInstance().createInterface()
558 .getServiceModel(id, details.getVersionInfo().getActiveVersion());
560 Map<String, CapabilityDefinition> capabilities = new HashMap<>();
561 for (org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity component : components) {
562 model.getServiceTemplates().
565 filter(entryValue -> entryValue.getValue() != null &&
566 entryValue.getValue().getNode_types() != null &&
567 entryValue.getValue().
569 containsKey(component.getComponentCompositionData().getName())).
570 forEach(entryValue -> entryValue.getValue().getNode_types().
573 filter(type -> MapUtils.isNotEmpty(type.getCapabilities())).
574 forEach(type -> type.getCapabilities().
576 forEach(entry -> addCapability(entryValue.getKey(), capabilities, entry.getKey(),
577 entry.getValue()))));
581 Assert.assertNotNull(capabilities);
584 @Test(dependsOnMethods = {"testEnrichModelInSubmit"})
585 public void testVSPListSortedByModificationTimeDescOreder() {
587 .createVspDetails(null, null, "vsp1_test", "Test-vsp", "vendorName", vlm1Id, "icon",
588 "category", "subCategory", "123", null);
589 id006 = vendorSoftwareProductManager.createNewVsp(vsp1, USER3).getId();
592 .createVspDetails(null, null, "vsp2_test", "Test-vsp", "vendorName", vlm1Id, "icon",
593 "category", "subCategory", "123", null);
594 id007 = vendorSoftwareProductManager.createNewVsp(vsp2, USER3).getId();
596 assertVSPInWantedLocationInVSPList(id007, 0, USER3);
597 assertVSPInWantedLocationInVSPList(id006, 1, USER3);
600 @Test(dependsOnMethods = {"testVSPListSortedByModificationTimeDescOreder"})
601 public void testUpdatedVSPShouldBeInBeginningOfList() {
602 vendorSoftwareProductManager.updateVsp(vsp1, USER3);
603 assertVSPInWantedLocationInVSPList(id006, 0, USER3);
605 vendorSoftwareProductManager
606 .uploadFile(id007, getFileInputStream("/vspmanager/zips/emptyComposition.zip"), USER3);
607 assertVSPInWantedLocationInVSPList(id007, 0, USER3);
610 @Test(dependsOnMethods = {"testUpdatedVSPShouldBeInBeginningOfList"})
611 public void testVSPInBeginningOfListAfterCheckin() {
612 vendorSoftwareProductManager.checkin(id006, USER3);
613 assertVSPInWantedLocationInVSPList(id006, 0, USER3);
615 vendorSoftwareProductManager.checkin(id007, USER3);
616 assertVSPInWantedLocationInVSPList(id007, 0, USER3);
619 @Test(dependsOnMethods = {"testVSPInBeginningOfListAfterCheckin"})
620 public void testVSPInBeginningOfListAfterCheckout() {
621 vendorSoftwareProductManager.checkout(id006, USER3);
622 assertVSPInWantedLocationInVSPList(id006, 0, USER3);
625 @Test(dependsOnMethods = {"testVSPInBeginningOfListAfterCheckout"})
626 public void testVSPInBeginningOfListAfterUndoCheckout() {
627 vendorSoftwareProductManager.checkout(id007, USER3);
628 assertVSPInWantedLocationInVSPList(id007, 0, USER3);
630 vendorSoftwareProductManager.undoCheckout(id006, USER3);
631 assertVSPInWantedLocationInVSPList(id006, 0, USER3);
634 @Test(dependsOnMethods = {"testVSPInBeginningOfListAfterUndoCheckout"})
635 public void testVSPInBeginningOfListAfterSubmit() throws IOException {
636 vendorSoftwareProductManager.checkin(id007, USER3);
637 vendorSoftwareProductManager.submit(id007, USER3);
639 assertVSPInWantedLocationInVSPList(id007, 0, USER3);
642 private void testLegalUpload(String vspId, Version version, InputStream upload, String user) {
643 vendorSoftwareProductManager.uploadFile(vspId, upload, user);
645 UploadDataEntity uploadData =
646 vendorSoftwareProductDao.getUploadData(new UploadDataEntity(vspId, version));
647 Assert.assertNotNull(uploadData);
648 Assert.assertNotNull(uploadData.getContentData());
651 private void addCapability(String entryValueKey, Map<String, CapabilityDefinition> capabilities,
652 String key, CapabilityDefinition value) {
654 capabilities.put(entryValueKey + "_" + key, value);
657 private InputStream getFileInputStream(String fileName) {
658 URL url = this.getClass().getResource(fileName);
660 return url.openStream();
661 } catch (IOException e) {
667 private void assertVSPInWantedLocationInVSPList(String vspId, int location, String user) {
668 List<VersionedVendorSoftwareProductInfo> vspList =
669 vendorSoftwareProductManager.getVspList(null, user);
670 Assert.assertEquals(vspList.get(location).getVspDetails().getId(), vspId);