Class DataSetResourcePathResolver

java.lang.Object
org.dbunit.annotation.runtime.DataSetResourcePathResolver

public class DataSetResourcePathResolver extends Object
Normalizes a dataset path from org.dbunit.annotation's DbUnitPrep or DbUnitExpected annotations into an absolute classpath resource path, the form DataFileLoader.load(String) expects.

DataFileLoader.load(String) itself resolves a path without a leading / relative to org/dbunit/util/fileloader/, not to the test class, so this resolution has to happen before the loader is called at all.

Resolution order:

  1. A path already starting with / - an absolute classpath path, used as-is. Always wins, so a shared file outside the base directory stays reachable.
  2. DbUnitConfig.dataSetBaseDir(), when set - prefixed to the path.
  3. Otherwise - resolved relative to the test class's package.
Since:
3.6.0
Author:
Jeff Jensen
  • Constructor Details

    • DataSetResourcePathResolver

      public DataSetResourcePathResolver()
  • Method Details

    • resolve

      public String resolve(String path, Class<?> testClass, String dataSetBaseDir)
      Resolves path to an absolute classpath resource path.
      Parameters:
      path - The path to resolve, as written on @DbUnitPrep or @DbUnitExpected.
      testClass - The test class; used to resolve a path relative to its package.
      dataSetBaseDir - The configured base directory, or null/empty when not set.
      Returns:
      The absolute classpath resource path.
      Throws:
      IllegalStateException - If path is null - e.g. a DataSetPathsProvider returning an array containing a null element.