Class TigerConfigurationHelper<T>
- java.lang.Object
-
- de.gematik.test.tiger.common.config.TigerConfigurationHelper<T>
-
- Type Parameters:
T-
public class TigerConfigurationHelper<T> extends Object
This helper class helps managing test suite configuration based on yaml config files.First step is to use
yamlToJson(String)to create a JSON representation of the yaml config file. Now you can optionally apply a template by callingapplyTemplate(JSONArray, String, JSONArray, String). Then you can overwrite yaml config values with env vars or system properties by callingoverwriteWithSysPropsAndEnvVars(String, String, JSONObject). Finally you can convert to your data structure config class by callingjsonStringToConfig(String, Class).For simple test configurations without templating you can use the instance method
yamlReadOverwriteToConfig(String, String, Class). This method also performs the overwriting of yaml config values with env vars and system properties. Due to Java Generics restrictions you will need to instantiate an instance to use this method.The format of the environment variables looks exemplaric like:
- TIGER_TESTENV_TIGERPROXY_PROXYLOGLEVEL
- TIGER_TESTENV_TIGERPROXY_PORT
- TIGER_TESTENV_SERVERS_0_TEMPLATE
- TIGER_TESTENV_SERVERS_0_STARTUPTIMEOUTSEC
- ...
For Envrionmental variables:
TIGER is the product name passed in as parameter tooverwriteWithSysPropsAndEnvVars(String, String, JSONObject)and then separated by "_" the hierarchy walking down all properties / path nodes being uppercase. Entries in Lists are indexed by integer value.For System properties:
- tiger.testenv.tigerProxy.proxyLogLevel
- tiger.testenv.tigerProxy.port
- tiger.testenv.tigerProxy.servers.0.template
- tiger.testenv.tigerProxy.servers.0.startupTimeoutSec
To use tokens such as ${TESTENV.xxxx} in the yaml file and replace it with appropriate values, first convert the JSON Object to string and use the
TokenSubstituteHelper.substitute(String, String, Map)method to replace all tokens. Afterwards convert it back to JSONObject.
-
-
Constructor Summary
Constructors Constructor Description TigerConfigurationHelper()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static voidapplyTemplate(org.json.JSONArray cfgArray, String templateKey, org.json.JSONArray templates, String templateIdKey)TjsonStringToConfig(String jsonStr, Class<T> cfgClazz)TjsonToConfig(String jsonFile, Class<T> cfgClazz)static voidoverwriteWithSysPropsAndEnvVars(String rootEnv, String rootProps, org.json.JSONObject json)static StringtoJson(Object cfg)static StringtoYaml(Object cfg)static org.json.JSONObjectyamlConfigReadOverwriteToJson(String yamlBaseFilename, String product)TyamlReadOverwriteToConfig(String yamlPath, String product, Class<T> cfgClazz)reads given yaml file to JSON object, applies env var / system property overwrite and returns the configuration class's instance.static org.json.JSONObjectyamlStringToJson(String yamlStr)converts a given yaml content string to JSON object.TyamlToConfig(String yamlPath, String product, Class<T> cfgClazz)Deprecated.static org.json.JSONObjectyamlToJson(String yamlPath)reads a given yaml file to JSON object.
-
-
-
Method Detail
-
yamlToConfig
public T yamlToConfig(String yamlPath, String product, Class<T> cfgClazz)
Deprecated.Old method, seeyamlReadOverwriteToConfig(String, String, Class).- Parameters:
yamlPath- absolute path to yaml config fileproduct- name/id of productcfgClazz- class reference for the Configuration object to be created from config yaml file.- Returns:
- Configuration object
-
yamlReadOverwriteToConfig
public T yamlReadOverwriteToConfig(String yamlPath, String product, Class<T> cfgClazz)
reads given yaml file to JSON object, applies env var / system property overwrite and returns the configuration class's instance.- Parameters:
yamlPath- path to yaml config fileproduct- name/id of productcfgClazz- class reference for the Configuration object to be created from config yaml file.- Returns:
- Configuration object
-
yamlToJson
public static org.json.JSONObject yamlToJson(String yamlPath)
reads a given yaml file to JSON object.- Parameters:
yamlPath- path to yaml config file- Returns:
- json object
-
yamlStringToJson
public static org.json.JSONObject yamlStringToJson(String yamlStr)
converts a given yaml content string to JSON object.- Parameters:
yamlStr-- Returns:
-
yamlConfigReadOverwriteToJson
public static org.json.JSONObject yamlConfigReadOverwriteToJson(String yamlBaseFilename, String product)
-
overwriteWithSysPropsAndEnvVars
public static void overwriteWithSysPropsAndEnvVars(String rootEnv, String rootProps, org.json.JSONObject json)
-
-