org.apache.commons.configuration
Class DatabaseConfigurationTestHelper

java.lang.Object
  extended by org.apache.commons.configuration.DatabaseConfigurationTestHelper

public class DatabaseConfigurationTestHelper
extends Object

A helper class for performing tests for DatabaseConfiguration. This class maintains an in-process database that stores configuration data and can be accessed from a DatabaseConfiguration instance. Constants for table and column names and database connection settings are provided, too.

Version:
$Id: DatabaseConfigurationTestHelper.java 1222447 2011-12-22 20:59:44Z oheger $

Field Summary
static String COL_KEY
          Constant for the column with the keys.
static String COL_NAME
          Constant for the column with the configuration name.
static String COL_VALUE
          Constant for the column with the values.
static String CONFIG_NAME
          Constant for the name of the test configuration.
 String DATABASE_DRIVER
          Constant for the JDBC driver class.
 String DATABASE_PASSWORD
          Constant for the DB password.
 String DATABASE_URL
          Constant for the connection URL.
 String DATABASE_USERNAME
          Constant for the DB user name.
static String TABLE
          Constant for the configuration table.
static String TABLE_MULTI
          Constant for the multi configuration table.
 
Constructor Summary
DatabaseConfigurationTestHelper()
           
 
Method Summary
 DataSource getDatasource()
          Returns the DataSource managed by this class.
 boolean isAutoCommit()
          Returns the auto-commit mode of the connections created by the managed data source.
 void setAutoCommit(boolean autoCommit)
          Sets the auto-commit mode of the connections created by the managed data source.
 void setUp()
          Initializes this helper object.
 DatabaseConfiguration setUpConfig()
          Creates a database configuration with default values.
 DatabaseConfiguration setUpMultiConfig()
          Creates a database configuration that supports multiple configurations in a table with default values.
 DatabaseConfiguration setUpMultiConfig(String configName)
          Creates a database configuration that supports multiple configurations in a table and sets the specified configuration name.
 void tearDown()
          Frees the resources used by this helper class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DATABASE_DRIVER

public final String DATABASE_DRIVER
Constant for the JDBC driver class.

See Also:
Constant Field Values

DATABASE_URL

public final String DATABASE_URL
Constant for the connection URL.

See Also:
Constant Field Values

DATABASE_USERNAME

public final String DATABASE_USERNAME
Constant for the DB user name.

See Also:
Constant Field Values

DATABASE_PASSWORD

public final String DATABASE_PASSWORD
Constant for the DB password.

See Also:
Constant Field Values

TABLE

public static final String TABLE
Constant for the configuration table.

See Also:
Constant Field Values

TABLE_MULTI

public static final String TABLE_MULTI
Constant for the multi configuration table.

See Also:
Constant Field Values

COL_KEY

public static final String COL_KEY
Constant for the column with the keys.

See Also:
Constant Field Values

COL_VALUE

public static final String COL_VALUE
Constant for the column with the values.

See Also:
Constant Field Values

COL_NAME

public static final String COL_NAME
Constant for the column with the configuration name.

See Also:
Constant Field Values

CONFIG_NAME

public static final String CONFIG_NAME
Constant for the name of the test configuration.

See Also:
Constant Field Values
Constructor Detail

DatabaseConfigurationTestHelper

public DatabaseConfigurationTestHelper()
Method Detail

isAutoCommit

public boolean isAutoCommit()
Returns the auto-commit mode of the connections created by the managed data source.

Returns:
the auto-commit mode

setAutoCommit

public void setAutoCommit(boolean autoCommit)
Sets the auto-commit mode of the connections created by the managed data source.

Parameters:
autoCommit - the auto-commit mode

setUp

public void setUp()
           throws Exception
Initializes this helper object. This method can be called from a setUp() method of a unit test class. It creates the database instance if necessary.

Throws:
Exception - if an error occurs

tearDown

public void tearDown()
              throws Exception
Frees the resources used by this helper class. This method can be called by a tearDown() method of a unit test class.

Throws:
Exception - if an error occurs

setUpConfig

public DatabaseConfiguration setUpConfig()
Creates a database configuration with default values.

Returns:
the configuration

setUpMultiConfig

public DatabaseConfiguration setUpMultiConfig()
Creates a database configuration that supports multiple configurations in a table with default values.

Returns:
the configuration

setUpMultiConfig

public DatabaseConfiguration setUpMultiConfig(String configName)
Creates a database configuration that supports multiple configurations in a table and sets the specified configuration name.

Parameters:
configName - the name of the configuration
Returns:
the configuration

getDatasource

public DataSource getDatasource()
Returns the DataSource managed by this class. The data source is created on first access.

Returns:
the DataSource


Copyright © 2001-2012 The Apache Software Foundation. All Rights Reserved.