Class 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 Detail

      • 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 Detail

      • 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.