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