re base code
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / US / LocalGeneralUtilities.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.ci.tests.US;
22
23 import org.json.JSONArray;
24 import org.json.simple.JSONObject;
25 import org.json.simple.JSONValue;
26 import org.openecomp.sdc.be.model.User;
27 import org.openecomp.sdc.ci.tests.datatypes.AmdocsLicenseMembers;
28 import org.openecomp.sdc.ci.tests.datatypes.DataTestIdEnum;
29 import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails;
30 import org.openecomp.sdc.ci.tests.datatypes.VendorSoftwareProductObject;
31 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
32 import org.openecomp.sdc.ci.tests.pages.HomePage;
33 import org.openecomp.sdc.ci.tests.utilities.FileHandling;
34 import org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils;
35 import org.openecomp.sdc.ci.tests.utilities.OnboardingUiUtils;
36 import org.openecomp.sdc.ci.tests.utils.general.VendorLicenseModelRestUtils;
37 import org.openecomp.sdc.ci.tests.utils.general.VendorSoftwareProductRestUtils;
38
39 import java.io.File;
40 import java.util.ArrayList;
41 import java.util.List;
42
43 public class LocalGeneralUtilities {
44
45         public LocalGeneralUtilities() {
46         }
47         public static final String FILE_PATH = FileHandling.getBasePath() + "\\src\\main\\resources\\Files\\VNFs\\";
48         public static final String Env_FILE_PATH = FileHandling.getBasePath() + "\\src\\main\\resources\\Files\\Env_files\\";
49         public static String downloadPath = "C:\\Users\\th0695\\Downloads";
50
51 public static String getValueFromJsonResponse(String response, String fieldName) {
52         try {
53                 JSONObject jsonResp = (JSONObject) JSONValue.parse(response);
54                 Object fieldValue = jsonResp.get(fieldName);
55                 return fieldValue.toString();
56
57         } catch (Exception e) {
58                 return null;
59         }
60
61 }
62
63 public static List<String> getValuesFromJsonArray(RestResponse message) throws Exception {
64         List<String> artifactTypesArrayFromApi = new ArrayList<String>();
65
66         org.json.JSONObject responseObject = new org.json.JSONObject(message.getResponse());
67         JSONArray jArr = responseObject.getJSONArray("componentInstances");
68
69         for (int i = 0; i < jArr.length(); i++) {
70                 org.json.JSONObject jObj = jArr.getJSONObject(i);
71                 String value = jObj.get("uniqueId").toString();
72
73                 artifactTypesArrayFromApi.add(value);
74         }
75         return artifactTypesArrayFromApi;
76 }
77
78 public static String simpleOnBoarding(ResourceReqDetails resourceReqDetails, String fileName, String filePath,User user) throws Exception {
79         AmdocsLicenseMembers amdocsLicenseMembers = VendorLicenseModelRestUtils.createVendorLicense(user);
80         VendorSoftwareProductObject createVendorSoftwareProduct = VendorSoftwareProductRestUtils.createVendorSoftwareProduct(resourceReqDetails, fileName, filePath, user, amdocsLicenseMembers);
81         String vspName = createVendorSoftwareProduct.getName();
82         HomePage.showVspRepository();
83         OnboardingUiUtils.importVSP(createVendorSoftwareProduct);
84         GeneralUIUtils.getWebElementByTestID(DataTestIdEnum.GeneralElementsEnum.CHECKIN_BUTTON.getValue()).click();
85         GeneralUIUtils.waitForLoader();
86         return vspName;
87 }
88
89 //check if file downloaded successfully.
90 public static boolean isFileDownloaded(String downloadPath, String fileName) {
91         boolean flag = false;
92         File dir = new File(downloadPath);
93         File[] dir_contents = dir.listFiles();
94         for (int i = 0; i < dir_contents.length; i++) {
95                 if (dir_contents[i].getName().equals(fileName))
96                         return flag = true;
97         }
98         return flag;
99 }
100 }