Package org.dbunit

Class DatabaseEnvironment

java.lang.Object
org.dbunit.DatabaseEnvironment
Direct Known Subclasses:
DerbyEnvironment, H2Environment, HypersonicEnvironment, MsSqlEnvironment, MySqlEnvironment, OracleEnvironment, PostgresqlEnvironment

public class DatabaseEnvironment extends Object
Since:
Feb 18, 2002
Version:
$Revision$
Author:
Manuel Laflamme
  • Constructor Details

  • Method Details

    • getProperties

      protected static Properties getProperties() throws IOException
      Optional "dbunit.properties" is loaded (if present and the "dbunit.profile" property is null) and merged with System properties and the whole set is returned.

      If absent (which is the normal scenario), only System properties are returned.

      "dbunit.properties" is useful for environment which make it difficult if not impossible to use Maven's profiles. Example is IntelliJ IDEA which when calling Junit tests, bypass Maven completely. Since profiles are not used, database configuration is not properly set and tests fail. "dbunit.properties" contains the missing properties which a profile would set.

      Following is a few properties as an example of the content of "dbunit.properties":

       database.profile=h2
       dbunit.profile.driverClass=org.hsqldb.jdbcDriver
       dbunit.profile.url=jdbc:hsqldb:mem:.
       

      Simply create "dbunit.properties" under "src/test/resources".

      Returns:
      Merged DbUnit and System properties.
      Throws:
      IOException - Thrown if an error occurs when attempting to read "dbunit.properties".
    • loadDbunitPropertiesFromFile

      protected static void loadDbunitPropertiesFromFile(Properties properties) throws IOException
      Throws:
      IOException
    • getInstance

      public static DatabaseEnvironment getInstance() throws Exception
      Throws:
      Exception
    • getConnection

      public IDatabaseConnection getConnection() throws Exception
      Throws:
      Exception
    • setupDatabaseConfig

      protected void setupDatabaseConfig(DatabaseConfig config)
    • getDatabaseTester

      public IDatabaseTester getDatabaseTester()
    • closeConnection

      public void closeConnection() throws Exception
      Throws:
      Exception
    • getInitDataSet

      public IDataSet getInitDataSet() throws Exception
      Throws:
      Exception
    • getProfile

      public DatabaseProfile getProfile() throws Exception
      Throws:
      Exception
    • support

      public boolean support(TestFeature feature)
    • convertString

      public String convertString(String str)
      Returns the string converted as an identifier according to the metadata rules of the database environment. Most databases convert all metadata identifiers to uppercase. PostgreSQL converts identifiers to lowercase. MySQL preserves case.
      Parameters:
      str - The identifier.
      Returns:
      The identifier converted according to database rules.
    • toString

      public String toString()
      Overrides:
      toString in class Object