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 java.util.Vector; 27 28 import lib.MultiMethodTest; 29 30 import com.sun.star.io.XDataInputStream; 31 import com.sun.star.io.XInputStream; 32 import com.sun.star.io.XTextInputStream; 33 import com.sun.star.sdbc.SQLException; 34 import com.sun.star.sdbc.XArray; 35 import com.sun.star.sdbc.XBlob; 36 import com.sun.star.sdbc.XClob; 37 import com.sun.star.sdbc.XRef; 38 import com.sun.star.sdbc.XRow; 39 import com.sun.star.util.Date; 40 import com.sun.star.util.DateTime; 41 import com.sun.star.util.Time; 42 43 /** 44 * Testing <code>com.sun.star.sdbc.XRow</code> 45 * interface methods : 46 * <ul> 47 * <li><code> wasNull()</code></li> 48 * <li><code> getString()</code></li> 49 * <li><code> getBoolean()</code></li> 50 * <li><code> getByte()</code></li> 51 * <li><code> getShort()</code></li> 52 * <li><code> getInt()</code></li> 53 * <li><code> getLong()</code></li> 54 * <li><code> getFloat()</code></li> 55 * <li><code> getDouble()</code></li> 56 * <li><code> getBytes()</code></li> 57 * <li><code> getDate()</code></li> 58 * <li><code> getTime()</code></li> 59 * <li><code> getTimestamp()</code></li> 60 * <li><code> getBinaryStream()</code></li> 61 * <li><code> getCharacterStream()</code></li> 62 * <li><code> getObject()</code></li> 63 * <li><code> getRef()</code></li> 64 * <li><code> getBlob()</code></li> 65 * <li><code> getClob()</code></li> 66 * <li><code> getArray()</code></li> 67 * </ul> <p> 68 * 69 * This interface is full tested in XRowUpdate interface test. Here 70 * only exceptions checked. 71 * <p> 72 * 73 * Object relations required : 74 * <ul> 75 * <li> <code>'CurrentRowData'</code> : (may be used in other 76 * interface tests) is a <code>java.util.Vector</code> object 77 * that contains column types and values in current row. Each 78 * element of vector corresponds to appropriate column (element 79 * with index 0 to column 1, 1 -> 2, etc.). <p> 80 * The following <code>XRow</code> methods correspond to classes 81 * in Vector : 82 * <ul> 83 * <li> <code>getBinaryStream</code> - 84 * <code>com.sun.star.io.XDataInputStream</code> class. </li> 85 * <li> <code>getCharacterStream</code> - 86 * <code>com.sun.star.io.XTextInputStream</code> class. </li> 87 * <li> <code>getObject</code> - 88 * <code>java.lang.Object[]</code> class, the element with 89 * index 0 must be used. </li> 90 * </ul> 91 * Other methods uses types they return (i.e. <code>java.lang.String</code> 92 * for <code>getString</code> method, <code>com.sun.star.sdbc.XRef</code> 93 * for <code>getRef</code> method). 94 * </li> 95 * </ul> 96 * @see com.sun.star.sdbc.XRaw 97 * @see ifc.sdbc._XRowUpdate 98 */ 99 public class _XRow extends MultiMethodTest { 100 101 // oObj filled by MultiMethodTest 102 public XRow oObj = null ; 103 private Vector data = null ; 104 private boolean notNullRes = true ; 105 106 /** 107 * Retrieves object relation first. 108 */ 109 public void before() { 110 data = (Vector) tEnv.getObjRelation("CurrentRowData") ; 111 } 112 113 /** 114 * Always has <b>OK</b> status. 115 */ 116 public void _wasNull() { 117 executeMethod("getString()") ; 118 executeMethod("getBoolean()") ; 119 executeMethod("getByte()") ; 120 executeMethod("getShort()") ; 121 executeMethod("getInt()") ; 122 executeMethod("getLong()") ; 123 executeMethod("getFloat()") ; 124 executeMethod("getDouble()") ; 125 executeMethod("getBytes()") ; 126 executeMethod("getDate()") ; 127 executeMethod("getTime()") ; 128 executeMethod("getTimestamp()") ; 129 executeMethod("getBinaryStream()") ; 130 executeMethod("getCharacterStream()") ; 131 executeMethod("getObject()") ; 132 executeMethod("getRef()") ; 133 executeMethod("getBlob()") ; 134 executeMethod("getClob()") ; 135 executeMethod("getArray()") ; 136 137 tRes.tested("wasNull()", notNullRes) ; 138 } 139 140 /** 141 * Has <b>OK</b> status if no exceptions occured in method call. 142 */ 143 public void _getString() { 144 boolean result = true ; 145 int col = findColumnOfType(String.class) ; 146 if (col < 0) log.println("Type not found in relation: not tested"); 147 else { 148 try { 149 String getStr = oObj.getString(col) ; 150 //result &= ((String)data.get(col - 1)).equals(getStr) ; 151 //notNullRes &= !oObj.wasNull() ; 152 } catch (SQLException e) { 153 log.println("Unexpected SQL exception:") ; 154 log.println(e) ; 155 result = false ; 156 } 157 } 158 159 tRes.tested("getString()", result) ; 160 } 161 162 /** 163 * Has <b>OK</b> status if no exceptions occured in method call. 164 */ 165 public void _getBoolean() { 166 boolean result = true ; 167 int col = findColumnOfType(Boolean.class) ; 168 if (col < 0) log.println("Type not found in relation: not tested"); 169 else { 170 try { 171 boolean getVal = oObj.getBoolean(col) ; 172 //result &= ((Boolean)data.get(col - 1)).booleanValue() == getVal ; 173 //notNullRes &= !oObj.wasNull() ; 174 } catch (SQLException e) { 175 log.println("Unexpected SQL exception:") ; 176 log.println(e) ; 177 result = false ; 178 } 179 } 180 181 tRes.tested("getBoolean()", result) ; 182 } 183 184 /** 185 * Has <b>OK</b> status if no exceptions occured in method call. 186 */ 187 public void _getByte() { 188 boolean result = true ; 189 int col = findColumnOfType(Byte.class) ; 190 if (col < 0) log.println("Type not found in relation: not tested"); 191 else { 192 try { 193 byte getVal = oObj.getByte(col) ; 194 //result &= ((Byte)data.get(col - 1)).byteValue() == getVal ; 195 //notNullRes &= !oObj.wasNull() ; 196 } catch (SQLException e) { 197 log.println("Unexpected SQL exception:") ; 198 log.println(e) ; 199 result = false ; 200 } 201 } 202 203 tRes.tested("getByte()", result) ; 204 } 205 206 /** 207 * Has <b>OK</b> status if no exceptions occured in method call. 208 */ 209 public void _getShort() { 210 boolean result = true ; 211 int col = findColumnOfType(Short.class) ; 212 if (col < 0) log.println("Type not found in relation: not tested"); 213 else { 214 try { 215 short getVal = oObj.getShort(col) ; 216 //result &= ((Short)data.get(col - 1)).shortValue() == getVal ; 217 //notNullRes &= !oObj.wasNull() ; 218 } catch (SQLException e) { 219 log.println("Unexpected SQL exception:") ; 220 log.println(e) ; 221 result = false ; 222 } 223 } 224 225 tRes.tested("getShort()", result) ; 226 } 227 228 /** 229 * Has <b>OK</b> status if no exceptions occured in method call. 230 */ 231 public void _getInt() { 232 boolean result = true ; 233 int col = findColumnOfType(Integer.class) ; 234 if (col < 0) log.println("Type not found in relation: not tested"); 235 else { 236 try { 237 int getVal = oObj.getInt(col) ; 238 } catch (SQLException e) { 239 log.println("Unexpected SQL exception:") ; 240 log.println(e) ; 241 result = false ; 242 } 243 } 244 245 tRes.tested("getInt()", result) ; 246 } 247 248 /** 249 * Has <b>OK</b> status if no exceptions occured in method call. 250 */ 251 public void _getLong() { 252 boolean result = true ; 253 int col = findColumnOfType(Long.class) ; 254 if (col < 0) log.println("Type not found in relation: not tested"); 255 else { 256 try { 257 long getVal = oObj.getLong(col) ; 258 } catch (SQLException e) { 259 log.println("Unexpected SQL exception:") ; 260 log.println(e) ; 261 result = false ; 262 } 263 } 264 265 tRes.tested("getLong()", result) ; 266 } 267 268 /** 269 * Has <b>OK</b> status if no exceptions occured in method call. 270 */ 271 public void _getFloat() { 272 boolean result = true ; 273 int col = findColumnOfType(Float.class) ; 274 if (col < 0) log.println("Type not found in relation: not tested"); 275 else { 276 try { 277 float getVal = oObj.getFloat(col) ; 278 } catch (SQLException e) { 279 log.println("Unexpected SQL exception:") ; 280 log.println(e) ; 281 result = false ; 282 } 283 } 284 285 tRes.tested("getFloat()", result) ; 286 } 287 288 /** 289 * Has <b>OK</b> status if no exceptions occured in method call. 290 */ 291 public void _getDouble() { 292 boolean result = true ; 293 int col = findColumnOfType(Double.class) ; 294 if (col < 0) log.println("Type not found in relation: not tested"); 295 else { 296 try { 297 double getVal = oObj.getDouble(col) ; 298 } catch (SQLException e) { 299 log.println("Unexpected SQL exception:") ; 300 log.println(e) ; 301 result = false ; 302 } 303 } 304 305 tRes.tested("getDouble()", result) ; 306 } 307 308 /** 309 * Has <b>OK</b> status if no exceptions occured in method call. 310 */ 311 public void _getBytes() { 312 boolean result = true ; 313 int col = findColumnOfType(byte[].class) ; 314 if (col < 0) log.println("Type not found in relation: not tested"); 315 else { 316 try { 317 byte[] getVal = oObj.getBytes(col) ; 318 } catch (SQLException e) { 319 log.println("Unexpected SQL exception:") ; 320 log.println(e) ; 321 result = false ; 322 } 323 } 324 325 tRes.tested("getBytes()", result) ; 326 } 327 328 /** 329 * Has <b>OK</b> status if no exceptions occured in method call. 330 */ 331 public void _getDate() { 332 boolean result = true ; 333 int col = findColumnOfType(Date.class) ; 334 if (col < 0) log.println("Type not found in relation: not tested"); 335 else { 336 try { 337 Date getVal = oObj.getDate(col) ; 338 } catch (SQLException e) { 339 log.println("Unexpected SQL exception:") ; 340 log.println(e) ; 341 result = false ; 342 } 343 } 344 345 tRes.tested("getDate()", result) ; 346 } 347 348 /** 349 * Has <b>OK</b> status if no exceptions occured in method call. 350 */ 351 public void _getTime() { 352 boolean result = true ; 353 int col = findColumnOfType(Time.class) ; 354 if (col < 0) log.println("Type not found in relation: not tested"); 355 else { 356 try { 357 Time getVal = oObj.getTime(col) ; 358 } catch (SQLException e) { 359 log.println("Unexpected SQL exception:") ; 360 log.println(e) ; 361 result = false ; 362 } 363 } 364 365 tRes.tested("getTime()", result) ; 366 } 367 368 /** 369 * Has <b>OK</b> status if no exceptions occured in method call. 370 */ 371 public void _getTimestamp() { 372 boolean result = true ; 373 int col = findColumnOfType(DateTime.class) ; 374 if (col < 0) log.println("Type not found in relation: not tested"); 375 else { 376 try { 377 DateTime getVal = oObj.getTimestamp(col) ; 378 } catch (SQLException e) { 379 log.println("Unexpected SQL exception:") ; 380 log.println(e) ; 381 result = false ; 382 } 383 } 384 385 tRes.tested("getTimestamp()", result) ; 386 } 387 388 /** 389 * Has <b>OK</b> status if no exceptions occured in method call. 390 */ 391 public void _getBinaryStream() { 392 boolean result = true ; 393 int col = findColumnOfType(XDataInputStream.class) ; 394 if (col < 0) log.println("Type not found in relation: not tested"); 395 else { 396 try { 397 XInputStream getVal = oObj.getBinaryStream(col) ; 398 } catch (SQLException e) { 399 log.println("Unexpected SQL exception:") ; 400 log.println(e) ; 401 result = false ; 402 } 403 } 404 405 tRes.tested("getBinaryStream()", result) ; 406 } 407 408 /** 409 * Has <b>OK</b> status if no exceptions occured in method call. 410 */ 411 public void _getCharacterStream() { 412 boolean result = true ; 413 int col = findColumnOfType(XTextInputStream.class) ; 414 if (col < 0) log.println("Type not found in relation: not tested"); 415 else { 416 try { 417 XInputStream getVal = oObj.getCharacterStream(col) ; 418 } catch (SQLException e) { 419 log.println("Unexpected SQL exception:") ; 420 log.println(e) ; 421 result = false ; 422 } 423 } 424 425 tRes.tested("getCharacterStream()", result) ; 426 } 427 428 /** 429 * Has <b>OK</b> status if no exceptions occured in method call. 430 */ 431 public void _getObject() { 432 boolean result = true ; 433 int col = findColumnOfType(Object[].class) ; 434 if (col < 0) log.println("Type not found in relation: not tested"); 435 else { 436 try { 437 Object getVal = oObj.getObject(col, null) ; 438 } catch (SQLException e) { 439 log.println("Unexpected SQL exception:") ; 440 log.println(e) ; 441 result = false ; 442 } 443 } 444 445 tRes.tested("getObject()", result) ; 446 } 447 448 /** 449 * Has <b>OK</b> status if no exceptions occured in method call. 450 */ 451 public void _getRef() { 452 boolean result = true ; 453 int col = findColumnOfType(XRef.class) ; 454 if (col < 0) log.println("Type not found in relation: not tested"); 455 else { 456 try { 457 XRef getVal = oObj.getRef(col) ; 458 } catch (SQLException e) { 459 log.println("Unexpected SQL exception:") ; 460 log.println(e) ; 461 result = false ; 462 } 463 } 464 465 tRes.tested("getRef()", result) ; 466 } 467 468 /** 469 * Has <b>OK</b> status if no exceptions occured in method call. 470 */ 471 public void _getBlob() { 472 boolean result = true ; 473 int col = findColumnOfType(XBlob.class) ; 474 if (col < 0) log.println("Type not found in relation: not tested"); 475 else { 476 try { 477 XBlob getVal = oObj.getBlob(col) ; 478 } catch (SQLException e) { 479 log.println("Unexpected SQL exception:") ; 480 log.println(e) ; 481 result = false ; 482 } 483 } 484 485 tRes.tested("getBlob()", result) ; 486 } 487 488 /** 489 * Has <b>OK</b> status if no exceptions occured in method call. 490 */ 491 public void _getClob() { 492 boolean result = true ; 493 int col = findColumnOfType(XClob.class) ; 494 if (col < 0) log.println("Type not found in relation: not tested"); 495 else { 496 try { 497 XClob getVal = oObj.getClob(col) ; 498 } catch (SQLException e) { 499 log.println("Unexpected SQL exception:") ; 500 log.println(e) ; 501 result = false ; 502 } 503 } 504 505 tRes.tested("getClob()", result) ; 506 } 507 508 /** 509 * Has <b>OK</b> status if no exceptions occured in method call. 510 */ 511 public void _getArray() { 512 boolean result = true ; 513 int col = findColumnOfType(XArray.class) ; 514 if (col < 0) log.println("Type not found in relation: not tested"); 515 else { 516 try { 517 XArray getVal = oObj.getArray(col) ; 518 } catch (SQLException e) { 519 log.println("Unexpected SQL exception:") ; 520 log.println(e) ; 521 result = false ; 522 } 523 } 524 525 tRes.tested("getArray()", result) ; 526 } 527 528 /** 529 * Finds in relation vector index of column of the appropriate 530 * type. 531 */ 532 protected int findColumnOfType(Class clz) { 533 534 for (int i = 0; i < data.size(); i++) 535 if (clz.isInstance(data.get(i))) return i + 1 ; 536 return -1 ; 537 } 538 } // finish class _XRow 539 540 541