KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > logicalcobwebs > proxool > ProxyConnectionTest


1 /*
2  * This software is released under a licence similar to the Apache Software Licence.
3  * See org.logicalcobwebs.proxool.package.html for details.
4  * The latest version is available at http://proxool.sourceforge.net
5  */

6 package org.logicalcobwebs.proxool;
7
8 import org.apache.commons.logging.Log;
9 import org.apache.commons.logging.LogFactory;
10
11 import java.sql.Connection JavaDoc;
12 import java.sql.DriverManager JavaDoc;
13 import java.sql.SQLException JavaDoc;
14 import java.sql.Statement JavaDoc;
15 import java.util.Properties JavaDoc;
16
17 /**
18  * Test whether ProxyConnection works
19  *
20  * @version $Revision: 1.6 $, $Date: 2006/01/18 14:40:06 $
21  * @author bill
22  * @author $Author: billhorsman $ (current maintainer)
23  * @since Proxool 0.8
24  */

25 public class ProxyConnectionTest extends AbstractProxoolTest {
26
27     private static final Log LOG = LogFactory.getLog(ProxyConnectionTest.class);
28
29     public ProxyConnectionTest(String JavaDoc alias) {
30         super(alias);
31     }
32
33     /**
34      * Tests whether a statement gets closed automatically by the
35      * Connection. I can't think of a way of asserting this but you should
36      * see a line in the log saying it was closed.
37      */

38     public void testCloseStatement() throws Exception JavaDoc {
39
40         String JavaDoc testName = "closeStatement";
41         String JavaDoc alias = testName;
42
43         String JavaDoc url = TestHelper.buildProxoolUrl(alias,
44                 TestConstants.HYPERSONIC_DRIVER,
45                 TestConstants.HYPERSONIC_TEST_URL);
46         Properties JavaDoc info = new Properties JavaDoc();
47         info.setProperty(ProxoolConstants.USER_PROPERTY, TestConstants.HYPERSONIC_USER);
48         info.setProperty(ProxoolConstants.PASSWORD_PROPERTY, TestConstants.HYPERSONIC_PASSWORD);
49         ProxoolFacade.registerConnectionPool(url, info);
50
51         Connection JavaDoc c = DriverManager.getConnection(url);
52         Statement JavaDoc s = c.createStatement();
53         try {
54             s.execute("drop table foo");
55         } catch (SQLException JavaDoc e) {
56             // Expected exception (foo doesn't exist)
57
LOG.debug("Ignoring excepted exception", e);
58         } finally {
59             // this should trigger an automatic close of the statement.
60
// Unfortunately, I can't find a way of asserting that this
61
// really happens. Hypersonic seems to let me continue
62
// to use all the methods on the Statement despite it being
63
// closed.
64
c.close();
65         }
66
67         c = DriverManager.getConnection(url);
68         Statement JavaDoc s2 = c.createStatement();
69         try {
70             s2.execute("drop table foo");
71         } catch (SQLException JavaDoc e) {
72             // Expected exception (foo doesn't exist)
73
LOG.debug("Excepted exception", e);
74         } finally {
75             if (s2 != null) {
76                 s2.close();
77             }
78             // this should NOT trigger an automatic close of the statement
79
// because it's been closed explicitly above
80
c.close();
81         }
82
83     }
84
85 }
86
87
88 /*
89  Revision history:
90  $Log: ProxyConnectionTest.java,v $
91  Revision 1.6 2006/01/18 14:40:06 billhorsman
92  Unbundled Jakarta's Commons Logging.
93
94  Revision 1.5 2003/03/04 10:24:40 billhorsman
95  removed try blocks around each test
96
97  Revision 1.4 2003/03/03 17:09:04 billhorsman
98  all tests now extend AbstractProxoolTest
99
100  Revision 1.3 2003/03/03 11:12:05 billhorsman
101  fixed licence
102
103  Revision 1.2 2003/03/01 15:27:24 billhorsman
104  checkstyle
105
106  Revision 1.1 2003/02/27 18:01:48 billhorsman
107  completely rethought the test structure. it's now
108  more obvious. no new tests yet though.
109
110  */
Popular Tags