[sdc] docker file fix for cassandra
[sdc.git] / openecomp-be / backend / openecomp-sdc-vendor-software-product-manager / src / test / java / org / openecomp / sdc / vendorsoftwareproduct / VSPCommon.java
1 package org.openecomp.sdc.vendorsoftwareproduct;
2
3 import org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity;
4 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
5
6 import org.openecomp.sdc.versioning.dao.types.Version;
7 import org.openecomp.core.utilities.file.FileUtils;
8
9 import java.io.*;
10 import java.util.List;
11 import java.util.zip.ZipEntry;
12 import java.util.zip.ZipOutputStream;
13
14 public class VSPCommon {
15
16   public static VspDetails createVspDetails(String id, Version version, String name, String desc,
17                                             String vendorName, String vlm, String icon,
18                                             String category, String subCategory,
19                                             String licenseAgreement, List<String> featureGroups) {
20     VspDetails vspDetails = new VspDetails(id, version);
21     vspDetails.setName(name);
22     vspDetails.setDescription(desc);
23     vspDetails.setIcon(icon);
24     vspDetails.setCategory(category);
25     vspDetails.setSubCategory(subCategory);
26     vspDetails.setVendorName(vendorName);
27     vspDetails.setVendorId(vlm);
28     vspDetails.setVlmVersion(new Version(1, 0));
29     vspDetails.setLicenseAgreement(licenseAgreement);
30     vspDetails.setFeatureGroups(featureGroups);
31     return vspDetails;
32   }
33
34
35   public static VendorLicenseModelEntity createVendorLicenseModel(String name, String desc,
36                                                                   String icon) {
37     VendorLicenseModelEntity vendorLicenseModel = new VendorLicenseModelEntity();
38     vendorLicenseModel.setVendorName(name);
39     vendorLicenseModel.setDescription(desc);
40     vendorLicenseModel.setIconRef(icon);
41     return vendorLicenseModel;
42   }
43
44   public static void zipDir(File file, String path, ZipOutputStream zos) {
45     zipDir(file, path, zos, false);
46   }
47
48   public static void zipDir(File file, String path, ZipOutputStream zos, boolean isRootDir) {
49     if (file.isDirectory()) {
50       path += File.separator + file.getName();
51       File[] files = file.listFiles();
52       if (files != null) {
53         for (File innerFile : files) {
54           if (isRootDir) {
55             zipDir(innerFile, "", zos, false);
56           } else {
57             zipDir(innerFile, path, zos, false);
58           }
59         }
60       }
61     } else {
62
63       try {
64         if (!path.isEmpty()) {
65           path += File.separator;
66         }
67         zos.putNextEntry(new ZipEntry(path + file.getName()));
68         InputStream is = new FileInputStream(file);
69         byte[] data = FileUtils.toByteArray(is);
70         zos.write(data);
71         zos.closeEntry();
72       } catch (IOException e) {
73         e.printStackTrace();
74       }
75     }
76   }
77
78 }