Class TigerConfigurationHelper<T>

  • Type Parameters:
    T -

    public class TigerConfigurationHelper<T>
    extends Object
    This helper class helps to manage 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 calling applyTemplate(JSONObject, String, JSONArray, String). Then you can overwrite yaml config values with env vars or system properties by calling overwriteWithSysPropsAndEnvVars(String, String, JSONObject). Finally, you can convert to your data structure config class by calling jsonStringToConfig(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. XXXSERVERIDXXX is a placeholder here for the server id of the server you want to modify. With version 0.15.0 of Tiger we switched from server list to server map. More details can be found in {@link /doc/testenv-config-types.md}.

    The format of the environment variables looks exemplaric like:

    • TIGER_TESTENV_TIGERPROXY_PROXYLOGLEVEL
    • TIGER_TESTENV_TIGERPROXY_PORT
    • TIGER_TESTENV_SERVERS_XXXSERVERID0XXX_TEMPLATE
    • TIGER_TESTENV_SERVERS_XXXSERVERID0XXX_STARTUPTIMEOUTSEC
    • ...

    For Envrionmental variables:
    TIGER is the product name passed in as parameter to overwriteWithSysPropsAndEnvVars(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.XXXserveridXXX.template
    • tiger.testenv.tigerProxy.servers.XXXserveridXXX.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 Detail

      • TigerConfigurationHelper

        public TigerConfigurationHelper()
    • Method Detail

      • yamlToConfig

        public T yamlToConfig​(String yamlPath,
                              String product,
                              Class<T> cfgClazz)
        Deprecated.
        Parameters:
        yamlPath - absolute path to yaml config file
        product - name/id of product
        cfgClazz - 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 file
        product - name/id of product
        cfgClazz - 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 - YAML content
        Returns:
        JSON object representing the yaml content
      • yamlConfigReadOverwriteToJson

        public static org.json.JSONObject yamlConfigReadOverwriteToJson​(String yamlBaseFilename,
                                                                        String product)
      • jsonToConfig

        public T jsonToConfig​(String jsonFile,
                              Class<T> cfgClazz)
      • jsonStringToConfig

        public T jsonStringToConfig​(String jsonStr,
                                    Class<T> cfgClazz)
      • overwriteWithSysPropsAndEnvVars

        public static void overwriteWithSysPropsAndEnvVars​(String rootEnv,
                                                           String rootProps,
                                                           org.json.JSONObject json)
      • applyTemplate

        public static void applyTemplate​(org.json.JSONArray cfgArray,
                                         String templateKey,
                                         org.json.JSONArray templates,
                                         String templateIdKey)
      • applyTemplate

        public static void applyTemplate​(org.json.JSONObject cfgMap,
                                         String templateKey,
                                         org.json.JSONArray templates,
                                         String templateIdKey)