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.utils.rest;
24 import java.io.FileNotFoundException;
25 import java.io.FileOutputStream;
26 import java.io.IOException;
28 import org.openecomp.sdc.ci.tests.config.Config;
29 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
30 import org.openecomp.sdc.ci.tests.utils.Utils;
32 public class AutomationUtils extends BaseRestUtils {
35 public static String getOnboardVersion() {
36 String onboardVersionStr = null;
39 RestResponse onboardVersion = CatalogRestUtils.getOnboardVersion();
40 onboardVersionStr = ResponseParser.getValueFromJsonResponse(onboardVersion.getResponse() , "Version");
42 } catch (Exception e) {
43 System.out.println("UnknownOnboardVersion");
45 return onboardVersionStr != null ? onboardVersionStr : "UnknownOnboardVersion";
49 public static String getOSVersion() {
50 String osVersionStr = null;
52 RestResponse osVersion = CatalogRestUtils.getOsVersion();
53 osVersionStr = ResponseParser.getVersionFromResponse(osVersion);
55 } catch (Exception e) {
56 System.out.println("UnknownOSversion");
59 return osVersionStr != null ? osVersionStr : "UnknownOSversion" ;
64 public static void createVersionsInfoFile(String filepath, String onboardVersion, String osVersion, String envData, String suiteName) throws IOException {
65 File myFoo = new File(filepath);
66 FileOutputStream fooStream = new FileOutputStream(myFoo, false); // true to append
67 String versions = ("onboardVersion=\""+ onboardVersion+ "\"\n" + "osVersion=\"" + osVersion + "\"\n" + "env=\""+ envData + "\"\n" + "suiteName=\""+ suiteName+ "\"\n");
68 byte[] myBytes = versions.getBytes();
69 fooStream.write(myBytes);
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 FileOutputStream fooStream = new FileOutputStream(myFoo, false); // true to append
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);
82 public static void createVersionsInfoFile(String filepath, String onboardVersion, String osVersion, String envData)
83 throws FileNotFoundException, IOException {
84 createVersionsInfoFile(filepath, onboardVersion, osVersion, envData, null);
87 public static void addEnvDetailsToReport() throws FileNotFoundException{
89 Config config = Utils.getConfig();
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);
101 public static String getCiFilesPath() {
102 return getBasePath() + File.separator + "src" + File.separator + "main" + File.separator + "resources"
103 + File.separator + "ci";
106 public static String getConfFilesPath() {
107 return getCiFilesPath() + File.separator + "conf" + File.separator;
110 public static String getTestSuitesFilesPath() {
111 return getCiFilesPath() + File.separator + "testSuites" + File.separator;
113 public static String getBasePath() {
114 return System.getProperty("user.dir");