Class GroovyDataProvider
- java.lang.Object
-
- org.identityconnectors.contract.data.GroovyDataProvider
-
- All Implemented Interfaces:
DataProvider
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 instanceLazy.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) boo
In 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 Modifier and Type Field Description static String
MULTI_VALUE_TYPE_PREFIX
prefix of default values that are multiprotected static String
PROPERTY_SEPARATOR
-
Constructor Summary
Constructors Constructor Description GroovyDataProvider()
default constructorGroovyDataProvider(String connectorName)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
dispose()
free the allocated resourcesObject
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 parametersObject
get(Class<?> dataTypeName, String name, String componentName, int sequenceNumber, boolean isMultivalue)
Gets data value by the specified parametersObject
get(String name)
Acquire a property value for given nameObject
get(String name, int sequenceNumber)
Aquire a property value marked with given iteration, for example i1.testPropertyObject
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 parametersString
getString(String name, String componentName)
Gets data value by the specified parametersString
getString(String name, String componentName, int sequenceNumber)
Gets data value by the specified parametersObject
getTestSuiteAttribute(String propName)
Gets test suite attributeObject
getTestSuiteAttribute(String propName, String testName)
Gets test suite attributevoid
loadConfiguration(String configName, Configuration cfg)
adds to 'cfg' the complete map defined by property 'propertyName'
-
-
-
Field Detail
-
PROPERTY_SEPARATOR
protected static final String PROPERTY_SEPARATOR
- See Also:
- Constant Field Values
-
MULTI_VALUE_TYPE_PREFIX
public static final String MULTI_VALUE_TYPE_PREFIX
prefix of default values that are multi- See Also:
- Constant Field Values
-
-
Constructor Detail
-
GroovyDataProvider
public GroovyDataProvider()
default constructor
-
GroovyDataProvider
public GroovyDataProvider(String connectorName)
-
-
Method Detail
-
get
public Object get(String name, String type, boolean useDefault)
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:
get
in interfaceDataProvider
isMultivalue
- switch between single and multivalue query- Returns:
-
get
public Object get(Class<?> dataTypeName, String name, String componentName)
Gets data value by the specified parameters- Specified by:
get
in interfaceDataProvider
- Returns:
-
getString
public String getString(String name, String componentName, int sequenceNumber)
Gets data value by the specified parameters- Specified by:
getString
in interfaceDataProvider
- Returns:
-
getString
public String getString(String name, String componentName)
Gets data value by the specified parameters- Specified by:
getString
in interfaceDataProvider
- Returns:
-
getTestSuiteAttribute
public Object getTestSuiteAttribute(String propName)
Gets test suite attribute- Specified by:
getTestSuiteAttribute
in interfaceDataProvider
- Returns:
-
getTestSuiteAttribute
public Object getTestSuiteAttribute(String propName, String testName)
Gets test suite attribute- Specified by:
getTestSuiteAttribute
in interfaceDataProvider
- Returns:
-
getConnectorAttribute
public Object getConnectorAttribute(String propName)
Gets data value by the specified parameters- Specified by:
getConnectorAttribute
in interfaceDataProvider
- Returns:
-
get
public Object get(String name)
Acquire a property value for given name- Specified by:
get
in interfaceDataProvider
-
generate
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):
- # - 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:
generate
in interfaceDataProvider
- Parameters:
pattern
- the pattern for generationclazz
- the type of returned random object- Returns:
- randomly generated object with content based on given type.
-
generate
public Object generate(String pattern)
generates a random string dynamically.DataProvider.generate(String, Class)
- Specified by:
generate
in interfaceDataProvider
-
get
public Object get(String name, int sequenceNumber)
Aquire a property value marked with given iteration, for example i1.testProperty- Specified by:
get
in interfaceDataProvider
- Parameters:
name
- the suffix- Returns:
- the property value
-
getAttributeSet
public Set<Attribute> getAttributeSet(String propertySetName)
Description copied from interface:DataProvider
converts the given property submap to Attribute set.- Specified by:
getAttributeSet
in interfaceDataProvider
- Parameters:
propertySetName
-- Returns:
- The set
Set<Attribute>
of attributes
-
loadConfiguration
public void loadConfiguration(String configName, Configuration cfg)
Description copied from interface:DataProvider
adds to 'cfg' the complete map defined by property 'propertyName'- Specified by:
loadConfiguration
in 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:
NoSuchFieldException
IllegalAccessException
InvocationTargetException
NoSuchMethodException
SecurityException
-
dispose
public void dispose()
Description copied from interface:DataProvider
free the allocated resources- Specified by:
dispose
in interfaceDataProvider
-
-