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 Spring Data
CrudRepository 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.
- Author:
- RealLifeDeveloper
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T,E, ID extends Serializable>
voidread(String resourceName, org.springframework.data.repository.CrudRepository<T, ID> repository, Class<T> repositoryEntityType, Class<E> entityType) 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,E, void readID extends Serializable> (String resourceName, org.springframework.data.repository.CrudRepository<T, ID> repository, Class<T> repositoryEntityType, Class<E> entityType) 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 entities in the repositoryE- the type of entity being createdID- the type of the primary key of the entities in the repository- Parameters:
resourceName- the classpath resource containing a DBUnit flat XML documentrepository- the repository to populate with the entities from the XML documentrepositoryEntityType- the class object representing<T>, i.e., the class of the entities in the repositoryentityType- the class object representing<E>, i.e., the class of the eneity being created- Throws:
IOException- if reading the file failedSAXException- if parsing the file failed
-