Merge automation from ECOMP's repository
[vid.git] / vid-automation / src / main / java / org / onap / sdc / ci / tests / run / StartTest.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.onap.sdc.ci.tests.run;
22
23 import java.util.ArrayList;
24 import java.util.List;
25 import java.util.concurrent.atomic.AtomicBoolean;
26
27 import org.apache.log4j.Logger;
28 import org.apache.log4j.PropertyConfigurator;
29 import org.testng.TestNG;
30
31 public class StartTest {
32
33         public static long timeOfTest = 0;
34
35         public static boolean debug = false;
36
37         public static AtomicBoolean loggerInitialized = new AtomicBoolean(false);
38
39         protected static Logger logger = null;
40
41         public static void main(String[] args) {
42
43                 String debugEnabled = System.getProperty("debug");
44                 if (debugEnabled != null && debugEnabled.equalsIgnoreCase("true")) {
45                         debug = true;
46                 }
47                 System.out.println("Debug mode is " + (debug ? "enabled" : "disabled"));
48
49                 enableLogger();
50
51                 TestNG testng = new TestNG();
52
53                 List<String> suites = new ArrayList<String>();
54                 suites.add(args[0]);
55                 testng.setTestSuites(suites);
56                 testng.setUseDefaultListeners(true);
57                 testng.setOutputDirectory("target/");
58
59                 testng.run();
60
61         }
62
63         public StartTest() {
64                 logger = Logger.getLogger(StartTest.class.getName());
65         }
66
67         public static void enableLogger() {
68
69                 if (false == loggerInitialized.get()) {
70
71                         loggerInitialized.set(true);
72
73                         String log4jPropsFile = System.getProperty("log4j.configuration");
74                         if (System.getProperty("os.name").contains("Windows")) {
75                                 String logProps = "src/main/resources/ci/conf/log4j.properties";
76                                 if (log4jPropsFile == null) {
77                                         System.setProperty("targetlog", "target/");
78                                         log4jPropsFile = logProps;
79                                 }
80
81                         }
82                         PropertyConfigurator.configureAndWatch(log4jPropsFile);
83
84                 }
85         }
86
87 }