Class EntityTestUnit
java.lang.Object
is.codion.framework.domain.entity.test.EntityTestUnit
A class for unit testing a domain model.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final PropertyValue<String>
Specifies the database user to use when running domain unit tests. -
Constructor Summary
ConstructorDescriptionEntityTestUnit
(Domain domain) Instantiates a new EntityTestUnit.EntityTestUnit
(Domain domain, User user) Instantiates a new EntityTestUnit. -
Method Summary
Modifier and TypeMethodDescriptionprotected final EntityConnection
final 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 statefinal void
test
(EntityType entityType) Runs the insert/update/select/delete tests for the given entityType
-
Field Details
-
TEST_USER
Specifies the database user to use when running domain unit tests.
-
-
Constructor Details
-
EntityTestUnit
Instantiates a new EntityTestUnit. The default database user is based on theTEST_USER
configuration value.- Parameters:
domain
- the domain model- Throws:
NullPointerException
- in case domainClass is null
-
EntityTestUnit
Instantiates a new EntityTestUnit.- Parameters:
domain
- the domain modeluser
- the user to use when running the tests- Throws:
NullPointerException
- in case domainClass or user is null
-
-
Method Details
-
entities
- Returns:
- the domain entities
-
test
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
- 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 DatabaseExceptionInitializes 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
This method should returntestEntity
in a modified state- Parameters:
testEntity
- the entity to modifyforeignKeyEntities
- the entities referenced via foreign keys
-