001: /*
002: Copyright (C) 2002-2004 MySQL AB
003:
004: This program is free software; you can redistribute it and/or modify
005: it under the terms of version 2 of the GNU General Public License as
006: published by the Free Software Foundation.
007:
008: There are special exceptions to the terms and conditions of the GPL
009: as it is applied to this software. View the full text of the
010: exception in file EXCEPTIONS-CONNECTOR-J in the directory of this
011: software distribution.
012:
013: This program is distributed in the hope that it will be useful,
014: but WITHOUT ANY WARRANTY; without even the implied warranty of
015: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: GNU General Public License for more details.
017:
018: You should have received a copy of the GNU General Public License
019: along with this program; if not, write to the Free Software
020: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
021:
022:
023:
024: */
025: package testsuite.regression;
026:
027: import java.lang.reflect.Method;
028: import java.sql.ResultSet;
029:
030: import javax.sql.RowSet;
031:
032: import testsuite.BaseTestCase;
033:
034: /**
035: * Regression test cases for the ResultSet class.
036: *
037: * @author Eric Herman
038: */
039: public class CachedRowsetTest extends BaseTestCase {
040: /**
041: * Creates a new CachedRowsetTest
042: *
043: * @param name
044: * the name of the test to run
045: */
046: public CachedRowsetTest(String name) {
047: super (name);
048: }
049:
050: /**
051: * Runs all test cases in this test suite
052: *
053: * @param args
054: */
055: public static void main(String[] args) {
056: junit.textui.TestRunner.run(CachedRowsetTest.class);
057: }
058:
059: /**
060: * Tests fix for BUG#5188, CachedRowSet errors using PreparedStatement. Uses
061: * Sun's "com.sun.rowset.CachedRowSetImpl"
062: *
063: * @throws Exception
064: */
065: public void testBug5188() throws Exception {
066: String implClass = "com.sun.rowset.CachedRowSetImpl";
067: Class c;
068: Method populate;
069: try {
070: c = Class.forName(implClass);
071: } catch (ClassNotFoundException e) {
072: System.out.println("skipping testBug5188. Requires: "
073: + implClass);
074: return;
075: }
076: populate = c.getMethod("populate",
077: new Class[] { ResultSet.class });
078:
079: try {
080: this .stmt.executeUpdate("DROP TABLE IF EXISTS testBug5188");
081: this .stmt.executeUpdate("CREATE TABLE testBug5188 "
082: + "(ID int NOT NULL AUTO_INCREMENT, "
083: + "datafield VARCHAR(64), " + "PRIMARY KEY(ID))");
084:
085: this .stmt
086: .executeUpdate("INSERT INTO testBug5188(datafield) "
087: + "values('test data stuff !')");
088:
089: String sql = "SELECT * FROM testBug5188 where ID = ?";
090: this .pstmt = this .conn.prepareStatement(sql);
091: this .pstmt.setString(1, "1");
092: this .rs = this .pstmt.executeQuery();
093:
094: // create a CachedRowSet and populate it
095: RowSet cachedRowSet = (RowSet) c.newInstance();
096: // cachedRowSet.populate(rs);
097: populate.invoke(cachedRowSet, new Object[] { this .rs });
098:
099: // scroll through CachedRowSet ...
100: assertTrue(cachedRowSet.next());
101: assertEquals("1", cachedRowSet.getString("ID"));
102: assertEquals("test data stuff !", cachedRowSet
103: .getString("datafield"));
104: assertFalse(cachedRowSet.next());
105: } finally {
106: this .stmt.executeUpdate("DROP TABLE IF EXISTS testBug5188");
107: }
108: }
109: }
|