Package org.fastnate.generator.test
Class AbstractEntitySqlGeneratorTest
java.lang.Object
org.fastnate.generator.test.AbstractEntitySqlGeneratorTest
- Direct Known Subclasses:
AccessTest,CollectionsTest,DateEntityTest,EmbeddedTest,IdsTest,InheritanceTest,MapsTest,OverridesTest,PerformanceTest,PrimitiveEntityTest,RecursiveEntityTest,ReferenceEntityTest,SchemaTest,SpringDataTest,VersionTest
Test the
EntitySqlGenerator framework.- Author:
- Tobias Liefke
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe settings key that indicates whichStatementsWriterto use for tests. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<E> jakarta.persistence.TypedQuery<E> createQuery(String query, Class<E> entityClass, String... parameters) Creates a typed JPQL query.protected voidexecuteSql(SqlRunnable work) Execute some SQL using thecurrent JDBC connection.<E> List<E> findResults(Class<E> entityClass) Finds all entities of the given entity class.<E> List<E> findResults(String query, Class<E> entityClass, String... parameters) Finds all entities for the given query and entity class.<E> EfindSingleResult(Class<E> entityClass) Finds the only entity for the given entity class.<E> EfindSingleResult(String query, Class<E> entityClass, String... parameters) Finds the entity for the given query and entity class.protected ConnectionResolves the connection from the session.protected jakarta.persistence.EntityManagergetEm()protected org.fastnate.generator.EntitySqlGeneratorprotected PropertiesProperties for configuring thegenerator.voidsetup()Build a entity manager factory (with an empty connected database) for testing.protected voidBuild a entity manager factory (with a connected database) for testing.voidtearDown()Close the entity manager factory.protected <E> voidwrite(E entity) Writes the entity with the generator.
-
Field Details
-
WRITER_KEY
The settings key that indicates whichStatementsWriterto use for tests.- See Also:
-
-
Constructor Details
-
AbstractEntitySqlGeneratorTest
public AbstractEntitySqlGeneratorTest()
-
-
Method Details
-
createQuery
public <E> jakarta.persistence.TypedQuery<E> createQuery(String query, Class<E> entityClass, String... parameters) throws IOException Creates a typed JPQL query.- Parameters:
query- the JPQL queryentityClass- the type of the result objectparameters- the list of parameter names and values- Returns:
- the typed query
- Throws:
IOException- if the generator throws one during flush
-
executeSql
Execute some SQL using thecurrent JDBC connection.- Parameters:
work- The work to be performed.- Throws:
SQLException- if there is a problem with the work
-
findResults
Finds all entities of the given entity class.- Parameters:
entityClass- the class of the entity- Returns:
- all entities of that class
- Throws:
IOException- if the generator throws one during flush
-
findResults
public <E> List<E> findResults(String query, Class<E> entityClass, String... parameters) throws IOException Finds all entities for the given query and entity class.- Parameters:
query- the JPA-QL queryentityClass- the class of the entityparameters- the list of parameter names and values- Returns:
- the result entities for the query
- Throws:
IOException- if the generator throws one during flush
-
findSingleResult
Finds the only entity for the given entity class.- Parameters:
entityClass- the class of the entity- Returns:
- the single entity of that class
- Throws:
IOException- if the generator throws one during flush
-
findSingleResult
public <E> E findSingleResult(String query, Class<E> entityClass, String... parameters) throws IOException Finds the entity for the given query and entity class.- Parameters:
query- the JPA-QL queryentityClass- the class of the entityparameters- the list of parameter names and values- Returns:
- the single result entity for the query
- Throws:
IOException- if the generator throws one during flush
-
getConnection
Resolves the connection from the session.- Returns:
- the connection
- Throws:
SQLException- Indicates a problem getting the connection
-
getGeneratorProperties
Properties for configuring thegenerator.- Returns:
- the test specific properties for the generator
-
setup
@BeforeEach public void setup()Build a entity manager factory (with an empty connected database) for testing. -
setup
Build a entity manager factory (with a connected database) for testing.- Parameters:
schemaCreation- indicates how to initialize the database ("create" vs. "")
-
tearDown
@AfterEach public void tearDown()Close the entity manager factory. -
write
Writes the entity with the generator.- Parameters:
entity- the entity to write- Throws:
IOException- if the generator throws one
-
getEm
protected jakarta.persistence.EntityManager getEm() -
getGenerator
protected org.fastnate.generator.EntitySqlGenerator getGenerator()
-