01: package net.sourceforge.jaxor.db.tests;
02:
03: import junit.framework.TestCase;
04: import net.sourceforge.jaxor.JaxorContextImpl;
05: import net.sourceforge.jaxor.db.SingleConnectionTransaction;
06: import net.sourceforge.jaxor.example.db.HyperConnection;
07:
08: import java.sql.Connection;
09: import java.sql.DriverManager;
10: import java.sql.SQLException;
11:
12: /**
13: * Created By: Mike
14: * Date: Nov 12, 2003
15: * Time: 5:11:36 PM
16: *
17: * Last Checkin: $Author: mrettig $
18: * Date: $Date: 2004/01/21 04:09:51 $
19: * Revision: $Revision: 1.6 $
20: */
21: public class SingleConnectionTransactionTest extends TestCase {
22:
23: public void testClosing() throws SQLException {
24: Connection connection = HyperConnection.INSTANCE
25: .getConnection();
26: assertTrue(!connection.isClosed());
27: JaxorContextImpl context = new JaxorContextImpl(connection);
28: context.commit();
29: context.end();
30: assertTrue(connection.isClosed());
31: }
32:
33: public void testRegisterAndExecute() throws SQLException {
34: Connection connection = getConnection();
35: assertTrue(!connection.isClosed());
36: JaxorContextImpl context = new JaxorContextImpl(connection);
37: context.commit();
38: context.end();
39: assertTrue(connection.isClosed());
40: }
41:
42: private Connection getConnection() throws SQLException {
43: DriverManager.registerDriver(new org.hsqldb.jdbcDriver());
44: Connection connection = DriverManager.getConnection(
45: "jdbc:hsqldb:.", "sa", "");
46: return connection;
47: }
48:
49: public void testFactoryConstructor() throws SQLException {
50: SingleConnectionTransaction trans = new SingleConnectionTransaction(
51: HyperConnection.INSTANCE);
52: Connection conn = trans.getConnection();
53: trans.rollback(null);
54: trans.end();
55: assertTrue(conn.isClosed());
56: }
57: }
|