Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / sdbc / _XResultSetUpdate.java
blob3723739107dcb63eac910a9687214732319528a3
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;
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;
29 /**
30 /**
31 * Testing <code>com.sun.star.sdbc.XResultSetUpdate</code>
32 * interface methods :
33 * <ul>
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>
40 * </ul> <p>
41 * The test requires the following object relations :
42 * <ul>
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>
47 * </ul>
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 ;
59 /**
60 * Interface contains some methods for checking
61 * test results. It's implementation must be passed
62 * to this test.
64 public interface UpdateTester {
65 /**
66 * @return Current number of rows.
68 int rowCount() throws SQLException ;
69 /**
70 * Updates some data in the current row but doesn't commit
71 * changes to the source.
73 void update() throws SQLException ;
74 /**
75 * Checks if updates made by method <code>update</code> was
76 * committed to the data source.
78 boolean wasUpdated() throws SQLException ;
79 /**
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 ;
86 /**
87 * Retrieves relation.
88 * @throw StatusException If relation not found.
90 @Override
91 public void before() throws StatusException {
92 tester = (UpdateTester)tEnv.getObjRelation
93 ("XResultSetUpdate.UpdateTester") ;
95 if (tester == null) {
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
108 * by one.
110 public void _deleteRow() {
111 executeMethod("moveToCurrentRow()") ;
113 //temporary to avoid SOffice hanging
114 executeMethod("updateRow()") ;
115 executeMethod("cancelRowUpdates()") ;
117 boolean result = true ;
118 try {
119 int rowsBefore = tester.rowCount() ;
120 oObj.deleteRow() ;
121 int rowsAfter = tester.rowCount() ;
123 result = rowsBefore == rowsAfter + 1 ;
124 } catch (SQLException e) {
125 e.printStackTrace(log) ;
126 result = false ;
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 ;
143 try {
144 tester.update() ;
145 oObj.updateRow() ;
147 result = tester.wasUpdated() ;
148 } catch (SQLException e) {
149 e.printStackTrace(log) ;
150 result = false ;
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 ;
166 try {
167 tester.update() ;
168 oObj.cancelRowUpdates() ;
170 result = !tester.wasUpdated() ;
171 } catch (SQLException e) {
172 e.printStackTrace(log) ;
173 result = false ;
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 ;
184 try {
185 oObj.moveToInsertRow() ;
187 result = tester.currentRow() < 1 ;
188 } catch (SQLException e) {
189 e.printStackTrace(log) ;
190 result = false ;
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
200 * above 0.
202 public void _moveToCurrentRow() {
203 boolean result = true ;
204 try {
205 oObj.moveToCurrentRow() ;
207 result = tester.currentRow() >= 1 ;
208 } catch (SQLException e) {
209 e.printStackTrace(log) ;
210 result = false ;
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
220 * by one.
222 public void _insertRow() {
223 executeMethod("moveToInsertRow()") ;
224 boolean result = true ;
225 try {
226 oObj.moveToCurrentRow();
227 int rowsBefore = tester.rowCount() ;
228 oObj.moveToInsertRow() ;
229 XRowUpdate rowU = UnoRuntime.queryInterface(XRowUpdate.class, oObj);
230 rowU.updateString(1,"open");
231 rowU.updateInt(2,5);
232 rowU.updateDouble(5,3.4);
233 rowU.updateBoolean(10,true);
234 oObj.insertRow() ;
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());
241 result = false ;
243 tRes.tested("insertRow()", result) ;
247 * Forces environment to be recreated.
249 @Override
250 public void after() {
251 //disposeEnvironment() ;
253 } // finish class _XResultSetUpdate