merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / ifc / sdbc / _XResultSetUpdate.java
blob92e86a437579431cda6ab809a92e15e415529b3e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XResultSetUpdate.java,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package ifc.sdbc;
33 import lib.MultiMethodTest;
34 import lib.StatusException;
36 import com.sun.star.sdbc.SQLException;
37 import com.sun.star.sdbc.XResultSetUpdate;
38 import com.sun.star.sdbc.XRowUpdate;
39 import com.sun.star.uno.UnoRuntime;
41 /**
42 /**
43 * Testing <code>com.sun.star.sdbc.XResultSetUpdate</code>
44 * interface methods :
45 * <ul>
46 * <li><code> insertRow()</code></li>
47 * <li><code> updateRow()</code></li>
48 * <li><code> deleteRow()</code></li>
49 * <li><code> cancelRowUpdates()</code></li>
50 * <li><code> moveToInsertRow()</code></li>
51 * <li><code> moveToCurrentRow()</code></li>
52 * </ul> <p>
53 * The test requires the following object relations :
54 * <ul>
55 * <li><code>'XResultSetUpdate.UpdateTester'</code>
56 * inner <code>UpdateTester</code> interface implementation :
57 * is used for checking test results. See interface
58 * documentation for more information.</li>
59 * </ul>
60 * The test is <b>not designed</b> for multithreaded testing. <p>
61 * After it's execution environment must be recreated.
62 * @see com.sun.star.sdbc.XResultSetUpdate
64 public class _XResultSetUpdate extends MultiMethodTest {
66 // oObj filled by MultiMethodTest
67 public XResultSetUpdate oObj = null ;
69 private UpdateTester tester = null ;
71 /**
72 * Interface contains some methods for checking
73 * test results. It's implementation must be passed
74 * to this test.
76 public static interface UpdateTester {
77 /**
78 * @return Current number of rows.
80 public int rowCount() throws SQLException ;
81 /**
82 * Updates some data in the current row but doesn't commit
83 * changes to the source.
85 public void update() throws SQLException ;
86 /**
87 * Checks if updates made by method <code>update</code> was
88 * commited to the data source.
90 public boolean wasUpdated() throws SQLException ;
91 /**
92 * Returns current row number. Really it must returns value
93 * < 1 if the current position is on insert row.
95 public int currentRow() throws SQLException ;
98 /**
99 * Retrieves relation.
100 * @throw StatusException If relation not found.
102 public void before() throws StatusException {
103 tester = (UpdateTester)tEnv.getObjRelation
104 ("XResultSetUpdate.UpdateTester") ;
106 if (tester == null) {
107 log.println("Required relation not found !!!") ;
108 throw new StatusException("Required relation not found !!!",
109 new NullPointerException()) ;
114 * Calls method when the cursor position is on existing row.
115 * Checks total number of rows before and after method call. <p>
116 * Executes <code>moveToCurrentRow</code> method test before to
117 * be sure that cursor is not on the insert row. <p>
118 * Has OK status if after method execution number of rows decreased
119 * by one.
121 public void _deleteRow() {
122 executeMethod("moveToCurrentRow()") ;
124 //temporary to avoid SOffice hanging
125 executeMethod("updateRow()") ;
126 executeMethod("cancelRowUpdates()") ;
128 boolean result = true ;
129 try {
130 int rowsBefore = tester.rowCount() ;
131 oObj.deleteRow() ;
132 int rowsAfter = tester.rowCount() ;
134 result = rowsBefore == rowsAfter + 1 ;
135 } catch (SQLException e) {
136 e.printStackTrace(log) ;
137 result = false ;
140 tRes.tested("deleteRow()", result) ;
144 * Using relation methods first updates some data in the current
145 * row, then calls <code>updateRow</code> method to commit data.
146 * Then checks if the data changed was commited. <p>
147 * Executes <code>moveToCurrentRow</code> method test before to
148 * be sure that cursor is not on the insert row. <p>
149 * Has OK status if data in the source was changed.
151 public void _updateRow() {
152 executeMethod("moveToCurrentRow()") ;
153 boolean result = true ;
154 try {
155 tester.update() ;
156 oObj.updateRow() ;
158 result = tester.wasUpdated() ;
159 } catch (SQLException e) {
160 e.printStackTrace(log) ;
161 result = false ;
163 tRes.tested("updateRow()", result) ;
167 * Using relation methods first updates some data in the current
168 * row, then calls <code>cancelRowUpdates</code> method.
169 * Then checks if the data changed was not commited. <p>
170 * Executes <code>moveToCurrentRow</code> method test before to
171 * be sure that cursor is not on the insert row. <p>
172 * Has OK status if data in the source was not changed.
174 public void _cancelRowUpdates() {
175 executeMethod("moveToCurrentRow()") ;
176 boolean result = true ;
177 try {
178 tester.update() ;
179 oObj.cancelRowUpdates() ;
181 result = !tester.wasUpdated() ;
182 } catch (SQLException e) {
183 e.printStackTrace(log) ;
184 result = false ;
186 tRes.tested("cancelRowUpdates()", result) ;
190 * Tries to move cursor to insert row. Then checks current row
191 * number. It must be less than 1. (0 as I know) <p>
193 public void _moveToInsertRow() {
194 boolean result = true ;
195 try {
196 oObj.moveToInsertRow() ;
198 result = tester.currentRow() < 1 ;
199 } catch (SQLException e) {
200 e.printStackTrace(log) ;
201 result = false ;
203 tRes.tested("moveToInsertRow()", result) ;
207 * Returns cursor from insert row back to previous row. <p>
208 * <code>moveToInsertRow</code> method test must be executed
209 * first for positioning curosr to insert row. <p>
210 * Has OK status if after method call current row number is
211 * above 0.
213 public void _moveToCurrentRow() {
214 boolean result = true ;
215 try {
216 oObj.moveToCurrentRow() ;
218 result = tester.currentRow() >= 1 ;
219 } catch (SQLException e) {
220 e.printStackTrace(log) ;
221 result = false ;
223 tRes.tested("moveToCurrentRow()", result) ;
227 * Moves cursor to the insert row, then calls the method
228 * <code>insertRow</code>. Before and after call stores
229 * total number of rows. <p>
230 * Has OK status if after method call rows number increases
231 * by one.
233 public void _insertRow() {
234 executeMethod("moveToInsertRow()") ;
235 boolean result = true ;
236 try {
237 oObj.moveToCurrentRow();
238 int rowsBefore = tester.rowCount() ;
239 oObj.moveToInsertRow() ;
240 XRowUpdate rowU = (XRowUpdate)
241 UnoRuntime.queryInterface(XRowUpdate.class, oObj);
242 rowU.updateString(1,"open");
243 rowU.updateInt(2,5);
244 rowU.updateDouble(5,3.4);
245 rowU.updateBoolean(10,true);
246 oObj.insertRow() ;
247 oObj.moveToCurrentRow();
248 int rowsAfter = tester.rowCount() ;
249 result = rowsBefore + 1 == rowsAfter ;
250 } catch (SQLException e) {
251 e.printStackTrace(log) ;
252 log.println("******"+e.getMessage());
253 result = false ;
255 tRes.tested("insertRow()", result) ;
259 * Forces environment to be recreated.
261 public void after() {
262 //disposeEnvironment() ;
264 } // finish class _XResultSetUpdate