com.github.springtestdbunit
Class DbUnitRule

java.lang.Object
  extended by com.github.springtestdbunit.DbUnitRule
All Implemented Interfaces:
org.junit.rules.MethodRule

public class DbUnitRule
extends Object
implements org.junit.rules.MethodRule

JUnit @Rule which provides support for @DatabaseSetup, @DatabaseTearDown and @ExpectedDatabase annotations.

The fields of the test class will inspected to locate the IDatabaseConnection or DataSource to use. Generally, a single @Autowired field is expected. It is also possible to configure the connection directly using the setDatabaseConnection(org.dbunit.database.IDatabaseConnection) and setDataSource(javax.sql.DataSource) methods.

Datasets are loaded using the FlatXmlDataSetLoader unless a loader is located from a field of the test class or specifically configured.

Author:
Phillip Webb

Nested Class Summary
protected  class DbUnitRule.DbUnitTestContextAdapter
           
 
Constructor Summary
DbUnitRule()
           
 
Method Summary
 org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base, org.junit.runners.model.FrameworkMethod method, Object target)
           
 void setDatabaseConnection(org.dbunit.database.IDatabaseConnection connection)
          Set the IDatabaseConnection that will be used when running DBUnit tests.
 void setDataSetLoader(DataSetLoader dataSetLoader)
          Set the DataSetLoader that will be used to load IDataSets.
 void setDataSource(DataSource dataSource)
          Set the DataSource that will be used when running DBUnit tests.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DbUnitRule

public DbUnitRule()
Method Detail

apply

public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base,
                                               org.junit.runners.model.FrameworkMethod method,
                                               Object target)
Specified by:
apply in interface org.junit.rules.MethodRule

setDataSource

public void setDataSource(DataSource dataSource)
Set the DataSource that will be used when running DBUnit tests. Note: Setting a data source will replace any previously configured connection.

Parameters:
dataSource - The data source

setDatabaseConnection

public void setDatabaseConnection(org.dbunit.database.IDatabaseConnection connection)
Set the IDatabaseConnection that will be used when running DBUnit tests. Note: Setting a connection will replace any previously configured dataSource.

Parameters:
connection - The connection

setDataSetLoader

public void setDataSetLoader(DataSetLoader dataSetLoader)
Set the DataSetLoader that will be used to load IDataSets.

Parameters:
dataSetLoader - The data set loader


Copyright © 2012. All Rights Reserved.