[SDC-29] Amdocs OnBoard 1707 initial commit.
[sdc.git] / openecomp-be / backend / openecomp-sdc-vendor-software-product-manager / src / test / java / org / openecomp / sdc / vendorsoftwareproduct / utils / VSPCommon.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.vendorsoftwareproduct.utils;
22
23 import org.openecomp.core.utilities.file.FileUtils;
24 import org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity;
25 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
26 import org.openecomp.sdc.versioning.dao.types.Version;
27
28 import java.io.File;
29 import java.io.FileInputStream;
30 import java.io.IOException;
31 import java.io.InputStream;
32 import java.util.List;
33 import java.util.zip.ZipEntry;
34 import java.util.zip.ZipOutputStream;
35
36 public class VSPCommon {
37
38   public static VspDetails createVspDetails(String id, Version version, String name, String desc,
39                                             String vendorName, String vlm, String icon,
40                                             String category, String subCategory,
41                                             String licenseAgreement, List<String> featureGroups) {
42     VspDetails vspDetails = new VspDetails(id, version);
43     vspDetails.setName(name);
44     vspDetails.setDescription(desc);
45     vspDetails.setIcon(icon);
46     vspDetails.setCategory(category);
47     vspDetails.setSubCategory(subCategory);
48     vspDetails.setVendorName(vendorName);
49     vspDetails.setVendorId(vlm);
50     vspDetails.setVlmVersion(new Version(1, 0));
51     vspDetails.setLicenseAgreement(licenseAgreement);
52     vspDetails.setFeatureGroups(featureGroups);
53     return vspDetails;
54   }
55
56
57   public static VendorLicenseModelEntity createVendorLicenseModel(String name, String desc,
58                                                                   String icon) {
59     VendorLicenseModelEntity vendorLicenseModel = new VendorLicenseModelEntity();
60     vendorLicenseModel.setVendorName(name);
61     vendorLicenseModel.setDescription(desc);
62     vendorLicenseModel.setIconRef(icon);
63     return vendorLicenseModel;
64   }
65
66   public static void zipDir(File file, String path, ZipOutputStream zos) {
67     zipDir(file, path, zos, false);
68   }
69
70   public static void zipDir(File file, String path, ZipOutputStream zos, boolean isRootDir) {
71     if (file.isDirectory()) {
72       path += File.separator + file.getName();
73       File[] files = file.listFiles();
74       if (files != null) {
75         for (File innerFile : files) {
76           if (isRootDir) {
77             zipDir(innerFile, "", zos, false);
78           } else {
79             zipDir(innerFile, path, zos, false);
80           }
81         }
82       }
83     } else {
84
85       try {
86         if (!path.isEmpty()) {
87           path += File.separator;
88         }
89         zos.putNextEntry(new ZipEntry(path + file.getName()));
90         InputStream is = new FileInputStream(file);
91         byte[] data = FileUtils.toByteArray(is);
92         zos.write(data);
93         zos.closeEntry();
94       } catch (IOException exception) {
95         exception.printStackTrace();
96       }
97     }
98   }
99
100 }