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.
26: * @author <A HREF="mailto:mandarax@jbdietrich.com">Jens Dietrich</A>
27: * @version 3.3.2 <29 December 2004>
28: * @since 3.0
29: */
30:
31: public class QueryTestCase2 extends AbstractQueryTestCase {
32:
33: private String colName = null;
34: private Object expected = null;
35: private Object paramValue = null;
36:
37: /*
38: * Constructor.
39: * @param url the kb url
40: * @param sql the sql statement
41: * @param colName the column name
42: * @param expected the expected object (the value of the substitution in the first result)
43: * @param paramValue the parameter value passed to the prepared statement
44: */
45: public QueryTestCase2(String url, String sql, String colName,
46: Object expected, Object paramValue) {
47: super (url, sql);
48: this .colName = colName;
49: this .expected = expected;
50: this .paramValue = paramValue;
51: }
52:
53: /**
54: * Perform the test.
55: */
56: public void test() throws Exception {
57:
58: Connection connection = java.sql.DriverManager
59: .getConnection(url);
60: PreparedStatement stmnt = connection.prepareStatement(sql);
61: stmnt.setObject(1, paramValue);
62: ResultSet rs = stmnt.executeQuery();
63: rs.next();
64: Object computed = rs.getObject(colName);
65: rs.close();
66: connection.close();
67: assertTrue(expected.equals(computed));
68:
69: }
70:
71: }
|