Package com.microej.crypto.test.util
Class Configuration
- java.lang.Object
-
- com.microej.crypto.test.util.Configuration
-
public class Configuration extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringPROPERTY_PREFIXPrefix 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 booleangetBoolean(java.lang.String key, boolean defaultValue)static byte[]getHex(java.lang.String key, java.lang.String defaultValue)static intgetInt(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.StringgetString(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, seegetSubset(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.
-
-
-
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
-
-
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 propertyallowedValues- the values the property may list, returned as is when the property is not set or emptyallowedKey- the property the allowed values come from, for the error message- Returns:
- the listed values, or
allowedValueswhen the property is not set or empty - Throws:
java.lang.IllegalStateException- if the property lists a value outsideallowedValues
-
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, seegetSubset(String, String[], String).- Parameters:
key- the property, for the error messagevalue- the property value,nullwhen the property is not setallowedValues- the values the property may list, returned as is whenvalueisnullor emptyallowedKey- the property the allowed values come from, for the error message- Returns:
- the listed values, or
allowedValueswhenvalueisnullor lists no value - Throws:
java.lang.IllegalStateException- if the value lists a value outsideallowedValues
-
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 messagevalues- 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, withoutPROPERTY_PREFIXresourcePath- 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 splitdelim- the delimiter characters- Returns:
- the tokens
-
-