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 newDbUnitDtdGenerator
using the given Spring application context. -
Method Summary
Modifier and TypeMethodDescriptionstatic DbUnitDtdGenerator
createFromSpringConfigurationClass
(Class<?> configClass) Factory method to create a newDbUnitDtdGenerator
instance using an application context constructed from a Spring configuration class, i.e., a class annotated withorg.springframework.context.annotation.Configuration
.static DbUnitDtdGenerator
createFromSpringXmlConfiguration
(String springConfigResourceName) Factory method to create a newDbUnitDtdGenerator
instance using an application context constructed from a Spring XML configuration file loaded from the classpath.Gives the DbUnit DTD as a string.static void
Main method that prints the generated DTD toSystem.out
.
-
Constructor Details
-
DbUnitDtdGenerator
public DbUnitDtdGenerator(org.springframework.context.ApplicationContext applicationContext) Creates a newDbUnitDtdGenerator
using 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.DataSource
to read from. It may optionally define aorg.dbunit.dataset.datatype.IDataTypeFactory
matching the database used.- Parameters:
applicationContext
- the application context to use to find theDataSource
and possiblyIDataTypeFactory
-
-
Method Details
-
createFromSpringXmlConfiguration
Factory method to create a newDbUnitDtdGenerator
instance 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
DbUnitDtdGenerator
instance
-
createFromSpringConfigurationClass
Factory method to create a newDbUnitDtdGenerator
instance using an application context constructed from a Spring configuration class, i.e., a class annotated withorg.springframework.context.annotation.Configuration
.- Parameters:
configClass
- the@Configuration
class- Returns:
- the new
DbUnitDtdGenerator
instance
-
main
Main method that prints the generated DTD toSystem.out
. 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
-