[Proxool-cvs] proxool/src/java-test/org/logicalcobwebs/proxool ConnectionListenerTest.java,1.12,1.13
UNMAINTAINED!
Brought to you by:
billhorsman
|
From: <bil...@us...> - 2004-06-02 20:04:09
|
Update of /cvsroot/proxool/proxool/src/java-test/org/logicalcobwebs/proxool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9091/src/java-test/org/logicalcobwebs/proxool Modified Files: ConnectionListenerTest.java Log Message: Added test for onExecute command Index: ConnectionListenerTest.java =================================================================== RCS file: /cvsroot/proxool/proxool/src/java-test/org/logicalcobwebs/proxool/ConnectionListenerTest.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** ConnectionListenerTest.java 26 May 2004 17:19:10 -0000 1.12 --- ConnectionListenerTest.java 2 Jun 2004 20:04:00 -0000 1.13 *************** *** 6,12 **** --- 6,18 ---- package org.logicalcobwebs.proxool; + import org.logicalcobwebs.logging.Log; + import org.logicalcobwebs.logging.LogFactory; + import java.sql.Connection; + import java.sql.Date; import java.sql.DriverManager; + import java.sql.PreparedStatement; import java.sql.SQLException; + import java.util.Calendar; import java.util.Properties; *************** *** 22,25 **** --- 28,33 ---- public class ConnectionListenerTest extends AbstractProxoolTest { + private static final Log LOG = LogFactory.getLog(ConnectionListenerTest.class); + private int onBirthCalls; private int onDeathCalls; *************** *** 84,87 **** --- 92,155 ---- /** + * See whether the command parameter passed to {@link ConnectionListenerIF#onFail(java.lang.String, java.lang.Exception)} + * is correct. And assume it is also right for onExecute. + * @throws Exception if the test fails. + */ + public void testExecuteCommand() throws Exception { + clear(); + String alias = "executeCommand"; + String url = TestHelper.buildProxoolUrl(alias, + TestConstants.HYPERSONIC_DRIVER, + TestConstants.HYPERSONIC_TEST_URL); + Properties info = new Properties(); + info.setProperty(ProxoolConstants.USER_PROPERTY, TestConstants.HYPERSONIC_USER); + info.setProperty(ProxoolConstants.PASSWORD_PROPERTY, TestConstants.HYPERSONIC_PASSWORD); + Connection connection1 = DriverManager.getConnection(url, info); + final TestConnectionListener tcl = new TestConnectionListener(); + ProxoolFacade.addConnectionListener(alias, tcl); + + // provoke execution error + java.util.Date date = null; + try { + PreparedStatement ps = connection1.prepareStatement("select * from NOTHING where a = ? and b = ? and c = ? and d = ? and e = ?"); + ps.setBoolean(1, true); + Calendar c = Calendar.getInstance(); + date = c.getTime(); + ps.setDate(2, new Date(c.getTime().getTime())); + ps.setInt(3, 3); + ps.setDouble(4, 4.0); + ps.setString(5, "test"); + ps.execute(); + } catch (SQLException e) { + // we expect this + } + LOG.debug(tcl.getCommand()); + assertEquals("command", "select * from NOTHING where a = true and b = '" + AbstractProxyStatement.getDateAsString(date) + "' and c = 3 and d = 4.0 and e = 'test';", tcl.getCommand().trim()); + + // Check that it works with no parameters + final String s2 = "select * from NOTHING;"; + try { + tcl.clear(); + PreparedStatement ps = connection1.prepareStatement(s2); + ps.execute(); + } catch (SQLException e) { + // we expect this + } + LOG.debug(tcl.getCommand()); + assertEquals("command", s2, tcl.getCommand().trim()); + + try { + tcl.clear(); + PreparedStatement ps = connection1.prepareStatement(s2); + ps.execute(); + } catch (SQLException e) { + // we expect this + } + LOG.debug(tcl.getCommand()); + assertEquals("command", s2, tcl.getCommand().trim()); + + } + + /** * Test that multiple connection listeners can be added through ProxoolFacade, * and then removed, and that they do not receive events after they have been removed. *************** *** 154,157 **** --- 222,228 ---- class TestConnectionListener implements ConnectionListenerIF { + + String command; + public void onBirth(Connection connection) throws SQLException { onBirthCalls++; *************** *** 164,171 **** --- 235,252 ---- public void onExecute(String command, long elapsedTime) { onExecuteCalls++; + this.command = command; } public void onFail(String command, Exception exception) { onFailCalls++; + this.command = command; + } + + public String getCommand() { + return command; + } + + public void clear() { + command = null; } } *************** *** 175,178 **** --- 256,262 ---- Revision history: $Log$ + Revision 1.13 2004/06/02 20:04:00 billhorsman + Added test for onExecute command + Revision 1.12 2004/05/26 17:19:10 brenuart Allow JUnit tests to be executed against another database. |