[SDC-29] rebase continue work to align source
[sdc.git] / test-apis-ci / src / main / java / org / openecomp / sdc / ci / tests / config / Config.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.config;
22
23 import java.io.File;
24 import java.io.IOException;
25 import java.io.InputStream;
26 import java.nio.file.Files;
27 import java.nio.file.Paths;
28 import java.util.List;
29
30 import org.yaml.snakeyaml.Yaml;
31
32 public class Config {
33
34         private static String WINDOWS_CONFIG_FILE = "src/main/resources/ci/conf/attsdc.yaml";
35         private boolean systemUnderDebug;
36         private boolean rerun;
37         private String reportDBhost;
38         private int reportDBport;
39         
40         private String browser;
41         private String catalogBeHost;
42         private String esHost;
43         private String esPort;
44         private String neoHost;
45         private String neoPort;
46         private String disributionClientHost;
47         private String disributionClientPort;
48         private boolean isDistributionClientRunning;
49
50
51         private String errorConfigurationFile;
52         private String resourceConfigDir;
53         private String componentsConfigDir;
54         private String importResourceConfigDir;
55         private String importResourceTestsConfigDir;
56         private String importTypesConfigDir;
57
58         private String testSuites;
59
60         private String catalogFeHost;
61         private String catalogFePort;
62         private String catalogBePort;
63         private String catalogBeTlsPort;
64
65         private String neoDBusername;
66         private String neoDBpassword;
67
68         private String titanPropertiesFile;
69         private List<String> packages;
70         private List<String> bugs;
71         private List<String> resourcesNotToDelete;
72         private List<String> resourceCategoriesNotToDelete;
73         private List<String> serviceCategoriesNotToDelete;
74         private boolean stopOnClassFailure = false;
75
76         private String outputFolder;
77         private String reportName;
78         private String url;
79         private String remoteTestingMachineIP;
80         private String remoteTestingMachinePort;
81         private boolean remoteTesting;
82
83         private String cassandraHost;
84         private String cassandraAuditKeySpace;
85         private String cassandraArtifactKeySpace;
86         private boolean cassandraAuthenticate;
87         private String cassandraUsername;
88         private String cassandraPassword;
89         private boolean cassandraSsl;
90         private String cassandraTruststorePath;
91         private String cassandraTruststorePassword;
92         private String windowsDownloadDirectory;
93         private boolean captureTraffic;
94         private boolean useBrowserMobProxy;
95         
96         private static Config configIt = null;
97
98         private static Yaml yaml = new Yaml();
99
100         
101         private Config() {
102                 super();
103         }
104
105         public static class TestPackages {
106
107                 List<String> packages;
108                 List<String> bugs;
109
110                 public List<String> getPackages() {
111                         return packages;
112                 }
113
114                 public void setPackages(List<String> packages) {
115                         this.packages = packages;
116                 }
117
118                 public List<String> getBugs() {
119                         return bugs;
120                 }
121
122                 public void setBugs(List<String> bugs) {
123                         this.bugs = bugs;
124                 }
125
126                 @Override
127                 public String toString() {
128                         return "TestPackages [packages=" + packages + ", bugs=" + bugs + "]";
129                 }
130
131         }
132
133         public synchronized static Config instance() {
134                 if (configIt == null) {
135                         try {
136                                 configIt = init();
137                         } catch (IOException e) {
138                                 e.printStackTrace();
139                                 return null;
140                         }
141                 }
142                 return configIt;
143         }
144
145         private static Config init() throws IOException {
146
147                 Config config = null;
148
149                 String configFile = System.getProperty("config.resource");
150                 if (configFile == null) {
151                         if (System.getProperty("os.name").contains("Windows")) {
152                                 configFile = WINDOWS_CONFIG_FILE;
153                         } else {
154                                 throw new RuntimeException("Please Add Jvm Argument config.resource");
155                         }
156                 }
157
158                 File file = new File(configFile);
159                 if (false == file.exists()) {
160                         throw new RuntimeException("The config file " + configFile + " cannot be found.");
161                 }
162
163                 InputStream in = null;
164                 try {
165
166                         in = Files.newInputStream(Paths.get(configFile));
167
168                         config = yaml.loadAs(in, Config.class);
169
170                         setPackagesAndBugs(configFile, config);
171
172                 } finally {
173                         if (in != null) {
174                                 try {
175                                         in.close();
176                                 } catch (IOException e) {
177                                         // TODO Auto-generated catch block
178                                         e.printStackTrace();
179                                 }
180                         }
181                 }
182
183                 // JsonReader jsonReader = new JsonReader(new FileReader(configFile));
184                 // Config configAttOdlIt = new Gson().fromJson(jsonReader,
185                 // Config.class);
186
187                 return config;
188         }
189
190         private static void setPackagesAndBugs(String path, Config config) throws IOException {
191
192                 int separator = Math.max(path.lastIndexOf("\\"), path.lastIndexOf("/"));
193                 String dirPath = path.substring(0, separator + 1);
194                 String packagesFile = dirPath + File.separator + "attsdc-packages.yaml";
195                 File file = new File(packagesFile);
196                 if (false == file.exists()) {
197                         throw new RuntimeException("The config file " + packagesFile + " cannot be found.");
198                 }
199
200                 TestPackages testPackages = null;
201                 InputStream in = null;
202                 try {
203
204                         in = Files.newInputStream(Paths.get(packagesFile));
205
206                         testPackages = yaml.loadAs(in, TestPackages.class);
207
208                         List<String> bugs = testPackages.getBugs();
209                         List<String> packages = testPackages.getPackages();
210
211                         config.setBugs(bugs);
212                         config.setPackages(packages);
213
214                 } finally {
215                         if (in != null) {
216                                 try {
217                                         in.close();
218                                 } catch (IOException e) {
219                                         // TODO Auto-generated catch block
220                                         e.printStackTrace();
221                                 }
222                         }
223                 }
224
225         }
226
227         // public Config(String catalogBeHost, String esHost, String esPort, String
228         // resourceConfigDir, String componentsConfigDir, String catalogFeHost,
229         // String catalogFePort, String catalogBePort) {
230         // super();
231         // this.catalogBeHost = catalogBeHost;
232         // this.esHost = esHost;
233         // this.esPort = esPort;
234         // this.resourceConfigDir = resourceConfigDir;
235         // this.componentsConfigDir = componentsConfigDir;
236         // this.catalogFeHost = catalogFeHost;
237         // this.catalogFePort = catalogFePort;
238         // this.catalogBePort = catalogBePort;
239         // }
240
241         String configurationFile;
242         
243         public boolean getSystemUnderDebug() {
244                 return systemUnderDebug;
245         }
246
247         public void setSystemUnderDebug(boolean systemUnderDebug) {
248                 this.systemUnderDebug = systemUnderDebug;
249         }
250
251         public boolean getRerun() {
252                 return rerun;
253         }
254
255         public void setRerun(boolean rerun) {
256                 this.rerun = rerun;
257         }
258         
259         public String getReportDBhost() {
260                 return reportDBhost;
261         }
262
263         public void setReportDBhost(String reportDBhost) {
264                 this.reportDBhost = reportDBhost;
265         }
266
267         public int getReportDBport() {
268                 return reportDBport;
269         }
270
271         public void setReportDBport(int reportDBport) {
272                 this.reportDBport = reportDBport;
273         }
274 //      public boolean isUsingBrowserMobProxy() {
275 //              return useBrowserMobProxy;
276 //      }
277 //
278 //      public void setUsingBrowserMobProxy(boolean usingBrowserMobProxy) {
279 //              this.useBrowserMobProxy = usingBrowserMobProxy;
280 //      } 
281
282         
283         
284         
285         public String getBrowser() {
286                 return browser;
287         }
288         
289         public boolean getUseBrowserMobProxy() {
290                 return useBrowserMobProxy;
291         }
292
293         public void setUseBrowserMobProxy(boolean useBrowserMobProxy) {
294                 this.useBrowserMobProxy = useBrowserMobProxy;
295         }
296
297
298
299         public boolean getCaptureTraffic() {
300                 return captureTraffic;
301         }
302
303         public void setCaptureTraffic(boolean captureTraffic) {
304                 this.captureTraffic = captureTraffic;
305         }
306
307         public void setBrowser(String browser) {
308                 this.browser = browser;
309         }
310
311         public String getConfigurationFile() {
312                 return configurationFile;
313         }
314
315         public void setConfigurationFile(String configurationFile) {
316                 this.configurationFile = configurationFile;
317         }
318
319         public boolean getIsDistributionClientRunning() {
320                 return isDistributionClientRunning;
321         }
322
323         public void setIsDistributionClientRunning(boolean isDistributionClientRunning) {
324                 this.isDistributionClientRunning = isDistributionClientRunning;
325         }
326         
327         public String getCatalogBePort() {
328                 return catalogBePort;
329         }
330
331         public String getDisributionClientHost() {
332                 return disributionClientHost;
333         }
334
335         public void setDisributionClientHost(String disributionClientHost) {
336                 this.disributionClientHost = disributionClientHost;
337         }
338
339         public String getDisributionClientPort() {
340                 return disributionClientPort;
341         }
342
343         public void setDisributionClientPort(String disributionClientPort) {
344                 this.disributionClientPort = disributionClientPort;
345         }
346
347         public void setCatalogBePort(String catalogBePort) {
348                 this.catalogBePort = catalogBePort;
349         }
350
351         public String getCatalogFeHost() {
352                 return catalogFeHost;
353         }
354
355         public void setCatalogFeHost(String catalogFeHost) {
356                 this.catalogFeHost = catalogFeHost;
357         }
358
359         public String getCatalogFePort() {
360                 return catalogFePort;
361         }
362
363         public void setCatalogFePort(String catalogFePort) {
364                 this.catalogFePort = catalogFePort;
365         }
366
367         public String getCatalogBeHost() {
368                 return catalogBeHost;
369         }
370
371         public void setCatalogBeHost(String catalogBeHost) {
372                 this.catalogBeHost = catalogBeHost;
373         }
374
375         public String getEsHost() {
376                 return esHost;
377         }
378
379         public void setEsHost(String esHost) {
380                 this.esHost = esHost;
381         }
382
383         public String getEsPort() {
384                 return esPort;
385         }
386
387         public void setEsPort(String esPort) {
388                 this.esPort = esPort;
389         }
390
391         public String getResourceConfigDir() {
392                 return resourceConfigDir;
393         }
394
395         public void setResourceConfigDir(String resourceConfigDir) {
396                 this.resourceConfigDir = resourceConfigDir;
397         }
398
399         public String getComponentsConfigDir() {
400                 return componentsConfigDir;
401         }
402
403         public void setComponentsConfigDir(String componentsConfigDir) {
404                 this.componentsConfigDir = componentsConfigDir;
405         }
406
407         public String getOutputFolder() {
408                 return outputFolder;
409         }
410
411         public void setOutputFolder(String outputFolder) {
412                 this.outputFolder = outputFolder;
413         }
414
415         public String getReportName() {
416                 return reportName;
417         }
418
419         public void setReportName(String reportName) {
420                 this.reportName = reportName;
421         }
422
423         public String getNeoPort() {
424                 return neoPort;
425         }
426
427         public void setNeoPort(String neoPort) {
428                 this.neoPort = neoPort;
429         }
430
431         public String getNeoHost() {
432                 return neoHost;
433         }
434
435         public void setNeoHost(String neoHost) {
436                 this.neoHost = neoHost;
437         }
438
439         public String getNeoDBpassword() {
440                 return neoDBpassword;
441         }
442
443         public String getNeoDBusername() {
444                 return neoDBusername;
445         }
446
447         public void setNeoDBusername(String neoDBusername) {
448                 this.neoDBusername = neoDBusername;
449         }
450
451         public void setNeoDBpassword(String neoDBpassword) {
452                 this.neoDBpassword = neoDBpassword;
453         }
454
455         public String getTitanPropertiesFile() {
456                 return titanPropertiesFile;
457         }
458
459         public void setTitanPropertiesFile(String titanPropertiesFile) {
460                 this.titanPropertiesFile = titanPropertiesFile;
461         }
462
463         public List<String> getPackages() {
464                 return packages;
465         }
466
467         public void setPackages(List<String> packages) {
468                 this.packages = packages;
469         }
470
471         public List<String> getBugs() {
472                 return bugs;
473         }
474
475         public void setBugs(List<String> bugs) {
476                 this.bugs = bugs;
477         }
478
479         public boolean isStopOnClassFailure() {
480                 return stopOnClassFailure;
481         }
482
483         public void setStopOnClassFailure(boolean stopOnClassFailure) {
484                 this.stopOnClassFailure = stopOnClassFailure;
485         }
486
487         public String getImportResourceConfigDir() {
488                 return importResourceConfigDir;
489         }
490
491         public void setImportResourceConfigDir(String importResourceConfigDir) {
492                 this.importResourceConfigDir = importResourceConfigDir;
493         }
494
495         public String getImportResourceTestsConfigDir() {
496                 return importResourceTestsConfigDir;
497         }
498
499         public void setImportResourceTestsConfigDir(String importResourceTestsConfigDir) {
500                 this.importResourceTestsConfigDir = importResourceTestsConfigDir;
501         }
502
503         public String getErrorConfigurationFile() {
504                 return errorConfigurationFile;
505         }
506
507         public void setErrorConfigurationFile(String errorConfigurationFile) {
508                 this.errorConfigurationFile = errorConfigurationFile;
509         }
510
511         public String getCatalogBeTlsPort() {
512                 return catalogBeTlsPort;
513         }
514
515         public void setCatalogBeTlsPort(String catalogBeTlsPort) {
516                 this.catalogBeTlsPort = catalogBeTlsPort;
517         }
518
519         public List<String> getResourcesNotToDelete() {
520                 return resourcesNotToDelete;
521         }
522
523         public void setResourcesNotToDelete(List<String> resourcesNotToDelete) {
524                 this.resourcesNotToDelete = resourcesNotToDelete;
525         }
526
527         public List<String> getResourceCategoriesNotToDelete() {
528                 return resourceCategoriesNotToDelete;
529         }
530
531         public void setResourceCategoriesNotToDelete(List<String> resourceCategoriesNotToDelete) {
532                 this.resourceCategoriesNotToDelete = resourceCategoriesNotToDelete;
533         }
534
535         public List<String> getServiceCategoriesNotToDelete() {
536                 return serviceCategoriesNotToDelete;
537         }
538
539         public void setServiceCategoriesNotToDelete(List<String> serviceCategoriesNotToDelete) {
540                 this.serviceCategoriesNotToDelete = serviceCategoriesNotToDelete;
541         }
542
543         public String getImportTypesConfigDir() {
544                 return importTypesConfigDir;
545         }
546
547         public void setImportTypesConfigDir(String importTypesConfigDir) {
548                 this.importTypesConfigDir = importTypesConfigDir;
549         }
550
551         public String getCassandraHost() {
552                 return cassandraHost;
553         }
554
555         public void setCassandraHost(String cassandraHost) {
556                 this.cassandraHost = cassandraHost;
557         }
558
559         public String getCassandraAuditKeySpace() {
560                 return cassandraAuditKeySpace;
561         }
562
563         public void setCassandraAuditKeySpace(String cassandraAuditKeySpace) {
564                 this.cassandraAuditKeySpace = cassandraAuditKeySpace;
565         }
566
567         public String getCassandraArtifactKeySpace() {
568                 return cassandraArtifactKeySpace;
569         }
570
571         public void setCassandraArtifactKeySpace(String cassandraArtifactKeySpace) {
572                 this.cassandraArtifactKeySpace = cassandraArtifactKeySpace;
573         }
574
575         
576         public String getWindowsDownloadDirectory() {
577                 return windowsDownloadDirectory;
578         }
579         
580         public void setWindowsDownloadDirectory(String windowsDownloadDirectory) {
581                 this.windowsDownloadDirectory = windowsDownloadDirectory;
582         }
583         
584         @Override
585         public String toString() {
586                 return "Config [systemUnderDebug=" + systemUnderDebug + ", rerun=" + rerun + ", reportDBhost=" + reportDBhost
587                                 + ", reportDBport=" + reportDBport + ", browser=" + browser + ", catalogBeHost=" + catalogBeHost
588                                 + ", esHost=" + esHost + ", esPort=" + esPort + ", neoHost=" + neoHost + ", neoPort=" + neoPort
589                                 + ", disributionClientHost=" + disributionClientHost + ", disributionClientPort="
590                                 + disributionClientPort + ", isDistributionClientRunning=" + isDistributionClientRunning
591                                 + ", errorConfigurationFile=" + errorConfigurationFile + ", resourceConfigDir=" + resourceConfigDir
592                                 + ", componentsConfigDir=" + componentsConfigDir + ", importResourceConfigDir="
593                                 + importResourceConfigDir + ", importResourceTestsConfigDir=" + importResourceTestsConfigDir
594                                 + ", importTypesConfigDir=" + importTypesConfigDir + ", testSuites=" + testSuites + ", catalogFeHost="
595                                 + catalogFeHost + ", catalogFePort=" + catalogFePort + ", catalogBePort=" + catalogBePort
596                                 + ", catalogBeTlsPort=" + catalogBeTlsPort + ", neoDBusername=" + neoDBusername + ", neoDBpassword="
597                                 + neoDBpassword + ", titanPropertiesFile=" + titanPropertiesFile + ", packages=" + packages + ", bugs="
598                                 + bugs + ", resourcesNotToDelete=" + resourcesNotToDelete + ", resourceCategoriesNotToDelete="
599                                 + resourceCategoriesNotToDelete + ", serviceCategoriesNotToDelete=" + serviceCategoriesNotToDelete
600                                 + ", stopOnClassFailure=" + stopOnClassFailure + ", outputFolder=" + outputFolder + ", reportName="
601                                 + reportName + ", url=" + url + ", remoteTestingMachineIP=" + remoteTestingMachineIP
602                                 + ", remoteTestingMachinePort=" + remoteTestingMachinePort + ", remoteTesting=" + remoteTesting
603                                 + ", cassandraHost=" + cassandraHost + ", cassandraAuditKeySpace=" + cassandraAuditKeySpace
604                                 + ", cassandraArtifactKeySpace=" + cassandraArtifactKeySpace + ", cassandraAuthenticate="
605                                 + cassandraAuthenticate + ", cassandraUsername=" + cassandraUsername + ", cassandraPassword="
606                                 + cassandraPassword + ", cassandraSsl=" + cassandraSsl + ", cassandraTruststorePath="
607                                 + cassandraTruststorePath + ", cassandraTruststorePassword=" + cassandraTruststorePassword
608                                 + ", windowsDownloadDirectory=" + windowsDownloadDirectory + ", captureTraffic=" + captureTraffic
609                                 + ", useBrowserMobProxy=" + useBrowserMobProxy + ", configurationFile=" + configurationFile + "]";
610         }
611
612         public boolean isRemoteTesting() {
613                 return remoteTesting;
614         }
615
616         public void setRemoteTesting(boolean remoteTesting) {
617                 this.remoteTesting = remoteTesting;
618         }
619
620         public String getUrl() {
621                 try {
622                         return url;
623                 } catch (Exception e) {
624                         return null;
625                 }
626         }
627
628         public void setUrl(String url) {
629                 this.url = url;
630         }
631
632         public String getRemoteTestingMachineIP() {
633                 return remoteTestingMachineIP;
634         }
635
636         public void setRemoteTestingMachineIP(String remoteTestingMachineIP) {
637                 this.remoteTestingMachineIP = remoteTestingMachineIP;
638         }
639
640         public String getRemoteTestingMachinePort() {
641                 return remoteTestingMachinePort;
642         }
643
644         public void setRemoteTestingMachinePort(String remoteTestingMachinePort) {
645                 this.remoteTestingMachinePort = remoteTestingMachinePort;
646         }
647
648         public boolean getCassandraAuthenticate() {
649                 return cassandraAuthenticate;
650         }
651
652         public void setCassandraAuthenticate(boolean cassandraAuthenticate) {
653                 this.cassandraAuthenticate = cassandraAuthenticate;
654         }
655
656         public String getCassandraUsername() {
657                 return cassandraUsername;
658         }
659
660         public void setCassandraUsername(String cassandraUsername) {
661                 this.cassandraUsername = cassandraUsername;
662         }
663
664         public String getCassandraPassword() {
665                 return cassandraPassword;
666         }
667
668         public void setCassandraPassword(String cassandraPassword) {
669                 this.cassandraPassword = cassandraPassword;
670         }
671
672         public boolean getCassandraSsl() {
673                 return cassandraSsl;
674         }
675
676         public void setCassandraSsl(boolean cassandraSsl) {
677                 this.cassandraSsl = cassandraSsl;
678         }
679
680         public String getCassandraTruststorePath() {
681                 return cassandraTruststorePath;
682         }
683
684         public void setCassandraTruststorePath(String cassandraTruststorePath) {
685                 this.cassandraTruststorePath = cassandraTruststorePath;
686         }
687
688         public String getCassandraTruststorePassword() {
689                 return cassandraTruststorePassword;
690         }
691
692         public void setCassandraTruststorePassword(String cassandraTruststorePassword) {
693                 this.cassandraTruststorePassword = cassandraTruststorePassword;
694         }
695
696 }