bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / sdbc / _XResultSet.java
bloba2114d7d0a6ecf52a985c6540db14fa6649e94d6
1 /*
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 .
19 package ifc.sdbc;
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;
29 /**
30 /**
31 * Testing <code>com.sun.star.sdbc.XResultSet</code>
32 * interface methods :
33 * <ul>
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>
52 * </ul> <p>
53 * This test needs the following object relations :
54 * <ul>
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>
59 * <ul> <p>
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 ;
70 /**
71 * Positions the cursor to the first row.
72 * Forces method tests to be executed in definite order.
74 @Override
75 public void before() {
76 try {
77 oObj.last() ;
78 log.println("Totally number of rows is " + oObj.getRow()) ;
79 oObj.first() ;
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()") ;
93 /**
94 * Places the cursor before the first row. <p>
95 * Has <b>OK</b> status if no exceptions were thrown.
97 public void _beforeFirst() {
98 try {
99 oObj.beforeFirst() ;
100 } catch (SQLException e) {
101 log.println("Exception occurred :") ;
102 e.printStackTrace(log) ;
103 tRes.tested("beforeFirst()", false) ;
104 return ;
106 tRes.tested("beforeFirst()", true) ;
110 * The method is called immediately after <code>beforeFirst</code>
111 * method test. <p>
112 * Has <b>OK</b> status if method returns <code>true</code>. <p>
113 * The following method tests are to be completed successfully before :
114 * <ul>
115 * <li> <code> beforeFirst </code> : to position cursor before
116 * the first row. </li>
117 * </ul>
119 public void _isBeforeFirst() {
120 requiredMethod("beforeFirst()") ;
122 boolean result = true ;
124 try {
125 result = oObj.isBeforeFirst() ;
126 } catch (SQLException e) {
127 log.println("Exception occurred :") ;
128 e.printStackTrace(log) ;
129 result = false ;
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() {
139 try {
140 oObj.afterLast() ;
141 } catch (SQLException e) {
142 log.println("Exception occurred :") ;
143 e.printStackTrace(log) ;
144 tRes.tested("afterLast()", false) ;
145 return ;
147 tRes.tested("afterLast()", true) ;
151 * The method is called immediately after <code>afterLast</code>
152 * method test. <p>
153 * Has <b>OK</b> status if method returns <code>true</code> <p>
154 * The following method tests are to be completed successfully before :
155 * <ul>
156 * <li> <code> afterLast </code> : to position cursor after
157 * the last row. </li>
158 * </ul>
160 public void _isAfterLast() {
161 requiredMethod("afterLast()") ;
163 boolean result = true ;
165 try {
166 result = oObj.isAfterLast() ;
167 } catch (SQLException e) {
168 log.println("Exception occurred :") ;
169 e.printStackTrace(log) ;
170 result = false ;
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() {
180 try {
181 oObj.first() ;
182 } catch (SQLException e) {
183 log.println("Exception occurred :") ;
184 e.printStackTrace(log) ;
185 tRes.tested("first()", false) ;
186 return ;
188 tRes.tested("first()", true) ;
192 * The method is called immediately after <code>first</code>
193 * method test. <p>
194 * Has <b>OK</b> status if method returns <code>true</code>. <p>
195 * The following method tests are to be completed successfully before :
196 * <ul>
197 * <li> <code> first </code> : to position cursor on
198 * the first row. </li>
199 * </ul>
201 public void _isFirst() {
202 requiredMethod("first()") ;
204 boolean result = true ;
206 try {
207 result = oObj.isFirst() ;
208 } catch (SQLException e) {
209 log.println("Exception occurred :") ;
210 e.printStackTrace(log) ;
211 result = false ;
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() {
221 try {
222 oObj.last() ;
223 } catch (SQLException e) {
224 log.println("Exception occurred :") ;
225 e.printStackTrace(log) ;
226 tRes.tested("last()", false) ;
227 return ;
229 tRes.tested("last()", true) ;
233 * The method is called immediately after <code>last</code>
234 * method test. <p>
235 * Has <b>OK</b> status if method returns <code>true</code>. <p>
236 * The following method tests are to be completed successfully before :
237 * <ul>
238 * <li> <code> last </code> : to position cursor on
239 * the last row. </li>
240 * </ul>
242 public void _isLast() {
243 requiredMethod("last()") ;
244 boolean result = true ;
246 try {
247 result = oObj.isLast() ;
248 } catch (SQLException e) {
249 log.println("Exception occurred :") ;
250 e.printStackTrace(log) ;
251 result = false ;
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 ;
263 try {
264 oObj.absolute(1) ;
265 } catch (SQLException e) {
266 log.println("Exception occurred :") ;
267 e.printStackTrace(log) ;
268 result = false ;
270 tRes.tested("absolute()", result) ;
274 * The method is called immediately after <code>absolute</code>
275 * method test. <p>
276 * Has <b>OK</b> status if method returns 1. <p>
277 * The following method tests are to be completed successfully before :
278 * <ul>
279 * <li> <code> absolute </code> : to position cursor on
280 * the row number 1. </li>
281 * </ul>
283 public void _getRow() {
284 requiredMethod("absolute()");
285 boolean result = true;
287 try {
288 result &= oObj.getRow() == 1;
289 } catch (SQLException e) {
290 log.println("Exception occurred:");
291 e.printStackTrace(log);
292 result = false;
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 ;
307 try {
308 int prevRow = oObj.getRow() ;
309 oObj.next() ;
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) ;
316 result = false ;
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 ;
330 try {
331 int prevRow = oObj.getRow() ;
332 oObj.previous() ;
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) ;
339 result = false ;
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 ;
353 try {
354 oObj.first() ;
355 int prevRow = oObj.getRow() ;
356 oObj.relative(2) ;
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) ;
364 result = false ;
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");
385 try {
386 oObj.refreshRow() ;
387 tRes.tested("refreshRow()", true) ;
388 } catch (SQLException e) {
389 log.println("Exception occurred :") ;
390 e.printStackTrace(log) ;
391 tRes.tested("refreshRow()", false) ;
393 } else {
394 log.println("Testing of refreshRow()...");
395 try {
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));
402 oObj.refreshRow();
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() {
421 try {
422 oObj.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() {
436 try {
437 oObj.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() {
451 try {
452 oObj.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
465 * MetaData row set).
467 public void _getStatement() {
468 try {
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
485 @Override
486 public void after() {
487 log.println("Finally moving cursor to the first row ...");
488 try {
489 oObj.first();
490 } catch (SQLException e) {
491 log.println("Exception occurred :") ;
492 e.printStackTrace(log) ;
496 } // finish class _XResultSet