01: package net.sourceforge.jaxor.tests;
02:
03: import junit.framework.TestCase;
04: import net.sourceforge.jaxor.JaxorSession;
05: import net.sourceforge.jaxor.JaxorContextImpl;
06: import net.sourceforge.jaxor.db.SingleConnectionFactory;
07: import net.sourceforge.jaxor.db.ConnectionFactoryTransaction;
08: import net.sourceforge.jaxor.api.JaxorContextFactory;
09: import net.sourceforge.jaxor.api.JaxorContext;
10: import net.sourceforge.jaxor.example.db.HyperConnection;
11:
12: import java.sql.Connection;
13:
14: public class JaxorSessionTest extends TestCase {
15:
16: private Connection connection;
17: private JaxorContextFactory trans;
18:
19: protected void setUp() throws Exception {
20: connection = HyperConnection.INSTANCE.getConnection();
21: trans = new JaxorContextFactory() {
22: public JaxorContext create() {
23: return new JaxorContextImpl(
24: new ConnectionFactoryTransaction(
25: new SingleConnectionFactory(connection)));
26: }
27: };
28: }
29:
30: protected void tearDown() throws Exception {
31: connection.close();
32: }
33:
34: public void testNoDefaultConnectionFactoryException() {
35: try {
36: JaxorSession.begin();
37: } catch (NullPointerException expected) {
38:
39: }
40: }
41:
42: public void testDefaultConnectionFactory() throws Exception {
43: JaxorSession.setDefaultFactory(trans);
44: JaxorSession.begin();
45: // we're checking to see that the connection we
46: // created will be returned. This is exactly what
47: // will be done by the various Entity instances when
48: // they are trying to execute their SQL.
49: assertEquals(connection, JaxorSession.getJaxorContext()
50: .getConnection());
51:
52: // now, we start a new transaction, but the
53: // connections should still be equal
54: JaxorSession.begin();
55: assertEquals(connection, JaxorSession.getJaxorContext()
56: .getConnection());
57: }
58: }
|