1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package ifc.sdbc; 25 26 import lib.MultiMethodTest; 27 import lib.StatusException; 28 29 import com.sun.star.sdbc.SQLException; 30 import com.sun.star.sdbc.XResultSetUpdate; 31 import com.sun.star.sdbc.XRowUpdate; 32 import com.sun.star.uno.UnoRuntime; 33 34 /** 35 /** 36 * Testing <code>com.sun.star.sdbc.XResultSetUpdate</code> 37 * interface methods : 38 * <ul> 39 * <li><code> insertRow()</code></li> 40 * <li><code> updateRow()</code></li> 41 * <li><code> deleteRow()</code></li> 42 * <li><code> cancelRowUpdates()</code></li> 43 * <li><code> moveToInsertRow()</code></li> 44 * <li><code> moveToCurrentRow()</code></li> 45 * </ul> <p> 46 * The test requires the following object relations : 47 * <ul> 48 * <li><code>'XResultSetUpdate.UpdateTester'</code> 49 * inner <code>UpdateTester</code> interface implementation : 50 * is used for checking test results. See interface 51 * documentation for more information.</li> 52 * </ul> 53 * The test is <b>not designed</b> for multithreaded testing. <p> 54 * After it's execution environment must be recreated. 55 * @see com.sun.star.sdbc.XResultSetUpdate 56 */ 57 public class _XResultSetUpdate extends MultiMethodTest { 58 59 // oObj filled by MultiMethodTest 60 public XResultSetUpdate oObj = null ; 61 62 private UpdateTester tester = null ; 63 64 /** 65 * Interface contains some methods for checking 66 * test results. It's implementation must be passed 67 * to this test. 68 */ 69 public static interface UpdateTester { 70 /** 71 * @return Current number of rows. 72 */ rowCount()73 public int rowCount() throws SQLException ; 74 /** 75 * Updates some data in the current row but doesn't commit 76 * changes to the source. 77 */ update()78 public void update() throws SQLException ; 79 /** 80 * Checks if updates made by method <code>update</code> was 81 * commited to the data source. 82 */ wasUpdated()83 public boolean wasUpdated() throws SQLException ; 84 /** 85 * Returns current row number. Really it must returns value 86 * < 1 if the current position is on insert row. 87 */ currentRow()88 public int currentRow() throws SQLException ; 89 } 90 91 /** 92 * Retrieves relation. 93 * @throw StatusException If relation not found. 94 */ before()95 public void before() throws StatusException { 96 tester = (UpdateTester)tEnv.getObjRelation 97 ("XResultSetUpdate.UpdateTester") ; 98 99 if (tester == null) { 100 log.println("Required relation not found !!!") ; 101 throw new StatusException("Required relation not found !!!", 102 new NullPointerException()) ; 103 } 104 } 105 106 /** 107 * Calls method when the cursor position is on existing row. 108 * Checks total number of rows before and after method call. <p> 109 * Executes <code>moveToCurrentRow</code> method test before to 110 * be sure that cursor is not on the insert row. <p> 111 * Has OK status if after method execution number of rows decreased 112 * by one. 113 */ _deleteRow()114 public void _deleteRow() { 115 executeMethod("moveToCurrentRow()") ; 116 117 //temporary to avoid SOffice hanging 118 executeMethod("updateRow()") ; 119 executeMethod("cancelRowUpdates()") ; 120 121 boolean result = true ; 122 try { 123 int rowsBefore = tester.rowCount() ; 124 oObj.deleteRow() ; 125 int rowsAfter = tester.rowCount() ; 126 127 result = rowsBefore == rowsAfter + 1 ; 128 } catch (SQLException e) { 129 e.printStackTrace(log) ; 130 result = false ; 131 } 132 133 tRes.tested("deleteRow()", result) ; 134 } 135 136 /** 137 * Using relation methods first updates some data in the current 138 * row, then calls <code>updateRow</code> method to commit data. 139 * Then checks if the data changed was commited. <p> 140 * Executes <code>moveToCurrentRow</code> method test before to 141 * be sure that cursor is not on the insert row. <p> 142 * Has OK status if data in the source was changed. 143 */ _updateRow()144 public void _updateRow() { 145 executeMethod("moveToCurrentRow()") ; 146 boolean result = true ; 147 try { 148 tester.update() ; 149 oObj.updateRow() ; 150 151 result = tester.wasUpdated() ; 152 } catch (SQLException e) { 153 e.printStackTrace(log) ; 154 result = false ; 155 } 156 tRes.tested("updateRow()", result) ; 157 } 158 159 /** 160 * Using relation methods first updates some data in the current 161 * row, then calls <code>cancelRowUpdates</code> method. 162 * Then checks if the data changed was not commited. <p> 163 * Executes <code>moveToCurrentRow</code> method test before to 164 * be sure that cursor is not on the insert row. <p> 165 * Has OK status if data in the source was not changed. 166 */ _cancelRowUpdates()167 public void _cancelRowUpdates() { 168 executeMethod("moveToCurrentRow()") ; 169 boolean result = true ; 170 try { 171 tester.update() ; 172 oObj.cancelRowUpdates() ; 173 174 result = !tester.wasUpdated() ; 175 } catch (SQLException e) { 176 e.printStackTrace(log) ; 177 result = false ; 178 } 179 tRes.tested("cancelRowUpdates()", result) ; 180 } 181 182 /** 183 * Tries to move cursor to insert row. Then checks current row 184 * number. It must be less than 1. (0 as I know) <p> 185 */ _moveToInsertRow()186 public void _moveToInsertRow() { 187 boolean result = true ; 188 try { 189 oObj.moveToInsertRow() ; 190 191 result = tester.currentRow() < 1 ; 192 } catch (SQLException e) { 193 e.printStackTrace(log) ; 194 result = false ; 195 } 196 tRes.tested("moveToInsertRow()", result) ; 197 } 198 199 /** 200 * Returns cursor from insert row back to previous row. <p> 201 * <code>moveToInsertRow</code> method test must be executed 202 * first for positioning curosr to insert row. <p> 203 * Has OK status if after method call current row number is 204 * above 0. 205 */ 206 public void _moveToCurrentRow() { 207 boolean result = true ; 208 try { 209 oObj.moveToCurrentRow() ; 210 211 result = tester.currentRow() >= 1 ; 212 } catch (SQLException e) { 213 e.printStackTrace(log) ; 214 result = false ; 215 } 216 tRes.tested("moveToCurrentRow()", result) ; 217 } 218 219 /** 220 * Moves cursor to the insert row, then calls the method 221 * <code>insertRow</code>. Before and after call stores 222 * total number of rows. <p> 223 * Has OK status if after method call rows number increases 224 * by one. 225 */ _insertRow()226 public void _insertRow() { 227 executeMethod("moveToInsertRow()") ; 228 boolean result = true ; 229 try { 230 oObj.moveToCurrentRow(); 231 int rowsBefore = tester.rowCount() ; 232 oObj.moveToInsertRow() ; 233 XRowUpdate rowU = (XRowUpdate) 234 UnoRuntime.queryInterface(XRowUpdate.class, oObj); 235 rowU.updateString(1,"open"); 236 rowU.updateInt(2,5); 237 rowU.updateDouble(5,3.4); 238 rowU.updateBoolean(10,true); 239 oObj.insertRow() ; 240 oObj.moveToCurrentRow(); 241 int rowsAfter = tester.rowCount() ; 242 result = rowsBefore + 1 == rowsAfter ; 243 } catch (SQLException e) { 244 e.printStackTrace(log) ; 245 log.println("******"+e.getMessage()); 246 result = false ; 247 } 248 tRes.tested("insertRow()", result) ; 249 } 250 251 /** 252 * Forces environment to be recreated. 253 */ after()254 public void after() { 255 //disposeEnvironment() ; 256 } 257 } // finish class _XResultSetUpdate 258 259 260