java.lang.Object
is.codion.framework.domain.test.DomainTest
- All Implemented Interfaces:
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceHandles creating and modifying entities used for testing. -
Constructor Summary
ConstructorsConstructorDescriptionDomainTest(Domain domain) Instantiates a new DomainTest, using the user specified by the 'codion.test.user' system property.DomainTest(Domain domain, User user) Instantiates a new DomainTest.DomainTest(Domain domain, Function<EntityConnection, DomainTest.EntityFactory> entityFactory) Instantiates a new DomainTest.DomainTest(Domain domain, Function<EntityConnection, DomainTest.EntityFactory> entityFactory, User user) Instantiates a new DomainTest. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidclose()Closes the connection.protected final EntityConnectionfinal Entitiesentities()final voidtest(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.
-
Constructor Details
-
DomainTest
Instantiates a new DomainTest, using the user specified by the 'codion.test.user' system property.- Parameters:
domain- the domain model
-
DomainTest
Instantiates a new DomainTest.- Parameters:
domain- the domain modelentityFactory- provides the factory used to create test entities
-
DomainTest
Instantiates a new DomainTest.- Parameters:
domain- the domain modeluser- 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 modelentityFactory- provides the factory used to create test entitiesuser- the user to use when running the tests
-
-
Method Details
-
entities
- Returns:
- the domain entities
-
test
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:
closein interfaceAutoCloseable
-
connection
- Returns:
- the EntityConnection instance used by this DomainTest
-