d6a6c1f17d44f2b962413793fd51ed7a1e90684c
[vid.git] / vid-automation / src / main / java / org / onap / sdc / ci / tests / datatypes / Configuration.java
1 package org.onap.sdc.ci.tests.datatypes;
2
3 import java.io.File;
4 import java.io.IOException;
5 import java.io.InputStream;
6 import java.nio.file.Files;
7 import java.nio.file.Paths;
8
9 import org.yaml.snakeyaml.Yaml;
10
11 public class Configuration {
12         
13         private String beHost;
14         private String feHost;
15         private int bePort;
16         private int fePort;
17         private String url;
18         private String remoteTestingMachineIP;
19         private int remoteTestingMachinePort;
20         private boolean remoteTesting;
21         private String browser;
22         private String systemUnderDebug;
23         private String reportDBhost;
24         private int reportDBport;
25         private boolean captureTraffic;
26         private boolean useBrowserMobProxy;
27         private String stopOnClassFailure;
28         private String reportFileName;
29         private String reportFolder;
30         private int numOfAttemptsToRefresh;
31         private boolean rerun;
32         private String windowsDownloadDirectory; 
33         private String screenshotFolder;
34         private String harFilesFolder;
35         private boolean useCustomLogin;
36         private String geckoDriverPath;
37         
38         public Configuration(String url) {
39                 super();
40                 basicInit(url, false);
41         }
42         
43         public Configuration(String url, boolean useCustomLogin) {
44                 super();
45                 basicInit(url, useCustomLogin);
46         }
47         
48         private void basicInit(String url, boolean useCustomLogin) {
49                 this.remoteTesting = false;
50                 this.captureTraffic = false;
51                 this.useBrowserMobProxy = false;
52                 this.reportFolder = "." + File.separator + "ExtentReport" + File.separator;
53                 this.reportFileName = "UI_Extent_Report.html";
54                 this.screenshotFolder = reportFolder + "screenshots" + File.separator;
55                 this.harFilesFolder = reportFolder + "har_files" + File.separator;
56                 this.browser = "firefox";
57                 this.url = url;
58                 this.numOfAttemptsToRefresh = 2;
59                 this.useCustomLogin = useCustomLogin;
60                 this.geckoDriverPath = null;
61         }
62
63         public String getGeckoDriverPath(){
64                 return this.geckoDriverPath; }
65
66         public void setGeckoDriverPath(String geckoDriverPath){ this.geckoDriverPath = geckoDriverPath; }
67
68         public String getBeHost() {
69                 return beHost;
70         }
71
72         public void setBeHost(String beHost) {
73                 this.beHost = beHost;
74         }
75
76
77         public String getFeHost() {
78                 return feHost;
79         }
80
81
82         public void setFeHost(String feHost) {
83                 this.feHost = feHost;
84         }
85
86
87         public int getBePort() {
88                 return bePort;
89         }
90
91
92         public void setBePort(int bePort) {
93                 this.bePort = bePort;
94         }
95
96
97         public int getFePort() {
98                 return fePort;
99         }
100
101
102         public void setFePort(int fePort) {
103                 this.fePort = fePort;
104         }
105
106
107         public String getUrl() {
108                 return url;
109         }
110
111
112         public void setUrl(String url) {
113                 this.url = url;
114         }
115
116
117         public String getRemoteTestingMachineIP() {
118                 return remoteTestingMachineIP;
119         }
120
121
122         public void setRemoteTestingMachineIP(String remoteTestingMachineIP) {
123                 this.remoteTestingMachineIP = remoteTestingMachineIP;
124         }
125
126
127         public int getRemoteTestingMachinePort() {
128                 return remoteTestingMachinePort;
129         }
130
131
132         public void setRemoteTestingMachinePort(int remoteTestingMachinePort) {
133                 this.remoteTestingMachinePort = remoteTestingMachinePort;
134         }
135
136
137         public boolean isRemoteTesting() {
138                 return remoteTesting;
139         }
140
141
142         public void setRemoteTesting(boolean remoteTesting) {
143                 this.remoteTesting = remoteTesting;
144         }
145
146
147         public String getBrowser() {
148                 return browser;
149         }
150
151
152         public void setBrowser(String browser) {
153                 this.browser = browser;
154         }
155
156
157         public String getSystemUnderDebug() {
158                 return systemUnderDebug;
159         }
160
161
162         public void setSystemUnderDebug(String systemUnderDebug) {
163                 this.systemUnderDebug = systemUnderDebug;
164         }
165
166
167         public String getReportDBhost() {
168                 return reportDBhost;
169         }
170
171
172         public void setReportDBhost(String reportDBhost) {
173                 this.reportDBhost = reportDBhost;
174         }
175
176
177         public int getReportDBport() {
178                 return reportDBport;
179         }
180
181
182         public void setReportDBport(int reportDBport) {
183                 this.reportDBport = reportDBport;
184         }
185
186
187         public boolean isCaptureTraffic() {
188                 return captureTraffic;
189         }
190
191
192         public void setCaptureTraffic(boolean captureTraffic) {
193                 this.captureTraffic = captureTraffic;
194         }
195
196
197         public boolean isUseBrowserMobProxy() {
198                 return useBrowserMobProxy;
199         }
200
201
202         public void setUseBrowserMobProxy(boolean useBrowserMobProxy) {
203                 this.useBrowserMobProxy = useBrowserMobProxy;
204         }
205
206
207         public String getStopOnClassFailure() {
208                 return stopOnClassFailure;
209         }
210
211
212         public void setStopOnClassFailure(String stopOnClassFailure) {
213                 this.stopOnClassFailure = stopOnClassFailure;
214         }
215
216
217         public String getReportFileName() {
218                 return reportFileName;
219         }
220
221
222         public void setReportFileName(String reportFileName) {
223                 this.reportFileName = reportFileName;
224         }
225
226
227         public String getReportFolder() {
228                 return reportFolder;
229         }
230
231
232         public void setReportFolder(String reportFolder) {
233                 this.reportFolder = reportFolder;
234         }
235
236
237         public int getNumOfAttemptsToRefresh() {
238                 return numOfAttemptsToRefresh;
239         }
240
241
242         public void setNumOfAttemptsToRefresh(int numOfAttemptsToRefresh) {
243                 this.numOfAttemptsToRefresh = numOfAttemptsToRefresh;
244         }
245
246
247         public boolean isRerun() {
248                 return rerun;
249         }
250
251
252         public void setRerun(boolean rerun) {
253                 this.rerun = rerun;
254         }
255
256
257
258
259         public String getWindowsDownloadDirectory() {
260                 return windowsDownloadDirectory;
261         }
262
263         public void setWindowsDownloadDirectory(String windowsDownloadDirectory) {
264                 this.windowsDownloadDirectory = windowsDownloadDirectory;
265         }
266
267         public String getScreenshotFolder() {
268                 return screenshotFolder;
269         }
270
271         public void setScreenshotFolder(String screenshotFolder) {
272                 this.screenshotFolder = screenshotFolder;
273         }
274
275         public String getHarFilesFolder() {
276                 return harFilesFolder;
277         }
278
279         public void setHarFilesFolder(String harFilesFolder) {
280                 this.harFilesFolder = harFilesFolder;
281         }
282
283         public boolean isUseCustomLogin() {
284                 return useCustomLogin;
285         }
286
287         public void setUseCustomLogin(boolean useCustomLogin) {
288                 this.useCustomLogin = useCustomLogin;
289         }
290         
291         public synchronized static Configuration loadConfigFile(File configFile) {      
292                 return loadConfigFile(configFile, Configuration.class);
293         }
294         
295         public Configuration(){
296                 super();
297         }
298         
299         public synchronized static <T> T loadConfigFile(File configFile, Class<T> clazz){
300                 InputStream in = null;
301                 T config = null;
302                 try {
303                         String absolutePath = configFile.getAbsolutePath();
304                         in = Files.newInputStream(Paths.get(absolutePath));
305                         Yaml yaml = new Yaml();
306                         config = yaml.loadAs(in, clazz);
307                         
308                 } catch (IOException e) {
309                         e.printStackTrace();
310                 } finally {
311                         if (in != null) {
312                                 try {
313                                         in.close();
314                                 } catch (IOException e) {
315                                         e.printStackTrace();
316                                 }
317                         }
318                 }
319                 
320                 return config;
321         }
322                 
323                 
324                 
325 }