Class EntityTestUnit


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

      • TEST_USER

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

      • EntityTestUnit

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

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

      • 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.
        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