1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
30 import lib
.MultiMethodTest
;
32 import com
.sun
.star
.sdbc
.SQLException
;
33 import com
.sun
.star
.sdbc
.XResultSet
;
34 import com
.sun
.star
.sdbc
.XRow
;
35 import com
.sun
.star
.sdbc
.XRowUpdate
;
36 import com
.sun
.star
.uno
.UnoRuntime
;
40 * Testing <code>com.sun.star.sdbc.XResultSet</code>
43 * <li><code> next()</code></li>
44 * <li><code> isBeforeFirst()</code></li>
45 * <li><code> isAfterLast()</code></li>
46 * <li><code> isFirst()</code></li>
47 * <li><code> isLast()</code></li>
48 * <li><code> beforeFirst()</code></li>
49 * <li><code> afterLast()</code></li>
50 * <li><code> first()</code></li>
51 * <li><code> last()</code></li>
52 * <li><code> getRow()</code></li>
53 * <li><code> absolute()</code></li>
54 * <li><code> relative()</code></li>
55 * <li><code> previous()</code></li>
56 * <li><code> refreshRow()</code></li>
57 * <li><code> rowUpdated()</code></li>
58 * <li><code> rowInserted()</code></li>
59 * <li><code> rowDeleted()</code></li>
60 * <li><code> getStatement()</code></li>
62 * This test needs the following object relations :
64 * <li> <code>'XResultSet.hasStatement'</code> (<b>optional</b> of type
65 * <code>Object</code>):
66 * it the relation exists than <code>getStatement</code> method
67 * must not return <code>null</code> </li>
69 * Test places DB cursor to different positions and then checks
70 * its current position. <p>
71 * Test is <b> NOT </b> multithread compilant. <p>
72 * @see com.sun.star.sdbc.XResultSet
74 public class _XResultSet
extends MultiMethodTest
{
76 // oObj filled by MultiMethodTest
77 public XResultSet oObj
= null ;
80 * Positions the cursor to the first row.
81 * Forces method tests to be executed in definite order.
83 public void before() {
86 log
.println("Totally number of rows is " + oObj
.getRow()) ;
88 } catch (SQLException e
) {
89 log
.println("Ignored exception :") ;
90 e
.printStackTrace(log
);
93 executeMethod("isBeforeFirst()") ;
94 executeMethod("isAfterLast()") ;
95 executeMethod("isLast()") ;
96 executeMethod("isFirst()") ;
97 executeMethod("next()") ;
98 executeMethod("previous()") ;
102 * Places the cursor before the first row. <p>
103 * Has <b>OK</b> status if no exceptions were thrown.
105 public void _beforeFirst() {
108 } catch (SQLException e
) {
109 log
.println("Exception occurred :") ;
110 e
.printStackTrace(log
) ;
111 tRes
.tested("beforeFirst()", false) ;
114 tRes
.tested("beforeFirst()", true) ;
118 * The method is called immediatly after <code>beforeFirst</code>
120 * Has <b>OK</b> status if method returns <code>true</code>. <p>
121 * The following method tests are to be completed successfully before :
123 * <li> <code> beforeFirst </code> : to position cursor before
124 * the first row. </li>
127 public void _isBeforeFirst() {
128 requiredMethod("beforeFirst()") ;
130 boolean result
= true ;
133 result
= oObj
.isBeforeFirst() ;
134 } catch (SQLException e
) {
135 log
.println("Exception occurred :") ;
136 e
.printStackTrace(log
) ;
139 tRes
.tested("isBeforeFirst()", result
) ;
143 * Places the cursor after the last row. <p>
144 * Has <b>OK</b> status if no exceptions were thrown.
146 public void _afterLast() {
149 } catch (SQLException e
) {
150 log
.println("Exception occurred :") ;
151 e
.printStackTrace(log
) ;
152 tRes
.tested("afterLast()", false) ;
155 tRes
.tested("afterLast()", true) ;
159 * The method is called immediatly after <code>afterLast</code>
161 * Has <b>OK</b> status if method returns <code>true</code> <p>
162 * The following method tests are to be completed successfully before :
164 * <li> <code> afterLast </code> : to position cursor after
165 * the last row. </li>
168 public void _isAfterLast() {
169 requiredMethod("afterLast()") ;
171 boolean result
= true ;
174 result
= oObj
.isAfterLast() ;
175 } catch (SQLException e
) {
176 log
.println("Exception occurred :") ;
177 e
.printStackTrace(log
) ;
180 tRes
.tested("isAfterLast()", result
) ;
184 * Places the cursor on the first row. <p>
185 * Has <b>OK</b> status if no exceptions were thrown.
187 public void _first() {
190 } catch (SQLException e
) {
191 log
.println("Exception occurred :") ;
192 e
.printStackTrace(log
) ;
193 tRes
.tested("first()", false) ;
196 tRes
.tested("first()", true) ;
200 * The method is called immediatly after <code>first</code>
202 * Has <b>OK</b> status if method returns <code>true</code>. <p>
203 * The following method tests are to be completed successfully before :
205 * <li> <code> first </code> : to position cursor on
206 * the first row. </li>
209 public void _isFirst() {
210 requiredMethod("first()") ;
212 boolean result
= true ;
215 result
= oObj
.isFirst() ;
216 } catch (SQLException e
) {
217 log
.println("Exception occurred :") ;
218 e
.printStackTrace(log
) ;
221 tRes
.tested("isFirst()", result
) ;
225 * Places the cursor on the last row. <p>
226 * Has <b>OK</b> status if no exceptions were thrown.
228 public void _last() {
231 } catch (SQLException e
) {
232 log
.println("Exception occurred :") ;
233 e
.printStackTrace(log
) ;
234 tRes
.tested("last()", false) ;
237 tRes
.tested("last()", true) ;
241 * The method is called immediatly after <code>last</code>
243 * Has <b>OK</b> status if method returns <code>true</code>. <p>
244 * The following method tests are to be completed successfully before :
246 * <li> <code> last </code> : to position cursor on
247 * the last row. </li>
250 public void _isLast() {
251 requiredMethod("last()") ;
252 boolean result
= true ;
255 result
= oObj
.isLast() ;
256 } catch (SQLException e
) {
257 log
.println("Exception occurred :") ;
258 e
.printStackTrace(log
) ;
261 tRes
.tested("isLast()", result
) ;
265 * Places the cursor on the row number 1. <p>
266 * Has <b>OK</b> status if no exceptions were thrown.
268 public void _absolute() {
269 boolean result
= true ;
273 } catch (SQLException e
) {
274 log
.println("Exception occurred :") ;
275 e
.printStackTrace(log
) ;
278 tRes
.tested("absolute()", result
) ;
282 * The method is called immediatly after <code>absolute</code>
284 * Has <b>OK</b> status if method returns 1. <p>
285 * The following method tests are to be completed successfully before :
287 * <li> <code> absolute </code> : to position cursor on
288 * the row number 1. </li>
291 public void _getRow() {
292 requiredMethod("absolute()");
293 boolean result
= true;
296 result
&= oObj
.getRow() == 1;
297 } catch (SQLException e
) {
298 log
.println("Exception occurred:");
299 e
.printStackTrace(log
);
303 tRes
.tested("getRow()", result
);
307 * Positions the cursor to the next row. Current row
308 * number is retrieved before and after method call. <p>
309 * Has <b>OK</b> status if current row number increases
310 * by 1 after method call.
312 public void _next() {
313 boolean result
= true ;
316 int prevRow
= oObj
.getRow() ;
319 log
.println("Row was : " + prevRow
+ ", row is : " + oObj
.getRow());
320 result
&= prevRow
+ 1 == oObj
.getRow() ;
321 } catch (SQLException e
) {
322 log
.println("Exception occurred :") ;
323 e
.printStackTrace(log
) ;
326 tRes
.tested("next()", result
) ;
330 * Positions the cursor to the previous row. Current row
331 * number is retrieved before and after method call. <p>
332 * Has <b>OK</b> status if current row number decreases
333 * by 1 after method call.
335 public void _previous() {
336 boolean result
= true ;
339 int prevRow
= oObj
.getRow() ;
342 log
.println("Row was : " + prevRow
+ ", row is : " + oObj
.getRow());
343 result
&= prevRow
- 1 == oObj
.getRow() ;
344 } catch (SQLException e
) {
345 log
.println("Exception occurred :") ;
346 e
.printStackTrace(log
) ;
349 tRes
.tested("previous()", result
) ;
353 * Positions the cursor relatively by 2 rows forward.
354 * Current row number is retrieved before and after method call. <p>
355 * Has <b>OK</b> status if current row number increases
356 * by 2 after method call.
358 public void _relative() {
359 boolean result
= true ;
363 int prevRow
= oObj
.getRow() ;
366 log
.println("Row was : " + prevRow
+ ", row is : " + oObj
.getRow());
368 result
&= prevRow
+ 2 == oObj
.getRow() ;
369 } catch (SQLException e
) {
370 log
.println("Exception occurred :") ;
371 e
.printStackTrace(log
) ;
374 tRes
.tested("relative()", result
) ;
378 * If component supports XRow and XRowUpdate then:
379 * test saves current value of string field, updates string,
380 * calls refreshRow() and checks that value of
381 * string field was refetched from DB
382 * else: just calls method.<p>
383 * Has <b>OK</b> status if no exceptions were thrown and value after
384 * refreshRow() equals to saved value.
386 public void _refreshRow() {
387 XRowUpdate xRowUpdate
= (XRowUpdate
)
388 UnoRuntime
.queryInterface(XRowUpdate
.class, oObj
);
389 XRow xRow
= (XRow
)UnoRuntime
.queryInterface(XRow
.class, oObj
);
391 if (xRowUpdate
== null || xRow
== null) {
392 log
.println("Test must be modified because XRow or XRowUpdate is't supported");
393 log
.println("Only call method");
396 tRes
.tested("refreshRow()", true) ;
397 } catch (SQLException e
) {
398 log
.println("Exception occurred :") ;
399 e
.printStackTrace(log
) ;
400 tRes
.tested("refreshRow()", false) ;
403 log
.println("Testing of refreshRow()...");
405 String oldValue
= xRow
.getString(util
.DBTools
.TST_STRING
);
406 log
.println("Old value: " + oldValue
);
407 xRowUpdate
.updateString(util
.DBTools
.TST_STRING
,
408 "Test method refreshRow");
409 log
.println("New value: "
410 + xRow
.getString(util
.DBTools
.TST_STRING
));
412 String valAfterRefresh
=
413 xRow
.getString(util
.DBTools
.TST_STRING
);
414 log
.println("Value after refresh: " + valAfterRefresh
);
415 tRes
.tested("refreshRow()", valAfterRefresh
.equals(oldValue
));
416 } catch(SQLException e
) {
417 log
.println("Exception occurred :");
418 e
.printStackTrace(log
);
419 tRes
.tested("refreshRow()", false);
425 * Just the method is called. <p>
426 * Has <b>OK</b> status if no exceptions were thrown.
428 public void _rowUpdated() {
431 boolean res
= oObj
.rowUpdated() ;
432 tRes
.tested("rowUpdated()", true) ;
433 } catch (SQLException e
) {
434 log
.println("Exception occurred :") ;
435 e
.printStackTrace(log
) ;
436 tRes
.tested("rowUpdated()", false) ;
441 * Just the method is called. <p>
442 * Has <b>OK</b> status if no exceptions were thrown.
444 public void _rowInserted() {
446 boolean res
= oObj
.rowInserted() ;
447 tRes
.tested("rowInserted()", true) ;
448 } catch (SQLException e
) {
449 log
.println("Exception occurred :") ;
450 e
.printStackTrace(log
) ;
451 tRes
.tested("rowInserted()", false) ;
456 * Just the method is called. <p>
457 * Has <b>OK</b> status if no exceptions were thrown.
459 public void _rowDeleted() {
461 boolean res
= oObj
.rowDeleted() ;
462 tRes
.tested("rowDeleted()", true) ;
463 } catch (SQLException e
) {
464 log
.println("Exception occurred :") ;
465 e
.printStackTrace(log
) ;
466 tRes
.tested("rowDeleted()", false) ;
471 * Just the method is called. <p>
472 * Has <b>OK</b> status if the statement returned isn't null or
473 * the relation exists that informs that statement absent (e.g. for
476 public void _getStatement() {
478 boolean hasStatement
=
479 tEnv
.getObjRelation("XResultSet.hasStatement") != null ;
480 Object res
= oObj
.getStatement() ;
481 tRes
.tested("getStatement()",
482 (hasStatement
&& res
!= null) || !hasStatement
) ;
483 } catch (SQLException e
) {
484 log
.println("Exception occurred :") ;
485 e
.printStackTrace(log
) ;
486 tRes
.tested("getStatement()", false) ;
491 * Moves the cursor to the first row to avoid affection to
492 * the following interfaces tests
494 public void after() {
495 log
.println("Finally moving cursor to the first row ...");
498 } catch (SQLException e
) {
499 log
.println("Exception occurred :") ;
500 e
.printStackTrace(log
) ;
504 } // finish class _XResultSet