2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.ci.tests.utilities;
23 public class OnboardingUtillViaApis {
25 // protected static Map<String, String> prepareHeadersMap(String userId) {
26 // Map<String, String> headersMap = new HashMap<String, String>();
27 // headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), "application/json");
28 // headersMap.put(HttpHeaderEnum.ACCEPT.getValue(), "application/json");
29 // headersMap.put(HttpHeaderEnum.USER_ID.getValue(), userId);
33 // public static Pair<String, VendorSoftwareProductObject> createVspViaApis(ResourceReqDetails resourceReqDetails, String filepath, String vnfFile, User user, Boolean skipReport) throws Exception {
35 // VendorSoftwareProductObject vendorSoftwareProductObject = new VendorSoftwareProductObject();
37 // AmdocsLicenseMembers amdocsLicenseMembers = OnboardingUiUtils.createVendorLicense(user);
38 // Pair<String, Map<String, String>> createVendorSoftwareProduct = OnboardingUiUtils.createVendorSoftwareProduct(resourceReqDetails, vnfFile, filepath, user, amdocsLicenseMembers);
39 // Map<String, String> map = createVendorSoftwareProduct.right;
40 // vendorSoftwareProductObject.setAttContact(map.get("attContact"));
41 // vendorSoftwareProductObject.setCategory(map.get("category"));
42 // vendorSoftwareProductObject.setComponentId(map.get("componentId"));
43 // vendorSoftwareProductObject.setDescription(map.get("description"));
44 // vendorSoftwareProductObject.setSubCategory(map.get("subCategory"));
45 // vendorSoftwareProductObject.setVendorName(map.get("vendorName"));
46 // vendorSoftwareProductObject.setVspId(map.get("vspId"));
47 // Pair<String, VendorSoftwareProductObject> pair = new Pair<String, VendorSoftwareProductObject>(createVendorSoftwareProduct.left, vendorSoftwareProductObject);
51 /* public static Resource createResourceFromVSP(Pair<String, Map<String, String>> createVendorSoftwareProduct, String vspName) throws Exception {
52 List<String> tags = new ArrayList<>();
54 Map<String, String> map = createVendorSoftwareProduct.right;
55 ResourceReqDetails resourceDetails = new ResourceReqDetails();
56 resourceDetails.setCsarUUID(map.get("vspId"));
57 resourceDetails.setCsarVersion("1.0");
58 resourceDetails.setName(vspName);
59 resourceDetails.setTags(tags);
60 resourceDetails.setDescription(map.get("description"));
61 resourceDetails.setResourceType(map.get("componentType"));
62 resourceDetails.addCategoryChain(ResourceCategoryEnum.GENERIC_DATABASE.getCategory(), ResourceCategoryEnum.GENERIC_DATABASE.getSubCategory());
63 resourceDetails.setVendorName(map.get("vendorName"));
64 resourceDetails.setVendorRelease("1.0");
65 resourceDetails.setResourceType("VF");
66 resourceDetails.setResourceVendorModelNumber("666");
67 resourceDetails.setContactId(map.get("attContact"));
68 resourceDetails.setIcon("defaulticon");
69 Resource resource = AtomicOperationUtils.createResourceByResourceDetails(resourceDetails, UserRoleEnum.DESIGNER, true).left().value();
74 // public static Resource createResourceFromVSP(ResourceReqDetails resourceDetails) throws Exception {
75 // Resource resource = AtomicOperationUtils.createResourceByResourceDetails(resourceDetails, UserRoleEnum.DESIGNER, true).left().value();
79 // public static void downloadToscaCsarToDirectory(Component component, File file) {
81 // Either<String, RestResponse> componentToscaArtifactPayload = AtomicOperationUtils.getComponenetArtifactPayload(component, "assettoscacsar");
82 // if(componentToscaArtifactPayload.left().value() != null){
83 // convertPayloadToFile(componentToscaArtifactPayload.left().value(), file);
85 // } catch (Exception e) {
86 // e.printStackTrace();
90 // public static void convertPayloadToFile(String payload, File file, boolean isBased64, boolean isSdcFormat) throws IOException{
92 // Gson gson = new Gson();
93 // byte[] byteArray = null;
94 // Map<String, String> fromJson;
95 // @SuppressWarnings("unchecked")
96 // String string = null;// = fromJson.get("base64Contents").toString();
98 // fromJson = gson.fromJson(payload, Map.class);
99 // string = fromJson.get("base64Contents").toString();
100 // }else if (isBased64) {
101 // byteArray = Base64.decode(string.getBytes(StandardCharsets.UTF_8));
103 // byteArray = payload.getBytes(StandardCharsets.UTF_8);
105 // File downloadedFile = new File(file.getAbsolutePath());
106 // FileOutputStream fos = new FileOutputStream(downloadedFile);
107 // fos.write(byteArray);
113 // public static void convertPayloadToFile(String payload, File file) throws IOException{
115 // Gson gson = new Gson();
116 // @SuppressWarnings("unchecked")
117 // Map<String, String> fromJson = gson.fromJson(payload, Map.class);
118 // String string = fromJson.get("base64Contents").toString();
119 // byte[] byteArray = Base64.decode(string.getBytes(StandardCharsets.UTF_8));
120 // File downloadedFile = new File(file.getAbsolutePath());
121 // FileOutputStream fos = new FileOutputStream(downloadedFile);
122 // fos.write(byteArray);
128 // public static void convertPayloadToZipFile(String payload, File file) throws IOException{
130 // byte[] byteArray = payload.getBytes(StandardCharsets.ISO_8859_1);
131 // File downloadedFile = new File(file.getAbsolutePath());
132 // FileOutputStream fos = new FileOutputStream(downloadedFile);
133 // fos.write(byteArray);
138 //// ZipOutputStream fos = null;
141 //// for (Charset charset : Charset.availableCharsets().values()) {
143 //// // System.out.println("How to do it???");
144 //// File downloadedFile = new File(file.getAbsolutePath() + "_" + charset +".csar");
145 //// fos = new ZipOutputStream(new FileOutputStream(downloadedFile));
146 //// byte[] byteArray = payload.getBytes(charset);
147 //// fos.write(byteArray);
151 //// catch(Exception e){
155 // System.out.println("");
157 //// ZipInputStream zipStream = new ZipInputStream(new ByteArrayInputStream(byteArray));
158 //// ZipEntry entry = null;
159 //// while ((entry = zipStream.getNextEntry()) != null) {
161 //// String entryName = entry.getName();
163 //// FileOutputStream out = new FileOutputStream(file+"/"+entryName);
165 //// byte[] byteBuff = new byte[4096];
166 //// int bytesRead = 0;
167 //// while ((bytesRead = zipStream.read(byteBuff)) != -1)
169 //// out.write(byteBuff, 0, bytesRead);
173 //// zipStream.closeEntry();
175 //// zipStream.close();
180 // BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(payload.getBytes(StandardCharsets.ISO_8859_1)));
181 // String filePath = file.toString();
182 // BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(new File(filePath)));
184 // while((inByte = bis.read()) != -1) bos.write(inByte);
189 // public static Either<String, RestResponse> getVendorSoftwareProduct(String vspId, User user, Boolean validateState) throws Exception {
191 // Config config = Utils.getConfig();
192 // String url = String.format(Urls.GET_VENDOR_SOFTWARE_PRODUCT, config.getCatalogBeHost(), config.getCatalogBePort(), vspId);
193 // String userId = user.getUserId();
194 // Map<String, String> headersMap = prepareHeadersMap(userId);
195 // headersMap.put(HttpHeaderEnum.X_ECOMP_REQUEST_ID_HEADER.getValue(), "123456");
196 // headersMap.put(HttpHeaderEnum.ACCEPT.getValue(), "*/*");
197 // headersMap.put("Accept-Encoding", "gzip, deflate, br");
198 // HttpRequest http = new HttpRequest();
199 // RestResponse response = http.httpSendGet(url, headersMap);
200 // if (validateState) {
201 // assertTrue("add property to resource failed: " + response.getResponseMessage(), response.getErrorCode() == BaseRestUtils.STATUS_CODE_SUCCESS);
203 // if (response.getErrorCode() != BaseRestUtils.STATUS_CODE_SUCCESS && response.getResponse().getBytes() == null && response.getResponse().getBytes().length == 0) {
204 // return Either.right(response);
206 // return Either.left(response.getResponse());
210 // public static ResourceReqDetails prepareOnboardedResourceDetailsBeforeCreate(ResourceReqDetails resourceDetails, VendorSoftwareProductObject vendorSoftwareProductObject) {
212 // List<String> tags = new ArrayList<>();
213 // tags.add(vendorSoftwareProductObject.getName());
214 //// ResourceReqDetails resourceDetails = new ResourceReqDetails();
215 // resourceDetails.setCsarUUID(vendorSoftwareProductObject.getVspId());
216 // resourceDetails.setCsarVersion(vendorSoftwareProductObject.getVersion());
217 // resourceDetails.setName(vendorSoftwareProductObject.getName());
218 // resourceDetails.setTags(tags);
219 // resourceDetails.setDescription(vendorSoftwareProductObject.getDescription());
220 //// resourceDetails.addCategoryChain(ResourceCategoryEnum.GENERIC_DATABASE.getCategory(), ResourceCategoryEnum.GENERIC_DATABASE.getSubCategory());
221 // resourceDetails.setVendorName(vendorSoftwareProductObject.getVendorName());
222 //// resourceDetails.setVendorRelease("1.0");
223 // resourceDetails.setResourceType("VF");
224 // resourceDetails.setResourceVendorModelNumber("666");
225 // resourceDetails.setContactId(vendorSoftwareProductObject.getAttContact());
226 //// resourceDetails.setIcon("defaulticon");
228 // return resourceDetails;
231 /*public static ServiceReqDetails prepareServiceDetailsBeforeCreate(ServiceReqDetails serviceDetails, User user) {
233 serviceDetails.setServiceType("MyServiceType");
234 serviceDetails.setServiceRole("MyServiceRole");
235 serviceDetails.setNamingPolicy("MyServiceNamingPolicy");
236 serviceDetails.setEcompGeneratedNaming(true);
238 return serviceDetails;