com.netriser.xmltestsuite
Class DBResource

java.lang.Object
  |
  +--junit.framework.Assert
        |
        +--com.netriser.xmltestsuite.TestResource
              |
              +--com.netriser.xmltestsuite.DBResource
All Implemented Interfaces:
junit.framework.TestListener, TestResourceInterface

public class DBResource
extends TestResource
implements junit.framework.TestListener

This class provides database resources to test objects. It also monitors designated database tables for insertions and deletions to verify for each test or step that only specified database tables are affected.

It is configured via the optional database element in the xml configuration file parsed by ConfigurationResource.

The monitoring uses nested selects, so that many tables can be efficiently monitored at the same time. This requires a database which supports nested selects. Most databases support this, the most notable exception being MS Access.

This class acts as a facade which hides the complexity of the database from the test objects. It is instantiated as a singleton using a factory To obtain a instance use

 	DBResource ResourceFactory.getDBResource();
 

Author:
david

Constructor Summary
DBResource()
           
 
Method Summary
 void addError(junit.framework.Test test, java.lang.Throwable t)
           
 void addFailure(junit.framework.Test test, junit.framework.AssertionFailedError t)
           
 void displayQuery(java.lang.String query)
           
 void endTest(junit.framework.Test test)
          Verifies the database tables at the end of a test or step.
 void exec(java.lang.String query)
          Executes a given query string.
 java.lang.String execR1C1(java.lang.String query)
          Returns the first column of the first row of a given query string.
 java.sql.Connection getDBConnection()
           
 void listdbInsertedRows()
          Prints a list of inserted rows.
 void setUp()
          Opens a connection to the database.
 void startTest(junit.framework.Test test)
           
 void tearDown()
          Closes the database connection and prints a list of inserted rows.
 void useTestResult(junit.framework.TestResult resultCollector)
          Called when testing starts ie by Main::RunTest Provides opportunity to calll TestResult::addListener addListener requires class to implement TestListener interface
 
Methods inherited from class com.netriser.xmltestsuite.TestResource
debug, getDebugMode, getVerboseMode, setDebug, setVerbose, verbose
 
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
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DBResource

public DBResource()
Method Detail

getDBConnection

public java.sql.Connection getDBConnection()

setUp

public void setUp()
Opens a connection to the database. Checks the inital state of those database tables which are going to be monitored.

Specified by:
setUp in interface TestResourceInterface
Specified by:
setUp in class TestResource
See Also:
TestResource.setUp()

tearDown

public void tearDown()
Closes the database connection and prints a list of inserted rows. This is an sql script which you could execute to remove the rows inserted into the database by testing. (only applies to tables with an identity column)

Specified by:
tearDown in interface TestResourceInterface
Specified by:
tearDown in class TestResource
See Also:
TestResource.tearDown()

exec

public void exec(java.lang.String query)
          throws java.sql.SQLException
Executes a given query string.

Throws:
java.sql.SQLException

execR1C1

public java.lang.String execR1C1(java.lang.String query)
                          throws java.sql.SQLException
Returns the first column of the first row of a given query string.

Throws:
java.sql.SQLException

listdbInsertedRows

public void listdbInsertedRows()
Prints a list of inserted rows. This is an sql script which you could execute to remove the rows inserted into the database by testing. (only applies to tables with an identity column)


useTestResult

public void useTestResult(junit.framework.TestResult resultCollector)
Description copied from interface: TestResourceInterface
Called when testing starts ie by Main::RunTest Provides opportunity to calll TestResult::addListener addListener requires class to implement TestListener interface

Specified by:
useTestResult in interface TestResourceInterface
Overrides:
useTestResult in class TestResource
See Also:
TestResourceInterface.useTestResult(TestResult)

addError

public void addError(junit.framework.Test test,
                     java.lang.Throwable t)
Specified by:
addError in interface junit.framework.TestListener
See Also:
TestListener.addError(Test, Throwable)

addFailure

public void addFailure(junit.framework.Test test,
                       junit.framework.AssertionFailedError t)
Specified by:
addFailure in interface junit.framework.TestListener
See Also:
TestListener.addFailure(Test, AssertionFailedError)

endTest

public void endTest(junit.framework.Test test)
Verifies the database tables at the end of a test or step.

Specified by:
endTest in interface junit.framework.TestListener
See Also:
TestListener.endTest(Test)

startTest

public void startTest(junit.framework.Test test)
Specified by:
startTest in interface junit.framework.TestListener
See Also:
TestListener.startTest(Test)

displayQuery

public void displayQuery(java.lang.String query)
                  throws java.sql.SQLException
java.sql.SQLException