Class EntityTestUnit
- java.lang.Object
-
- is.codion.framework.domain.entity.test.EntityTestUnit
-
public class EntityTestUnit extends Object
A class for unit testing a domain model.
-
-
Field Summary
Fields Modifier and Type Field Description static PropertyValue<String>
TEST_USER
Specifies the database user to use when running domain unit tests.
-
Constructor Summary
Constructors Constructor Description EntityTestUnit(String domainClass)
Instantiates a new EntityTestUnit.EntityTestUnit(String domainClass, User user)
Instantiates a new EntityTestUnit.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected EntityConnection
connection()
Entities
entities()
protected Entity
initializeForeignKeyEntity(ForeignKey foreignKey, Map<ForeignKey,Entity> foreignKeyEntities)
Initializes an Entity instance to reference via the given foreign key, by default this method creates an Entity filled with random values.protected Entity
initializeTestEntity(EntityType entityType, Map<ForeignKey,Entity> foreignKeyEntities)
This method returns the Entity instance on which to run the tests, by default this method creates an instance filled with random values.protected void
modifyEntity(Entity testEntity, Map<ForeignKey,Entity> foreignKeyEntities)
This method should returntestEntity
in a modified statevoid
test(EntityType entityType)
Runs the insert/update/select/delete tests for the given entityType
-
-
-
Field Detail
-
TEST_USER
public static final PropertyValue<String> TEST_USER
Specifies the database user to use when running domain unit tests.
-
-
Constructor Detail
-
EntityTestUnit
public EntityTestUnit(String domainClass)
Instantiates a new EntityTestUnit. The default database user is based on theTEST_USER
configuration value.- Parameters:
domainClass
- the name of the domain model class- Throws:
NullPointerException
- in case domainClass is null
-
EntityTestUnit
public EntityTestUnit(String domainClass, User user)
Instantiates a new EntityTestUnit.- Parameters:
domainClass
- the name of the domain model classuser
- the user to use when running the tests- Throws:
NullPointerException
- in case domainClass or user is null
-
-
Method Detail
-
entities
public final Entities entities()
- Returns:
- the domain entities
-
test
public final void test(EntityType entityType) throws DatabaseException
Runs the insert/update/select/delete tests for the given entityType- Parameters:
entityType
- the type of the entity to test- Throws:
DatabaseException
- in case of an exception
-
connection
protected final EntityConnection connection()
- Returns:
- the EntityConnection instance used by this EntityTestUnit
-
initializeTestEntity
protected Entity initializeTestEntity(EntityType entityType, Map<ForeignKey,Entity> foreignKeyEntities)
This method returns the Entity instance on which to run the tests, by default this method creates an instance filled with random values.- Parameters:
entityType
- the entityType for which to initialize an entity instance for testingforeignKeyEntities
- the entities referenced via foreign keys- Returns:
- the entity instance to use for testing the entity type
-
initializeForeignKeyEntity
protected Entity initializeForeignKeyEntity(ForeignKey foreignKey, Map<ForeignKey,Entity> foreignKeyEntities) throws DatabaseException
Initializes an Entity instance to reference via the given foreign key, by default this method creates an Entity filled with random values. Subclasses can override and provide a hard coded instance or select one from the database. Note that this default implementation returns null in case the referenced entity type is read-only.- Parameters:
foreignKey
- the foreign key referencing the entityforeignKeyEntities
- the entities referenced via foreign keys- Returns:
- an entity for the given foreign key
- Throws:
DatabaseException
- in case of an exception
-
modifyEntity
protected void modifyEntity(Entity testEntity, Map<ForeignKey,Entity> foreignKeyEntities)
This method should returntestEntity
in a modified state- Parameters:
testEntity
- the entity to modifyforeignKeyEntities
- the entities referenced via foreign keys
-
-