Re: unit testing Cayenne objects

From: Erik Hatcher (eri..hatchersolutions.com)
Date: Wed May 04 2005 - 16:34:45 EDT

  • Next message: Cris Daniluk: "Re: unit testing Cayenne objects"

    On May 3, 2005, at 9:36 AM, Cris Daniluk wrote:

    >> I will also need to implement a TestSetup to only have the database
    >> created one time once I get more test cases in place and the set up
    >> time becomes too painful.
    >>
    >
    > Unfortunately, I don't have the time to give this the same level of
    > detail :)
    >
    > But, what you are suggesting is perfectly fine. Because HSQL can't
    > quite suit all of our testing needs, we have an Oracle schema
    > dedicated to the unit tests. The setUp() invokes a truncate_tables
    > procedure which ensures the schema is clean, then proceeds to load
    > global data using dbUnit. Then, an optional class-specific dataset is
    > loaded so that the TestCase has everything it needs to boostrap
    > itself. Something like this:
    >
    > InputStream classDataStream =
    > getClass().getResourceAsStream(getClass().getSimpleName() +
    > "-dataset.xml");
    > if (classDataStream != null) {
    > dataSet = new FlatXmlDataSet(classDataStream);
    > DatabaseOperation.CLEAN_INSERT.execute(conn, dataSet);
    > }
    >

    Cris - thanks again for the tips on DBUnit. I have successfully
    migrated to using DBUnit using a similar technique to the above.

    My next question is about configuration and how to do some of it
    through the API. I want to use a file-based cayenne.xml and .map.xml
    file, but I want to configure JDBC URL through the API rather than
    through a .driver.xml file.

    I'm currently doing this:

         // Configure the Cayenne DataContext to use a test-only set up,
    for an in-memory database
         // TODO: create this configuration dynamically rather than
    loading files, as there is duplication with the above
         // setup with the adapter, map file name, and JDBC URL and
    driver.
         FileConfiguration conf = new FileConfiguration("cayenne.xml");
         conf.addFilesystemPath(new File(baseDir, "test/"));
         conf.addFilesystemPath(new File(baseDir));
         Configuration.initializeSharedConfiguration(conf);

    Where my test subdirectory has a special .driver.xml file with the
    test (memory HSQL) JDBC URL. On a whim I tried that
    FileConfiguration with the paths and it worked beautifully with this
    hacked setup, by the way (very nice!). But since I have the JDBC URL
    in my code already I'd rather keep it in one isolated spot.

    How can I achieve this?

    Thanks,
         Erik



    This archive was generated by hypermail 2.0.0 : Wed May 04 2005 - 16:35:42 EDT