Package is.codion.framework.domain.test
Class DefaultEntityFactory
java.lang.Object
is.codion.framework.domain.test.DefaultEntityFactory
- All Implemented Interfaces:
DomainTest.EntityFactory
Handles creating and manipulating Entity instances for testing purposes.
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultEntityFactory(EntityConnection connection) Instantiates a newDefaultEntityFactory -
Method Summary
Modifier and TypeMethodDescriptionprotected final EntityConnectionprotected final Entitiesentities()entity(ForeignKey foreignKey) Initializes an Entity instance to reference via the given foreign key.entity(EntityType entityType) Initializes the Entity instance on which to run the tests, by default this method creates an instance filled with random values.voidModifies one or more values inentity, for the update test.protected <T> TCreates a value for the given attribute.
-
Constructor Details
-
DefaultEntityFactory
Instantiates a newDefaultEntityFactory- Parameters:
connection- the connection to use
-
-
Method Details
-
entity
Description copied from interface:DomainTest.EntityFactoryInitializes the Entity instance on which to run the tests, by default this method creates an instance filled with random values.- Specified by:
entityin interfaceDomainTest.EntityFactory- Parameters:
entityType- the entityType for which to initialize an entity instance for testing- Returns:
- the entity instance to use for testing the entity type
-
entity
Description copied from interface:DomainTest.EntityFactoryInitializes an Entity instance to reference via the given foreign key. The entity returned by this method must exist in the database, so it can either return an entity with a known hard-coded primary key value or return a newly inserted one. By default, this method returns a newly inserted Entity populated with random values. Note that this default implementation returns an empty Optional in case the referenced entity type is read-only.- Specified by:
entityin interfaceDomainTest.EntityFactory- Parameters:
foreignKey- the foreign key referencing the entity- Returns:
- an entity for the given foreign key or an empty Optional if none is required
-
modify
Description copied from interface:DomainTest.EntityFactoryModifies one or more values inentity, for the update test. If the returned entity is not modified, the update test will not be run. The default implementation populates the entity with random values.- Specified by:
modifyin interfaceDomainTest.EntityFactory- Parameters:
entity- the entity to modify
-
connection
- Returns:
- the underlying
EntityConnectioninstance
-
entities
- Returns:
- the underlying
Entitiesinstance
-
value
Creates a value for the given attribute.- Type Parameters:
T- the attribute value type- Parameters:
attribute- the attribute- Returns:
- a random value
- Throws:
DatabaseException- in case of an exception
-