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.util.Properties;
012: import java.sql.Connection;
013: import java.sql.DriverManager;
014: import java.sql.Statement;
015: import java.sql.PreparedStatement;
016: import java.sql.CallableStatement;
017:
018: /**
019: * Tests whether we can inject a new interface into one of the proxy objects
020: * @version $Revision: 1.3 $, $Date: 2006/01/18 14:40:06 $
021: * @author <a href="mailto:bill@logicalcobwebs.co.uk">Bill Horsman</a>
022: * @author $Author: billhorsman $ (current maintainer)
023: * @since Proxool 0.9
024: */
025: public class InjectableInterfaceTest extends AbstractProxoolTest {
026:
027: private static final Log LOG = LogFactory
028: .getLog(InjectableInterfaceTest.class);
029:
030: /**
031: * @see AbstractProxoolTest
032: */
033: public InjectableInterfaceTest(String alias) {
034: super (alias);
035: }
036:
037: /**
038: * Get a connection and cast it into the appropriate interface
039: */
040: public void testInjectableConnectionInterface() throws Exception {
041: String alias = "injectableConnectionInterface";
042: String url = TestHelper.buildProxoolUrl(alias,
043: TestConstants.HYPERSONIC_DRIVER,
044: TestConstants.HYPERSONIC_TEST_URL);
045: Properties info = new Properties();
046: info.setProperty(ProxoolConstants.USER_PROPERTY,
047: TestConstants.HYPERSONIC_USER);
048: info.setProperty(ProxoolConstants.PASSWORD_PROPERTY,
049: TestConstants.HYPERSONIC_PASSWORD);
050: info
051: .setProperty(
052: ProxoolConstants.INJECTABLE_CONNECTION_INTERFACE_NAME_PROPERTY,
053: HsqlConnectionIF.class.getName());
054: Connection c1 = DriverManager.getConnection(url, info);
055: // Can we cast it?
056: HsqlConnectionIF hc = (HsqlConnectionIF) c1;
057: // TODO - need to test a vendor specific method?
058: // Does close() still work?
059: hc.close();
060: assertTrue("c1.isClosed()", c1.isClosed());
061: }
062:
063: /**
064: * Get a statement and cast it into the appropriate interface
065: */
066: public void testInjectableStatementInterface() throws Exception {
067: String alias = "injectableStatementInterface";
068: String url = TestHelper.buildProxoolUrl(alias,
069: TestConstants.HYPERSONIC_DRIVER,
070: TestConstants.HYPERSONIC_TEST_URL);
071: Properties info = new Properties();
072: info.setProperty(ProxoolConstants.USER_PROPERTY,
073: TestConstants.HYPERSONIC_USER);
074: info.setProperty(ProxoolConstants.PASSWORD_PROPERTY,
075: TestConstants.HYPERSONIC_PASSWORD);
076: info
077: .setProperty(
078: ProxoolConstants.INJECTABLE_STATEMENT_INTERFACE_NAME_PROPERTY,
079: HsqlStatementIF.class.getName());
080: Connection c1 = DriverManager.getConnection(url, info);
081: Statement s = c1.createStatement();
082: // Can we cast it?
083: HsqlStatementIF hs = (HsqlStatementIF) s;
084: // TODO : call a vendor specific method?
085: // hs.checkClosed();
086: // Does close() still work?
087: hs.close();
088: c1.close();
089: }
090:
091: /**
092: * Get a statement and cast it into the appropriate interface
093: */
094: public void testInjectablePreparedStatementInterface()
095: throws Exception {
096: String alias = "injectablePreparedStatementInterface";
097: String url = TestHelper.buildProxoolUrl(alias,
098: TestConstants.HYPERSONIC_DRIVER,
099: TestConstants.HYPERSONIC_TEST_URL);
100: Properties info = new Properties();
101: info.setProperty(ProxoolConstants.USER_PROPERTY,
102: TestConstants.HYPERSONIC_USER);
103: info.setProperty(ProxoolConstants.PASSWORD_PROPERTY,
104: TestConstants.HYPERSONIC_PASSWORD);
105: info
106: .setProperty(
107: ProxoolConstants.INJECTABLE_PREPARED_STATEMENT_INTERFACE_NAME_PROPERTY,
108: HsqlPreparedStatementIF.class.getName());
109: Connection c1 = DriverManager.getConnection(url, info);
110: PreparedStatement ps = c1
111: .prepareStatement(TestConstants.HYPERSONIC_TEST_SQL);
112: // Can we cast it?
113: HsqlPreparedStatementIF hps = (HsqlPreparedStatementIF) ps;
114: // TODO : call a vendor specific method?
115: // hps.build();
116: // Does close() still work?
117: hps.close();
118: c1.close();
119: }
120:
121: /**
122: * Get a statement and cast it into the appropriate interface
123: */
124: public void testInjectableCallableStatementInterface()
125: throws Exception {
126: String alias = "injectableCallableStatementInterface";
127: String url = TestHelper.buildProxoolUrl(alias,
128: TestConstants.HYPERSONIC_DRIVER,
129: TestConstants.HYPERSONIC_TEST_URL);
130: Properties info = new Properties();
131: info.setProperty(ProxoolConstants.USER_PROPERTY,
132: TestConstants.HYPERSONIC_USER);
133: info.setProperty(ProxoolConstants.PASSWORD_PROPERTY,
134: TestConstants.HYPERSONIC_PASSWORD);
135: info
136: .setProperty(
137: ProxoolConstants.INJECTABLE_CALLABLE_STATEMENT_INTERFACE_NAME_PROPERTY,
138: HsqlPreparedStatementIF.class.getName());
139: Connection c1 = DriverManager.getConnection(url, info);
140: CallableStatement cs = c1
141: .prepareCall(TestConstants.HYPERSONIC_TEST_SQL);
142: // Can we cast it? (Note: HSQLDB uses the same class for both Prepared and Callable statements)
143: HsqlPreparedStatementIF hps = (HsqlPreparedStatementIF) cs;
144: // TODO - call a vendor specific method?
145: // Does close() still work?
146: hps.close();
147: c1.close();
148: }
149:
150: }
151: /*
152: Revision history:
153: $Log: InjectableInterfaceTest.java,v $
154: Revision 1.3 2006/01/18 14:40:06 billhorsman
155: Unbundled Jakarta's Commons Logging.
156:
157: Revision 1.2 2004/06/17 21:36:39 billhorsman
158: Removed call to private methods. They're going to fail anyway.
159:
160: Revision 1.1 2004/06/02 20:59:52 billhorsman
161: New injectable interface tests
162:
163: */
|