org.osesb.scheduledjobs.databasepoller.test
Class DatabasePollerTest

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.osesb.utilities.junit.OSESBTestCase
              extended by org.osesb.utilities.junit.OSESBDBUnitTestCase
                  extended by org.osesb.scheduledjobs.databasepoller.test.DatabasePollerTest
All Implemented Interfaces:
junit.framework.Test

public class DatabasePollerTest
extends OSESBDBUnitTestCase

JUnit Tests for the org.osesb.scheduledjobs.databasepoller package.

Tests a database poller that is configured by the ScheduledJobConfiguration file specified by the 'testConfiguration' property Test.properties.

Tests can be configured to run against different database applications using the </scheduled-job/job-configuration/database-poller-configuration/tableset-configuration/jdbc-configuration> element in the ScheduledJobConfiguration file and the 'databasePollerTestDriverConfiguration' property in Test.properties.

The target database application must be up and available for the tests to run. The JDBCTEST test tables must be created in the target database application. See org/osesb/utilities/jdbc/test/testdata for .sql files that create the test database.

The test DatabasePollerConfiguration(s) in the example folders (example1, example2,...) are configured to use the Customer table in the JDBC test database.

DatabasePollerTest uses a test driver, DatabasePollerTestDriver, which runs in a Thread that periodically inserts a random number of rows into the table(s) which are being scanned by the database poller. The update period is a random interval between (1 times) and (5 times) the repeatInterval that is configured for the database poller and the maximum number of rows that are inserted during each run is given by MAX_ROWS_TO_INSERT.

DatabasePollerTestDriver is configured using the DataSetConfiguration file specified in Test.properties. The DataSetConfiguration includes at least a SQLStatement that is used to update the database table(s) configured for the database poller that is being tested.

DatabasePollerTestDriver gets its database connection using the JDBCConfiguration that is configured for the TableSet that the database poller uses. The SQL statement configured for DatabasePollerTestDriver must update the databse table(s) configured for the database poller that is being tested. The tester should make sure that the DataSetConfiguration for DatabasePollerTestDriver is consistent with the <jdbc-configuration> element in the ScheduledJobConfiguration file.

The test succeeds if the number of rows processed by the database poller is equal to 'the number of rows initially in the target table(s)' + 'the number of rows added by DatabasePollerTestDriver'. The number of rows initially in the target table(s) is given by the 'initialNumberOfTestRows' property in Test.properties.


Field Summary
protected  DatabasePollerTestDriver databasePollerTestDriver
          The DatabasePollerTestDriver for the test.
protected  java.lang.Class databsePollerClass
          The database poller class that is being tested.
protected  int initialNumberOfTestRows
          The test succeeds if the number of rows processed by the database poller is equal to 'the number of rows initially in the target table(s)' + 'the number of rows added by DatabasePollerTestDriver'.
protected  int testMethodSleepTimeMultiplier
          testMethodSleepTimeMultiplier, which determines how long a test is run.
protected  ScheduledJobConfiguration testScheduledJobConfiguration
          The ScheduledJobConfiguration for the test.
 
Fields inherited from class org.osesb.utilities.junit.OSESBDBUnitTestCase
dbunitDataSet, dbunitJDBCConnection
 
Fields inherited from class org.osesb.utilities.junit.OSESBTestCase
configFile, log, reader, testDataDirectory, testProperties, thisClassName
 
Constructor Summary
DatabasePollerTest(java.lang.String name)
          Construct a new instance.
 
Method Summary
static void main(java.lang.String[] args)
          The main method runs all the tests in the text ui
 void setUp()
          This method is called before a test is executed.
static junit.framework.Test suite()
          The suite method runs all the tests
 void tearDown()
          This method is called after a test is executed.
 void testDatabasePollerAsQuartzJob()
          Tests a database poller as a Quartz Job.
 void testDatabasePollerAsRunnableJob()
          Tests a database poller as a Runnable Job.
 
Methods inherited from class org.osesb.utilities.junit.OSESBDBUnitTestCase
displayStartupMessage, loadDBUnitDatabaseConnection
 
Methods inherited from class org.osesb.utilities.junit.OSESBTestCase
getBooleanTestProperty, getIntTestProperty, getLongTestProperty, getTestResourcesAsStreams, getTestResourcesAsText, getTestResourcesFiles, loadTestProperties, readTestFilesAsStreams
 
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, format
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

testScheduledJobConfiguration

protected ScheduledJobConfiguration testScheduledJobConfiguration
The ScheduledJobConfiguration for the test. see setUp().


databasePollerTestDriver

protected DatabasePollerTestDriver databasePollerTestDriver
The DatabasePollerTestDriver for the test. see setUp().


databsePollerClass

protected java.lang.Class databsePollerClass
The database poller class that is being tested. see setUp().


testMethodSleepTimeMultiplier

protected int testMethodSleepTimeMultiplier
testMethodSleepTimeMultiplier, which determines how long a test is run. It is used to calculate the number of seconds that the test method sleeps while the database poller and test driver run. It is specified as a multiplier of the repeat interval or heartbeat interval. For example, if testMethodSleepTimeMultiplier = 30, and if a heartbeatInterval is configured for the ScheduledJob, the test method will sleep 30 times the heartbeatInterval. If a heartbeatInterval is not configured, the test method will sleep 30 times the repeatInterval that is configured for the ScheduledJob. see setUp().


initialNumberOfTestRows

protected int initialNumberOfTestRows
The test succeeds if the number of rows processed by the database poller is equal to 'the number of rows initially in the target table(s)' + 'the number of rows added by DatabasePollerTestDriver'. The number of rows initially in the target table(s) is given by the 'initialNumberOfTestRows' property in Test.properties. see setUp().

Constructor Detail

DatabasePollerTest

public DatabasePollerTest(java.lang.String name)
Construct a new instance.

OSESBTestCase (ancestor) constructor does the following:

  1. Instantiates a logging implementation.
  2. Instantiates an instance of ClassLoaderFileReader for reading test files from the ClassPath (not the file system).
  3. Loads Test.properties into ResourceBundle testProperties.
  4. Sets the testDataDirectory property using the testDataDirectory entry from Test.properties.

Method Detail

suite

public static junit.framework.Test suite()
The suite method runs all the tests


setUp

public void setUp()
           throws java.lang.Exception
This method is called before a test is executed.

Overrides:
setUp in class OSESBTestCase
Throws:
java.lang.Exception

tearDown

public void tearDown()
              throws java.lang.Exception
This method is called after a test is executed.

Overrides:
tearDown in class OSESBDBUnitTestCase
Throws:
java.lang.Exception

main

public static void main(java.lang.String[] args)
The main method runs all the tests in the text ui


testDatabasePollerAsQuartzJob

public void testDatabasePollerAsQuartzJob()
                                   throws java.lang.Exception
Tests a database poller as a Quartz Job.

The test succeeds if the number of rows processed by the database poller is equal to 'the number of rows initially in the target table(s)' + 'the number of rows added by DatabasePollerTestDriver'. The number of rows initially in the target table(s) is given by the 'initialNumberOfTestRows' property in Test.properties.

Throws:
java.lang.Exception

testDatabasePollerAsRunnableJob

public void testDatabasePollerAsRunnableJob()
                                     throws java.lang.Exception
Tests a database poller as a Runnable Job.

The test succeeds if the number of rows processed by the database poller is equal to 'the number of rows initially in the target table(s)' + 'the number of rows added by DatabasePollerTestDriver'.

Throws:
java.lang.Exception