Results 1 to 4 of 4

Thread: Using DBUnit with AbstractSpringContextTests

  1. #1
    Join Date
    Sep 2004
    Location
    Winterthur, Switzerland
    Posts
    58

    Default Using DBUnit with AbstractSpringContextTests

    I was wondering, if others also have come across the Requirement to use both the org.dbunit.DatabaseTestCase and die org.springframework.test.AbstractSpringContextTest s Hierarchie.

    Specially if there is any commited code around, which helps me with some kind of Mixin Class Composition Approach. If not what would be the a "recommended" approach to achieve this?

    Any hints or links appreciated.

    Christoph Henrici

  2. #2
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    I know some users have combined these. There is nothing in development (so far) within Spring, although a contribution would be considered.
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

  3. #3
    Join Date
    Sep 2004
    Posts
    1,086

    Default Re: Using DBUnit with AbstractSpringContextTests

    Quote Originally Posted by chenrici
    I was wondering, if others also have come across the Requirement to use both the org.dbunit.DatabaseTestCase and die org.springframework.test.AbstractSpringContextTest s Hierarchie.

    Specially if there is any commited code around, which helps me with some kind of Mixin Class Composition Approach. If not what would be the a "recommended" approach to achieve this?

    Any hints or links appreciated.

    Christoph Henrici
    If you take a look at DatabaseTestCase class, you will notice that it doesn't do much at all. You can write your own base test class that extends a Spring test class and add dbUnit setup/teardown to it. It's just a couple of lines really, something like:

    Code:
        protected void onSetUp() throws Exception {
            super.onSetUp();
    
            dataSet=...
    
            connection = new DatabaseDataSourceConnection(dataSource);
            DatabaseOperation.INSERT.execute(connection, dataSet);
        }
    
        protected void onTearDown() throws Exception {
            super.onTearDown();
    
            DatabaseOperation.DELETE_ALL.execute(connection, dataSet);
            
            connection.close();
        }
    or something simmilar.

  4. #4
    Join Date
    Sep 2004
    Location
    Winterthur, Switzerland
    Posts
    58

    Default

    Spring is already tremendously feature-rich adressing real live development requirements ..;-)

    Here's what i found out , ater some "research" of my own:

    DBUnit does not require to inherit the Testcase from org.dbunit.DatabaseTestCase.

    What i did is subclass Springs AbstractTransactionalDataSourceSpringContextTests with a abstract class, who main purpose is to wrap the Connection of jdbcTemplate as a IDatabaseConnection.

    Code:
        protected IDatabaseConnection getDbUnitConnection() throws Exception {
            final DataSource dataSource = jdbcTemplate.getDataSource();
            return new DatabaseConnection(DataSourceUtils.getConnection(dataSource));
        }
    Using then the wrapped Connection with the other DbUnit classes as required.

    Best thanx
    Christoph Henrici

Similar Threads

  1. Replies: 3
    Last Post: Jul 19th, 2011, 08:42 AM
  2. Replies: 3
    Last Post: Oct 22nd, 2005, 04:44 PM
  3. Replies: 7
    Last Post: Aug 18th, 2005, 02:41 PM
  4. Replies: 3
    Last Post: May 14th, 2005, 09:16 AM
  5. Using DbUnit.
    By sherihan in forum Data
    Replies: 5
    Last Post: May 12th, 2005, 02:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •