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
;
31 import lib
.StatusException
;
33 import com
.sun
.star
.sdbc
.SQLException
;
34 import com
.sun
.star
.sdbc
.XResultSetUpdate
;
35 import com
.sun
.star
.sdbc
.XRowUpdate
;
36 import com
.sun
.star
.uno
.UnoRuntime
;
40 * Testing <code>com.sun.star.sdbc.XResultSetUpdate</code>
43 * <li><code> insertRow()</code></li>
44 * <li><code> updateRow()</code></li>
45 * <li><code> deleteRow()</code></li>
46 * <li><code> cancelRowUpdates()</code></li>
47 * <li><code> moveToInsertRow()</code></li>
48 * <li><code> moveToCurrentRow()</code></li>
50 * The test requires the following object relations :
52 * <li><code>'XResultSetUpdate.UpdateTester'</code>
53 * inner <code>UpdateTester</code> interface implementation :
54 * is used for checking test results. See interface
55 * documentation for more information.</li>
57 * The test is <b>not designed</b> for multithreaded testing. <p>
58 * After it's execution environment must be recreated.
59 * @see com.sun.star.sdbc.XResultSetUpdate
61 public class _XResultSetUpdate
extends MultiMethodTest
{
63 // oObj filled by MultiMethodTest
64 public XResultSetUpdate oObj
= null ;
66 private UpdateTester tester
= null ;
69 * Interface contains some methods for checking
70 * test results. It's implementation must be passed
73 public static interface UpdateTester
{
75 * @return Current number of rows.
77 public int rowCount() throws SQLException
;
79 * Updates some data in the current row but doesn't commit
80 * changes to the source.
82 public void update() throws SQLException
;
84 * Checks if updates made by method <code>update</code> was
85 * commited to the data source.
87 public boolean wasUpdated() throws SQLException
;
89 * Returns current row number. Really it must returns value
90 * < 1 if the current position is on insert row.
92 public int currentRow() throws SQLException
;
97 * @throw StatusException If relation not found.
99 public void before() throws StatusException
{
100 tester
= (UpdateTester
)tEnv
.getObjRelation
101 ("XResultSetUpdate.UpdateTester") ;
103 if (tester
== null) {
104 log
.println("Required relation not found !!!") ;
105 throw new StatusException("Required relation not found !!!",
106 new NullPointerException()) ;
111 * Calls method when the cursor position is on existing row.
112 * Checks total number of rows before and after method call. <p>
113 * Executes <code>moveToCurrentRow</code> method test before to
114 * be sure that cursor is not on the insert row. <p>
115 * Has OK status if after method execution number of rows decreased
118 public void _deleteRow() {
119 executeMethod("moveToCurrentRow()") ;
121 //temporary to avoid SOffice hanging
122 executeMethod("updateRow()") ;
123 executeMethod("cancelRowUpdates()") ;
125 boolean result
= true ;
127 int rowsBefore
= tester
.rowCount() ;
129 int rowsAfter
= tester
.rowCount() ;
131 result
= rowsBefore
== rowsAfter
+ 1 ;
132 } catch (SQLException e
) {
133 e
.printStackTrace(log
) ;
137 tRes
.tested("deleteRow()", result
) ;
141 * Using relation methods first updates some data in the current
142 * row, then calls <code>updateRow</code> method to commit data.
143 * Then checks if the data changed was commited. <p>
144 * Executes <code>moveToCurrentRow</code> method test before to
145 * be sure that cursor is not on the insert row. <p>
146 * Has OK status if data in the source was changed.
148 public void _updateRow() {
149 executeMethod("moveToCurrentRow()") ;
150 boolean result
= true ;
155 result
= tester
.wasUpdated() ;
156 } catch (SQLException e
) {
157 e
.printStackTrace(log
) ;
160 tRes
.tested("updateRow()", result
) ;
164 * Using relation methods first updates some data in the current
165 * row, then calls <code>cancelRowUpdates</code> method.
166 * Then checks if the data changed was not commited. <p>
167 * Executes <code>moveToCurrentRow</code> method test before to
168 * be sure that cursor is not on the insert row. <p>
169 * Has OK status if data in the source was not changed.
171 public void _cancelRowUpdates() {
172 executeMethod("moveToCurrentRow()") ;
173 boolean result
= true ;
176 oObj
.cancelRowUpdates() ;
178 result
= !tester
.wasUpdated() ;
179 } catch (SQLException e
) {
180 e
.printStackTrace(log
) ;
183 tRes
.tested("cancelRowUpdates()", result
) ;
187 * Tries to move cursor to insert row. Then checks current row
188 * number. It must be less than 1. (0 as I know) <p>
190 public void _moveToInsertRow() {
191 boolean result
= true ;
193 oObj
.moveToInsertRow() ;
195 result
= tester
.currentRow() < 1 ;
196 } catch (SQLException e
) {
197 e
.printStackTrace(log
) ;
200 tRes
.tested("moveToInsertRow()", result
) ;
204 * Returns cursor from insert row back to previous row. <p>
205 * <code>moveToInsertRow</code> method test must be executed
206 * first for positioning curosr to insert row. <p>
207 * Has OK status if after method call current row number is
210 public void _moveToCurrentRow() {
211 boolean result
= true ;
213 oObj
.moveToCurrentRow() ;
215 result
= tester
.currentRow() >= 1 ;
216 } catch (SQLException e
) {
217 e
.printStackTrace(log
) ;
220 tRes
.tested("moveToCurrentRow()", result
) ;
224 * Moves cursor to the insert row, then calls the method
225 * <code>insertRow</code>. Before and after call stores
226 * total number of rows. <p>
227 * Has OK status if after method call rows number increases
230 public void _insertRow() {
231 executeMethod("moveToInsertRow()") ;
232 boolean result
= true ;
234 oObj
.moveToCurrentRow();
235 int rowsBefore
= tester
.rowCount() ;
236 oObj
.moveToInsertRow() ;
237 XRowUpdate rowU
= (XRowUpdate
)
238 UnoRuntime
.queryInterface(XRowUpdate
.class, oObj
);
239 rowU
.updateString(1,"open");
241 rowU
.updateDouble(5,3.4);
242 rowU
.updateBoolean(10,true);
244 oObj
.moveToCurrentRow();
245 int rowsAfter
= tester
.rowCount() ;
246 result
= rowsBefore
+ 1 == rowsAfter
;
247 } catch (SQLException e
) {
248 e
.printStackTrace(log
) ;
249 log
.println("******"+e
.getMessage());
252 tRes
.tested("insertRow()", result
) ;
256 * Forces environment to be recreated.
258 public void after() {
259 //disposeEnvironment() ;
261 } // finish class _XResultSetUpdate