public class GroovyDataProvider extends Object implements 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")
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.
Modifier and Type | Field and Description |
---|---|
static String |
MULTI_VALUE_TYPE_PREFIX
prefix of default values that are multi
|
Constructor and Description |
---|
GroovyDataProvider()
default constructor
|
GroovyDataProvider(String connectorName) |
Modifier and Type | Method and Description |
---|---|
void |
dispose()
free the allocated resources
|
Object |
generate(String pattern)
generates a random string dynamically.
|
Object |
generate(String pattern,
Class<?> clazz)
Random generator uses a pattern to generate a random
sequence based on given pattern.
|
Object |
get(Class<?> dataTypeName,
String name,
String componentName)
Gets data value by the specified parameters
|
Object |
get(Class<?> dataTypeName,
String name,
String componentName,
int sequenceNumber,
boolean isMultivalue)
Gets data value by the specified parameters
|
Object |
get(String name)
Acquire a property value for given name
|
Object |
get(String name,
int sequenceNumber)
Aquire a property value marked with given iteration,
for example i1.testProperty
|
Object |
get(String name,
String type,
boolean useDefault)
Main get method.
|
Set<Attribute> |
getAttributeSet(String propertySetName)
converts the given property submap to Attribute set.
|
Object |
getConnectorAttribute(String propName)
Gets data value by the specified parameters
|
String |
getString(String name,
String componentName)
Gets data value by the specified parameters
|
String |
getString(String name,
String componentName,
int sequenceNumber)
Gets data value by the specified parameters
|
Object |
getTestSuiteAttribute(String propName)
Gets test suite attribute
|
Object |
getTestSuiteAttribute(String propName,
String testName)
Gets test suite attribute
|
void |
loadConfiguration(String configName,
Configuration cfg)
adds to 'cfg' the complete map defined by property 'propertyName'
|
public static final String MULTI_VALUE_TYPE_PREFIX
public GroovyDataProvider()
public GroovyDataProvider(String connectorName)
public Object get(String name, String type, boolean useDefault)
public Object get(Class<?> dataTypeName, String name, String componentName, int sequenceNumber, boolean isMultivalue)
get
in interface DataProvider
isMultivalue
- switch between single and multivalue querypublic Object get(Class<?> dataTypeName, String name, String componentName)
get
in interface DataProvider
public String getString(String name, String componentName, int sequenceNumber)
getString
in interface DataProvider
public String getString(String name, String componentName)
getString
in interface DataProvider
public Object getTestSuiteAttribute(String propName)
getTestSuiteAttribute
in interface DataProvider
public Object getTestSuiteAttribute(String propName, String testName)
getTestSuiteAttribute
in interface DataProvider
public Object getConnectorAttribute(String propName)
getConnectorAttribute
in interface DataProvider
public Object get(String name)
get
in interface DataProvider
public Object generate(String pattern, Class<?> clazz)
Random generator uses a pattern to generate a random sequence based on given pattern.
the supported characters are (can appear in pattern string):
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
generate
in interface DataProvider
pattern
- the pattern for generationclazz
- the type of returned random objectpublic Object generate(String pattern)
DataProvider.generate(String, Class)
generate
in interface DataProvider
public Object get(String name, int sequenceNumber)
get
in interface DataProvider
name
- the suffixpublic Set<Attribute> getAttributeSet(String propertySetName)
DataProvider
getAttributeSet
in interface DataProvider
propertySetName
- Set
of attributespublic void loadConfiguration(String configName, Configuration cfg)
DataProvider
loadConfiguration
in interface DataProvider
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" }
NoSuchFieldException
IllegalAccessException
InvocationTargetException
NoSuchMethodException
SecurityException
public void dispose()
DataProvider
dispose
in interface DataProvider
Copyright © 2019. All rights reserved.