com.github.springtestdbunit.dataset
Class AbstractDataSetLoader

java.lang.Object
  extended by com.github.springtestdbunit.dataset.AbstractDataSetLoader
All Implemented Interfaces:
DataSetLoader
Direct Known Subclasses:
FlatXmlDataSetLoader

public abstract class AbstractDataSetLoader
extends Object
implements DataSetLoader

Abstract data set loader, which provides a basis for concrete implementations of the DataSetLoader strategy. Provides a Template Method based approach for loading data using a Spring resource loader.

Author:
Phillip Webb
See Also:
getResourceLoader(java.lang.Class), getResourceLocations(java.lang.Class, java.lang.String), createDataSet(Resource)

Constructor Summary
AbstractDataSetLoader()
           
 
Method Summary
protected abstract  org.dbunit.dataset.IDataSet createDataSet(org.springframework.core.io.Resource resource)
          Factory method used to create the dataset
protected  org.springframework.core.io.ResourceLoader getResourceLoader(Class<?> testClass)
          Gets the ResourceLoader that will be used to load the dataset Resources.
protected  String[] getResourceLocations(Class<?> testClass, String location)
          Get the resource locations that should be considered when attempting to load a dataset from the specified location.
 org.dbunit.dataset.IDataSet loadDataSet(Class<?> testClass, String location)
          Loads a dataset from Resources obtained from the specified location.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractDataSetLoader

public AbstractDataSetLoader()
Method Detail

loadDataSet

public org.dbunit.dataset.IDataSet loadDataSet(Class<?> testClass,
                                               String location)
                                        throws Exception
Loads a dataset from Resources obtained from the specified location. Each location can be mapped to a number of potential resources, the first resource that exists will be used. Resources are loaded using the ResourceLoader returned from getResourceLoader(java.lang.Class).

If no resource can be found then null will be returned.

Specified by:
loadDataSet in interface DataSetLoader
Parameters:
testClass - The class under test
location - The location to load
Returns:
a dataset or null
Throws:
Exception - If the dataset cannot be loaded
See Also:
createDataSet(Resource), java.lang.String)

getResourceLoader

protected org.springframework.core.io.ResourceLoader getResourceLoader(Class<?> testClass)
Gets the ResourceLoader that will be used to load the dataset Resources.

Parameters:
testClass - The class under test
Returns:
a resource loader

getResourceLocations

protected String[] getResourceLocations(Class<?> testClass,
                                        String location)
Get the resource locations that should be considered when attempting to load a dataset from the specified location.

Parameters:
testClass - The class under test
location - The source location
Returns:
an array of potential resource locations

createDataSet

protected abstract org.dbunit.dataset.IDataSet createDataSet(org.springframework.core.io.Resource resource)
                                                      throws Exception
Factory method used to create the dataset

Parameters:
resource - an existing resource that contains the dataset data
Returns:
a dataset
Throws:
Exception - if the dataset could not be loaded


Copyright © 2012. All Rights Reserved.