Class Configuration


  • public class Configuration
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String PROPERTY_PREFIX
      Prefix of every system property read by the test suite.
    • Constructor Summary

      Constructors 
      Constructor Description
      Configuration()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static byte[] getBase64​(java.lang.String key, java.lang.String defaultValue)  
      static byte[] getBase64OrResource​(java.lang.String key, java.lang.String resourcePath)
      Gets the Base64-decoded value of the given property, or the content of the given resource when the property is not set.
      static boolean getBoolean​(java.lang.String key, boolean defaultValue)  
      static byte[] getHex​(java.lang.String key, java.lang.String defaultValue)  
      static int getInt​(java.lang.String key, int defaultValue)  
      static int[] getInts​(java.lang.String key, java.lang.String defaultValues)  
      static char[] getPassword​(java.lang.String key, char[] defaultValue)  
      static java.lang.String getString​(java.lang.String key, java.lang.String defaultValue)  
      static java.lang.String[] getStrings​(java.lang.String key, java.lang.String defaultValues)  
      static java.lang.String[] getSubset​(java.lang.String key, java.lang.String[] allowedValues, java.lang.String allowedKey)
      Gets an optional comma separated list that restricts another list.
      static java.lang.String[] parseSubset​(java.lang.String key, java.lang.String value, java.lang.String[] allowedValues, java.lang.String allowedKey)
      Parses the value of a property that restricts another list, see getSubset(String, String[], String).
      static java.lang.String[] requireNotEmpty​(java.lang.String key, java.lang.String[] values)
      Checks that a list read from a property is not empty: an empty list would make the tests looping over it pass without checking anything.
      static java.lang.String[] splitAndTrim​(java.lang.String str, java.lang.String delim)
      Splits the given string on the given delimiters, trimming each token and dropping the empty ones.
      static int[] toInts​(java.lang.String[] strings)
      Parses a list of decimal integers.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • PROPERTY_PREFIX

        public static final java.lang.String PROPERTY_PREFIX
        Prefix of every system property read by the test suite.
        See Also:
        Constant Field Values
    • Constructor Detail

      • Configuration

        public Configuration()
    • Method Detail

      • getString

        public static java.lang.String getString​(java.lang.String key,
                                                 java.lang.String defaultValue)
      • getInt

        public static int getInt​(java.lang.String key,
                                 int defaultValue)
      • getBoolean

        public static boolean getBoolean​(java.lang.String key,
                                         boolean defaultValue)
      • getStrings

        public static java.lang.String[] getStrings​(java.lang.String key,
                                                    java.lang.String defaultValues)
      • getInts

        public static int[] getInts​(java.lang.String key,
                                    java.lang.String defaultValues)
      • getSubset

        public static java.lang.String[] getSubset​(java.lang.String key,
                                                   java.lang.String[] allowedValues,
                                                   java.lang.String allowedKey)
        Gets an optional comma separated list that restricts another list.
        Parameters:
        key - the property
        allowedValues - the values the property may list, returned as is when the property is not set or empty
        allowedKey - the property the allowed values come from, for the error message
        Returns:
        the listed values, or allowedValues when the property is not set or empty
        Throws:
        java.lang.IllegalStateException - if the property lists a value outside allowedValues
      • parseSubset

        public static java.lang.String[] parseSubset​(java.lang.String key,
                                                     java.lang.String value,
                                                     java.lang.String[] allowedValues,
                                                     java.lang.String allowedKey)
        Parses the value of a property that restricts another list, see getSubset(String, String[], String).
        Parameters:
        key - the property, for the error message
        value - the property value, null when the property is not set
        allowedValues - the values the property may list, returned as is when value is null or empty
        allowedKey - the property the allowed values come from, for the error message
        Returns:
        the listed values, or allowedValues when value is null or lists no value
        Throws:
        java.lang.IllegalStateException - if the value lists a value outside allowedValues
      • requireNotEmpty

        public static java.lang.String[] requireNotEmpty​(java.lang.String key,
                                                         java.lang.String[] values)
        Checks that a list read from a property is not empty: an empty list would make the tests looping over it pass without checking anything.
        Parameters:
        key - the property, for the error message
        values - the list read from the property
        Returns:
        values
        Throws:
        java.lang.IllegalStateException - if the list is empty
      • toInts

        public static int[] toInts​(java.lang.String[] strings)
        Parses a list of decimal integers.
        Parameters:
        strings - the values to parse
        Returns:
        the parsed values, in the same order
      • getBase64

        public static byte[] getBase64​(java.lang.String key,
                                       java.lang.String defaultValue)
      • getBase64OrResource

        public static byte[] getBase64OrResource​(java.lang.String key,
                                                 java.lang.String resourcePath)
        Gets the Base64-decoded value of the given property, or the content of the given resource when the property is not set.
        Parameters:
        key - the property name, without PROPERTY_PREFIX
        resourcePath - the absolute path to the resource read when the property is not set
        Returns:
        the decoded property value, or the resource content
        Throws:
        java.lang.IllegalStateException - if the property is not set and the resource cannot be read
      • getHex

        public static byte[] getHex​(java.lang.String key,
                                    java.lang.String defaultValue)
      • getPassword

        public static char[] getPassword​(java.lang.String key,
                                         char[] defaultValue)
      • splitAndTrim

        public static java.lang.String[] splitAndTrim​(java.lang.String str,
                                                      java.lang.String delim)
        Splits the given string on the given delimiters, trimming each token and dropping the empty ones.
        Parameters:
        str - the string to split
        delim - the delimiter characters
        Returns:
        the tokens