KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.Properties JavaDoc;
12 import java.sql.Connection JavaDoc;
13 import java.sql.DriverManager JavaDoc;
14 import java.sql.Statement JavaDoc;
15 import java.sql.PreparedStatement JavaDoc;
16 import java.sql.CallableStatement JavaDoc;
17
18 /**
19  * Tests whether we can inject a new interface into one of the proxy objects
20  * @version $Revision: 1.3 $, $Date: 2006/01/18 14:40:06 $
21  * @author <a HREF="mailto:bill@logicalcobwebs.co.uk">Bill Horsman</a>
22  * @author $Author: billhorsman $ (current maintainer)
23  * @since Proxool 0.9
24  */

25 public class InjectableInterfaceTest extends AbstractProxoolTest {
26
27     private static final Log LOG = LogFactory.getLog(InjectableInterfaceTest.class);
28
29     /**
30      * @see AbstractProxoolTest
31      */

32     public InjectableInterfaceTest(String JavaDoc alias) {
33         super(alias);
34     }
35
36     /**
37      * Get a connection and cast it into the appropriate interface
38      */

39     public void testInjectableConnectionInterface() throws Exception JavaDoc {
40         String JavaDoc alias = "injectableConnectionInterface";
41         String JavaDoc url = TestHelper.buildProxoolUrl(alias,
42                 TestConstants.HYPERSONIC_DRIVER,
43                 TestConstants.HYPERSONIC_TEST_URL);
44         Properties JavaDoc info = new Properties JavaDoc();
45         info.setProperty(ProxoolConstants.USER_PROPERTY, TestConstants.HYPERSONIC_USER);
46         info.setProperty(ProxoolConstants.PASSWORD_PROPERTY, TestConstants.HYPERSONIC_PASSWORD);
47         info.setProperty(ProxoolConstants.INJECTABLE_CONNECTION_INTERFACE_NAME_PROPERTY, HsqlConnectionIF.class.getName());
48         Connection JavaDoc c1 = DriverManager.getConnection(url, info);
49         // Can we cast it?
50
HsqlConnectionIF hc = (HsqlConnectionIF) c1;
51         // TODO - need to test a vendor specific method?
52
// Does close() still work?
53
hc.close();
54         assertTrue("c1.isClosed()", c1.isClosed());
55     }
56
57     /**
58      * Get a statement and cast it into the appropriate interface
59      */

60     public void testInjectableStatementInterface() throws Exception JavaDoc {
61         String JavaDoc alias = "injectableStatementInterface";
62         String JavaDoc url = TestHelper.buildProxoolUrl(alias,
63                 TestConstants.HYPERSONIC_DRIVER,
64                 TestConstants.HYPERSONIC_TEST_URL);
65         Properties JavaDoc info = new Properties JavaDoc();
66         info.setProperty(ProxoolConstants.USER_PROPERTY, TestConstants.HYPERSONIC_USER);
67         info.setProperty(ProxoolConstants.PASSWORD_PROPERTY, TestConstants.HYPERSONIC_PASSWORD);
68         info.setProperty(ProxoolConstants.INJECTABLE_STATEMENT_INTERFACE_NAME_PROPERTY, HsqlStatementIF.class.getName());
69         Connection JavaDoc c1 = DriverManager.getConnection(url, info);
70         Statement JavaDoc s = c1.createStatement();
71         // Can we cast it?
72
HsqlStatementIF hs = (HsqlStatementIF) s;
73         // TODO : call a vendor specific method?
74
// hs.checkClosed();
75
// Does close() still work?
76
hs.close();
77         c1.close();
78     }
79
80     /**
81      * Get a statement and cast it into the appropriate interface
82      */

83     public void testInjectablePreparedStatementInterface() throws Exception JavaDoc {
84         String JavaDoc alias = "injectablePreparedStatementInterface";
85         String JavaDoc url = TestHelper.buildProxoolUrl(alias,
86                 TestConstants.HYPERSONIC_DRIVER,
87                 TestConstants.HYPERSONIC_TEST_URL);
88         Properties JavaDoc info = new Properties JavaDoc();
89         info.setProperty(ProxoolConstants.USER_PROPERTY, TestConstants.HYPERSONIC_USER);
90         info.setProperty(ProxoolConstants.PASSWORD_PROPERTY, TestConstants.HYPERSONIC_PASSWORD);
91         info.setProperty(ProxoolConstants.INJECTABLE_PREPARED_STATEMENT_INTERFACE_NAME_PROPERTY, HsqlPreparedStatementIF.class.getName());
92         Connection JavaDoc c1 = DriverManager.getConnection(url, info);
93         PreparedStatement JavaDoc ps = c1.prepareStatement(TestConstants.HYPERSONIC_TEST_SQL);
94         // Can we cast it?
95
HsqlPreparedStatementIF hps = (HsqlPreparedStatementIF) ps;
96         // TODO : call a vendor specific method?
97
// hps.build();
98
// Does close() still work?
99
hps.close();
100         c1.close();
101     }
102
103     /**
104      * Get a statement and cast it into the appropriate interface
105      */

106     public void testInjectableCallableStatementInterface() throws Exception JavaDoc {
107         String JavaDoc alias = "injectableCallableStatementInterface";
108         String JavaDoc url = TestHelper.buildProxoolUrl(alias,
109                 TestConstants.HYPERSONIC_DRIVER,
110                 TestConstants.HYPERSONIC_TEST_URL);
111         Properties JavaDoc info = new Properties JavaDoc();
112         info.setProperty(ProxoolConstants.USER_PROPERTY, TestConstants.HYPERSONIC_USER);
113         info.setProperty(ProxoolConstants.PASSWORD_PROPERTY, TestConstants.HYPERSONIC_PASSWORD);
114         info.setProperty(ProxoolConstants.INJECTABLE_CALLABLE_STATEMENT_INTERFACE_NAME_PROPERTY, HsqlPreparedStatementIF.class.getName());
115         Connection JavaDoc c1 = DriverManager.getConnection(url, info);
116         CallableStatement JavaDoc cs = c1.prepareCall(TestConstants.HYPERSONIC_TEST_SQL);
117         // Can we cast it? (Note: HSQLDB uses the same class for both Prepared and Callable statements)
118
HsqlPreparedStatementIF hps = (HsqlPreparedStatementIF) cs;
119         // TODO - call a vendor specific method?
120
// Does close() still work?
121
hps.close();
122         c1.close();
123     }
124
125 }
126 /*
127  Revision history:
128  $Log: InjectableInterfaceTest.java,v $
129  Revision 1.3 2006/01/18 14:40:06 billhorsman
130  Unbundled Jakarta's Commons Logging.
131
132  Revision 1.2 2004/06/17 21:36:39 billhorsman
133  Removed call to private methods. They're going to fail anyway.
134
135  Revision 1.1 2004/06/02 20:59:52 billhorsman
136  New injectable interface tests
137
138  */
Popular Tags