1 package org.openecomp.sdc.vendorsoftwareproduct.upload.HeatCleanup;
3 import org.openecomp.sdc.datatypes.error.ErrorLevel;
4 import org.openecomp.sdc.vendorsoftwareproduct.VSPCommon;
5 import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants;
6 import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager;
7 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao;
8 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory;
9 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity;
10 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.UploadDataEntity;
11 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
12 import org.openecomp.sdc.vendorsoftwareproduct.impl.VendorSoftwareProductManagerImpl;
13 import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse;
14 import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileStatus;
15 import org.openecomp.sdc.versioning.dao.types.Version;
16 import org.openecomp.core.model.dao.ServiceModelDao;
17 import org.openecomp.core.model.dao.ServiceModelDaoFactory;
18 import org.openecomp.core.util.UniqueValueUtil;
19 import org.openecomp.core.validation.types.MessageContainerUtil;
20 import org.apache.commons.collections4.CollectionUtils;
21 import org.apache.commons.collections4.MapUtils;
22 import org.testng.Assert;
23 import org.testng.annotations.BeforeClass;
24 import org.testng.annotations.Test;
26 import java.io.IOException;
27 import java.io.InputStream;
29 import java.util.List;
31 public class HeatCleanupOnNewUploadTest {
32 private static final String USER1 = "vspTestUser1";
34 private static final VendorSoftwareProductManager vendorSoftwareProductManager =
35 new VendorSoftwareProductManagerImpl();
36 private static final VendorSoftwareProductDao vendorSoftwareProductDao =
37 VendorSoftwareProductDaoFactory.getInstance().createInterface();
38 private static final ServiceModelDao serviceModelDao =
39 ServiceModelDaoFactory.getInstance().createInterface();
41 private static String vspId = null;
42 private static Version vspActiveVersion = null;
44 private static void validateUploadContentExistence(boolean exist) {
45 UploadDataEntity uploadDataEntity =
46 vendorSoftwareProductDao.getUploadData(new UploadDataEntity(vspId, vspActiveVersion));
47 Assert.assertTrue((uploadDataEntity.getContentData() != null) == exist);
48 Assert.assertTrue((uploadDataEntity.getValidationData() != null) == exist);
49 Assert.assertTrue((uploadDataEntity.getPackageName() != null) == exist);
50 Assert.assertTrue((uploadDataEntity.getPackageVersion() != null) == exist);
51 Assert.assertTrue((serviceModelDao.getServiceModel(vspId, vspActiveVersion) != null) == exist);
54 private static void validateCompositionDataExistence(boolean exist) {
55 Assert.assertTrue(CollectionUtils
56 .isNotEmpty(vendorSoftwareProductDao.listNetworks(vspId, vspActiveVersion)) == exist);
57 Assert.assertTrue(CollectionUtils
58 .isNotEmpty(vendorSoftwareProductDao.listComponents(vspId, vspActiveVersion)) == exist);
59 Assert.assertTrue(CollectionUtils
60 .isNotEmpty(vendorSoftwareProductDao.listNicsByVsp(vspId, vspActiveVersion)) == exist);
63 private static InputStream getFileInputStream(String fileName) {
64 URL url = HeatCleanupOnNewUploadTest.class.getResource(fileName);
66 return url.openStream();
67 } catch (IOException e) {
76 .deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME,
79 VspDetails vspDetails = vendorSoftwareProductManager.createNewVsp(VSPCommon
80 .createVspDetails(null, null, "VSPTestEmpty", "Test-vsp-empty", "vendorName", "vlm1Id",
81 "icon", "category", "subCategory", "123", null), USER1);
82 vspId = vspDetails.getId();
83 vspActiveVersion = vspDetails.getVersion();
87 public void testUploadWithComposition() {
88 InputStream zis = getFileInputStream("/vspmanager/zips/fullComposition.zip");
90 UploadFileResponse uploadFileResponse =
91 vendorSoftwareProductManager.uploadFile(vspId, zis, USER1);
93 Assert.assertEquals(uploadFileResponse.getStatus(), UploadFileStatus.Success);
94 Assert.assertTrue(MapUtils.isEmpty(
95 MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, uploadFileResponse.getErrors())));
97 validateUploadContentExistence(true);
98 validateCompositionDataExistence(true);
101 @Test(dependsOnMethods = {"testUploadWithComposition"})
102 public void testProccesesMIBsDeletionAfterNewUpload() {
103 InputStream zis1 = getFileInputStream("/vspmanager/zips/fullComposition.zip");
104 InputStream zis2 = getFileInputStream("/vspmanager/zips/fullComposition.zip");
105 InputStream mib = getFileInputStream("/vspmanager/zips/vDNS.zip");
107 vendorSoftwareProductManager.uploadFile(vspId, zis1, USER1);
108 List<ComponentEntity> components =
109 (List<ComponentEntity>) vendorSoftwareProductDao.listComponents(vspId, vspActiveVersion);
110 String componentId = components.get(0).getId();
112 vendorSoftwareProductManager
113 .uploadComponentMib(mib, "vDNS.zip", vspId, componentId, true, USER1);
114 vendorSoftwareProductManager
115 .createProcess(new org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity(vspId, vspActiveVersion, componentId, null), USER1);
117 vendorSoftwareProductManager.uploadFile(vspId, zis2, USER1);
119 vendorSoftwareProductManager.listMibFilenames(vspId, componentId, USER1).getSnmpTrap() ==
121 Assert.assertTrue(CollectionUtils
122 .isEmpty(vendorSoftwareProductDao.listProcesses(vspId, vspActiveVersion, componentId)));
125 @Test(dependsOnMethods = {"testProccesesMIBsDeletionAfterNewUpload"})
126 public void testInvalidStructureUploadAfterFullComposition() {
127 InputStream zis = getFileInputStream("/vspmanager/zips/withoutManifest.zip");
129 UploadFileResponse uploadFileResponse =
130 vendorSoftwareProductManager.uploadFile(vspId, zis, USER1);
131 Assert.assertEquals(uploadFileResponse.getStatus(), UploadFileStatus.Failure);
132 Assert.assertTrue(MapUtils.isNotEmpty(
133 MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, uploadFileResponse.getErrors())));
135 validateUploadContentExistence(true);
136 validateCompositionDataExistence(true);
139 @Test(dependsOnMethods = {"testInvalidStructureUploadAfterFullComposition"})
140 public void testInvalidUploadAfterFullComposition() {
141 InputStream zis = getFileInputStream("/vspmanager/zips/missingYml.zip");
143 UploadFileResponse uploadFileResponse =
144 vendorSoftwareProductManager.uploadFile(vspId, zis, USER1);
145 Assert.assertEquals(uploadFileResponse.getStatus(), UploadFileStatus.Success);
146 Assert.assertTrue(MapUtils.isNotEmpty(
147 MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, uploadFileResponse.getErrors())));
149 validateUploadContentExistence(true);
150 validateCompositionDataExistence(false);
153 @Test(dependsOnMethods = {"testInvalidUploadAfterFullComposition"})
154 public void testEmptyCompositionUploadAfterFullComposition() throws IOException {
155 testUploadWithComposition();
157 InputStream zis = getFileInputStream("/vspmanager/zips/emptyComposition.zip");
158 UploadFileResponse uploadFileResponse =
159 vendorSoftwareProductManager.uploadFile(vspId, zis, USER1);
160 Assert.assertEquals(uploadFileResponse.getStatus(), UploadFileStatus.Success);
161 Assert.assertTrue(MapUtils.isEmpty(
162 MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, uploadFileResponse.getErrors())));
164 validateUploadContentExistence(true);
165 validateCompositionDataExistence(false);