1 16 17 package org.springframework.jdbc.core.support; 18 19 import java.util.ArrayList ; 20 import java.util.List ; 21 22 import javax.sql.DataSource ; 23 24 import junit.framework.TestCase; 25 import org.easymock.MockControl; 26 27 import org.springframework.jdbc.core.JdbcTemplate; 28 29 33 public class JdbcDaoSupportTests extends TestCase { 34 35 public void testJdbcDaoSupportWithDataSource() throws Exception { 36 MockControl dsControl = MockControl.createControl(DataSource .class); 37 DataSource ds = (DataSource ) dsControl.getMock(); 38 final List test = new ArrayList (); 39 JdbcDaoSupport dao = new JdbcDaoSupport() { 40 protected void initDao() { 41 test.add("test"); 42 } 43 }; 44 dao.setDataSource(ds); 45 dao.afterPropertiesSet(); 46 assertEquals("Correct DataSource", ds, dao.getDataSource()); 47 assertEquals("Correct JdbcTemplate", ds, dao.getJdbcTemplate().getDataSource()); 48 assertEquals("initDao called", test.size(), 1); 49 } 50 51 public void testJdbcDaoSupportWithJdbcTemplate() throws Exception { 52 JdbcTemplate template = new JdbcTemplate(); 53 final List test = new ArrayList (); 54 JdbcDaoSupport dao = new JdbcDaoSupport() { 55 protected void initDao() { 56 test.add("test"); 57 } 58 }; 59 dao.setJdbcTemplate(template); 60 dao.afterPropertiesSet(); 61 assertEquals("Correct JdbcTemplate", dao.getJdbcTemplate(), template); 62 assertEquals("initDao called", test.size(), 1); 63 } 64 65 } 66 | Popular Tags |