Class TestDatabase
java.lang.Object
petclinic.util.TestDatabase
Base test utility class for domain-specific "EntityXData" classes, which allow each test to create the required data
in the test database.
Ensures that tests execute in a database transaction which is always rolled back at the end.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidassertCreated(BaseEntity newEntity, String qlStatement, Object... qlArgs) Verifies that a given entity was properly inserted into the database, including the generation of its integer identifier.final <E extends BaseEntity>
EFinds one entity of the desired type.final voidrefresh(BaseEntity entity) Refreshes the persistent state of a given entity from the database, so that a test can verify that persistent state was modified as expected.
-
Field Details
-
db
-
-
Constructor Details
-
TestDatabase
public TestDatabase()
-
-
Method Details
-
refresh
Refreshes the persistent state of a given entity from the database, so that a test can verify that persistent state was modified as expected.- Parameters:
entity- the entity
-
findOne
Finds one entity of the desired type.- Type Parameters:
E- specifies the desired entity type- Parameters:
qlStatement- a JPQL statement for finding a list of entities of which the first gets returnedqlArgs- zero or more arguments for positional parameters in the JPQL statement- Returns:
- the first entity found, if any, or
nullif none
-
assertCreated
Verifies that a given entity was properly inserted into the database, including the generation of its integer identifier.- Parameters:
newEntity- an entity just persistedqlStatement- a JPQL statement for finding a set of entities which must contain the new entityqlArgs- zero or more arguments for positional parameters in the JPQL statement- Throws:
AssertionError- if the new entity has a null or negative id, or if it is not among the entities found by executing the given JPQL statement
-