org.unitils.dbunit.datasetfactory.impl
Class DefaultDataSetResolver

java.lang.Object
  extended by org.unitils.dbunit.datasetfactory.impl.DefaultDataSetResolver
All Implemented Interfaces:
Configurable, DataSetResolver

public class DefaultDataSetResolver
extends Object
implements DataSetResolver

Resolves the location for a data set with a certain name.

By default, the data set name is prefixed with the package name (. replaced by /).
E.g. MyDataSet.xml becomes com/myPackage/MyDataSet.xml

If a data set name starts with a / it will not be prefixed with the package name.
E.g. /MyDataSet.xml remains /MyDataSet.xml

Package name prefixing can be disabled using the PROPKEY_PREFIX_WITH_PACKAGE_NAME property.
prefixWithPackageName=false => MyDataSet.xml remains MyDataSet.xml

If a path prefix is specified using the PROPKEY_DATA_SET_PATH_PREFIX property it is added to the file name.
Examples:

pathPrefix=myPathPrefix: MyDataSet.xml becomes myPathPrefix/org/unitils/test/MyDataSet.xml
pathPrefix=myPathPrefix: /MyDataSet.xml becomes myPathPrefix/MyDataSet.xml

If the path prefix with '/', the file name is treated absolute, else it will be treated relative to the classpath.

Examples:

path prefix /c:/datasets --> looks for c:/datasets/myDataSet.xml on the file system path prefix datasets --> looks for datasets/myDataSet.xml on the classpath

Author:
Tim Ducheyne, Filip Neven, Tuomas Jormola

Field Summary
protected  FileResolver fileResolver
           
static String PROPKEY_DATA_SET_PATH_PREFIX
           
static String PROPKEY_PREFIX_WITH_PACKAGE_NAME
           
 
Constructor Summary
DefaultDataSetResolver()
           
 
Method Summary
 void init(Properties configuration)
          Initializes the resolver with the given configuration.
 File resolve(Class<?> testClass, String dataSetName)
          Resolves the location for a data set with a certain name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROPKEY_PREFIX_WITH_PACKAGE_NAME

public static final String PROPKEY_PREFIX_WITH_PACKAGE_NAME
See Also:
Constant Field Values

PROPKEY_DATA_SET_PATH_PREFIX

public static final String PROPKEY_DATA_SET_PATH_PREFIX
See Also:
Constant Field Values

fileResolver

protected FileResolver fileResolver
Constructor Detail

DefaultDataSetResolver

public DefaultDataSetResolver()
Method Detail

init

public void init(Properties configuration)
Initializes the resolver with the given configuration.

Specified by:
init in interface Configurable
Parameters:
configuration - The configuration, not null

resolve

public File resolve(Class<?> testClass,
                    String dataSetName)
Resolves the location for a data set with a certain name. An exception is raised if the file could not be found.

Specified by:
resolve in interface DataSetResolver
Parameters:
testClass - The test class, not null
dataSetName - The name of the data set, not null
Returns:
The data set file, not null


Copyright © 2011. All Rights Reserved.