1 package org.openecomp.sdc.vendorsoftwareproduct;
3 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
4 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacadeFactory;
5 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao;
6 import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory;
7 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity;
8 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
9 import org.openecomp.sdc.vendorsoftwareproduct.impl.VendorSoftwareProductManagerImpl;
10 import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.MibUploadStatus;
11 import org.openecomp.sdc.versioning.dao.types.Version;
12 import org.openecomp.core.util.UniqueValueUtil;
13 import org.openecomp.core.utilities.CommonMethods;
15 import org.testng.Assert;
16 import org.testng.annotations.BeforeTest;
17 import org.testng.annotations.Test;
19 import java.io.IOException;
20 import java.io.InputStream;
23 public class ComponentsUploadTest {
25 private static final String USER1 = "vspTestUser1";
27 private static VendorSoftwareProductManager vendorSoftwareProductManager =
28 new VendorSoftwareProductManagerImpl();
29 private static VendorSoftwareProductDao vendorSoftwareProductDao =
30 VendorSoftwareProductDaoFactory.getInstance().createInterface();
31 private static VendorLicenseFacade vendorLicenseFacade =
32 VendorLicenseFacadeFactory.getInstance().createInterface();
34 private static String vspId = null;
35 private static Version activeVersion = null;
36 private static String trapFileName = "MMSC.zip";
37 private static String pollFileName = "MNS OAM FW.zip";
38 private static String notZipFileName = "notZipFile";
39 private static String zipWithFoldersFileName = "zipFileWithFolder.zip";
40 private static String emptyZipFileName = "emptyZip.zip";
41 private String vlm1Id;
42 private String componentId;
47 .deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME,
49 vlm1Id = vendorLicenseFacade.createVendorLicenseModel(VSPCommon
50 .createVendorLicenseModel("vlmName " + CommonMethods.nextUuId(), "vlm1Id desc", "icon1"),
52 VspDetails vspDetails = vendorSoftwareProductManager.createNewVsp(VSPCommon
53 .createVspDetails(null, null, "VSPTestMib", "Test-vsp-mib", "vendorName", vlm1Id, "icon",
54 "category", "subCategory", "123", null), USER1);
56 vspId = vspDetails.getId();
57 activeVersion = vspDetails.getVersion();
58 componentId = createComponent(new ComponentEntity(vspId, activeVersion, null)).getId();
63 public void testUploadAndFilenamesList() {
64 InputStream zis1 = getFileInputStream("/validation/zips/various/MMSC.zip");
65 InputStream zis2 = getFileInputStream("/validation/zips/various/MNS OAM FW.zip");
67 vendorSoftwareProductManager
68 .uploadComponentMib(zis1, "MMSC.zip", vspId, componentId, true, USER1);
69 vendorSoftwareProductManager
70 .uploadComponentMib(zis2, "MNS OAM FW.zip", vspId, componentId, false, USER1);
72 MibUploadStatus mibUploadStatus =
73 vendorSoftwareProductManager.listMibFilenames(vspId, componentId, USER1);
74 Assert.assertEquals(mibUploadStatus.getSnmpTrap(), trapFileName);
75 Assert.assertEquals(mibUploadStatus.getSnmpPoll(), pollFileName);
78 @Test(dependsOnMethods = "testUploadAndFilenamesList")
79 public void testMibsExistentAfterCheckout() throws IOException {
80 activeVersion = vendorSoftwareProductManager.checkin(vspId, USER1);
81 // UniqueValueUtil.deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.COMPONENT_ARTIFACT_NAME, "MMSC.zip");
82 // UniqueValueUtil.deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.COMPONENT_ARTIFACT_NAME, "MNS OAM FW.zip");
83 activeVersion = vendorSoftwareProductManager.checkout(vspId, USER1);
85 MibUploadStatus mibUploadStatus =
86 vendorSoftwareProductManager.listMibFilenames(vspId, componentId, USER1);
87 Assert.assertNotNull(mibUploadStatus.getSnmpTrap());
88 Assert.assertNotNull(mibUploadStatus.getSnmpPoll());
91 @Test(dependsOnMethods = "testMibsExistentAfterCheckout")
92 public void testDeleteFile() {
93 vendorSoftwareProductManager.deleteComponentMib(vspId, componentId, true, USER1);
94 vendorSoftwareProductManager.deleteComponentMib(vspId, componentId, false, USER1);
96 MibUploadStatus mibUploadStatus =
97 vendorSoftwareProductManager.listMibFilenames(vspId, componentId, USER1);
98 Assert.assertNull(mibUploadStatus.getSnmpTrap());
99 Assert.assertNull(mibUploadStatus.getSnmpPoll());
102 @Test(dependsOnMethods = "testDeleteFile")
103 public void testUploadInvalidZip() {
104 URL url = this.getClass().getResource("/notZipFile");
107 vendorSoftwareProductManager
108 .uploadComponentMib(url.openStream(), notZipFileName, vspId, componentId, true, USER1);
110 } catch (Exception e) {
111 // Assert.assertEquals(e.getMessage(), "MIB uploaded for vendor software product with Id " + vspId + " and version " + activeVersion + " is invalid: Invalid zip file");
112 Assert.assertEquals(e.getMessage(), "Invalid zip file");
116 @Test(dependsOnMethods = "testUploadInvalidZip")
117 public void testUploadZipWithFolders() {
118 InputStream zis = getFileInputStream("/vspmanager/zips/zipFileWithFolder.zip");
121 vendorSoftwareProductManager
122 .uploadComponentMib(zis, zipWithFoldersFileName, vspId, componentId, true, USER1);
124 } catch (Exception e) {
125 Assert.assertEquals(e.getMessage(), "Zip file should not contain folders");
129 @Test(dependsOnMethods = "testUploadZipWithFolders")
130 public void testUploadEmptyZip() {
131 InputStream zis = getFileInputStream("/vspmanager/zips/emptyZip.zip");
134 vendorSoftwareProductManager
135 .uploadComponentMib(zis, emptyZipFileName, vspId, componentId, true, USER1);
137 } catch (Exception e) {
138 Assert.assertEquals(e.getMessage(), "Invalid zip file");
143 private InputStream getFileInputStream(String fileName) {
144 URL url = this.getClass().getResource(fileName);
146 return url.openStream();
147 } catch (IOException e) {
154 private ComponentEntity createComponent(ComponentEntity component) {
155 component.setId(CommonMethods.nextUuId());
156 vendorSoftwareProductDao.createComponent(component);