-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathGeneralConfig.java
More file actions
67 lines (49 loc) · 1.94 KB
/
GeneralConfig.java
File metadata and controls
67 lines (49 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package com.Config;
import com.webdriver.example.Utils.Log;
import java.io.FileInputStream;
import java.util.Properties;
public class GeneralConfig {
public static final String PROPERTIES_PATH = "src/main/resources/project.properties";
public static final String URI = "URI";
public static final String DEV_MAIL = "DEVELOPER_EMAIL";
public static final String API_TOKEN = "API_TOKEN";
public static final String PROJECT_ID = "PROJECT_ID";
protected static Properties m_props = new Properties();
private static boolean m_initialized = false;
// SINGLETON CONSTRUCTOR
GeneralConfig() {}
private static ThreadLocal<GeneralConfig> instanceContainer = new ThreadLocal<GeneralConfig>(){
@Override
protected GeneralConfig initialValue() {
return new GeneralConfig();
}
};
public static GeneralConfig getInstance() {
return instanceContainer.get();
}
public static boolean isInitialized() {
return m_initialized;
}
public static void loadConfig()
{
try{
m_props.load(new FileInputStream(PROPERTIES_PATH));
m_initialized = true;
}
catch (Exception e) {
e.printStackTrace();
Log.error("Unable to load parameters");
}
}
public static String getConfigurationValue(final String configurationName) {
if(!GeneralConfig.isInitialized())
throw new IllegalStateException("GeneralConfig is not initialized, please call GeneralConfig.loadConfig()");
return m_props.getProperty(configurationName);
}
/*
Should be used if any parameter should be modified during test execution
*/
public static boolean setConfigurationValue(final String configurationName, final String value) {
return m_props.setProperty(configurationName, value) != null;
}
}