1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XResultSet.java,v $
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 ************************************************************************/
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
;
43 * Testing <code>com.sun.star.sdbc.XResultSet</code>
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>
65 * This test needs the following object relations :
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>
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 ;
83 * Positions the cursor to the first row.
84 * Forces method tests to be executed in definite order.
86 public void before() {
89 log
.println("Totally number of rows is " + oObj
.getRow()) ;
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() {
111 } catch (SQLException e
) {
112 log
.println("Exception occured :") ;
113 e
.printStackTrace(log
) ;
114 tRes
.tested("beforeFirst()", false) ;
117 tRes
.tested("beforeFirst()", true) ;
121 * The method is called immediatly after <code>beforeFirst</code>
123 * Has <b>OK</b> status if method returns <code>true</code>. <p>
124 * The following method tests are to be completed successfully before :
126 * <li> <code> beforeFirst </code> : to position cursor before
127 * the first row. </li>
130 public void _isBeforeFirst() {
131 requiredMethod("beforeFirst()") ;
133 boolean result
= true ;
136 result
= oObj
.isBeforeFirst() ;
137 } catch (SQLException e
) {
138 log
.println("Exception occured :") ;
139 e
.printStackTrace(log
) ;
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() {
152 } catch (SQLException e
) {
153 log
.println("Exception occured :") ;
154 e
.printStackTrace(log
) ;
155 tRes
.tested("afterLast()", false) ;
158 tRes
.tested("afterLast()", true) ;
162 * The method is called immediatly after <code>afterLast</code>
164 * Has <b>OK</b> status if method returns <code>true</code> <p>
165 * The following method tests are to be completed successfully before :
167 * <li> <code> afterLast </code> : to position cursor after
168 * the last row. </li>
171 public void _isAfterLast() {
172 requiredMethod("afterLast()") ;
174 boolean result
= true ;
177 result
= oObj
.isAfterLast() ;
178 } catch (SQLException e
) {
179 log
.println("Exception occured :") ;
180 e
.printStackTrace(log
) ;
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() {
193 } catch (SQLException e
) {
194 log
.println("Exception occured :") ;
195 e
.printStackTrace(log
) ;
196 tRes
.tested("first()", false) ;
199 tRes
.tested("first()", true) ;
203 * The method is called immediatly after <code>first</code>
205 * Has <b>OK</b> status if method returns <code>true</code>. <p>
206 * The following method tests are to be completed successfully before :
208 * <li> <code> first </code> : to position cursor on
209 * the first row. </li>
212 public void _isFirst() {
213 requiredMethod("first()") ;
215 boolean result
= true ;
218 result
= oObj
.isFirst() ;
219 } catch (SQLException e
) {
220 log
.println("Exception occured :") ;
221 e
.printStackTrace(log
) ;
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() {
234 } catch (SQLException e
) {
235 log
.println("Exception occured :") ;
236 e
.printStackTrace(log
) ;
237 tRes
.tested("last()", false) ;
240 tRes
.tested("last()", true) ;
244 * The method is called immediatly after <code>last</code>
246 * Has <b>OK</b> status if method returns <code>true</code>. <p>
247 * The following method tests are to be completed successfully before :
249 * <li> <code> last </code> : to position cursor on
250 * the last row. </li>
253 public void _isLast() {
254 requiredMethod("last()") ;
255 boolean result
= true ;
258 result
= oObj
.isLast() ;
259 } catch (SQLException e
) {
260 log
.println("Exception occured :") ;
261 e
.printStackTrace(log
) ;
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 ;
276 } catch (SQLException e
) {
277 log
.println("Exception occured :") ;
278 e
.printStackTrace(log
) ;
281 tRes
.tested("absolute()", result
) ;
285 * The method is called immediatly after <code>absolute</code>
287 * Has <b>OK</b> status if method returns 1. <p>
288 * The following method tests are to be completed successfully before :
290 * <li> <code> absolute </code> : to position cursor on
291 * the row number 1. </li>
294 public void _getRow() {
295 requiredMethod("absolute()");
296 boolean result
= true;
299 result
&= oObj
.getRow() == 1;
300 } catch (SQLException e
) {
301 log
.println("Exception occured:");
302 e
.printStackTrace(log
);
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 ;
319 int prevRow
= oObj
.getRow() ;
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
) ;
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 ;
342 int prevRow
= oObj
.getRow() ;
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
) ;
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 ;
366 int prevRow
= oObj
.getRow() ;
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
) ;
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");
399 tRes
.tested("refreshRow()", true) ;
400 } catch (SQLException e
) {
401 log
.println("Exception occured :") ;
402 e
.printStackTrace(log
) ;
403 tRes
.tested("refreshRow()", false) ;
406 log
.println("Testing of refreshRow()...");
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
));
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() {
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() {
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() {
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
479 public void _getStatement() {
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 ...");
501 } catch (SQLException e
) {
502 log
.println("Exception occured :") ;
503 e
.printStackTrace(log
) ;
507 } // finish class _XResultSet