1 package org.controlhaus.hibernate; 2 3 import java.io.File; 4 import java.lang.reflect.Method; 5 import java.util.List; 6 7 import junit.framework.TestCase; 8 import net.sf.hibernate.Session; 9 import net.sf.hibernate.SessionFactory; 10 import net.sf.hibernate.Transaction; 11 12 import org.apache.beehive.controls.api.bean.Control; 13 import org.apache.beehive.controls.api.context.ControlBeanContext; 14 import org.apache.beehive.controls.runtime.bean.ControlContainerContext; 15 import org.controlhaus.hibernate.util.AbstractHibernateTest; 16 import org.controlhaus.hibernate.HibernateControl.ManagedTransactions; 17 18 /*** 19 * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a> 20 * @since Oct 28, 2004 21 */ 22 public class HibernateControlTest 23 extends AbstractHibernateTest 24 { 25 @Control HibernateControl hib; 26 27 @ManagedTransactions(true) 28 @Control HibernateControl txHib; 29 30 public void setUp() throws Exception 31 { 32 System.setProperty(SETUP_SQL, 33 new File("./src/sql/setup.sql").getAbsolutePath()); 34 System.setProperty(TEARDOWN_SQL, 35 new File("./src/sql/teardown.sql").getAbsolutePath()); 36 super.setUp(); 37 } 38 39 public void testControl() 40 throws Exception 41 { 42 assertNotNull(hib); 43 44 SessionFactory factory = hib.getSessionFactory(); 45 assertNotNull(factory); 46 47 Session session = hib.getSession(); 48 Transaction t = hib.getTransaction(); 49 assertNull(t); 50 51 session.save(new Parent()); 52 53 session.flush(); 54 hib.closeSession(); 55 56 Session session2 = hib.getSession(); 57 assertNotSame(session, session2); 58 59 List results = session2.find("select from " + Parent.class.getName()); 60 assertEquals(1, results.size()); 61 } 62 63 public void testControlTXs() 64 throws Exception 65 { 66 assertNotNull(txHib); 67 68 Session s = txHib.getSession(); 69 Transaction t = txHib.getTransaction(); 70 assertNotNull(t); 71 72 s.save(new Parent()); 73 74 s.flush(); 75 76 List results = s.find("select from " + Parent.class.getName()); 77 assertEquals(1, results.size()); 78 } 79 }