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
ConstructorDescriptionDefaultEntityFactory
(EntityConnection connection) Instantiates a newDefaultEntityFactory
-
Method Summary
Modifier and TypeMethodDescriptionprotected final EntityConnection
protected final Entities
entities()
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.void
Modifies one or more values inentity
, for the update test.protected <T> T
Creates 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.EntityFactory
Initializes the Entity instance on which to run the tests, by default this method creates an instance filled with random values.- Specified by:
entity
in 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
- Throws:
DatabaseException
- in case of an exception
-
entity
Description copied from interface:DomainTest.EntityFactory
Initializes 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:
entity
in 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
- Throws:
DatabaseException
- in case of an exception
-
modify
Description copied from interface:DomainTest.EntityFactory
Modifies one or more values inentity
, for the update test. If the entity is not modified, the update test will not be run. The default implementation populates the entity with random values.- Specified by:
modify
in interfaceDomainTest.EntityFactory
- Parameters:
entity
- the entity to modify- Throws:
DatabaseException
- in case of an exception
-
connection
- Returns:
- the underlying
EntityConnection
instance
-
entities
- Returns:
- the underlying
Entities
instance
-
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
-