Class FileExtensionDataFileLoader

java.lang.Object
org.dbunit.util.fileloader.AbstractDataFileLoader
org.dbunit.util.fileloader.FileExtensionDataFileLoader
All Implemented Interfaces:
DataFileLoader

public class FileExtensionDataFileLoader extends AbstractDataFileLoader
DataFileLoader that dispatches to another DataFileLoader based on the loaded file's extension: .xml to FlatXmlDataFileLoader, .json to JsonDataFileLoader, .yaml/.yml to YamlDataFileLoader, and .xls/.xlsx to XlsDataFileLoader.

.csv is deliberately not dispatched here: dbUnit's CSV format is directory-based (CsvURLDataSet expects a directory containing table-ordering.txt), so it cannot share this loader's one-file-per-path convention. Use CsvDataFileLoader directly, pointed at a directory, instead. Similarly, full (non-flat) XML has no extension of its own to dispatch on; use FullXmlDataFileLoader directly.

The delegate loaders are used only for their loadDataSet(URL) method, so this loader's own replacement objects and substrings - not any set on a delegate - are the ones applied, exactly once, to every file regardless of format. Because that method touches no delegate state, the delegates are shared static instances rather than rebuilt for each FileExtensionDataFileLoader - one per test method, otherwise.

Since:
3.6.0
Author:
Jeff Jensen
  • Constructor Details

    • FileExtensionDataFileLoader

      public FileExtensionDataFileLoader()
      Create new instance.
    • FileExtensionDataFileLoader

      public FileExtensionDataFileLoader(Map ro)
      Create new instance with replacement objects.
      Parameters:
      ro - The replacement objects for use with ReplacementDataSet.
    • FileExtensionDataFileLoader

      public FileExtensionDataFileLoader(Map ro, Map rs)
      Create new instance with replacement objects and replacement substrings.
      Parameters:
      ro - The replacement objects for use with ReplacementDataSet.
      rs - The replacement substrings for use with ReplacementDataSet.
  • Method Details

    • loadDataSet

      public IDataSet loadDataSet(URL url) throws DataSetException, IOException
      Load the specified URL file into a dbUnit dataset. The type of dbUnit dataset created is delegated to the implementing subclass.
      Parameters:
      url - The dbUnit data file url.
      Returns:
      dbUnit dataset of the corresponding input file type.
      Throws:
      DataSetException - On data errors.
      IOException - On file errors.