Class Configuration
HOCON Configuration tools to support unit testing
HOCON configurations can be loaded and activated at any time :
Map<String, String> substitutions = new HashMap<>(); // example load / activate on this node // config = new Configuration("test1.conf").load().activate();
and subsequently deactivated and removed :
// example deactive / remove on this node // config.deactivate().remove();
Substitution parameters can be specified :
// example load / activate on this node // substitutions.put("param", "value"); config = new Configuration("test1.conf", substitutions).load().activate();
By default, the configuration is loaded on the local node only - to load on a different node or on the cluster, the serviceName can be specified :
// example load / activate on a specific node or cluster // config = new Configuration("A.test-framework", "test2.conf", substitutions).load().activate(); config.deactivate().remove(); config = new Configuration("test-framework", "test3.conf", substitutions).load().activate(); config.deactivate().remove();
Test can call the deactiveRemoveAll function to automatically deactivate and remove configurations that are still loaded.
// Deactivate configurations previous loaded // Configuration.deactiveAndRemoveAll();
Note that there is no support for auto loading configurations - any configuration that is required for a test case must load and activate it using this API. This includes configurations used be any dependent components.
-
Constructor Summary
ConstructorsConstructorDescriptionConfiguration
(String resource) Create a configuration instanceCreate a configuration instanceConfiguration
(String serviceName, String resource, Map<String, String> substitutions, String substitutionResource) Create a configuration instanceConfiguration
(String resource, Map<String, String> substitutions) Create a configuration instance -
Method Summary
Modifier and TypeMethodDescriptionactivate()
Activate this configurationDeactivate this configurationstatic void
Deactivate and remove configurations in reverse orderstatic Configuration
Create a configuration instancestatic Configuration
Create a configuration instancestatic Configuration
forFile
(String serviceName, String resource, Map<String, String> substitutions, String substitutionResource) Create a configuration instancestatic Configuration
Create a configuration instancestatic List
<Configuration> Get all loaded configurationsgetName()
Get the currently loaded configuration namegetType()
Get the currently loaded configuration typeGet the currently loaded configuration versionboolean
isActive()
Check if this configuration is activatedboolean
isLoaded()
Check if this configuration is loadedload()
Load this configurationvoid
remove()
Remove this configurationtoString()
-
Constructor Details
-
Configuration
Create a configuration instance
- Parameters:
serviceName
- service name, can not be nullresource
- HOCON configuration resource / absolute file path to load, can not be nullsubstitutions
- Substitution variables, can not be null
-
Configuration
public Configuration(String serviceName, String resource, Map<String, String> substitutions, String substitutionResource) Create a configuration instance
- Parameters:
serviceName
- service name, can not be nullresource
- HOCON configuration resource / absolute file path to load, can not be nullsubstitutions
- Substitution variables, can not be nullsubstitutionResource
- Substitutions resource file, can not be null
-
Configuration
-
Configuration
Create a configuration instance
- Parameters:
resource
- HOCON configuration resource / absolute file path to load, can not be null
-
-
Method Details
-
forFile
public static Configuration forFile(String serviceName, String resource, Map<String, String> substitutions) Create a configuration instance
- Parameters:
serviceName
- service name, can not be nullresource
- HOCON configuration resource / absolute file path to load, can not be nullsubstitutions
- Substitution variables, can not be null- Returns:
- instance of Configuration
-
forFile
public static Configuration forFile(String serviceName, String resource, Map<String, String> substitutions, String substitutionResource) Create a configuration instance
- Parameters:
serviceName
- service name, can not be nullresource
- HOCON configuration resource / absolute file path to load, can not be nullsubstitutions
- Substitution variables, can not be nullsubstitutionResource
- Substitutions resource file, can not be null- Returns:
- instance of Configuration
-
forFile
Create a configuration instance
- Parameters:
resource
- HOCON configuration resource / absolute file path to load, can not be nullsubstitutions
- Substitution variables, can not be null- Returns:
- instance of Configuration
-
forFile
Create a configuration instance
- Parameters:
resource
- HOCON configuration resource/absolute file path to load, can not be null- Returns:
- instance of Configuration
-
load
Load this configuration
This method can be run within or outside a transaction
- Returns:
- Config instance
- Throws:
ConfigurationException
- on configuration failure or already loaded
-
activate
Activate this configuration
Fails if configuration is not loaded
This method can be run within or outside a transaction
- Returns:
- Config instance
- Throws:
ConfigurationException
- on configuration failure or already active
-
deactivate
Deactivate this configuration
Fails if configuration is not active
This method can be run within or outside a transaction
- Returns:
- Config instance
- Throws:
ConfigurationException
- on configuration failure or not active
-
remove
Remove this configuration
Fails if configuration is still active
This method can be run within or outside a transaction
- Throws:
ConfigurationException
- on configuration failure or still active
-
getLoadedConfigurations
Get all loaded configurations- Returns:
- list of loaded configurations
-
isActive
public boolean isActive()Check if this configuration is activated
This method can be run within or outside a transaction
- Returns:
- Return true if configuration is activated, false otherwise
-
isLoaded
public boolean isLoaded()Check if this configuration is loaded
This method can be run within or outside a transaction
- Returns:
- Return true if configuration is loaded, false otherwise
-
getName
-
getVersion
-
getType
-
deactiveAndRemoveAll
public static void deactiveAndRemoveAll()Deactivate and remove configurations in reverse order
This method can be run within or outside a transaction
Errors are ignored
-
toString
-