1 16 17 package org.springframework.orm.hibernate3.support; 18 19 import java.util.ArrayList ; 20 import java.util.List ; 21 22 import junit.framework.TestCase; 23 import org.hibernate.SessionFactory; 24 import org.easymock.MockControl; 25 26 import org.springframework.orm.hibernate3.HibernateTemplate; 27 28 32 public class HibernateDaoSupportTests extends TestCase { 33 34 public void testHibernateDaoSupportWithSessionFactory() throws Exception { 35 MockControl sfControl = MockControl.createControl(SessionFactory.class); 36 SessionFactory sf = (SessionFactory) sfControl.getMock(); 37 sfControl.replay(); 38 final List test = new ArrayList (); 39 HibernateDaoSupport dao = new HibernateDaoSupport() { 40 protected void initDao() { 41 test.add("test"); 42 } 43 }; 44 dao.setSessionFactory(sf); 45 dao.afterPropertiesSet(); 46 assertEquals("Correct SessionFactory", sf, dao.getSessionFactory()); 47 assertEquals("Correct HibernateTemplate", sf, dao.getHibernateTemplate().getSessionFactory()); 48 assertEquals("initDao called", test.size(), 1); 49 sfControl.verify(); 50 } 51 52 public void testHibernateDaoSupportWithHibernateTemplate() throws Exception { 53 HibernateTemplate template = new HibernateTemplate(); 54 final List test = new ArrayList (); 55 HibernateDaoSupport dao = new HibernateDaoSupport() { 56 protected void initDao() { 57 test.add("test"); 58 } 59 }; 60 dao.setHibernateTemplate(template); 61 dao.afterPropertiesSet(); 62 assertEquals("Correct HibernateTemplate", template, dao.getHibernateTemplate()); 63 assertEquals("initDao called", test.size(), 1); 64 } 65 66 } 67 | Popular Tags |