Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / tests / java / ifc / sdbc / _XResultSetUpdate.java
blobdb5b2d1599da259b6933a95ec1629963d81caf75
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 ************************************************************************/
28 package ifc.sdbc;
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;
38 /**
39 /**
40 * Testing <code>com.sun.star.sdbc.XResultSetUpdate</code>
41 * interface methods :
42 * <ul>
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>
49 * </ul> <p>
50 * The test requires the following object relations :
51 * <ul>
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>
56 * </ul>
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 ;
68 /**
69 * Interface contains some methods for checking
70 * test results. It's implementation must be passed
71 * to this test.
73 public static interface UpdateTester {
74 /**
75 * @return Current number of rows.
77 public int rowCount() throws SQLException ;
78 /**
79 * Updates some data in the current row but doesn't commit
80 * changes to the source.
82 public void update() throws SQLException ;
83 /**
84 * Checks if updates made by method <code>update</code> was
85 * commited to the data source.
87 public boolean wasUpdated() throws SQLException ;
88 /**
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 ;
95 /**
96 * Retrieves relation.
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
116 * by one.
118 public void _deleteRow() {
119 executeMethod("moveToCurrentRow()") ;
121 //temporary to avoid SOffice hanging
122 executeMethod("updateRow()") ;
123 executeMethod("cancelRowUpdates()") ;
125 boolean result = true ;
126 try {
127 int rowsBefore = tester.rowCount() ;
128 oObj.deleteRow() ;
129 int rowsAfter = tester.rowCount() ;
131 result = rowsBefore == rowsAfter + 1 ;
132 } catch (SQLException e) {
133 e.printStackTrace(log) ;
134 result = false ;
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 ;
151 try {
152 tester.update() ;
153 oObj.updateRow() ;
155 result = tester.wasUpdated() ;
156 } catch (SQLException e) {
157 e.printStackTrace(log) ;
158 result = false ;
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 ;
174 try {
175 tester.update() ;
176 oObj.cancelRowUpdates() ;
178 result = !tester.wasUpdated() ;
179 } catch (SQLException e) {
180 e.printStackTrace(log) ;
181 result = false ;
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 ;
192 try {
193 oObj.moveToInsertRow() ;
195 result = tester.currentRow() < 1 ;
196 } catch (SQLException e) {
197 e.printStackTrace(log) ;
198 result = false ;
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
208 * above 0.
210 public void _moveToCurrentRow() {
211 boolean result = true ;
212 try {
213 oObj.moveToCurrentRow() ;
215 result = tester.currentRow() >= 1 ;
216 } catch (SQLException e) {
217 e.printStackTrace(log) ;
218 result = false ;
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
228 * by one.
230 public void _insertRow() {
231 executeMethod("moveToInsertRow()") ;
232 boolean result = true ;
233 try {
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");
240 rowU.updateInt(2,5);
241 rowU.updateDouble(5,3.4);
242 rowU.updateBoolean(10,true);
243 oObj.insertRow() ;
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());
250 result = false ;
252 tRes.tested("insertRow()", result) ;
256 * Forces environment to be recreated.
258 public void after() {
259 //disposeEnvironment() ;
261 } // finish class _XResultSetUpdate