01: /**
02: * Copyright (C) 1999-2004 Jens Dietrich (mailto:mandarax@jbdietrich.com)
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */package test.org.mandarax.sql;
18:
19: import java.sql.Connection;
20: import java.sql.DriverManager;
21: import java.sql.SQLException;
22:
23: import javax.sql.DataSource;
24:
25: import junit.framework.TestCase;
26:
27: import org.mandarax.sql.DefaultConnectionManager;
28: import org.mandarax.sql.SQLConnectionManager;
29:
30: import test.org.mandarax.ser.SerializableDataSourceDummy;
31:
32: /**
33: * Test suite for the mandarax sql package.
34: * @author <a href="mailto:jochen.hiller@bauer-partner.com">Jochen Hiller</a>
35: * @version 3.4 <7 March 05>
36: * @since 2.2
37: */
38: public class TestDefaultConnectionManager extends TestCase {
39:
40: /**
41: * Constructor for DefaultConnectionManagerTest.
42: * @param arg0
43: */
44: public TestDefaultConnectionManager(String arg0) {
45: super (arg0);
46: }
47:
48: public static void main(String[] args) {
49: junit.textui.TestRunner.run(TestDefaultConnectionManager.class);
50: }
51:
52: // tests
53:
54: public void testConstructors() throws SQLException,
55: ClassNotFoundException {
56: // test constructor with data source, use dummy for testing
57: DataSource ds = new SerializableDataSourceDummy();
58: new DefaultConnectionManager(ds);
59:
60: // test constructor with a plain sql connection
61: // we are using mysql as default, with a named database
62: // mandarax
63: Class.forName("org.gjt.mm.mysql.Driver");
64: Connection con = DriverManager
65: .getConnection("jdbc:mysql://localhost/mandarax");
66: new DefaultConnectionManager(con);
67: }
68:
69: public void testGetDataSource() throws SQLException,
70: ClassNotFoundException {
71: Class.forName("org.gjt.mm.mysql.Driver");
72: Connection con = DriverManager
73: .getConnection("jdbc:mysql://localhost/mandarax");
74: SQLConnectionManager conMan = new DefaultConnectionManager(con);
75:
76: DataSource ds = conMan.getDataSource();
77: assertTrue(ds != null);
78: // the connection from the wrapper must return the
79: // same connection
80: assertEquals(con, ds.getConnection());
81: // user, pwd not yet implememted, returns same
82: // instance
83: assertEquals(ds.getConnection(), ds.getConnection("user",
84: "password"));
85: }
86:
87: public void testReleaseConnection() throws SQLException,
88: ClassNotFoundException {
89: Class.forName("org.gjt.mm.mysql.Driver");
90: Connection con = DriverManager
91: .getConnection("jdbc:mysql://localhost/mandarax");
92: SQLConnectionManager conMan = new DefaultConnectionManager(con);
93:
94: DataSource ds = conMan.getDataSource();
95: assertTrue(ds != null);
96: Connection newCon = ds.getConnection();
97: conMan.releaseConnection(newCon);
98: }
99: }
|