Class Configuration
- java.lang.Object
-
- com.tibco.ep.testing.framework.Configuration
-
public final class Configuration extends Object
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
Constructors Constructor Description Configuration(String resource)
Create a configuration instanceConfiguration(String serviceName, String resource, Map<String,String> substitutions)
Create 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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Configuration
activate()
Activate this configurationConfiguration
deactivate()
Deactivate this configurationstatic void
deactiveAndRemoveAll()
Deactivate and remove configurations in reverse orderstatic Configuration
forFile(String resource)
Create a configuration instancestatic Configuration
forFile(String serviceName, String resource, Map<String,String> substitutions)
Create a configuration instancestatic Configuration
forFile(String serviceName, String resource, Map<String,String> substitutions, String substitutionResource)
Create a configuration instancestatic Configuration
forFile(String resource, Map<String,String> substitutions)
Create a configuration instancestatic List<Configuration>
getLoadedConfigurations()
Get all loaded configurationsOptional<String>
getName()
Get the currently loaded configuration nameOptional<String>
getType()
Get the currently loaded configuration typeOptional<String>
getVersion()
Get the currently loaded configuration versionboolean
isActive()
Check if this configuration is activatedboolean
isLoaded()
Check if this configuration is loadedConfiguration
load()
Load this configurationvoid
remove()
Remove this configurationString
toString()
-
-
-
Constructor Detail
-
Configuration
public Configuration(String serviceName, String resource, Map<String,String> substitutions)
Create a configuration instance
- Parameters:
serviceName
- service name, can not be nullresource
- HOCON configuration resource 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 to load, can not be nullsubstitutions
- Substitution variables, can not be nullsubstitutionResource
- Substitutions resource file, can not be null
-
Configuration
public Configuration(String resource, Map<String,String> substitutions)
Create a configuration instance
- Parameters:
resource
- HOCON configuration resource to load, can not be nullsubstitutions
- Substitution variables, can not be null
-
Configuration
public Configuration(String resource)
Create a configuration instance
- Parameters:
resource
- HOCON configuration resource to load, can not be null
-
-
Method Detail
-
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 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 to load, can not be nullsubstitutions
- Substitution variables, can not be nullsubstitutionResource
- Substitutions resource file, can not be null- Returns:
- instance of Configuration
-
forFile
public static Configuration forFile(String resource, Map<String,String> substitutions)
Create a configuration instance
- Parameters:
resource
- HOCON configuration resource to load, can not be nullsubstitutions
- Substitution variables, can not be null- Returns:
- instance of Configuration
-
forFile
public static Configuration forFile(String resource)
Create a configuration instance
- Parameters:
resource
- HOCON configuration resource to load, can not be null- Returns:
- instance of Configuration
-
load
public Configuration load() throws ConfigurationException
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
public Configuration activate() throws ConfigurationException
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
public Configuration deactivate() throws ConfigurationException
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
public void remove() throws ConfigurationException
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
public static List<Configuration> 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
-
getVersion
public Optional<String> getVersion()
Get the currently loaded configuration version- Returns:
- version
-
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
-
-