Update ooo320-m1
[ooovba.git] / qadevOOo / tests / java / ifc / sdbc / _XResultSet.java
blob03516aa88b6e6af9806a63497c0a6abb7dad7500
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XResultSet.java,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package ifc.sdbc;
33 import lib.MultiMethodTest;
35 import com.sun.star.sdbc.SQLException;
36 import com.sun.star.sdbc.XResultSet;
37 import com.sun.star.sdbc.XRow;
38 import com.sun.star.sdbc.XRowUpdate;
39 import com.sun.star.uno.UnoRuntime;
41 /**
42 /**
43 * Testing <code>com.sun.star.sdbc.XResultSet</code>
44 * interface methods :
45 * <ul>
46 * <li><code> next()</code></li>
47 * <li><code> isBeforeFirst()</code></li>
48 * <li><code> isAfterLast()</code></li>
49 * <li><code> isFirst()</code></li>
50 * <li><code> isLast()</code></li>
51 * <li><code> beforeFirst()</code></li>
52 * <li><code> afterLast()</code></li>
53 * <li><code> first()</code></li>
54 * <li><code> last()</code></li>
55 * <li><code> getRow()</code></li>
56 * <li><code> absolute()</code></li>
57 * <li><code> relative()</code></li>
58 * <li><code> previous()</code></li>
59 * <li><code> refreshRow()</code></li>
60 * <li><code> rowUpdated()</code></li>
61 * <li><code> rowInserted()</code></li>
62 * <li><code> rowDeleted()</code></li>
63 * <li><code> getStatement()</code></li>
64 * </ul> <p>
65 * This test needs the following object relations :
66 * <ul>
67 * <li> <code>'XResultSet.hasStatement'</code> (<b>optional</b> of type
68 * <code>Object</code>):
69 * it the relation exists than <code>getStatement</code> method
70 * must not return <code>null</code> </li>
71 * <ul> <p>
72 * Test places DB cursor to different positions and then checks
73 * its current position. <p>
74 * Test is <b> NOT </b> multithread compilant. <p>
75 * @see com.sun.star.sdbc.XResultSet
77 public class _XResultSet extends MultiMethodTest {
79 // oObj filled by MultiMethodTest
80 public XResultSet oObj = null ;
82 /**
83 * Positions the cursor to the first row.
84 * Forces method tests to be executed in definite order.
86 public void before() {
87 try {
88 oObj.last() ;
89 log.println("Totally number of rows is " + oObj.getRow()) ;
90 oObj.first() ;
91 } catch (SQLException e) {
92 log.println("Ignored exception :") ;
93 e.printStackTrace(log);
96 executeMethod("isBeforeFirst()") ;
97 executeMethod("isAfterLast()") ;
98 executeMethod("isLast()") ;
99 executeMethod("isFirst()") ;
100 executeMethod("next()") ;
101 executeMethod("previous()") ;
105 * Places the cursor before the first row. <p>
106 * Has <b>OK</b> status if no exceptions were thrown.
108 public void _beforeFirst() {
109 try {
110 oObj.beforeFirst() ;
111 } catch (SQLException e) {
112 log.println("Exception occured :") ;
113 e.printStackTrace(log) ;
114 tRes.tested("beforeFirst()", false) ;
115 return ;
117 tRes.tested("beforeFirst()", true) ;
121 * The method is called immediatly after <code>beforeFirst</code>
122 * method test. <p>
123 * Has <b>OK</b> status if method returns <code>true</code>. <p>
124 * The following method tests are to be completed successfully before :
125 * <ul>
126 * <li> <code> beforeFirst </code> : to position cursor before
127 * the first row. </li>
128 * </ul>
130 public void _isBeforeFirst() {
131 requiredMethod("beforeFirst()") ;
133 boolean result = true ;
135 try {
136 result = oObj.isBeforeFirst() ;
137 } catch (SQLException e) {
138 log.println("Exception occured :") ;
139 e.printStackTrace(log) ;
140 result = false ;
142 tRes.tested("isBeforeFirst()", result) ;
146 * Places the cursor after the last row. <p>
147 * Has <b>OK</b> status if no exceptions were thrown.
149 public void _afterLast() {
150 try {
151 oObj.afterLast() ;
152 } catch (SQLException e) {
153 log.println("Exception occured :") ;
154 e.printStackTrace(log) ;
155 tRes.tested("afterLast()", false) ;
156 return ;
158 tRes.tested("afterLast()", true) ;
162 * The method is called immediatly after <code>afterLast</code>
163 * method test. <p>
164 * Has <b>OK</b> status if method returns <code>true</code> <p>
165 * The following method tests are to be completed successfully before :
166 * <ul>
167 * <li> <code> afterLast </code> : to position cursor after
168 * the last row. </li>
169 * </ul>
171 public void _isAfterLast() {
172 requiredMethod("afterLast()") ;
174 boolean result = true ;
176 try {
177 result = oObj.isAfterLast() ;
178 } catch (SQLException e) {
179 log.println("Exception occured :") ;
180 e.printStackTrace(log) ;
181 result = false ;
183 tRes.tested("isAfterLast()", result) ;
187 * Places the cursor on the first row. <p>
188 * Has <b>OK</b> status if no exceptions were thrown.
190 public void _first() {
191 try {
192 oObj.first() ;
193 } catch (SQLException e) {
194 log.println("Exception occured :") ;
195 e.printStackTrace(log) ;
196 tRes.tested("first()", false) ;
197 return ;
199 tRes.tested("first()", true) ;
203 * The method is called immediatly after <code>first</code>
204 * method test. <p>
205 * Has <b>OK</b> status if method returns <code>true</code>. <p>
206 * The following method tests are to be completed successfully before :
207 * <ul>
208 * <li> <code> first </code> : to position cursor on
209 * the first row. </li>
210 * </ul>
212 public void _isFirst() {
213 requiredMethod("first()") ;
215 boolean result = true ;
217 try {
218 result = oObj.isFirst() ;
219 } catch (SQLException e) {
220 log.println("Exception occured :") ;
221 e.printStackTrace(log) ;
222 result = false ;
224 tRes.tested("isFirst()", result) ;
228 * Places the cursor on the last row. <p>
229 * Has <b>OK</b> status if no exceptions were thrown.
231 public void _last() {
232 try {
233 oObj.last() ;
234 } catch (SQLException e) {
235 log.println("Exception occured :") ;
236 e.printStackTrace(log) ;
237 tRes.tested("last()", false) ;
238 return ;
240 tRes.tested("last()", true) ;
244 * The method is called immediatly after <code>last</code>
245 * method test. <p>
246 * Has <b>OK</b> status if method returns <code>true</code>. <p>
247 * The following method tests are to be completed successfully before :
248 * <ul>
249 * <li> <code> last </code> : to position cursor on
250 * the last row. </li>
251 * </ul>
253 public void _isLast() {
254 requiredMethod("last()") ;
255 boolean result = true ;
257 try {
258 result = oObj.isLast() ;
259 } catch (SQLException e) {
260 log.println("Exception occured :") ;
261 e.printStackTrace(log) ;
262 result = false ;
264 tRes.tested("isLast()", result) ;
268 * Places the cursor on the row number 1. <p>
269 * Has <b>OK</b> status if no exceptions were thrown.
271 public void _absolute() {
272 boolean result = true ;
274 try {
275 oObj.absolute(1) ;
276 } catch (SQLException e) {
277 log.println("Exception occured :") ;
278 e.printStackTrace(log) ;
279 result = false ;
281 tRes.tested("absolute()", result) ;
285 * The method is called immediatly after <code>absolute</code>
286 * method test. <p>
287 * Has <b>OK</b> status if method returns 1. <p>
288 * The following method tests are to be completed successfully before :
289 * <ul>
290 * <li> <code> absolute </code> : to position cursor on
291 * the row number 1. </li>
292 * </ul>
294 public void _getRow() {
295 requiredMethod("absolute()");
296 boolean result = true;
298 try {
299 result &= oObj.getRow() == 1;
300 } catch (SQLException e) {
301 log.println("Exception occured:");
302 e.printStackTrace(log);
303 result = false;
306 tRes.tested("getRow()", result);
310 * Positions the cursor to the next row. Current row
311 * number is retrieved before and after method call. <p>
312 * Has <b>OK</b> status if current row number increases
313 * by 1 after method call.
315 public void _next() {
316 boolean result = true ;
318 try {
319 int prevRow = oObj.getRow() ;
320 oObj.next() ;
322 log.println("Row was : " + prevRow + ", row is : " + oObj.getRow());
323 result &= prevRow + 1 == oObj.getRow() ;
324 } catch (SQLException e) {
325 log.println("Exception occured :") ;
326 e.printStackTrace(log) ;
327 result = false ;
329 tRes.tested("next()", result) ;
333 * Positions the cursor to the previous row. Current row
334 * number is retrieved before and after method call. <p>
335 * Has <b>OK</b> status if current row number decreases
336 * by 1 after method call.
338 public void _previous() {
339 boolean result = true ;
341 try {
342 int prevRow = oObj.getRow() ;
343 oObj.previous() ;
345 log.println("Row was : " + prevRow + ", row is : " + oObj.getRow());
346 result &= prevRow - 1 == oObj.getRow() ;
347 } catch (SQLException e) {
348 log.println("Exception occured :") ;
349 e.printStackTrace(log) ;
350 result = false ;
352 tRes.tested("previous()", result) ;
356 * Positions the cursor relatively by 2 rows forward.
357 * Current row number is retrieved before and after method call. <p>
358 * Has <b>OK</b> status if current row number increases
359 * by 2 after method call.
361 public void _relative() {
362 boolean result = true ;
364 try {
365 oObj.first() ;
366 int prevRow = oObj.getRow() ;
367 oObj.relative(2) ;
369 log.println("Row was : " + prevRow + ", row is : " + oObj.getRow());
371 result &= prevRow + 2 == oObj.getRow() ;
372 } catch (SQLException e) {
373 log.println("Exception occured :") ;
374 e.printStackTrace(log) ;
375 result = false ;
377 tRes.tested("relative()", result) ;
381 * If component supports XRow and XRowUpdate then:
382 * test saves current value of string field, updates string,
383 * calls refreshRow() and checks that value of
384 * string field was refetched from DB
385 * else: just calls method.<p>
386 * Has <b>OK</b> status if no exceptions were thrown and value after
387 * refreshRow() equals to saved value.
389 public void _refreshRow() {
390 XRowUpdate xRowUpdate = (XRowUpdate)
391 UnoRuntime.queryInterface(XRowUpdate.class, oObj);
392 XRow xRow = (XRow)UnoRuntime.queryInterface(XRow.class, oObj);
394 if (xRowUpdate == null || xRow == null) {
395 log.println("Test must be modified because XRow or XRowUpdate is't supported");
396 log.println("Only call method");
397 try {
398 oObj.refreshRow() ;
399 tRes.tested("refreshRow()", true) ;
400 } catch (SQLException e) {
401 log.println("Exception occured :") ;
402 e.printStackTrace(log) ;
403 tRes.tested("refreshRow()", false) ;
405 } else {
406 log.println("Testing of refreshRow()...");
407 try {
408 String oldValue = xRow.getString(util.DBTools.TST_STRING);
409 log.println("Old value: " + oldValue);
410 xRowUpdate.updateString(util.DBTools.TST_STRING,
411 "Test method refreshRow");
412 log.println("New value: "
413 + xRow.getString(util.DBTools.TST_STRING));
414 oObj.refreshRow();
415 String valAfterRefresh =
416 xRow.getString(util.DBTools.TST_STRING);
417 log.println("Value after refresh: " + valAfterRefresh);
418 tRes.tested("refreshRow()", valAfterRefresh.equals(oldValue));
419 } catch(SQLException e) {
420 log.println("Exception occured :");
421 e.printStackTrace(log);
422 tRes.tested("refreshRow()", false);
428 * Just the method is called. <p>
429 * Has <b>OK</b> status if no exceptions were thrown.
431 public void _rowUpdated() {
433 try {
434 boolean res = oObj.rowUpdated() ;
435 tRes.tested("rowUpdated()", true) ;
436 } catch (SQLException e) {
437 log.println("Exception occured :") ;
438 e.printStackTrace(log) ;
439 tRes.tested("rowUpdated()", false) ;
444 * Just the method is called. <p>
445 * Has <b>OK</b> status if no exceptions were thrown.
447 public void _rowInserted() {
448 try {
449 boolean res = oObj.rowInserted() ;
450 tRes.tested("rowInserted()", true) ;
451 } catch (SQLException e) {
452 log.println("Exception occured :") ;
453 e.printStackTrace(log) ;
454 tRes.tested("rowInserted()", false) ;
459 * Just the method is called. <p>
460 * Has <b>OK</b> status if no exceptions were thrown.
462 public void _rowDeleted() {
463 try {
464 boolean res = oObj.rowDeleted() ;
465 tRes.tested("rowDeleted()", true) ;
466 } catch (SQLException e) {
467 log.println("Exception occured :") ;
468 e.printStackTrace(log) ;
469 tRes.tested("rowDeleted()", false) ;
474 * Just the method is called. <p>
475 * Has <b>OK</b> status if the statement returned isn't null or
476 * the relation exists that informs that statement absent (e.g. for
477 * MetaData row set).
479 public void _getStatement() {
480 try {
481 boolean hasStatement =
482 tEnv.getObjRelation("XResultSet.hasStatement") != null ;
483 Object res = oObj.getStatement() ;
484 tRes.tested("getStatement()",
485 (hasStatement && res != null) || !hasStatement) ;
486 } catch (SQLException e) {
487 log.println("Exception occured :") ;
488 e.printStackTrace(log) ;
489 tRes.tested("getStatement()", false) ;
494 * Moves the cursor to the first row to avoid affection to
495 * the following interfaces tests
497 public void after() {
498 log.println("Finally moving cursor to the first row ...");
499 try {
500 oObj.first();
501 } catch (SQLException e) {
502 log.println("Exception occured :") ;
503 e.printStackTrace(log) ;
507 } // finish class _XResultSet