001: /*
002: * This software is released under a licence similar to the Apache Software Licence.
003: * See org.logicalcobwebs.proxool.package.html for details.
004: * The latest version is available at http://proxool.sourceforge.net
005: */
006: package org.logicalcobwebs.proxool;
007:
008: import org.apache.commons.logging.Log;
009: import org.apache.commons.logging.LogFactory;
010:
011: import java.sql.Connection;
012: import java.sql.DriverManager;
013: import java.sql.SQLException;
014: import java.sql.Statement;
015: import java.util.Properties;
016:
017: /**
018: * Test whether ProxyConnection works
019: *
020: * @version $Revision: 1.6 $, $Date: 2006/01/18 14:40:06 $
021: * @author bill
022: * @author $Author: billhorsman $ (current maintainer)
023: * @since Proxool 0.8
024: */
025: public class ProxyConnectionTest extends AbstractProxoolTest {
026:
027: private static final Log LOG = LogFactory
028: .getLog(ProxyConnectionTest.class);
029:
030: public ProxyConnectionTest(String alias) {
031: super (alias);
032: }
033:
034: /**
035: * Tests whether a statement gets closed automatically by the
036: * Connection. I can't think of a way of asserting this but you should
037: * see a line in the log saying it was closed.
038: */
039: public void testCloseStatement() throws Exception {
040:
041: String testName = "closeStatement";
042: String alias = testName;
043:
044: String url = TestHelper.buildProxoolUrl(alias,
045: TestConstants.HYPERSONIC_DRIVER,
046: TestConstants.HYPERSONIC_TEST_URL);
047: Properties info = new Properties();
048: info.setProperty(ProxoolConstants.USER_PROPERTY,
049: TestConstants.HYPERSONIC_USER);
050: info.setProperty(ProxoolConstants.PASSWORD_PROPERTY,
051: TestConstants.HYPERSONIC_PASSWORD);
052: ProxoolFacade.registerConnectionPool(url, info);
053:
054: Connection c = DriverManager.getConnection(url);
055: Statement s = c.createStatement();
056: try {
057: s.execute("drop table foo");
058: } catch (SQLException e) {
059: // Expected exception (foo doesn't exist)
060: LOG.debug("Ignoring excepted exception", e);
061: } finally {
062: // this should trigger an automatic close of the statement.
063: // Unfortunately, I can't find a way of asserting that this
064: // really happens. Hypersonic seems to let me continue
065: // to use all the methods on the Statement despite it being
066: // closed.
067: c.close();
068: }
069:
070: c = DriverManager.getConnection(url);
071: Statement s2 = c.createStatement();
072: try {
073: s2.execute("drop table foo");
074: } catch (SQLException e) {
075: // Expected exception (foo doesn't exist)
076: LOG.debug("Excepted exception", e);
077: } finally {
078: if (s2 != null) {
079: s2.close();
080: }
081: // this should NOT trigger an automatic close of the statement
082: // because it's been closed explicitly above
083: c.close();
084: }
085:
086: }
087:
088: }
089:
090: /*
091: Revision history:
092: $Log: ProxyConnectionTest.java,v $
093: Revision 1.6 2006/01/18 14:40:06 billhorsman
094: Unbundled Jakarta's Commons Logging.
095:
096: Revision 1.5 2003/03/04 10:24:40 billhorsman
097: removed try blocks around each test
098:
099: Revision 1.4 2003/03/03 17:09:04 billhorsman
100: all tests now extend AbstractProxoolTest
101:
102: Revision 1.3 2003/03/03 11:12:05 billhorsman
103: fixed licence
104:
105: Revision 1.2 2003/03/01 15:27:24 billhorsman
106: checkstyle
107:
108: Revision 1.1 2003/02/27 18:01:48 billhorsman
109: completely rethought the test structure. it's now
110: more obvious. no new tests yet though.
111:
112: */
|