2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import lib
.MultiMethodTest
;
23 import com
.sun
.star
.sdbc
.SQLException
;
24 import com
.sun
.star
.sdbc
.XResultSet
;
25 import com
.sun
.star
.sdbc
.XRow
;
26 import com
.sun
.star
.sdbc
.XRowUpdate
;
27 import com
.sun
.star
.uno
.UnoRuntime
;
31 * Testing <code>com.sun.star.sdbc.XResultSet</code>
34 * <li><code> next()</code></li>
35 * <li><code> isBeforeFirst()</code></li>
36 * <li><code> isAfterLast()</code></li>
37 * <li><code> isFirst()</code></li>
38 * <li><code> isLast()</code></li>
39 * <li><code> beforeFirst()</code></li>
40 * <li><code> afterLast()</code></li>
41 * <li><code> first()</code></li>
42 * <li><code> last()</code></li>
43 * <li><code> getRow()</code></li>
44 * <li><code> absolute()</code></li>
45 * <li><code> relative()</code></li>
46 * <li><code> previous()</code></li>
47 * <li><code> refreshRow()</code></li>
48 * <li><code> rowUpdated()</code></li>
49 * <li><code> rowInserted()</code></li>
50 * <li><code> rowDeleted()</code></li>
51 * <li><code> getStatement()</code></li>
53 * This test needs the following object relations :
55 * <li> <code>'XResultSet.hasStatement'</code> (<b>optional</b> of type
56 * <code>Object</code>):
57 * it the relation exists than <code>getStatement</code> method
58 * must not return <code>null</code> </li>
60 * Test places DB cursor to different positions and then checks
61 * its current position. <p>
62 * Test is <b> NOT </b> multithread compliant. <p>
63 * @see com.sun.star.sdbc.XResultSet
65 public class _XResultSet
extends MultiMethodTest
{
67 // oObj filled by MultiMethodTest
68 public XResultSet oObj
= null ;
71 * Positions the cursor to the first row.
72 * Forces method tests to be executed in definite order.
75 public void before() {
78 log
.println("Totally number of rows is " + oObj
.getRow()) ;
80 } catch (SQLException e
) {
81 log
.println("Ignored exception :") ;
82 e
.printStackTrace(log
);
85 executeMethod("isBeforeFirst()") ;
86 executeMethod("isAfterLast()") ;
87 executeMethod("isLast()") ;
88 executeMethod("isFirst()") ;
89 executeMethod("next()") ;
90 executeMethod("previous()") ;
94 * Places the cursor before the first row. <p>
95 * Has <b>OK</b> status if no exceptions were thrown.
97 public void _beforeFirst() {
100 } catch (SQLException e
) {
101 log
.println("Exception occurred :") ;
102 e
.printStackTrace(log
) ;
103 tRes
.tested("beforeFirst()", false) ;
106 tRes
.tested("beforeFirst()", true) ;
110 * The method is called immediately after <code>beforeFirst</code>
112 * Has <b>OK</b> status if method returns <code>true</code>. <p>
113 * The following method tests are to be completed successfully before :
115 * <li> <code> beforeFirst </code> : to position cursor before
116 * the first row. </li>
119 public void _isBeforeFirst() {
120 requiredMethod("beforeFirst()") ;
122 boolean result
= true ;
125 result
= oObj
.isBeforeFirst() ;
126 } catch (SQLException e
) {
127 log
.println("Exception occurred :") ;
128 e
.printStackTrace(log
) ;
131 tRes
.tested("isBeforeFirst()", result
) ;
135 * Places the cursor after the last row. <p>
136 * Has <b>OK</b> status if no exceptions were thrown.
138 public void _afterLast() {
141 } catch (SQLException e
) {
142 log
.println("Exception occurred :") ;
143 e
.printStackTrace(log
) ;
144 tRes
.tested("afterLast()", false) ;
147 tRes
.tested("afterLast()", true) ;
151 * The method is called immediately after <code>afterLast</code>
153 * Has <b>OK</b> status if method returns <code>true</code> <p>
154 * The following method tests are to be completed successfully before :
156 * <li> <code> afterLast </code> : to position cursor after
157 * the last row. </li>
160 public void _isAfterLast() {
161 requiredMethod("afterLast()") ;
163 boolean result
= true ;
166 result
= oObj
.isAfterLast() ;
167 } catch (SQLException e
) {
168 log
.println("Exception occurred :") ;
169 e
.printStackTrace(log
) ;
172 tRes
.tested("isAfterLast()", result
) ;
176 * Places the cursor on the first row. <p>
177 * Has <b>OK</b> status if no exceptions were thrown.
179 public void _first() {
182 } catch (SQLException e
) {
183 log
.println("Exception occurred :") ;
184 e
.printStackTrace(log
) ;
185 tRes
.tested("first()", false) ;
188 tRes
.tested("first()", true) ;
192 * The method is called immediately after <code>first</code>
194 * Has <b>OK</b> status if method returns <code>true</code>. <p>
195 * The following method tests are to be completed successfully before :
197 * <li> <code> first </code> : to position cursor on
198 * the first row. </li>
201 public void _isFirst() {
202 requiredMethod("first()") ;
204 boolean result
= true ;
207 result
= oObj
.isFirst() ;
208 } catch (SQLException e
) {
209 log
.println("Exception occurred :") ;
210 e
.printStackTrace(log
) ;
213 tRes
.tested("isFirst()", result
) ;
217 * Places the cursor on the last row. <p>
218 * Has <b>OK</b> status if no exceptions were thrown.
220 public void _last() {
223 } catch (SQLException e
) {
224 log
.println("Exception occurred :") ;
225 e
.printStackTrace(log
) ;
226 tRes
.tested("last()", false) ;
229 tRes
.tested("last()", true) ;
233 * The method is called immediately after <code>last</code>
235 * Has <b>OK</b> status if method returns <code>true</code>. <p>
236 * The following method tests are to be completed successfully before :
238 * <li> <code> last </code> : to position cursor on
239 * the last row. </li>
242 public void _isLast() {
243 requiredMethod("last()") ;
244 boolean result
= true ;
247 result
= oObj
.isLast() ;
248 } catch (SQLException e
) {
249 log
.println("Exception occurred :") ;
250 e
.printStackTrace(log
) ;
253 tRes
.tested("isLast()", result
) ;
257 * Places the cursor on the row number 1. <p>
258 * Has <b>OK</b> status if no exceptions were thrown.
260 public void _absolute() {
261 boolean result
= true ;
265 } catch (SQLException e
) {
266 log
.println("Exception occurred :") ;
267 e
.printStackTrace(log
) ;
270 tRes
.tested("absolute()", result
) ;
274 * The method is called immediately after <code>absolute</code>
276 * Has <b>OK</b> status if method returns 1. <p>
277 * The following method tests are to be completed successfully before :
279 * <li> <code> absolute </code> : to position cursor on
280 * the row number 1. </li>
283 public void _getRow() {
284 requiredMethod("absolute()");
285 boolean result
= true;
288 result
&= oObj
.getRow() == 1;
289 } catch (SQLException e
) {
290 log
.println("Exception occurred:");
291 e
.printStackTrace(log
);
295 tRes
.tested("getRow()", result
);
299 * Positions the cursor to the next row. Current row
300 * number is retrieved before and after method call. <p>
301 * Has <b>OK</b> status if current row number increases
302 * by 1 after method call.
304 public void _next() {
305 boolean result
= true ;
308 int prevRow
= oObj
.getRow() ;
311 log
.println("Row was : " + prevRow
+ ", row is : " + oObj
.getRow());
312 result
&= prevRow
+ 1 == oObj
.getRow() ;
313 } catch (SQLException e
) {
314 log
.println("Exception occurred :") ;
315 e
.printStackTrace(log
) ;
318 tRes
.tested("next()", result
) ;
322 * Positions the cursor to the previous row. Current row
323 * number is retrieved before and after method call. <p>
324 * Has <b>OK</b> status if current row number decreases
325 * by 1 after method call.
327 public void _previous() {
328 boolean result
= true ;
331 int prevRow
= oObj
.getRow() ;
334 log
.println("Row was : " + prevRow
+ ", row is : " + oObj
.getRow());
335 result
&= prevRow
- 1 == oObj
.getRow() ;
336 } catch (SQLException e
) {
337 log
.println("Exception occurred :") ;
338 e
.printStackTrace(log
) ;
341 tRes
.tested("previous()", result
) ;
345 * Positions the cursor relatively by 2 rows forward.
346 * Current row number is retrieved before and after method call. <p>
347 * Has <b>OK</b> status if current row number increases
348 * by 2 after method call.
350 public void _relative() {
351 boolean result
= true ;
355 int prevRow
= oObj
.getRow() ;
358 log
.println("Row was : " + prevRow
+ ", row is : " + oObj
.getRow());
360 result
&= prevRow
+ 2 == oObj
.getRow() ;
361 } catch (SQLException e
) {
362 log
.println("Exception occurred :") ;
363 e
.printStackTrace(log
) ;
366 tRes
.tested("relative()", result
) ;
370 * If component supports XRow and XRowUpdate then:
371 * test saves current value of string field, updates string,
372 * calls refreshRow() and checks that value of
373 * string field was refetched from DB
374 * else: just calls method.<p>
375 * Has <b>OK</b> status if no exceptions were thrown and value after
376 * refreshRow() equals to saved value.
378 public void _refreshRow() {
379 XRowUpdate xRowUpdate
= UnoRuntime
.queryInterface(XRowUpdate
.class, oObj
);
380 XRow xRow
= UnoRuntime
.queryInterface(XRow
.class, oObj
);
382 if (xRowUpdate
== null || xRow
== null) {
383 log
.println("Test must be modified because XRow or XRowUpdate is't supported");
384 log
.println("Only call method");
387 tRes
.tested("refreshRow()", true) ;
388 } catch (SQLException e
) {
389 log
.println("Exception occurred :") ;
390 e
.printStackTrace(log
) ;
391 tRes
.tested("refreshRow()", false) ;
394 log
.println("Testing of refreshRow()...");
396 String oldValue
= xRow
.getString(util
.DBTools
.TST_STRING
);
397 log
.println("Old value: " + oldValue
);
398 xRowUpdate
.updateString(util
.DBTools
.TST_STRING
,
399 "Test method refreshRow");
400 log
.println("New value: "
401 + xRow
.getString(util
.DBTools
.TST_STRING
));
403 String valAfterRefresh
=
404 xRow
.getString(util
.DBTools
.TST_STRING
);
405 log
.println("Value after refresh: " + valAfterRefresh
);
406 tRes
.tested("refreshRow()", valAfterRefresh
.equals(oldValue
));
407 } catch(SQLException e
) {
408 log
.println("Exception occurred :");
409 e
.printStackTrace(log
);
410 tRes
.tested("refreshRow()", false);
416 * Just the method is called. <p>
417 * Has <b>OK</b> status if no exceptions were thrown.
419 public void _rowUpdated() {
423 tRes
.tested("rowUpdated()", true) ;
424 } catch (SQLException e
) {
425 log
.println("Exception occurred :") ;
426 e
.printStackTrace(log
) ;
427 tRes
.tested("rowUpdated()", false) ;
432 * Just the method is called. <p>
433 * Has <b>OK</b> status if no exceptions were thrown.
435 public void _rowInserted() {
438 tRes
.tested("rowInserted()", true) ;
439 } catch (SQLException e
) {
440 log
.println("Exception occurred :") ;
441 e
.printStackTrace(log
) ;
442 tRes
.tested("rowInserted()", false) ;
447 * Just the method is called. <p>
448 * Has <b>OK</b> status if no exceptions were thrown.
450 public void _rowDeleted() {
453 tRes
.tested("rowDeleted()", true) ;
454 } catch (SQLException e
) {
455 log
.println("Exception occurred :") ;
456 e
.printStackTrace(log
) ;
457 tRes
.tested("rowDeleted()", false) ;
462 * Just the method is called. <p>
463 * Has <b>OK</b> status if the statement returned isn't null or
464 * the relation exists that informs that statement absent (e.g. for
467 public void _getStatement() {
469 boolean hasStatement
=
470 tEnv
.getObjRelation("XResultSet.hasStatement") != null ;
471 Object res
= oObj
.getStatement() ;
472 tRes
.tested("getStatement()",
473 (hasStatement
&& res
!= null) || !hasStatement
) ;
474 } catch (SQLException e
) {
475 log
.println("Exception occurred :") ;
476 e
.printStackTrace(log
) ;
477 tRes
.tested("getStatement()", false) ;
482 * Moves the cursor to the first row to avoid affection to
483 * the following interfaces tests
486 public void after() {
487 log
.println("Finally moving cursor to the first row ...");
490 } catch (SQLException e
) {
491 log
.println("Exception occurred :") ;
492 e
.printStackTrace(log
) ;
496 } // finish class _XResultSet