testdefaultconnectionmanager.java
来自「Mandarax是一个规则引擎的纯Java实现。它支持多类型的事实和基于反映的规」· Java 代码 · 共 98 行
JAVA
98 行
/**
* Copyright (C) 1999-2004 Jens Dietrich (mailto:mandarax@jbdietrich.com)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package test.org.mandarax.sql;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.sql.DataSource;
import junit.framework.TestCase;
import org.mandarax.sql.DefaultConnectionManager;
import org.mandarax.sql.SQLConnectionManager;
import test.org.mandarax.ser.SerializableDataSourceDummy;
/**
* Test suite for the mandarax sql package.
* @author <a href="mailto:jochen.hiller@bauer-partner.com">Jochen Hiller</a>
* @version 3.4 <7 March 05>
* @since 2.2
*/
public class TestDefaultConnectionManager extends TestCase {
/**
* Constructor for DefaultConnectionManagerTest.
* @param arg0
*/
public TestDefaultConnectionManager(String arg0) {
super(arg0);
}
public static void main(String[] args) {
junit.textui.TestRunner.run(TestDefaultConnectionManager.class);
}
// tests
public void testConstructors()
throws SQLException, ClassNotFoundException {
// test constructor with data source, use dummy for testing
DataSource ds = new SerializableDataSourceDummy();
new DefaultConnectionManager (ds);
// test constructor with a plain sql connection
// we are using mysql as default, with a named database
// mandarax
Class.forName ("org.gjt.mm.mysql.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/mandarax");
new DefaultConnectionManager (con);
}
public void testGetDataSource()
throws SQLException, ClassNotFoundException {
Class.forName ("org.gjt.mm.mysql.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/mandarax");
SQLConnectionManager conMan = new DefaultConnectionManager (con);
DataSource ds = conMan.getDataSource();
assertTrue (ds != null);
// the connection from the wrapper must return the
// same connection
assertEquals (con, ds.getConnection());
// user, pwd not yet implememted, returns same
// instance
assertEquals (ds.getConnection(), ds.getConnection("user", "password"));
}
public void testReleaseConnection()
throws SQLException, ClassNotFoundException {
Class.forName ("org.gjt.mm.mysql.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/mandarax");
SQLConnectionManager conMan = new DefaultConnectionManager (con);
DataSource ds = conMan.getDataSource();
assertTrue (ds != null);
Connection newCon = ds.getConnection();
conMan.releaseConnection(newCon);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?