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

public class DomainTest extends Object implements AutoCloseable
A class for unit testing a domain model.

The connection is closed via close(), which runs automatically after each test method when this class is extended, being AfterEach annotated. When used programmatically, close explicitly or via try-with-resources.

  • Constructor Details

    • DomainTest

      public DomainTest(Domain domain)
      Instantiates a new DomainTest, using the user specified by the 'codion.test.user' system property.
      Parameters:
      domain - the domain model
    • DomainTest

      public DomainTest(Domain domain, Function<EntityConnection,DomainTest.EntityFactory> entityFactory)
      Instantiates a new DomainTest.
      Parameters:
      domain - the domain model
      entityFactory - provides the factory used to create test entities
    • DomainTest

      public DomainTest(Domain domain, User user)
      Instantiates a new DomainTest.
      Parameters:
      domain - the domain model
      user - the user to use when running the tests
    • DomainTest

      public DomainTest(Domain domain, Function<EntityConnection,DomainTest.EntityFactory> entityFactory, User user)
      Instantiates a new DomainTest.
      Parameters:
      domain - the domain model
      entityFactory - provides the factory used to create test entities
      user - the user to use when running the tests
  • Method Details

    • entities

      public final Entities entities()
      Returns:
      the domain entities
    • test

      public final void test(EntityType entityType)
      Runs the insert/update/select/delete tests for the given entityType, within a transaction which is rolled back, leaving the connection ready for the next call.
      Parameters:
      entityType - the type of the entity to test
      Throws:
      DatabaseException - in case of an exception
    • close

      @AfterEach public final void close()
      Closes the connection. Runs automatically after each test method when this class is extended.
      Specified by:
      close in interface AutoCloseable
    • connection

      protected final EntityConnection connection()
      Returns:
      the EntityConnection instance used by this DomainTest