push addional code
[sdc.git] / openecomp-be / backend / openecomp-sdc-vendor-software-product-manager / src / test / java / org / openecomp / sdc / vendorsoftwareproduct / tree / UploadFileTest.java
1 package org.openecomp.sdc.vendorsoftwareproduct.tree;
2
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;
15
16 import java.io.*;
17 import java.net.URL;
18 import java.util.zip.ZipOutputStream;
19
20 public class UploadFileTest {
21
22
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;
35
36   @BeforeClass
37   static public void init() {
38
39     //testCreateVSP
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);
45
46     VspDetails createdVsp = vendorSoftwareProductManager.createNewVsp(expectedVsp, USER1);
47     id001 = createdVsp.getId();
48
49     VspDetails actualVsp =
50         vendorSoftwareProductDao.getVendorSoftwareProductInfo(new VspDetails(id001, VERSION01));
51     expectedVsp.setId(id001);
52     expectedVsp.setVersion(VERSION01);
53
54
55   }
56
57   @Test
58   public void testUploadFile() {
59     //vspActiveVersion = vendorSoftwareProductManager.checkout(id001, USER1);
60     vendorSoftwareProductManager.uploadFile(id001, getZipInputStream("/legalUpload"), USER1);
61     //testLegalUpload(id001, vspActiveVersion, getZipInputStream("/legalUpload"), USER1);
62   }
63
64
65   private void testLegalUpload(String vspId, Version version, InputStream upload, String user) {
66     vendorSoftwareProductManager.uploadFile(vspId, upload, user);
67
68     UploadDataEntity uploadData =
69         vendorSoftwareProductDao.getUploadData(new UploadDataEntity(vspId, version));
70
71   }
72
73   public InputStream getZipInputStream(String name) {
74     URL url = this.getClass().getResource(name);
75     File templateDir = new File(url.getFile());
76
77     ByteArrayOutputStream baos = new ByteArrayOutputStream();
78     ZipOutputStream zos = new ZipOutputStream(baos);
79
80     VSPCommon.zipDir(templateDir, "", zos, true);
81     try {
82       zos.close();
83     } catch (IOException e) {
84       e.printStackTrace();
85     }
86     return new ByteArrayInputStream(baos.toByteArray());
87   }
88
89
90 }