Class DbUnitEmbeddedDatabaseRule

java.lang.Object
com.github.mjeanroy.dbunit.integration.spring.junit4.DbUnitEmbeddedDatabaseRule
All Implemented Interfaces:
org.junit.rules.TestRule

public class DbUnitEmbeddedDatabaseRule extends Object implements org.junit.rules.TestRule
This rule provide a fine integration between spring embedded database and dbunit:
  • Ensure that embedded database is started and available before dbUnit load dataSet.
  • Shutdown database after test.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create rule, embedded database will be initialized with EmbeddedDatabaseConfiguration if defined on the test class, or using a default embedded database.
    DbUnitEmbeddedDatabaseRule(org.springframework.jdbc.datasource.embedded.EmbeddedDatabase db)
    Create rule with given EmbeddedDatabase.
  • Method Summary

    Modifier and Type
    Method
    Description
    org.junit.runners.model.Statement
    apply(org.junit.runners.model.Statement base, org.junit.runner.Description description)
     
    Return new database connection, may return null if the database has not been initialized yet.
    org.springframework.jdbc.datasource.embedded.EmbeddedDatabase
    Get embedded database, may return null if the database has not been initialized yet.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DbUnitEmbeddedDatabaseRule

      public DbUnitEmbeddedDatabaseRule()
      Create rule, embedded database will be initialized with EmbeddedDatabaseConfiguration if defined on the test class, or using a default embedded database.
    • DbUnitEmbeddedDatabaseRule

      public DbUnitEmbeddedDatabaseRule(org.springframework.jdbc.datasource.embedded.EmbeddedDatabase db)
      Create rule with given EmbeddedDatabase.
      Parameters:
      db - Embedded database.
  • Method Details

    • apply

      public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base, org.junit.runner.Description description)
      Specified by:
      apply in interface org.junit.rules.TestRule
    • getDb

      public org.springframework.jdbc.datasource.embedded.EmbeddedDatabase getDb()
      Get embedded database, may return null if the database has not been initialized yet.
      Returns:
      Embedded database.
    • getConnection

      public Connection getConnection()
      Return new database connection, may return null if the database has not been initialized yet.
      Returns:
      New database connection.