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