01: /*
02: * Copyright (C) 1999-2004 <a href="mailto:mandarax@jbdietrich.com">Jens Dietrich</a>
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18:
19: package test.org.mandarax.jdbc;
20:
21: import java.sql.*;
22:
23: /**
24: * Simple test case for queries - only one result is expected.
25: * Uses prepared statements with one variable. First another variable value is set
26: * and later updated.
27: * @author <A HREF="mailto:mandarax@jbdietrich.com">Jens Dietrich</A>
28: * @version 3.3.2 <29 December 2004>
29: * @since 3.0
30: */
31:
32: public class QueryTestCase3 extends AbstractQueryTestCase {
33:
34: private String colName = null;
35: private Object expected = null;
36: private Object paramValue = null;
37:
38: /*
39: * Constructor.
40: * @param url the kb url
41: * @param sql the sql statement
42: * @param colName the column name
43: * @param expected the expected object (the value of the substitution in the first result)
44: * @param paramValue the parameter value passed to the prepared statement
45: */
46: public QueryTestCase3(String url, String sql, String colName,
47: Object expected, Object paramValue) {
48: super (url, sql);
49: this .colName = colName;
50: this .expected = expected;
51: this .paramValue = paramValue;
52: }
53:
54: /**
55: * Perform the test.
56: */
57: public void test() throws Exception {
58:
59: Connection connection = java.sql.DriverManager
60: .getConnection(url);
61: PreparedStatement stmnt = connection.prepareStatement(sql);
62: stmnt.setObject(1, "this is not the real value");
63: stmnt.clearParameters();
64: stmnt.setObject(1, paramValue);
65: ResultSet rs = stmnt.executeQuery();
66: rs.next();
67: Object computed = rs.getObject(colName);
68:
69: rs.close();
70: connection.close();
71: assertTrue(expected.equals(computed));
72:
73: }
74:
75: }
|