org.jminor.framework.tools.testing
Class EntityTestUnit

java.lang.Object
  extended by org.jminor.framework.tools.testing.EntityTestUnit

public abstract class EntityTestUnit
extends Object

A class for unit testing domain entities.


Constructor Summary
EntityTestUnit()
          Instantiates a new EntityTestUnit.
 
Method Summary
protected  void doSetUp()
          Override to provide specific setup for this test
protected  void doTearDown()
          Override to provide specific tear down for this test
protected  EntityConnection getConnection()
           
protected  EntityConnectionProvider getConnectionProvider()
           
protected  Entity getReferenceEntity(String entityID)
           
protected  User getTestUser()
          Returns the database user to use when running the tests, this default implementation prompts for the user/password information, usually overridden
protected  EntityConnectionProvider initializeConnectionProvider()
           
protected  void initializeReferencedEntities(String testEntityID, String entityID)
          This method should initialize instances of entities specified by the entityIDs found in the entityIDs Collection and map them to their respective entityIDs via the setReferenceEntity method
protected  Entity initializeReferenceEntity(String entityID)
          Initializes a new Entity of the given type, by default this method creates a Entity filled with random values.
protected  Entity initializeTestEntity(String entityID)
          This method should return an instance of the entity specified by entityID
protected abstract  void loadDomainModel()
          This method should load the domain model, for example by instantiating the domain model class or simply loading it by name
protected  void modifyEntity(Entity testEntity)
          This method should return testEntity in a modified state
protected  void setReferenceEntity(String entityID, Entity entity)
          Maps the given reference entity to the given entityID
 void setUp()
          Sets up the database connection
 void tearDown()
          Tears down the database connection
 void testEntity(String entityID)
          Runs the insert/update/select/delete tests for the given entityID
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EntityTestUnit

public EntityTestUnit()
Instantiates a new EntityTestUnit.

Method Detail

setUp

public final void setUp()
                 throws CancelException
Sets up the database connection

Throws:
CancelException - in case the test is cancelled during setup

tearDown

public final void tearDown()
Tears down the database connection


testEntity

public final void testEntity(String entityID)
                      throws DatabaseException
Runs the insert/update/select/delete tests for the given entityID

Parameters:
entityID - the ID of the entity to test
Throws:
DatabaseException - in case of an exception

doSetUp

protected void doSetUp()
Override to provide specific setup for this test


doTearDown

protected void doTearDown()
Override to provide specific tear down for this test


initializeConnectionProvider

protected EntityConnectionProvider initializeConnectionProvider()
                                                         throws CancelException
Returns:
the EntityConnectionProvider instance this test case should use
Throws:
CancelException - in case the login was cancelled

getTestUser

protected User getTestUser()
                    throws CancelException
Returns the database user to use when running the tests, this default implementation prompts for the user/password information, usually overridden

Returns:
the db user to use when running the test
Throws:
CancelException - in case the user cancels the login

getConnectionProvider

protected final EntityConnectionProvider getConnectionProvider()
Returns:
the EntityConnectionProvider instance used by this EntityTestUnit

getConnection

protected final EntityConnection getConnection()
Returns:
the EntityConnection instance used by this EntityTestUnit

getReferenceEntity

protected final Entity getReferenceEntity(String entityID)
Parameters:
entityID - the entityID of the the reference entity to retrieve
Returns:
the entity mapped to the given entityID
See Also:
setReferenceEntity(String, org.jminor.framework.domain.Entity)

setReferenceEntity

protected final void setReferenceEntity(String entityID,
                                        Entity entity)
                                 throws DatabaseException
Maps the given reference entity to the given entityID

Parameters:
entityID - the entityID
entity - the reference entity to map to the given entityID
Throws:
DatabaseException - in case of an exception
See Also:
getReferenceEntity(String)

loadDomainModel

protected abstract void loadDomainModel()
This method should load the domain model, for example by instantiating the domain model class or simply loading it by name


initializeTestEntity

protected Entity initializeTestEntity(String entityID)
This method should return an instance of the entity specified by entityID

Parameters:
entityID - the entityID for which to initialize an entity instance
Returns:
the entity instance to use for testing the entity type

initializeReferenceEntity

protected Entity initializeReferenceEntity(String entityID)
Initializes a new Entity of the given type, by default this method creates a Entity filled with random values.

Parameters:
entityID - the entity ID
Returns:
a entity of the given type

modifyEntity

protected void modifyEntity(Entity testEntity)
This method should return testEntity in a modified state

Parameters:
testEntity - the entity to modify

initializeReferencedEntities

protected final void initializeReferencedEntities(String testEntityID,
                                                  String entityID)
                                           throws DatabaseException
This method should initialize instances of entities specified by the entityIDs found in the entityIDs Collection and map them to their respective entityIDs via the setReferenceEntity method

Parameters:
testEntityID - the ID of the entity being tested
entityID - the ID of the entity for which to initialize the referenced entities
Throws:
DatabaseException - in case of an exception
See Also:
setReferenceEntity(String, org.jminor.framework.domain.Entity)