001: package com.mockrunner.test.jdbc;
002:
003: import java.sql.ResultSet;
004: import java.sql.SQLException;
005: import java.util.ArrayList;
006: import java.util.List;
007:
008: import com.mockrunner.mock.jdbc.MockResultSet;
009: import com.mockrunner.mock.jdbc.PolyResultSet;
010:
011: import junit.framework.TestCase;
012:
013: public class PolyResultSetTest extends TestCase {
014: private List getTestResultSetList() {
015: List list = new ArrayList();
016: MockResultSet resultSet1 = new MockResultSet("id1");
017: resultSet1.addRow(new String[] { "id1row1column1",
018: "id1row1column2" });
019: resultSet1.addRow(new String[] { "id1row2column1",
020: "id1row2column2" });
021: MockResultSet resultSet2 = new MockResultSet("id2");
022: resultSet1.addRow(new String[] { "id2row1column1",
023: "id2row1column2" });
024: MockResultSet resultSet3 = new MockResultSet("id3");
025: resultSet1.addRow(new String[] { "id3row1column1",
026: "id3row1column2" });
027: resultSet1.addRow(new String[] { "id3row2column1",
028: "id3row2column2" });
029: resultSet1.addRow(new String[] { "id3row3column1",
030: "id3row3column2" });
031: list.add(resultSet1);
032: list.add(resultSet2);
033: list.add(resultSet3);
034: return list;
035: }
036:
037: public void testGetUnderlyingResultSetList() {
038: PolyResultSet resultSet = new PolyResultSet(
039: getTestResultSetList());
040: List resultSetList = resultSet.getUnderlyingResultSetList();
041: assertEquals(3, resultSetList.size());
042: MockResultSet resultSet1 = (MockResultSet) resultSetList.get(0);
043: MockResultSet resultSet2 = (MockResultSet) resultSetList.get(1);
044: MockResultSet resultSet3 = (MockResultSet) resultSetList.get(2);
045: assertEquals("id1", resultSet1.getId());
046: assertEquals("id2", resultSet2.getId());
047: assertEquals("id3", resultSet3.getId());
048: }
049:
050: public void testNext() throws Exception {
051: PolyResultSet resultSet = new PolyResultSet(new ArrayList());
052: assertFalse(resultSet.next());
053: assertFalse(resultSet.next());
054: resultSet = new PolyResultSet(getTestResultSetList());
055: assertTrue(resultSet.next());
056: assertEquals("id1row1column1", resultSet.getString(1));
057: assertEquals("id1row1column2", resultSet.getString(2));
058: assertTrue(resultSet.next());
059: assertEquals("id1row2column1", resultSet.getString(1));
060: assertEquals("id1row2column2", resultSet.getString(2));
061: assertTrue(resultSet.next());
062: assertEquals("id2row1column1", resultSet.getString(1));
063: assertEquals("id2row1column2", resultSet.getString(2));
064: assertTrue(resultSet.next());
065: assertEquals("id3row1column1", resultSet.getString(1));
066: assertEquals("id3row1column2", resultSet.getString(2));
067: assertTrue(resultSet.next());
068: assertEquals("id3row2column1", resultSet.getString(1));
069: assertEquals("id3row2column2", resultSet.getString(2));
070: assertTrue(resultSet.next());
071: assertEquals("id3row3column1", resultSet.getString(1));
072: assertEquals("id3row3column2", resultSet.getString(2));
073: assertFalse(resultSet.next());
074: assertFalse(resultSet.next());
075: }
076:
077: public void testIllegalMethods() throws Exception {
078: PolyResultSet resultSet = new PolyResultSet(
079: getTestResultSetList());
080: resultSet.next();
081: try {
082: resultSet.updateLong(1, 123);
083: fail();
084: } catch (SQLException exc) {
085: //should throw exception
086: }
087: try {
088: resultSet.first();
089: fail();
090: } catch (SQLException exc) {
091: //should throw exception
092: }
093: try {
094: resultSet.setFetchDirection(ResultSet.FETCH_FORWARD);
095: fail();
096: } catch (SQLException exc) {
097: //should throw exception
098: }
099: try {
100: resultSet.updateString(2, "abc");
101: fail();
102: } catch (SQLException exc) {
103: //should throw exception
104: }
105: try {
106: resultSet.refreshRow();
107: fail();
108: } catch (SQLException exc) {
109: //should throw exception
110: }
111: }
112: }
|