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 java.sql.Connection;
009: import java.sql.DriverManager;
010: import java.sql.ResultSet;
011: import java.sql.ResultSetMetaData;
012: import java.sql.SQLException;
013: import java.sql.Statement;
014: import java.util.Properties;
015:
016: /**
017: * Tests whether {@link ConnectionPoolDefinition} recognises properties
018: * properly
019: * @version $Revision: 1.3 $, $Date: 2006/03/24 00:18:46 $
020: * @author billhorsman
021: * @author $Author: billhorsman $ (current maintainer)
022: * @since Proxool 0.8.2
023: */
024: public class PropertyTest extends AbstractProxoolTest {
025:
026: public PropertyTest(String alias) {
027: super (alias);
028: }
029:
030: /**
031: * Test whether we are successfully passing properties onto the delegate driver. This
032: * relies on a feature of Hypersonic 1.7.1 where ResultSetMetaData.isWritable() is
033: * unsupported. The default behaviour, however, is just to return a value that maybe
034: * incorrect but without throwing an exception. If you set the property jdbc.strict_md = true
035: * then Hypersonic does throw an exception. This might change in future versions of Hypersonic
036: * so we should keep an eye on this.
037: * See <a href="http://hsqldb.sourceforge.net/doc/src/org/hsqldb/jdbcResultSet.html">http://hsqldb.sourceforge.net/doc/src/org/hsqldb/jdbcResultSet.html</a>
038: */
039: public void testDelegateProperty() throws Exception {
040:
041: String testName = "delegateProperty";
042: String alias = testName;
043:
044: // Register pool
045: String url = TestHelper.buildProxoolUrl(alias,
046: TestConstants.HYPERSONIC_DRIVER,
047: TestConstants.HYPERSONIC_TEST_URL);
048: Properties info = new Properties();
049: info.setProperty(ProxoolConstants.USER_PROPERTY,
050: TestConstants.HYPERSONIC_USER);
051: info.setProperty(ProxoolConstants.PASSWORD_PROPERTY,
052: TestConstants.HYPERSONIC_PASSWORD);
053: info.setProperty(
054: ProxoolConstants.HOUSE_KEEPING_TEST_SQL_PROPERTY,
055: TestConstants.HYPERSONIC_TEST_SQL);
056:
057: Connection c = null;
058: try {
059: c = DriverManager.getConnection(url, info);
060: Statement s = c.createStatement();
061: try {
062: s.execute("drop table z");
063: } catch (SQLException e) {
064: // Probably because it doesn't exist.
065: }
066: s.execute("create table z (a int)");
067:
068: s.execute("select * from z");
069: ResultSet rs = s.getResultSet();
070: ResultSetMetaData rsmd = rs.getMetaData();
071: // by default, this should work without error (even if the value returned is rubbish)
072: rsmd.isWritable(1);
073: } finally {
074: if (c != null) {
075: c.close();
076: c = null;
077: }
078: }
079: /*
080: This doesn't work with HSQLDB 1.8.0. They don't seem to mention the strict_md propertry in their
081: documentation anymore.
082:
083: // And now test with the strict meta data
084: info.setProperty("jdbc.strict_md", "true");
085: try {
086: c = DriverManager.getConnection(url, info);
087: Statement s = c.createStatement();
088: s.execute("select * from z");
089: ResultSet rs = s.getResultSet();
090: ResultSetMetaData rsmd = rs.getMetaData();
091: try {
092: rsmd.isWritable(1);
093: fail("Expected isWritable() to throw unsupported exception");
094: } catch (SQLException e) {
095: // Expected an exception
096: }
097: } finally {
098: if (c != null) {
099: c.close();
100: }
101: }
102: */
103:
104: }
105: }
106: /*
107: Revision history:
108: $Log: PropertyTest.java,v $
109: Revision 1.3 2006/03/24 00:18:46 billhorsman
110: Changes for HSQL 1.8
111:
112: Revision 1.2 2004/05/26 17:19:09 brenuart
113: Allow JUnit tests to be executed against another database.
114: By default the test configuration will be taken from the 'testconfig-hsqldb.properties' file located in the org.logicalcobwebs.proxool package.
115: This behavior can be overriden by setting the 'testConfig' environment property to another location.
116:
117: Revision 1.1 2003/11/04 13:22:43 billhorsman
118: New test for delegate properties
119:
120: */
|