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
;
22 import lib
.StatusException
;
24 import com
.sun
.star
.sdbc
.SQLException
;
25 import com
.sun
.star
.sdbc
.XResultSetUpdate
;
26 import com
.sun
.star
.sdbc
.XRowUpdate
;
27 import com
.sun
.star
.uno
.UnoRuntime
;
31 * Testing <code>com.sun.star.sdbc.XResultSetUpdate</code>
34 * <li><code> insertRow()</code></li>
35 * <li><code> updateRow()</code></li>
36 * <li><code> deleteRow()</code></li>
37 * <li><code> cancelRowUpdates()</code></li>
38 * <li><code> moveToInsertRow()</code></li>
39 * <li><code> moveToCurrentRow()</code></li>
41 * The test requires the following object relations :
43 * <li><code>'XResultSetUpdate.UpdateTester'</code>
44 * inner <code>UpdateTester</code> interface implementation :
45 * is used for checking test results. See interface
46 * documentation for more information.</li>
48 * The test is <b>not designed</b> for multithreaded testing. <p>
49 * After it's execution environment must be recreated.
50 * @see com.sun.star.sdbc.XResultSetUpdate
52 public class _XResultSetUpdate
extends MultiMethodTest
{
54 // oObj filled by MultiMethodTest
55 public XResultSetUpdate oObj
= null ;
57 private UpdateTester tester
= null ;
60 * Interface contains some methods for checking
61 * test results. It's implementation must be passed
64 public interface UpdateTester
{
66 * @return Current number of rows.
68 int rowCount() throws SQLException
;
70 * Updates some data in the current row but doesn't commit
71 * changes to the source.
73 void update() throws SQLException
;
75 * Checks if updates made by method <code>update</code> was
76 * committed to the data source.
78 boolean wasUpdated() throws SQLException
;
80 * Returns current row number. Really it must returns value
81 * < 1 if the current position is on insert row.
83 int currentRow() throws SQLException
;
88 * @throw StatusException If relation not found.
91 public void before() throws StatusException
{
92 tester
= (UpdateTester
)tEnv
.getObjRelation
93 ("XResultSetUpdate.UpdateTester") ;
96 log
.println("Required relation not found !!!") ;
97 throw new StatusException("Required relation not found !!!",
98 new NullPointerException()) ;
103 * Calls method when the cursor position is on existing row.
104 * Checks total number of rows before and after method call. <p>
105 * Executes <code>moveToCurrentRow</code> method test before to
106 * be sure that cursor is not on the insert row. <p>
107 * Has OK status if after method execution number of rows decreased
110 public void _deleteRow() {
111 executeMethod("moveToCurrentRow()") ;
113 //temporary to avoid SOffice hanging
114 executeMethod("updateRow()") ;
115 executeMethod("cancelRowUpdates()") ;
117 boolean result
= true ;
119 int rowsBefore
= tester
.rowCount() ;
121 int rowsAfter
= tester
.rowCount() ;
123 result
= rowsBefore
== rowsAfter
+ 1 ;
124 } catch (SQLException e
) {
125 e
.printStackTrace(log
) ;
129 tRes
.tested("deleteRow()", result
) ;
133 * Using relation methods first updates some data in the current
134 * row, then calls <code>updateRow</code> method to commit data.
135 * Then checks if the data changed was committed. <p>
136 * Executes <code>moveToCurrentRow</code> method test before to
137 * be sure that cursor is not on the insert row. <p>
138 * Has OK status if data in the source was changed.
140 public void _updateRow() {
141 executeMethod("moveToCurrentRow()") ;
142 boolean result
= true ;
147 result
= tester
.wasUpdated() ;
148 } catch (SQLException e
) {
149 e
.printStackTrace(log
) ;
152 tRes
.tested("updateRow()", result
) ;
156 * Using relation methods first updates some data in the current
157 * row, then calls <code>cancelRowUpdates</code> method.
158 * Then checks if the data changed was not committed. <p>
159 * Executes <code>moveToCurrentRow</code> method test before to
160 * be sure that cursor is not on the insert row. <p>
161 * Has OK status if data in the source was not changed.
163 public void _cancelRowUpdates() {
164 executeMethod("moveToCurrentRow()") ;
165 boolean result
= true ;
168 oObj
.cancelRowUpdates() ;
170 result
= !tester
.wasUpdated() ;
171 } catch (SQLException e
) {
172 e
.printStackTrace(log
) ;
175 tRes
.tested("cancelRowUpdates()", result
) ;
179 * Tries to move cursor to insert row. Then checks current row
180 * number. It must be less than 1. (0 as I know) <p>
182 public void _moveToInsertRow() {
183 boolean result
= true ;
185 oObj
.moveToInsertRow() ;
187 result
= tester
.currentRow() < 1 ;
188 } catch (SQLException e
) {
189 e
.printStackTrace(log
) ;
192 tRes
.tested("moveToInsertRow()", result
) ;
196 * Returns cursor from insert row back to previous row. <p>
197 * <code>moveToInsertRow</code> method test must be executed
198 * first for positioning cursor to insert row. <p>
199 * Has OK status if after method call current row number is
202 public void _moveToCurrentRow() {
203 boolean result
= true ;
205 oObj
.moveToCurrentRow() ;
207 result
= tester
.currentRow() >= 1 ;
208 } catch (SQLException e
) {
209 e
.printStackTrace(log
) ;
212 tRes
.tested("moveToCurrentRow()", result
) ;
216 * Moves cursor to the insert row, then calls the method
217 * <code>insertRow</code>. Before and after call stores
218 * total number of rows. <p>
219 * Has OK status if after method call rows number increases
222 public void _insertRow() {
223 executeMethod("moveToInsertRow()") ;
224 boolean result
= true ;
226 oObj
.moveToCurrentRow();
227 int rowsBefore
= tester
.rowCount() ;
228 oObj
.moveToInsertRow() ;
229 XRowUpdate rowU
= UnoRuntime
.queryInterface(XRowUpdate
.class, oObj
);
230 rowU
.updateString(1,"open");
232 rowU
.updateDouble(5,3.4);
233 rowU
.updateBoolean(10,true);
235 oObj
.moveToCurrentRow();
236 int rowsAfter
= tester
.rowCount() ;
237 result
= rowsBefore
+ 1 == rowsAfter
;
238 } catch (SQLException e
) {
239 e
.printStackTrace(log
) ;
240 log
.println("******"+e
.getMessage());
243 tRes
.tested("insertRow()", result
) ;
247 * Forces environment to be recreated.
250 public void after() {
251 //disposeEnvironment() ;
253 } // finish class _XResultSetUpdate