java.lang.Object
is.codion.framework.domain.entity.test.EntityTestUnit

public class EntityTestUnit extends Object
A class for unit testing a domain model.
  • Field Details

    • TEST_USER

      public static final PropertyValue<String> TEST_USER
      Specifies the database user to use when running domain unit tests.
  • Constructor Details

    • EntityTestUnit

      public EntityTestUnit(Domain domain)
      Instantiates a new EntityTestUnit. The default database user is based on the TEST_USER configuration value.
      Parameters:
      domain - the domain model
      Throws:
      NullPointerException - in case domainClass is null
    • EntityTestUnit

      public EntityTestUnit(Domain domain, User user)
      Instantiates a new EntityTestUnit.
      Parameters:
      domain - the domain model
      user - the user to use when running the tests
      Throws:
      NullPointerException - in case domainClass or user is null
  • Method Details

    • 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 testing
      foreignKeyEntities - 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 entity
      foreignKeyEntities - 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 return testEntity in a modified state
      Parameters:
      testEntity - the entity to modify
      foreignKeyEntities - the entities referenced via foreign keys