001: /*
002: * $Id: TestForwardOnlyResultSet.java,v 1.2 2005/06/18 01:03:45 ahimanikya Exp $
003: * =======================================================================
004: * Copyright (c) 2005 Axion Development Team. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * 1. Redistributions of source code must retain the above
011: * copyright notice, this list of conditions and the following
012: * disclaimer.
013: *
014: * 2. Redistributions in binary form must reproduce the above copyright
015: * notice, this list of conditions and the following disclaimer in
016: * the documentation and/or other materials provided with the
017: * distribution.
018: *
019: * 3. The names "Tigris", "Axion", nor the names of its contributors may
020: * not be used to endorse or promote products derived from this
021: * software without specific prior written permission.
022: *
023: * 4. Products derived from this software may not be called "Axion", nor
024: * may "Tigris" or "Axion" appear in their names without specific prior
025: * written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
028: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
029: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
030: * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
031: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
032: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
033: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
034: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
035: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
036: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
037: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
038: * =======================================================================
039: */
040: package org.axiondb.jdbc;
041:
042: import java.sql.ResultSet;
043: import java.sql.SQLException;
044: import java.sql.Statement;
045:
046: import junit.framework.Test;
047: import junit.framework.TestSuite;
048:
049: /**
050: * Tests forward-only ResultSet decorator for AxionResultSet.
051: *
052: * @author Jonathan Giron
053: * @version $Revision: 1.2 $
054: */
055: public class TestForwardOnlyResultSet extends AxionTestCaseSupport {
056: private ResultSet _fwdOnlyRs;
057:
058: /**
059: * @param testName
060: */
061: public TestForwardOnlyResultSet(String testName) {
062: super (testName);
063: }
064:
065: public static Test suite() {
066: return new TestSuite(TestForwardOnlyResultSet.class);
067: }
068:
069: /* (non-Javadoc)
070: * @see junit.framework.TestCase#setUp()
071: */
072: public void setUp() throws Exception {
073: super .setUp();
074:
075: Statement stmt = getConnection()
076: .createStatement(ResultSet.TYPE_FORWARD_ONLY,
077: ResultSet.CONCUR_READ_ONLY);
078: stmt.execute("create table foo (id int, name varchar(50))");
079: stmt.execute("insert into foo values (1, 'my first line')");
080: stmt.execute("insert into foo values (2, 'my second line')");
081:
082: _fwdOnlyRs = stmt.executeQuery("select * from foo");
083: }
084:
085: /* (non-Javadoc)
086: * @see junit.framework.TestCase#tearDown()
087: */
088: public void tearDown() throws Exception {
089: super .tearDown();
090: }
091:
092: public void testAfterLast() {
093: try {
094: _fwdOnlyRs.afterLast();
095: fail("Expected SQLException.");
096: } catch (SQLException ignore) {
097: // expected.
098: }
099: }
100:
101: public void testBeforeFirst() {
102: try {
103: _fwdOnlyRs.beforeFirst();
104: fail("Expected SQLException.");
105: } catch (SQLException ignore) {
106: // expected.
107: }
108: }
109:
110: public void testFirst() {
111: try {
112: _fwdOnlyRs.first();
113: fail("Expected SQLException.");
114: } catch (SQLException ignore) {
115: // expected.
116: }
117: }
118:
119: public void testLast() {
120: try {
121: _fwdOnlyRs.last();
122: fail("Expected SQLException.");
123: } catch (SQLException ignore) {
124: // expected.
125: }
126: }
127:
128: public void testPrevious() {
129: try {
130: _fwdOnlyRs.previous();
131: fail("Expected SQLException.");
132: } catch (SQLException ignore) {
133: // expected.
134: }
135: }
136:
137: public void testSetFetchDirection() {
138: try {
139: _fwdOnlyRs.setFetchDirection(ResultSet.FETCH_REVERSE);
140: fail("Expected SQLException.");
141: } catch (SQLException ignore) {
142: // expected.
143: }
144:
145: }
146:
147: public void testAbsolute() {
148: try {
149: _fwdOnlyRs.absolute(15);
150: fail("Expected SQLException.");
151: } catch (SQLException ignore) {
152: // expected.
153: }
154: }
155:
156: public void testRelative() {
157: try {
158: _fwdOnlyRs.relative(-1);
159: fail("Expected SQLException.");
160: } catch (SQLException ignore) {
161: // expected.
162: }
163: }
164:
165: public void testIteration() throws SQLException {
166: assertTrue(_fwdOnlyRs.next());
167: assertTrue(_fwdOnlyRs.isFirst());
168:
169: int rowId = 1;
170: do {
171: try {
172: _fwdOnlyRs.previous();
173: fail("Expected SQLException.");
174: } catch (SQLException ignore) {
175: // expected.
176: }
177:
178: assertEquals(rowId++, _fwdOnlyRs.getInt(1));
179: } while (_fwdOnlyRs.next());
180: }
181: }
|