org.opensubsystems.core.persist.db
Class DatabaseTest

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.opensubsystems.core.persist.db.DatabaseTest
All Implemented Interfaces:
junit.framework.Test
Direct Known Subclasses:
AddBatchTest.AddBatchTestInternal, DatabaseConnectionFactoryBaseTest, DateTest.DateTestInternal, DBProcReturnInsertedRowsCountTest.DBProcReturnInsertedRowsCountTestInternal, DeleteWithSubqueryTest.DeleteWithSubqueryTestInternal, GeneratedKeyTest.GeneratedKeyTestInternal, PreparedStatementTest.PreparedStatementTestInternal, QueryTest.QueryTestInternal, SameColumnTest.SameColumnTestInternal, SelectAfterInsertIntoUniqueColumnTest.SelectAfterInsertIntoUniqueColumnTestInternal, SetNullColumnTest.SetNullColumnTestInternal, TimestampTest.TimestampTestInternal, TimeTest.TimeTestInternal, TransactionTest.TransactionTestInternal, UpdatableResultSetTest.UpdatableResultSetTestInternal, UpdateDBProcWithoutOutputTest.UpdateDBProcWithoutOutputTestInternal

public abstract class DatabaseTest
extends junit.framework.TestCase

Base class for all tests that access the database. Test cases derived from this class should use DatabaseTestSetup adapter and follow comments in this class to properly initialize and shutdown database.

Version:
$Id: DatabaseTest.java,v 1.11 2007/01/07 06:14:20 bastafidli Exp $
Author:
Miro Halas
Code reviewer:
Miro Halas
Code reviewed:
1.5 2004/12/18 06:18:22 bastafidli

Field Summary
protected static java.lang.String DEFAULT_DB_PASSWORD
          Default password for database user.
protected static java.lang.String DEFAULT_DB_USER
          Default name for database user.
protected static java.lang.String DEFAULT_PROPERTY_FILE
          Default property file used to run tests.
protected  java.sql.Connection m_connection
          Connection to the database which can be used by test.
protected  int m_iRequestedConnectionCount
          How many connections were requested at the beginning of the test from the pool.
protected  javax.transaction.UserTransaction m_transaction
          Database transaction which can be used by test.
 
Constructor Summary
DatabaseTest(java.lang.String strTestName)
          Create new DatabaseTest.
 
Method Summary
static void addDataSource(java.lang.String strDataSourceName, java.lang.String strDriverName, java.lang.String strUrl)
          Create data source to be managed by the transaction manager.
static void addDataSource(java.lang.String strDataSourceName, java.lang.String strDriverName, java.lang.String strUrl, java.lang.String strUser, java.lang.String strPassword)
          Create data source to be managed by the transaction manager.
static java.lang.String getDataSourceName()
          Get the name of the data source used by this test.
static void setDataSourceName(java.lang.String strDataSourceName)
          Set the data source to be used by this database test.
protected  void setUp()
          Set up environment for the test case.
protected  void tearDown()
          Restore original environment after the test case.
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, failNotEquals, failNotSame, failSame
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_DB_USER

protected static final java.lang.String DEFAULT_DB_USER
Default name for database user. Make this name different from the name used by the real code so that tests execute in tables owned by different user.

See Also:
Constant Field Values

DEFAULT_DB_PASSWORD

protected static final java.lang.String DEFAULT_DB_PASSWORD
Default password for database user.

See Also:
Constant Field Values

DEFAULT_PROPERTY_FILE

protected static final java.lang.String DEFAULT_PROPERTY_FILE
Default property file used to run tests.

See Also:
Constant Field Values

m_transaction

protected javax.transaction.UserTransaction m_transaction
Database transaction which can be used by test. This transaction object is instantiated before every test is started and checked if the transaction was propertly finished after the test is done.


m_connection

protected java.sql.Connection m_connection
Connection to the database which can be used by test. This connection object is instantiated before every test is started and returned after the test is done. This connection may be used to quickly access the database in the test without worrying about its creation and destruction.


m_iRequestedConnectionCount

protected int m_iRequestedConnectionCount
How many connections were requested at the beginning of the test from the pool. This should must the number of requested connection after the test.

Constructor Detail

DatabaseTest

public DatabaseTest(java.lang.String strTestName)
Create new DatabaseTest.

Parameters:
strTestName - - name of the test
Method Detail

addDataSource

public static void addDataSource(java.lang.String strDataSourceName,
                                 java.lang.String strDriverName,
                                 java.lang.String strUrl)
                          throws org.opensubsystems.core.error.OSSException
Create data source to be managed by the transaction manager. Each test must specify the name of the data source. If it doesn't exist, it will be created.

Parameters:
strDataSourceName - - data source which will be used by this test
strDriverName - - driver name which will be used by this test
strUrl - - url this test connects to the database \
Throws:
org.opensubsystems.core.error.OSSException - - an error has occured

addDataSource

public static void addDataSource(java.lang.String strDataSourceName,
                                 java.lang.String strDriverName,
                                 java.lang.String strUrl,
                                 java.lang.String strUser,
                                 java.lang.String strPassword)
                          throws org.opensubsystems.core.error.OSSException
Create data source to be managed by the transaction manager. Each test must specify the name of the data source. If it doesn't exist, it will be created.

Parameters:
strDataSourceName - - data source which will be used by this test
strDriverName - - driver name which will be used by this test
strUrl - - url this test connects to the database
strUser - - user name to connects to the database
strPassword - - password to connects to the database
Throws:
org.opensubsystems.core.error.OSSException - - an error has occured

setDataSourceName

public static void setDataSourceName(java.lang.String strDataSourceName)
                              throws org.opensubsystems.core.error.OSSException
Set the data source to be used by this database test. THis method must be called before any test can be run.

Parameters:
strDataSourceName - - data source which will be used by this test
Throws:
org.opensubsystems.core.error.OSSException - - an error has occured

getDataSourceName

public static java.lang.String getDataSourceName()
                                          throws org.opensubsystems.core.error.OSSException
Get the name of the data source used by this test.

Returns:
String - data source name
Throws:
org.opensubsystems.core.error.OSSException - - an error has occured

setUp

protected void setUp()
              throws java.lang.Exception
Set up environment for the test case.

Overrides:
setUp in class junit.framework.TestCase
Throws:
java.lang.Exception - - an error has occured while setting up test

tearDown

protected void tearDown()
                 throws java.lang.Exception
Restore original environment after the test case.

Overrides:
tearDown in class junit.framework.TestCase
Throws:
java.lang.Exception - - an error has occured while tearing down test


Copyright © 2003 - 2006 OpenSubsystems s.r.o.