01: package test.org.mandarax.jdbc;
02:
03: /*
04: * Copyright (C) 1999-2004 <a href="mailto:mandarax@jbdietrich.com">Jens Dietrich</a>
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2 of the License, or (at your option) any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: */
20:
21: import java.sql.*;
22: import java.util.*;
23:
24: /**
25: * Test case based on the memory kb from the test.org.mandarax.util.resultsetfilters package.
26: * Suitable to test SELECT COUNT(*) statements.
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 QueryTestCase6 extends AbstractQueryTestCase implements
33: Constants {
34:
35: private String name;
36: private int expectedResults;
37:
38: /**
39: * Constructor.
40: * @param name the name of this test case
41: * @param orderByConditions the order by conditions
42: * @param expected the expected number of results
43: */
44: public QueryTestCase6(String sql, int expected) {
45: super ("jdbc:mandarax:ref:"
46: + test.org.mandarax.jdbc.TestKnowledgeBaseRef.class
47: .getName(), sql);
48: this .sql = sql;
49: this .expectedResults = expected;
50: }
51:
52: /**
53: * Run the test case.
54: */
55: public void test() throws Exception {
56:
57: Connection connection = java.sql.DriverManager
58: .getConnection(url);
59: Statement stmnt = connection.createStatement();
60: java.sql.ResultSet rs = stmnt.executeQuery(sql);
61: rs.next();
62: Integer result = (Integer) rs.getObject("COUNT(*)");
63: rs.last();
64: int rowCount = rs.getRow();
65: // there should be only one row (aggregation!)
66: assertTrue(rowCount == 1
67: && expectedResults == result.intValue());
68: connection.close();
69:
70: }
71:
72: /**
73: * Get the container used to organise results.
74: * The container selected will determine whether the order of the results is retained etc.
75: */
76: protected List getPrefContainer() {
77: return new ArrayList();
78: }
79:
80: /**
81: * Convert this object to a string.
82: * @return the string representation of this object
83: */
84: public String toString() {
85: return "Testing results returned by SQL statement: " + sql;
86: }
87:
88: }
|