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