1 package org.openecomp.sdc.vendorsoftwareproduct.tree;
3 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
4 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacadeFactory;
5 import org.openecomp.sdc.vendorsoftwareproduct.VSPCommon;
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.UploadDataEntity;
10 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
11 import org.openecomp.sdc.vendorsoftwareproduct.impl.VendorSoftwareProductManagerImpl;
12 import org.openecomp.sdc.versioning.dao.types.Version;
13 import org.junit.BeforeClass;
14 import org.junit.Test;
18 import java.util.zip.ZipOutputStream;
20 public class UploadFileTest {
23 public static final Version VERSION01 = new Version(0, 1);
24 private static final String USER1 = "vspTestUser1";
25 public static String id001 = null;
26 public static String id002 = null;
27 public static Version activeVersion002 = null;
28 private static VendorSoftwareProductManager vendorSoftwareProductManager =
29 new VendorSoftwareProductManagerImpl();
30 private static VendorSoftwareProductDao vendorSoftwareProductDao =
31 VendorSoftwareProductDaoFactory.getInstance().createInterface();
32 private static VendorLicenseFacade vendorLicenseFacade =
33 VendorLicenseFacadeFactory.getInstance().createInterface();
34 private static String vlm1Id;
37 static public void init() {
40 vlm1Id = vendorLicenseFacade.createVendorLicenseModel(
41 VSPCommon.createVendorLicenseModel("vlmName", "vlm1Id desc", "icon1"), USER1).getId();
42 VspDetails expectedVsp = VSPCommon
43 .createVspDetails(null, null, "VSP1", "Test-vsp", "vendorName", vlm1Id, "icon", "category",
44 "subCategory", "123", null);
46 VspDetails createdVsp = vendorSoftwareProductManager.createNewVsp(expectedVsp, USER1);
47 id001 = createdVsp.getId();
49 VspDetails actualVsp =
50 vendorSoftwareProductDao.getVendorSoftwareProductInfo(new VspDetails(id001, VERSION01));
51 expectedVsp.setId(id001);
52 expectedVsp.setVersion(VERSION01);
58 public void testUploadFile() {
59 //vspActiveVersion = vendorSoftwareProductManager.checkout(id001, USER1);
60 vendorSoftwareProductManager.uploadFile(id001, getZipInputStream("/legalUpload"), USER1);
61 //testLegalUpload(id001, vspActiveVersion, getZipInputStream("/legalUpload"), USER1);
65 private void testLegalUpload(String vspId, Version version, InputStream upload, String user) {
66 vendorSoftwareProductManager.uploadFile(vspId, upload, user);
68 UploadDataEntity uploadData =
69 vendorSoftwareProductDao.getUploadData(new UploadDataEntity(vspId, version));
73 public InputStream getZipInputStream(String name) {
74 URL url = this.getClass().getResource(name);
75 File templateDir = new File(url.getFile());
77 ByteArrayOutputStream baos = new ByteArrayOutputStream();
78 ZipOutputStream zos = new ZipOutputStream(baos);
80 VSPCommon.zipDir(templateDir, "", zos, true);
83 } catch (IOException e) {
86 return new ByteArrayInputStream(baos.toByteArray());