Class DbUnitDtdGenerator
java.lang.Object
com.reallifedeveloper.tools.test.database.dbunit.DbUnitDtdGenerator
Generates a DTD for DbUnit XML files used to populate the test database.
- Author:
- RealLifeDeveloper
-
Constructor Summary
ConstructorsConstructorDescriptionDbUnitDtdGenerator(org.springframework.context.ApplicationContext applicationContext) Creates a newDbUnitDtdGeneratorusing the given Spring application context. -
Method Summary
Modifier and TypeMethodDescriptionstatic DbUnitDtdGeneratorcreateFromSpringConfigurationClass(Class<?> configClass) Factory method to create a newDbUnitDtdGeneratorinstance using an application context constructed from a Spring configuration class, i.e., a class annotated withorg.springframework.context.annotation.Configuration.static DbUnitDtdGeneratorcreateFromSpringXmlConfiguration(String springConfigResourceName) Factory method to create a newDbUnitDtdGeneratorinstance using an application context constructed from a Spring XML configuration file loaded from the classpath.Gives the DbUnit DTD as a string.static voidMain method that logs the generated DTD on info level.
-
Constructor Details
-
DbUnitDtdGenerator
public DbUnitDtdGenerator(org.springframework.context.ApplicationContext applicationContext) Creates a newDbUnitDtdGeneratorusing the given Spring application context. It reads all tables in the database pointed to by a data source from the application context and generates a DTD matching that database.The application context should define at least a
javax.sql.DataSourceto read from. It may optionally define aorg.dbunit.dataset.datatype.IDataTypeFactorymatching the database used.- Parameters:
applicationContext- the application context to use to find theDataSourceand possiblyIDataTypeFactory
-
-
Method Details
-
createFromSpringXmlConfiguration
Factory method to create a newDbUnitDtdGeneratorinstance using an application context constructed from a Spring XML configuration file loaded from the classpath.- Parameters:
springConfigResourceName- the name of the classpath resource containing the Spring XML configuration- Returns:
- the new
DbUnitDtdGeneratorinstance
-
createFromSpringConfigurationClass
Factory method to create a newDbUnitDtdGeneratorinstance using an application context constructed from a Spring configuration class, i.e., a class annotated withorg.springframework.context.annotation.Configuration.- Parameters:
configClass- the@Configurationclass- Returns:
- the new
DbUnitDtdGeneratorinstance
-
main
Main method that logs the generated DTD on info level. The only argument should be either the fully-qualified name of a Spring configuration class on the classpath, or the name of a Spring XML configuration file, also on the classpath.- Parameters:
args- should contain one argument, either configuration class or XML configuration file on classpath- Throws:
SQLException- if a database problem occurredorg.dbunit.DatabaseUnitException- if a DbUnit problem occurred
-
generateDtd
Gives the DbUnit DTD as a string.- Returns:
- the DbUnit DTD
- Throws:
SQLException- if a database problem occurredorg.dbunit.DatabaseUnitException- if a DbUnit problem occurred
-