Class DbUnitFlatXmlReader
java.lang.Object
com.reallifedeveloper.tools.test.database.dbunit.DbUnitFlatXmlReader
A class to read a DBUnit flat XML dataset file and populate a
JpaRepository
using the information in the file.
This is useful for testing in-memory repositories using the same test cases as for real repository implementations, and also for populating in-memory repositories for testing services, without having to use a real database.
TODO: The current implementation only has basic support for "to many" associations (there must be a &JoinTable annotation on a field, with &JoinColumn annotations), and for enums (an enum must be stored as a string).
- Author:
- RealLifeDeveloper
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T,
ID extends Serializable>
voidread
(String resourceName, org.springframework.data.jpa.repository.JpaRepository<T, ID> repository, Class<T> entityType, Class<ID> primaryKeyType) Reads a DBUnit flat XML file from the named resource, populating the given repository with entities of the given type.
-
Constructor Details
-
DbUnitFlatXmlReader
public DbUnitFlatXmlReader()Creates a newDbUnitFlatXmlReader
.
-
-
Method Details
-
read
public <T,ID extends Serializable> void read(String resourceName, org.springframework.data.jpa.repository.JpaRepository<T, ID> repository, Class<T> entityType, Class<ID> primaryKeyType) throws IOException, SAXExceptionReads a DBUnit flat XML file from the named resource, populating the given repository with entities of the given type.- Type Parameters:
T
- the type of entity to readID
- the type of the primary key of the entities- Parameters:
resourceName
- the classpath resource containing a DBUnit flat XML documentrepository
- the repository to populate with the entities from the XML documententityType
- the entity class to readprimaryKeyType
- the type of primary key the entities use- Throws:
IOException
- if reading the file failedSAXException
- if parsing the file failed
-