Results 1 to 4 of 4

Thread: MockObjects or DBUnit for testing Code using JdbcTemplate

  1. #1

    Default MockObjects or DBUnit for testing Code using JdbcTemplate

    Hi,

    I'm looking at a way to test the following code against a mock object,
    or test database using DBUnit:
    Code:
    public List getLinePairs() {
            JdbcTemplate targetTemplate = new JdbcTemplate(target);
            RowMapper hqLineMapper = new RowMapper() {
                public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
                    return new LinePair(rs.getString(hqAbbrColumnName), rs.getString(catAbbrColumnName));
                }
            };
            return targetTemplate.query(selectTargetHqLineSql, hqLineMapper);
        }
    What is the recommended approach? MockObjects' MockDataSource and MockConnection2 seem easy enough to setup, but I'm getting an NPE because the statment wrapped by targetTemplate.query() is null.

    Is it easier or more appropriate to setup a dbunit database and test the DataSource code against a real database? Or is there a secret getting all the right mock statements initialized?

  2. #2
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    puffybsd, you can review Spring tests for JDBC abstraction layer (from Spring distribution), more particulary org.springframework.jdbc.core.RowMapperTests' method testStaticQueryWithRowMapper.

    HTH
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  3. #3

    Default Thanks!

    irbouho,

    Thanks, that's exactly what I was looking for! My new motto is RTFT.

  4. #4

    Default

    Although this is an old post maybe someone may weigh in on my question

    I am looking for a way to setup a test suite for a site that is using EJB-JSF-Hibernate and was hoping to hook into the EJBs using SpringSecurity... would I be able to add spring integration easily ? I see Part III 9. testing and Part VI Integration 20. EJBs that it looks doable but was wondering how hard that would be ?

    Can you mix Spring and JSF configurations? Usually you put your test src code in a test pkg alongside the main... would I have to run another 'spring module' configured alongside the code I want to test?

    Hoping for some insight, any responses welcome (Thx) !

Similar Threads

  1. Replies: 13
    Last Post: Oct 24th, 2007, 10:55 AM
  2. Replies: 4
    Last Post: Jun 20th, 2007, 11:06 AM
  3. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  4. Spring code remarks
    By Alarmnummer in forum Architecture
    Replies: 18
    Last Post: Apr 7th, 2005, 07:17 AM
  5. Please help! Unit testing code for JPetStore
    By lakershen in forum Container
    Replies: 4
    Last Post: Jan 13th, 2005, 05:00 PM

Posting Permissions

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