org.opensubsystems.patterns.listdata.persist.db
Class ListDatabaseFactoryTest

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.opensubsystems.core.persist.db.DatabaseTest
              extended by org.opensubsystems.patterns.listdata.persist.db.ListDatabaseFactoryTest
All Implemented Interfaces:
junit.framework.Test

public abstract class ListDatabaseFactoryTest
extends org.opensubsystems.core.persist.db.DatabaseTest

Base class for classes that test functionality of classes that implement ListDatabaseFactory interface and ListDatabaseFactoryImpl class. This class implements tests for all list related functionality provided by the mentioned interface. Once you derive your test from this class, just add test that tests the functionality you have implemented in your derived database factory class, the base class functionality will be tested automatically.

Version:
$Id: ListDatabaseFactoryTest.java,v 1.33 2007/02/01 07:26:30 bastafidli Exp $
Author:
Julo Legeny
Code reviewer:
Miro Halas
Code reviewed:
1.28 2007/01/07 06:15:17 bastafidli

Field Summary
static int DEFAULT_LOADTEST_LIST_SIZE
          How many items to use for load testing.
static int DEFAULT_LOADTEST_LOADTIME
          What time to retrieve page should be considered too slow and will cause given test to fail? 4 sec to load one page of list is considered slow.
static int DEFAULT_LOADTEST_PAGE_SIZE
          What page size should be used for load testing.
protected  ListDatabaseTestUtils m_listTestUtils
          Utility class to implement helper methods for list functionality.
protected static int s_iLoadtestListSize
          Value telling us list size for loadtests
protected static int s_iLoadtestLoadTime
          Value telling us predetermined time the data in the list should be retrieved in
protected static int s_iLoadtestPageSize
          Value telling us page size for loadtests
 
Fields inherited from class org.opensubsystems.core.persist.db.DatabaseTest
DEFAULT_DB_PASSWORD, DEFAULT_DB_USER, DEFAULT_PROPERTY_FILE, m_connection, m_iRequestedConnectionCount, m_transaction
 
Constructor Summary
ListDatabaseFactoryTest(java.lang.String strTestName, ListDatabaseTestUtils listTestUtils)
          Constructor with data object specific parameters
 
Method Summary
protected  long doLoadTestGet(java.lang.Object parent, int iListSize, int iPageSize, int iBeginPos, boolean bCountLastPageSize, int[] arrColumns, int iOrderColumn, boolean bOrderDirectionAsc, boolean bTestDataValues)
          Helper method to test get method of ListFactory.
protected  void doTestGet(java.lang.Object parent, int pageSize, int beginPos, int[] columns)
          Helper method to test get(ListOptions) method of List using the modified default list options.
protected  void doTestGetColumns(int[] columns)
          Helper method to test getColumns method of ListDatabaseSchema.
protected  void doTestLoadPagesFromFirstToLast(java.lang.Object parent, java.lang.String strExtraText)
          Load test for data performance.
protected  void doTestLoadPagesFromLastToFirst(java.lang.Object parent, java.lang.String strExtraText, int iOrderColumn, boolean bOrderDirectionAsc, boolean bTestDataValues)
          Load test for data performance.
protected  void doTestLoadPagesRandom(java.lang.Object parent, java.lang.String strExtraText)
          Load test for data performance.
protected  void setUp()
          Set up environment for the test case.
protected  void tearDown()
          Restore original environment after the test case.
 void testGet()
          Test of get(ListOptions) method of the ListFactory accessing data in database.
 void testGetColumns()
          Test implementation of the getColumns method in the database schema.
 void testGetColumnsUsingId()
          Some controllers needs to know the code for the ID column so they can operate properly.
 void testLoadPagesFromFirstToLast()
          Test loading pages by browsing through the whole list page by page from the first to the last therefore retrieving every page of the list in sequential order.
 void testLoadPagesFromLastToFirst()
          Test loading pages by browsing through the whole list page by page from the last to the first therefore retrieving every page of the list in sequential order and testing the retrieved data to make sure that we have retrieved the correct data.
 void testLoadPagesFromLastToFirstMoreSortableColumns()
          Test loading pages by browsing through the whole list page by page from the last to the first therefore retrieving every page of the list in sequential order.
 void testLoadPagesRandom()
          Test loading pages from the list by randomly selecting a page and then retrieving it.
 
Methods inherited from class org.opensubsystems.core.persist.db.DatabaseTest
addDataSource, addDataSource, getDataSourceName, setDataSourceName
 
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_LOADTEST_LIST_SIZE

public static final int DEFAULT_LOADTEST_LIST_SIZE
How many items to use for load testing. This is the maximal amount of items to exist in single domain. When running multi domain tests the total amount of data is usually larger. By default make this small by default for casual use.

See Also:
Constant Field Values

DEFAULT_LOADTEST_PAGE_SIZE

public static final int DEFAULT_LOADTEST_PAGE_SIZE
What page size should be used for load testing. This number specifies how many items to retrieve at once.

See Also:
Constant Field Values

DEFAULT_LOADTEST_LOADTIME

public static final int DEFAULT_LOADTEST_LOADTIME
What time to retrieve page should be considered too slow and will cause given test to fail? 4 sec to load one page of list is considered slow.

See Also:
Constant Field Values

m_listTestUtils

protected ListDatabaseTestUtils m_listTestUtils
Utility class to implement helper methods for list functionality.


s_iLoadtestListSize

protected static int s_iLoadtestListSize
Value telling us list size for loadtests


s_iLoadtestPageSize

protected static int s_iLoadtestPageSize
Value telling us page size for loadtests


s_iLoadtestLoadTime

protected static int s_iLoadtestLoadTime
Value telling us predetermined time the data in the list should be retrieved in

Constructor Detail

ListDatabaseFactoryTest

public ListDatabaseFactoryTest(java.lang.String strTestName,
                               ListDatabaseTestUtils listTestUtils)
Constructor with data object specific parameters

Parameters:
strTestName - - name of the test
listTestUtils - - utilities used during test
Method Detail

setUp

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

Overrides:
setUp in class org.opensubsystems.core.persist.db.DatabaseTest
Throws:
java.lang.Exception - - an error has occured during setting up test

tearDown

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

Overrides:
tearDown in class org.opensubsystems.core.persist.db.DatabaseTest
Throws:
java.lang.Exception - - an error has occured during tearing down up test

testGetColumnsUsingId

public void testGetColumnsUsingId()
                           throws java.lang.Exception
Some controllers needs to know the code for the ID column so they can operate properly. For example getRightsForCurrentUser method in AuthorizationControllerImpl class in security package has hardcoded assumption that the code for the ID column is the value for datatype + 1. This test will test that assumption This test should be really in ListDatabaseSchemaTest class but that would require developer to derive two classes instead of one and therefore we will bundle it with tests for factory.

Throws:
java.lang.Exception - - an error has occured

testGetColumns

public void testGetColumns()
                    throws java.lang.Exception
Test implementation of the getColumns method in the database schema. This test should be really in ListDatabaseSchemaTest class but that would require developer to derive two classes instead of one and therefore we will bundle it with tests for factory.

Throws:
java.lang.Exception - - an error has occured

testGet

public void testGet()
             throws java.lang.Exception
Test of get(ListOptions) method of the ListFactory accessing data in database. This test use test util to do various tests

Throws:
java.lang.Exception - - an error has occured during test

testLoadPagesFromFirstToLast

public void testLoadPagesFromFirstToLast()
                                  throws java.lang.Exception
Test loading pages by browsing through the whole list page by page from the first to the last therefore retrieving every page of the list in sequential order.

Throws:
java.lang.Exception - - an error has occured

testLoadPagesFromLastToFirst

public void testLoadPagesFromLastToFirst()
                                  throws java.lang.Exception
Test loading pages by browsing through the whole list page by page from the last to the first therefore retrieving every page of the list in sequential order and testing the retrieved data to make sure that we have retrieved the correct data.

Throws:
java.lang.Exception - - an error has occured

testLoadPagesFromLastToFirstMoreSortableColumns

public void testLoadPagesFromLastToFirstMoreSortableColumns()
                                                     throws java.lang.Exception
Test loading pages by browsing through the whole list page by page from the last to the first therefore retrieving every page of the list in sequential order. This tests just ensures that the database can use the specified columns for sorting and doesnt actually tests if the retrieved data are the correct data.

Throws:
java.lang.Exception - - an error has occured

testLoadPagesRandom

public void testLoadPagesRandom()
                         throws java.lang.Exception
Test loading pages from the list by randomly selecting a page and then retrieving it. Every page in the data set will be retrieved in random order and performance of the data retrieval will be monitored.

Throws:
java.lang.Exception - - an error has occured

doTestGetColumns

protected void doTestGetColumns(int[] columns)
                         throws org.opensubsystems.core.error.OSSException
Helper method to test getColumns method of ListDatabaseSchema.

Parameters:
columns - - columns to test
Throws:
org.opensubsystems.core.error.OSSException - - an error has occured

doTestGet

protected void doTestGet(java.lang.Object parent,
                         int pageSize,
                         int beginPos,
                         int[] columns)
                  throws java.lang.Exception
Helper method to test get(ListOptions) method of List using the modified default list options.

Parameters:
parent - - parent object to which the items in the list belongs to it can be null if those items do not have any parent
pageSize - - how many items to retrieve at once
beginPos - - what should be the first parameter retrieved
columns - - columns to retrieve
Throws:
java.lang.Exception - - an error has occured

doLoadTestGet

protected long doLoadTestGet(java.lang.Object parent,
                             int iListSize,
                             int iPageSize,
                             int iBeginPos,
                             boolean bCountLastPageSize,
                             int[] arrColumns,
                             int iOrderColumn,
                             boolean bOrderDirectionAsc,
                             boolean bTestDataValues)
                      throws java.lang.Exception
Helper method to test get method of ListFactory. This is used for load tests that test different retrieval strategies of the list pages.

Parameters:
parent - - parent object, to which items in the list should belong to
iListSize - - the total list size
iPageSize - - the page size to retrieve
iBeginPos - - where to retrieve the page
bCountLastPageSize - - flag specifying if the retrieved page is the last and its size needs to be computed
arrColumns - - columns to retrieve
iOrderColumn - - column code that will be used for sorting (in clause order by). Use -1 if no sorting should be done.
bOrderDirectionAsc - - true, if the list should be sorted in ascending order - false, if the list should be sorted in descending order
bTestDataValues - - true, if the test will actually test the retrieved values (1st and last record) - false, if the test will not test the retrieved values and just retrieve the data
Returns:
long - time duration how long it took to load the page
Throws:
java.lang.Exception - - an error has occured

doTestLoadPagesFromFirstToLast

protected void doTestLoadPagesFromFirstToLast(java.lang.Object parent,
                                              java.lang.String strExtraText)
                                       throws java.lang.Exception
Load test for data performance. Browse through the whole list page by page from the first to the last therefore retrieving every page of the list in sequential order.

Parameters:
parent - - parent object containing all data using which to execute the test
strExtraText - - text to use in reporting of performance
Throws:
java.lang.Exception - - an error has occured

doTestLoadPagesFromLastToFirst

protected void doTestLoadPagesFromLastToFirst(java.lang.Object parent,
                                              java.lang.String strExtraText,
                                              int iOrderColumn,
                                              boolean bOrderDirectionAsc,
                                              boolean bTestDataValues)
                                       throws java.lang.Exception
Load test for data performance. Browse through the whole list from the last to the first therefore retrieving every page of the list in sequential order but in reverse. This method will also providing test for all possible sorting columns (columns used in the clause ORDER BY). Direction will be changed for each 2nd sortable column.

Parameters:
parent - - parent object containing all data using which to execute the test
strExtraText - - text to use in reporting of performance
iOrderColumn - - column code that will be used for sorting (in clause order by)
bOrderDirectionAsc - - true, if there will be used ASC direction - false, if there will be used DESC direction
bTestDataValues - - true, if there will be tested retrieved values (1st and last record) - false, if there will be not tested retrieved values
Throws:
java.lang.Exception - - an error has occured during test

doTestLoadPagesRandom

protected void doTestLoadPagesRandom(java.lang.Object parent,
                                     java.lang.String strExtraText)
                              throws java.lang.Exception
Load test for data performance. Retrieve the pages from the list randomly, generate page number or starting position somewhere in the list and then retrieve the page.

Parameters:
parent - - parent object containing all data using which to execute the test
strExtraText - - text to use in reporting of performance
Throws:
java.lang.Exception - - an error has occured


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