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