KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.sql.Connection JavaDoc;
9 import java.sql.DriverManager JavaDoc;
10 import java.sql.ResultSet JavaDoc;
11 import java.sql.ResultSetMetaData JavaDoc;
12 import java.sql.SQLException JavaDoc;
13 import java.sql.Statement JavaDoc;
14 import java.util.Properties JavaDoc;
15
16 /**
17  * Tests whether {@link ConnectionPoolDefinition} recognises properties
18  * properly
19  * @version $Revision: 1.3 $, $Date: 2006/03/24 00:18:46 $
20  * @author billhorsman
21  * @author $Author: billhorsman $ (current maintainer)
22  * @since Proxool 0.8.2
23  */

24 public class PropertyTest extends AbstractProxoolTest {
25
26     public PropertyTest(String JavaDoc alias) {
27         super(alias);
28     }
29
30     /**
31      * Test whether we are successfully passing properties onto the delegate driver. This
32      * relies on a feature of Hypersonic 1.7.1 where ResultSetMetaData.isWritable() is
33      * unsupported. The default behaviour, however, is just to return a value that maybe
34      * incorrect but without throwing an exception. If you set the property jdbc.strict_md = true
35      * then Hypersonic does throw an exception. This might change in future versions of Hypersonic
36      * so we should keep an eye on this.
37      * See <a HREF="http://hsqldb.sourceforge.net/doc/src/org/hsqldb/jdbcResultSet.html">http://hsqldb.sourceforge.net/doc/src/org/hsqldb/jdbcResultSet.html</a>
38      */

39     public void testDelegateProperty() throws Exception JavaDoc {
40
41         String JavaDoc testName = "delegateProperty";
42         String JavaDoc alias = testName;
43
44         // Register pool
45
String JavaDoc url = TestHelper.buildProxoolUrl(alias,
46                 TestConstants.HYPERSONIC_DRIVER,
47                 TestConstants.HYPERSONIC_TEST_URL);
48         Properties JavaDoc info = new Properties JavaDoc();
49         info.setProperty(ProxoolConstants.USER_PROPERTY, TestConstants.HYPERSONIC_USER);
50         info.setProperty(ProxoolConstants.PASSWORD_PROPERTY, TestConstants.HYPERSONIC_PASSWORD);
51         info.setProperty(ProxoolConstants.HOUSE_KEEPING_TEST_SQL_PROPERTY, TestConstants.HYPERSONIC_TEST_SQL);
52
53         Connection JavaDoc c = null;
54         try {
55             c = DriverManager.getConnection(url, info);
56             Statement JavaDoc s = c.createStatement();
57             try {
58                 s.execute("drop table z");
59             } catch (SQLException JavaDoc e) {
60                 // Probably because it doesn't exist.
61
}
62             s.execute("create table z (a int)");
63
64             s.execute("select * from z");
65             ResultSet JavaDoc rs = s.getResultSet();
66             ResultSetMetaData JavaDoc rsmd = rs.getMetaData();
67             // by default, this should work without error (even if the value returned is rubbish)
68
rsmd.isWritable(1);
69         } finally {
70             if (c != null) {
71                 c.close();
72                 c = null;
73             }
74         }
75 /*
76      This doesn't work with HSQLDB 1.8.0. They don't seem to mention the strict_md propertry in their
77      documentation anymore.
78
79         // And now test with the strict meta data
80         info.setProperty("jdbc.strict_md", "true");
81         try {
82             c = DriverManager.getConnection(url, info);
83             Statement s = c.createStatement();
84             s.execute("select * from z");
85             ResultSet rs = s.getResultSet();
86             ResultSetMetaData rsmd = rs.getMetaData();
87             try {
88                 rsmd.isWritable(1);
89                 fail("Expected isWritable() to throw unsupported exception");
90             } catch (SQLException e) {
91                 // Expected an exception
92             }
93         } finally {
94             if (c != null) {
95                 c.close();
96             }
97         }
98 */

99
100     }
101 }
102 /*
103  Revision history:
104  $Log: PropertyTest.java,v $
105  Revision 1.3 2006/03/24 00:18:46 billhorsman
106  Changes for HSQL 1.8
107
108  Revision 1.2 2004/05/26 17:19:09 brenuart
109  Allow JUnit tests to be executed against another database.
110  By default the test configuration will be taken from the 'testconfig-hsqldb.properties' file located in the org.logicalcobwebs.proxool package.
111  This behavior can be overriden by setting the 'testConfig' environment property to another location.
112
113  Revision 1.1 2003/11/04 13:22:43 billhorsman
114  New test for delegate properties
115
116   */
Popular Tags