Class GroovyDataProvider
- All Implemented Interfaces:
DataProvider
Default implementation of DataProvider. It uses ConfigSlurper from
Groovy to parse the property file.
The groovy files are read as classpath resources using following paths :
loader.getResource(prefix + "/config/config.groovy")loader.getResource(prefix + "/config/" + cfg + "/config.groovy")optionally where cfg is passed configuration-
loader.getResource(prefix + "/config-private/config.groovy") invalid input: '<'/ -
loader.getResource(prefix + "/config-private/" + cfg + "/config.groovy")optionally where cfg is passed configuration
Lazy.random("####") is used for generating random strings, in
case numeric object is needed, use for instance
Lazy.random("####", Long.class) to get a Long object with
random value.
Snapshot generation to output file -- this feature is
implemented by method flatten(Object). Snapshot
generating works in one direction, but the snapshot itself cannot be directly
used as an input to next testing.
Snapshots -- usage: add switch -Dtest.parameters.outFile=generated.properties
as an ANT parameter. The result snapshot file will be included in the connector's directory.
Note: snapshots for now support basic types such as Lazy, String. Other objects will be converted with toString() method to the output.
Snapshots of queried properties -- usage:
add switch -Dtest.parameters.outQueriedFile=dumpedq.properties
as an ANT parameter. The result snapshot file will be included in the connector's directory.
default values -- these values reside in file bootstrap.groovy. When the property foo.bar.boo is queried the following queries are executed:
1) foo.bar.boo 2) bar.boo 3) booIn case none of these queries succeed, the default value is used based on the type of the query.
isMultivalue boolean property -- is passed in get(...) methods of GroovyDataProvider. It has influence on default values generated, when property is missing.
- Author:
- David Adam, Zdenek Louzensky
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddispose()free the allocated resourcesgenerates a random string dynamically.Random generator uses a pattern to generate a random sequence based on given pattern.Gets data value by the specified parametersget(Class<?> dataTypeName, String name, String componentName, int sequenceNumber, boolean isMultivalue) Gets data value by the specified parametersAcquire a property value for given nameAquire a property value marked with given iteration, for example i1.testPropertyMain get method.getAttributeSet(String propertySetName) converts the given property submap to Attribute set.getConnectorAttribute(String propName) Gets data value by the specified parametersGets data value by the specified parametersGets data value by the specified parametersgetTestSuiteAttribute(String propName) Gets test suite attributegetTestSuiteAttribute(String propName, String testName) Gets test suite attributevoidloadConfiguration(String configName, Configuration cfg) adds to 'cfg' the complete map defined by property 'propertyName'
-
Field Details
-
PROPERTY_SEPARATOR
- See Also:
-
MULTI_VALUE_TYPE_PREFIX
prefix of default values that are multi- See Also:
-
-
Constructor Details
-
GroovyDataProvider
public GroovyDataProvider()default constructor -
GroovyDataProvider
-
-
Method Details
-
get
Main get method. Property lookup starts here. -
get
public Object get(Class<?> dataTypeName, String name, String componentName, int sequenceNumber, boolean isMultivalue) Gets data value by the specified parameters- Specified by:
getin interfaceDataProvider- Parameters:
dataTypeName-name-componentName-sequenceNumber-isMultivalue- switch between single and multivalue query- Returns:
-
get
Gets data value by the specified parameters- Specified by:
getin interfaceDataProvider- Parameters:
dataTypeName-name-componentName-- Returns:
-
getString
Gets data value by the specified parameters- Specified by:
getStringin interfaceDataProvider- Parameters:
name-componentName-sequenceNumber-- Returns:
-
getString
Gets data value by the specified parameters- Specified by:
getStringin interfaceDataProvider- Parameters:
name-componentName-- Returns:
-
getTestSuiteAttribute
Gets test suite attribute- Specified by:
getTestSuiteAttributein interfaceDataProvider- Parameters:
propName-- Returns:
-
getTestSuiteAttribute
Gets test suite attribute- Specified by:
getTestSuiteAttributein interfaceDataProvider- Parameters:
propName-- Returns:
-
getConnectorAttribute
Gets data value by the specified parameters- Specified by:
getConnectorAttributein interfaceDataProvider- Parameters:
propName-- Returns:
-
get
Acquire a property value for given name- Specified by:
getin interfaceDataProvider
-
generate
Random generator uses a pattern to generate a random sequence based on given pattern.
the supported characters are (can appear in pattern string):
- # - numeric
- a - lowercase letter
- A - uppercase letter
- ? - lowercase and uppercase letter
- . - any character
Any other character inside the pattern is directly printed to the output.
Backslash is used to escape any character. For instance pattern "###\\.##" prints a floating point random number
- Specified by:
generatein interfaceDataProvider- Parameters:
pattern- the pattern for generationclazz- the type of returned random object- Returns:
- randomly generated object with content based on given type.
-
generate
generates a random string dynamically.DataProvider.generate(String, Class)- Specified by:
generatein interfaceDataProvider
-
get
Aquire a property value marked with given iteration, for example i1.testProperty- Specified by:
getin interfaceDataProvider- Parameters:
name- the suffixsequenceNumber-- Returns:
- the property value
-
getAttributeSet
Description copied from interface:DataProviderconverts the given property submap to Attribute set.- Specified by:
getAttributeSetin interfaceDataProvider- Parameters:
propertySetName-- Returns:
- The set
Set<Attribute>of attributes
-
loadConfiguration
Description copied from interface:DataProvideradds to 'cfg' the complete map defined by property 'propertyName'- Specified by:
loadConfigurationin interfaceDataProvider- Parameters:
configName-cfg- the configuration that will be updated by information from property 'propertyName'Sample usage:
static final String DEFAULT_CONFIGURATINON = "configuration.init" // attempt to create the database in the directory.. config = new ConnectorConfiguration(); // LOAD THE submap in 'configuration' prefix to 'config' object. dataProvider.loadConfiguration(DEFAULT_CONFIGURATINON, config); //////// The groovy configuration // account configurations configuration{ init.driver="foo" init.hostName="bar" init.port="boo" }- Throws:
NoSuchFieldExceptionIllegalAccessExceptionInvocationTargetExceptionNoSuchMethodExceptionSecurityException
-
dispose
public void dispose()Description copied from interface:DataProviderfree the allocated resources- Specified by:
disposein interfaceDataProvider
-