KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > smallsql > junit > TestScrollable


1 /* =============================================================
2  * SmallSQL : a free Java DBMS library for the Java(tm) platform
3  * =============================================================
4  *
5  * (C) Copyright 2004-2006, by Volker Berlin.
6  *
7  * Project Info: http://www.smallsql.de/
8  *
9  * This library is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22  * USA.
23  *
24  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
25  * in the United States and other countries.]
26  *
27  * ---------------
28  * TestScrollable.java
29  * ---------------
30  * Author: Volker Berlin
31  *
32  * Created on 14.08.2004
33  */

34 package smallsql.junit;
35
36 import java.sql.*;
37
38 /**
39  * @author Volker Berlin
40  */

41 public class TestScrollable extends BasicTestCase {
42     
43     public void testLastWithWhere() throws Exception JavaDoc{
44         Connection con = AllTests.getConnection();
45         try{
46             con.createStatement().execute("Create Table Scrollable (i counter, v varchar(20))");
47             assertRowCount( 0, "Select * from Scrollable");
48
49             con.createStatement().execute("Insert Into Scrollable(v) Values('qwert')");
50             assertRowCount( 1, "Select * from Scrollable");
51             assertRowCount( 0, "Select * from Scrollable Where 1=0");
52
53             ResultSet rs = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)
54                                 .executeQuery("Select * from Scrollable Where 1=0");
55             
56             assertFalse("There should be no rows:", rs.last());
57             try{
58                 rs.getString("v");
59                 fail("SQLException 'No current row' should be throw");
60             }catch(SQLException e){
61                 //TODO check error code of "No current row"
62
}
63         }finally{
64             dropTable( con, "Scrollable");
65         }
66     }
67     
68
69     public void testNextWithWhere() throws Exception JavaDoc{
70         Connection con = AllTests.getConnection();
71         try{
72             con.createStatement().execute("Create Table Scrollable (i counter, v varchar(20))");
73             assertRowCount( 0, "Select * from Scrollable");
74
75             con.createStatement().execute("Insert Into Scrollable(v) Values('qwert')");
76             assertRowCount( 1, "Select * from Scrollable");
77             assertRowCount( 0, "Select * from Scrollable Where 1=0");
78
79             ResultSet rs = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)
80                                 .executeQuery("Select * from Scrollable Where 1=0");
81             
82             assertFalse("There should be no rows:", rs.next());
83             try{
84                 rs.getString("v");
85                 fail("SQLException 'No current row' should be throw");
86             }catch(SQLException e){
87                 //TODO check error code of "No current row"
88
}
89         }finally{
90             dropTable( con, "Scrollable");
91         }
92     }
93     
94     
95     public void testFirstWithWhere() throws Exception JavaDoc{
96         Connection con = AllTests.getConnection();
97         try{
98             con.createStatement().execute("Create Table Scrollable (i counter, v varchar(20))");
99             assertRowCount( 0, "Select * from Scrollable");
100
101             con.createStatement().execute("Insert Into Scrollable(v) Values('qwert')");
102             assertRowCount( 1, "Select * from Scrollable");
103             assertRowCount( 0, "Select * from Scrollable Where 1=0");
104
105             ResultSet rs = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)
106                                 .executeQuery("Select * from Scrollable Where 1=0");
107             
108             assertFalse("There should be no rows:", rs.first());
109             try{
110                 rs.getString("v");
111                 fail("SQLException 'No current row' should be throw");
112             }catch(SQLException e){
113                 //TODO check error code of "No current row"
114
}
115         }finally{
116             dropTable( con, "Scrollable");
117         }
118     }
119
120
121     public void testPreviousWithWhere() throws Exception JavaDoc{
122         Connection con = AllTests.getConnection();
123         try{
124             con.createStatement().execute("Create Table Scrollable (i counter, v varchar(20))");
125             assertRowCount( 0, "Select * from Scrollable");
126
127             con.createStatement().execute("Insert Into Scrollable(v) Values('qwert')");
128             assertRowCount( 1, "Select * from Scrollable");
129             assertRowCount( 0, "Select * from Scrollable Where 1=0");
130
131             ResultSet rs = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)
132                                 .executeQuery("Select * from Scrollable Where 1=0");
133             
134             rs.afterLast();
135             assertFalse("There should be no rows:", rs.previous());
136             try{
137                 rs.getString("v");
138                 fail("SQLException 'No current row' should be throw");
139             }catch(SQLException e){
140                 //TODO check error code of "No current row"
141
}
142         }finally{
143             dropTable( con, "Scrollable");
144         }
145     }
146
147
148     public void testAbsolute() throws Exception JavaDoc{
149         Connection con = AllTests.getConnection();
150         try{
151             con.createStatement().execute("Create Table Scrollable (i counter, v varchar(20))");
152             assertRowCount( 0, "Select * from Scrollable");
153
154             con.createStatement().execute("Insert Into Scrollable(v) Values('qwert1')");
155             con.createStatement().execute("Insert Into Scrollable(v) Values('qwert2')");
156             con.createStatement().execute("Insert Into Scrollable(v) Values('qwert3')");
157
158             ResultSet rs = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)
159                                 .executeQuery("Select * from Scrollable");
160             
161             assertTrue(rs.absolute(2));
162             assertEquals("qwert2", rs.getString("v"));
163
164             assertTrue(rs.absolute(1));
165             assertEquals("qwert1", rs.getString("v"));
166
167             assertTrue(rs.absolute(-1));
168             assertEquals("qwert3", rs.getString("v"));
169
170             assertFalse(rs.absolute(4));
171         }finally{
172             dropTable( con, "Scrollable");
173         }
174     }
175
176
177 }
178
Popular Tags