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") invalid input: '<'/
  • loader.getResource(prefix + "/config-private/" + cfg + "/config.groovy") optionally where cfg is passed configuration
where prefix is FQN of your connector set as "connectorName" system property. Note: If two property files contain the same property name, the value from the latter file the list overrides the others. I.e. the last file from the list has the greatest chance to propagate its values to the final 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) 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 Details

  • Constructor Details

    • GroovyDataProvider

      public GroovyDataProvider()
      default constructor
    • GroovyDataProvider

      public GroovyDataProvider(String connectorName)
  • Method Details

    • 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 interface DataProvider
      Parameters:
      dataTypeName -
      name -
      componentName -
      sequenceNumber -
      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 interface DataProvider
      Parameters:
      dataTypeName -
      name -
      componentName -
      Returns:
    • getString

      public String getString(String name, String componentName, int sequenceNumber)
      Gets data value by the specified parameters
      Specified by:
      getString in interface DataProvider
      Parameters:
      name -
      componentName -
      sequenceNumber -
      Returns:
    • getString

      public String getString(String name, String componentName)
      Gets data value by the specified parameters
      Specified by:
      getString in interface DataProvider
      Parameters:
      name -
      componentName -
      Returns:
    • getTestSuiteAttribute

      public Object getTestSuiteAttribute(String propName)
      Gets test suite attribute
      Specified by:
      getTestSuiteAttribute in interface DataProvider
      Parameters:
      propName -
      Returns:
    • getTestSuiteAttribute

      public Object getTestSuiteAttribute(String propName, String testName)
      Gets test suite attribute
      Specified by:
      getTestSuiteAttribute in interface DataProvider
      Parameters:
      propName -
      Returns:
    • getConnectorAttribute

      public Object getConnectorAttribute(String propName)
      Gets data value by the specified parameters
      Specified by:
      getConnectorAttribute in interface DataProvider
      Parameters:
      propName -
      Returns:
    • get

      public Object get(String name)
      Acquire a property value for given name
      Specified by:
      get in interface DataProvider
    • 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 interface DataProvider
      Parameters:
      pattern - the pattern for generation
      clazz - 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 interface DataProvider
    • get

      public Object get(String name, int sequenceNumber)
      Aquire a property value marked with given iteration, for example i1.testProperty
      Specified by:
      get in interface DataProvider
      Parameters:
      name - the suffix
      sequenceNumber -
      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 interface DataProvider
      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 interface DataProvider
      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 interface DataProvider