re base code
[sdc.git] / test-apis-ci / src / main / java / org / openecomp / sdc / ci / tests / utils / rest / AutomationUtils.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.utils.rest;
22
23 import org.openecomp.sdc.ci.tests.config.Config;
24 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
25 import org.openecomp.sdc.ci.tests.utils.Utils;
26
27 import java.io.File;
28 import java.io.FileNotFoundException;
29 import java.io.FileOutputStream;
30 import java.io.IOException;
31
32 public class AutomationUtils extends BaseRestUtils {
33         
34         
35         public static String getOnboardVersion()  {
36                 String onboardVersionStr = null;
37                 try {
38                         
39                         RestResponse onboardVersion = CatalogRestUtils.getOnboardVersion();
40                         onboardVersionStr = ResponseParser.getValueFromJsonResponse(onboardVersion.getResponse() , "Version");
41                                                 
42                 } catch (Exception e) {
43                         System.out.println("UnknownOnboardVersion");
44                 }
45                 return onboardVersionStr != null ? onboardVersionStr : "UnknownOnboardVersion";
46                 
47         }
48
49         public static String getOSVersion()  {
50                 String osVersionStr = null;
51                 try {
52                         RestResponse osVersion = CatalogRestUtils.getOsVersion();
53                         osVersionStr = ResponseParser.getVersionFromResponse(osVersion);
54                         
55                 } catch (Exception e) {
56                         System.out.println("UnknownOSversion");
57                 }
58         
59                 return osVersionStr != null  ? osVersionStr : "UnknownOSversion" ;
60         }
61         
62         
63         
64         public static void createVersionsInfoFile(String filepath, String onboardVersion, String osVersion, String envData, String suiteName) throws IOException {
65                 File myFoo = new File(filepath);
66                 try (FileOutputStream fooStream = new FileOutputStream(myFoo, false)) {
67                         String versions = ("onboardVersion=\"" + onboardVersion + "\"\n" + "osVersion=\"" + osVersion + "\"\n" + "env=\"" + envData + "\"\n" + "suiteName=\"" + suiteName + "\"\n");
68                         byte[] myBytes = versions.getBytes();
69                         fooStream.write(myBytes);
70                 }
71         }
72
73         public static void createVersionsInfoFile(String filepath, String onboardVersion, String osVersion, String envData, String suiteName, String reportStartTime) throws IOException {
74                 File myFoo = new File(filepath);
75                 try (FileOutputStream fooStream = new FileOutputStream(myFoo, false)) {
76                         String versions = ("onboardVersion=\"" + onboardVersion + "\"\n" + "osVersion=\"" + osVersion + "\"\n" + "env=\"" + envData + "\"\n" + "suiteName=\"" + suiteName + "\"\n" + "reportStartTime=\"" + reportStartTime + "\"\n");
77                         byte[] myBytes = versions.getBytes();
78                         fooStream.write(myBytes);
79                 }
80         }
81         
82         public static void createVersionsInfoFile(String filepath, String onboardVersion, String osVersion, String envData)
83                         throws IOException {
84                 createVersionsInfoFile(filepath, onboardVersion, osVersion, envData, null);
85         }
86         
87         public static void addEnvDetailsToReport() throws FileNotFoundException{
88         
89                 Config config = Utils.getConfig();
90                 config.getUrl();
91         }
92         
93         public static File getConfigFile(String configFileName) throws Exception {
94                 File configFile = new File(getBasePath() + File.separator + "conf" + File.separator + configFileName);
95                 if (!configFile.exists()) {
96                         configFile = new File(getConfFilesPath() + configFileName);
97                 }
98                 return configFile;
99         }
100         
101         public static String getCiFilesPath() {
102                 return getBasePath() + File.separator + "src" + File.separator + "main" + File.separator + "resources"
103                                 + File.separator + "ci";
104         }
105
106         public static String getConfFilesPath() {
107                 return getCiFilesPath() + File.separator + "conf" + File.separator;
108         }
109
110         public static String getTestSuitesFilesPath() {
111                 return getCiFilesPath() + File.separator + "testSuites" + File.separator;
112         }
113         public static String getBasePath() {
114                 return System.getProperty("user.dir");
115         }
116         
117
118 }