Class DbUnitDtdGenerator

java.lang.Object
com.reallifedeveloper.tools.test.database.dbunit.DbUnitDtdGenerator

public class DbUnitDtdGenerator extends Object
Generates a DTD for DbUnit XML files used to populate the test database.
Author:
RealLifeDeveloper
  • Constructor Summary

    Constructors
    Constructor
    Description
    DbUnitDtdGenerator(org.springframework.context.ApplicationContext applicationContext)
    Creates a new DbUnitDtdGenerator using the given Spring application context.
  • Method Summary

    Modifier and Type
    Method
    Description
    Factory method to create a new DbUnitDtdGenerator instance using an application context constructed from a Spring configuration class, i.e., a class annotated with org.springframework.context.annotation.Configuration.
    createFromSpringXmlConfiguration(String springConfigResourceName)
    Factory method to create a new DbUnitDtdGenerator 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(String... args)
    Main method that prints the generated DTD to System.out.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DbUnitDtdGenerator

      public DbUnitDtdGenerator(org.springframework.context.ApplicationContext applicationContext)
      Creates a new DbUnitDtdGenerator 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 a org.dbunit.dataset.datatype.IDataTypeFactory matching the database used.

      Parameters:
      applicationContext - the application context to use to find the DataSource and possibly IDataTypeFactory
  • Method Details

    • createFromSpringXmlConfiguration

      public static DbUnitDtdGenerator createFromSpringXmlConfiguration(String springConfigResourceName)
      Factory method to create a new DbUnitDtdGenerator 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

      public static DbUnitDtdGenerator createFromSpringConfigurationClass(Class<?> configClass)
      Factory method to create a new DbUnitDtdGenerator instance using an application context constructed from a Spring configuration class, i.e., a class annotated with org.springframework.context.annotation.Configuration.
      Parameters:
      configClass - the &#064;Configuration class
      Returns:
      the new DbUnitDtdGenerator instance
    • main

      public static void main(String... args) throws SQLException, org.dbunit.DatabaseUnitException
      Main method that prints the generated DTD to System.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 occurred
      org.dbunit.DatabaseUnitException - if a DbUnit problem occurred
    • generateDtd

      public String generateDtd() throws SQLException, org.dbunit.DatabaseUnitException
      Gives the DbUnit DTD as a string.
      Returns:
      the DbUnit DTD
      Throws:
      SQLException - if a database problem occurred
      org.dbunit.DatabaseUnitException - if a DbUnit problem occurred