Class DefaultEntityFactory

java.lang.Object
is.codion.framework.domain.test.DefaultEntityFactory
All Implemented Interfaces:
DomainTest.EntityFactory

public class DefaultEntityFactory extends Object implements DomainTest.EntityFactory
Handles creating and manipulating Entity instances for testing purposes.
  • Constructor Details

  • Method Details

    • entity

      public Entity entity(EntityType entityType) throws DatabaseException
      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 interface DomainTest.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

      public Optional<Entity> entity(ForeignKey foreignKey) throws DatabaseException
      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 interface DomainTest.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

      public void modify(Entity entity) throws DatabaseException
      Description copied from interface: DomainTest.EntityFactory
      Modifies one or more values in entity, 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 interface DomainTest.EntityFactory
      Parameters:
      entity - the entity to modify
      Throws:
      DatabaseException - in case of an exception
    • connection

      protected final EntityConnection connection()
      Returns:
      the underlying EntityConnection instance
    • entities

      protected final Entities entities()
      Returns:
      the underlying Entities instance
    • value

      protected <T> T value(Attribute<T> attribute) throws DatabaseException
      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