ResultSetGetterTests.java revision cc05ad238516f1303687aba4a978e24e57c0c07a
1/* 2 * Copyright (C) 2007 Google Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package tests.sql; 18 19 20import dalvik.annotation.KnownFailure; 21import dalvik.annotation.TestTargets; 22import dalvik.annotation.TestLevel; 23import dalvik.annotation.TestTargetNew; 24import dalvik.annotation.TestTargetClass; 25 26import java.io.UnsupportedEncodingException; 27import java.net.MalformedURLException; 28import java.net.URL; 29import java.sql.DatabaseMetaData; 30import java.sql.Date; 31import java.sql.ResultSet; 32import java.sql.ResultSetMetaData; 33import java.sql.SQLException; 34import java.sql.Statement; 35import java.sql.Time; 36import java.sql.Timestamp; 37import java.util.Arrays; 38import java.util.Calendar; 39import java.util.GregorianCalendar; 40import java.util.Iterator; 41import java.util.LinkedList; 42import java.util.List; 43import java.util.ListIterator; 44 45/** 46 * Tests based on 47 * <a href="http://java.sun.com/products/jdbc/download.html">JDBC 1.0 API spec 48 * </a> Table 1.0 49 */ 50@TestTargetClass(ResultSet.class) 51public class ResultSetGetterTests extends SQLTest { 52 53 String queryAllSelect = "select * from type"; 54 55 ResultSet res = null; 56 57 Statement st = null; 58 59 // Judgement concerning support is based on the result of ResultSet.getOject 60 // and Table 1 of JDBC 1.0 spec. 61 static boolean booleanSupported = false; 62 static boolean blobSupported = false; 63 static boolean bigIntSupported = false; 64 static boolean smallIntSupported = false; 65 static boolean mediumIntSupported = false; 66 static boolean realSupported = false; 67 static boolean floatSupported = false; 68 static boolean dateSupported = false; 69 static boolean timeSupported = false; 70 static boolean timeStampSupported = false; 71 static boolean dateTimeSupported = false; 72 static boolean urlSupported= false; 73 static boolean tinyIntSupported = false; 74 static boolean decimalSupported = false; 75 static boolean numericSupported = false; 76 77 static List<String> colNames = Arrays.asList("BoolVal", "IntVal", "LongVal", 78 "Bint", "Tint", "Sint", "Mint", "IntegerVal", "RealVal", 79 "DoubleVal", "FloatVal", "DecVal", "NumVal", "charStr", 80 "dateVal", "timeVal", "TS", "DT", "TBlob", "BlobVal", "MBlob", 81 "LBlob", "TText", "TextVal", "MText", "LText", "MaxLongVal", 82 "MinLongVal", "validURL", "invalidURL"); 83 84 static List<String> values = Arrays.asList("1", "-1", "22", "2", "33", 85 "3","1","2","3.9","23.2","33.3","44", 86 "5", "test string", "1799-05-26", "12:35:45", "2007-10-09 14:28:02.0", 87 "1221-09-22 10:11:55","1","2","3","4","Test text message tiny", 88 "Test text", "Test text message medium", 89 "Test text message long"); 90 91 static boolean[] supported = new boolean[]{ 92 booleanSupported, 93 true, 94 true, 95 bigIntSupported, 96 tinyIntSupported, 97 smallIntSupported, 98 mediumIntSupported, 99 true, 100 realSupported, 101 true, 102 floatSupported, 103 decimalSupported, 104 numericSupported, 105 true, 106 dateSupported, 107 timeSupported, 108 timeStampSupported, 109 dateTimeSupported, 110 blobSupported, 111 blobSupported, 112 blobSupported, 113 blobSupported, 114 true, 115 true, 116 true, 117 true, 118 bigIntSupported, 119 bigIntSupported, 120 urlSupported, 121 urlSupported 122 }; 123 124 // Not supported: BIT,VARBINARY, LONGVARBINARY, BINARY, VARCHAR, LONGVARCHAR 125 static Class[] typeMap = new Class[]{ 126 java.lang.String.class, // 127 java.lang.Integer.class,//Types.INTEGER, 128 java.lang.String.class, //Types.LONG, not a JDBC 1.0 type 129 java.lang.Long.class, // Types.BIGINT, 130 java.lang.Byte.class, // Types.TINYINT, 131 java.lang.Short.class, // Types.SMALLINT, 132 java.lang.Integer.class, //Types.MEDIUMINT, , not a JDBC 1.0 type 133 java.lang.Integer.class, // Types.Integer 134 java.lang.Float.class, // Types.REAL, 135 java.lang.Double.class, // Types.FLOAT, 136 java.lang.Double.class, // Types.DOUBLE, 137 java.math.BigDecimal.class, // Types.DECIMAL, 138 java.math.BigDecimal.class, // Types.NUMERIC, 139 java.lang.String.class, // Types.CHAR 140 java.sql.Date.class, // Types.DATE, 141 java.sql.Time.class, // Types.TIME, 142 java.sql.Timestamp.class, // Types.TIMESTAMP, 143 java.sql.Date.class, // types datetime, not a JDBC 1.0 type 144 java.sql.Blob.class, // Types.BLOB, not a JDBC 1.0 type 145 java.sql.Blob.class, // Types.BLOB, not a JDBC 1.0 type 146 java.sql.Blob.class, // Types.BLOB, not a JDBC 1.0 type 147 java.sql.Blob.class, // Types.BLOB, not a JDBC 1.0 type 148 java.lang.String.class, // not a JDBC 1.0 type 149 java.lang.String.class, // not a JDBC 1.0 type 150 java.lang.String.class, // not a JDBC 1.0 type 151 java.lang.String.class, // not a JDBC 1.0 type 152 java.lang.Long.class, // Types.BIGINT, 153 java.lang.Long.class, // Types.BIGINT, 154 java.net.URL.class, // not a JDBC 1.0 type 155 java.net.URL.class // not a JDBC 1.0 type 156 157 158 }; 159 160 // first inserted row : actual values 161 // second inserted row: null values 162 String[] queries = { 163 "create table type (" + 164 165 " BoolVal BOOLEAN," + " IntVal INT," + " LongVal LONG," 166 + " Bint BIGINT," + " Tint TINYINT," + " Sint SMALLINT," 167 + " Mint MEDIUMINT, " + 168 169 " IntegerVal INTEGER, " + " RealVal REAL, " 170 + " DoubleVal DOUBLE, " + " FloatVal FLOAT, " 171 + " DecVal DECIMAL, " + 172 173 " NumVal NUMERIC, " + " charStr CHAR(20), " 174 + " dateVal DATE, " + " timeVal TIME, " + " TS TIMESTAMP, " 175 + 176 177 " DT DATETIME, " + " TBlob TINYBLOB, " + " BlobVal BLOB, " 178 + " MBlob MEDIUMBLOB, " + " LBlob LONGBLOB, " + 179 180 " TText TINYTEXT, " + " TextVal TEXT, " 181 + " MText MEDIUMTEXT, " + " LText LONGTEXT, " + 182 183 " MaxLongVal BIGINT, MinLongVal BIGINT, "+ 184 185 " validURL URL, invalidURL URL "+ 186 187 ");" 188 , 189 190 "insert into type (BoolVal, IntVal, LongVal, Bint, Tint, Sint, Mint," 191 + "IntegerVal, RealVal, DoubleVal, FloatVal, DecVal," 192 + "NumVal, charStr, dateVal, timeVal, TS," 193 + "DT, TBlob, BlobVal, MBlob, LBlob," 194 + "TText, TextVal, MText, LText, MaxLongVal, MinLongVal," 195 + " validURL, invalidURL" 196 + ") " 197 + "values (1, -1, 22, 2, 33," 198 + "3, 1, 2, 3.9, 23.2, 33.3, 44," 199 + "5, 'test string', '1799-05-26', '12:35:45', '2007-10-09 14:28:02.0'," 200 + "'1221-09-22 10:11:55', 1, 2, 3, 4," 201 + "'Test text message tiny', 'Test text'," 202 + " 'Test text message medium', 'Test text message long', " 203 + Long.MAX_VALUE+", "+Long.MIN_VALUE+", " 204 + "'http://www.android.com', 'helloWorld' "+ 205 ");" 206 , 207 208 "insert into type (BoolVal, IntVal, LongVal, Bint, Tint, Sint, Mint," 209 + "IntegerVal, RealVal, DoubleVal, FloatVal, DecVal," 210 + "NumVal, charStr, dateVal, timeVal, TS," 211 + "DT, TBlob, BlobVal, MBlob, LBlob," 212 + "TText, TextVal, MText, LText, MaxLongVal, MinLongVal," 213 +" validURL, invalidURL" 214 + ") " 215 + "values (null, null, null, null, null," 216 + "null, null, null, null, null, null, null," 217 + "null, null, null, null, null," 218 + "null, null, null, null, null," 219 + "null, null, null, null,null, null, null, null);" 220 }; 221 222 @Override 223 public void setUp() { 224 super.setUp(); 225 try { 226 conn.setAutoCommit(false); 227 st = conn.createStatement(); 228 for (int i = 0; i < queries.length; i++) { 229 st.execute(queries[i]); 230 } 231 res = st.executeQuery(queryAllSelect); 232 assertTrue(res.next()); 233 } catch (SQLException e) { 234 fail("SQLException is thrown: " + e.getMessage()); 235 } 236 } 237 238 public void tearDown() { 239 try { 240 st.execute("drop table if exists type"); 241 st.close(); 242 res.close(); 243 } catch (SQLException e) { 244 fail("SQLException is thrown "+e.getMessage()); 245 } finally { 246 try { 247 st.close(); 248 res.close(); 249 } catch (SQLException ee) { 250 } 251 } 252 super.tearDown(); 253 } 254 255 /** 256 * Test method for {@link java.sql.ResultSet#getBytes(int)}. 257 */ 258 @TestTargetNew( 259 level = TestLevel.PARTIAL_COMPLETE, 260 notes = "Exception testing", 261 method = "getBytes", 262 args = {int.class} 263 ) 264 public void testGetBytesInt() { 265 int i = 1; 266 /* 267 268 // null value 269 try { 270 i = 1; 271 res.next(); 272 for (String t : values) { 273 assertNull(res.getBytes(i)); 274 i++; 275 } 276 } catch (SQLException e) { 277 fail("Unexpected exception: " + e.getMessage()); 278 } 279 280 try { 281 res.close(); 282 res.getBytes(24); 283 fail("Should get Exception"); 284 } catch (SQLException e) { 285 //ok 286 } 287 */ 288 } 289 290 /** 291 * Test method for {@link java.sql.ResultSet#getBytes(int)}. 292 */ 293 @TestTargetNew( 294 level = TestLevel.PARTIAL_COMPLETE, 295 notes = "Integer, test fails", 296 method = "getBytes", 297 args = {int.class} 298 ) 299 @KnownFailure("res.close() does not wrap up") 300 public void testGetBytesIntInteger() { 301 try { 302 303 Integer input = -1; 304 String output = ""; 305 306 Byte inputB = Byte.valueOf(input.toString()); 307 String hexInput = Integer.toHexString(inputB); 308 // byte[] inputBytes = 309 byte[] outputBytes = res.getBytes(2); 310 for (byte b : outputBytes) { 311 output += Integer.toHexString(b); 312 } 313 314 assertEquals(1, outputBytes.length); 315 assertEquals(hexInput, output); 316 317 318 319 } catch (SQLException e) { 320 fail("Unexpected exception: " + e.getMessage()); 321 } 322 323 // null value 324 try { 325 assertTrue(res.next()); 326 byte[] b = res.getBytes(2); 327 assertNull(b); 328 } catch (SQLException e) { 329 fail("Unexpected exception: " + e.getMessage()); 330 } 331 332 try { 333 res.close(); 334 res.getBytes(2); 335 fail("Should get Exception"); 336 } catch (SQLException e) { 337 //ok 338 } 339 } 340 341 342 /** 343 * Test method for {@link java.sql.ResultSet#getBytes(java.lang.String)}. 344 */ 345 @TestTargetNew( 346 level = TestLevel.NOT_FEASIBLE, 347 notes = "no BINARY type supported", 348 method = "getBytes", 349 args = {java.lang.String.class} 350 ) 351 public void testGetBytesString() { 352 /* 353 354 355 // null value 356 try { 357 res.next(); 358 359 for (String name: colNames) { 360 assertNull(res.getBytes(name)); 361 } 362 } catch (SQLException e) { 363 fail("Unexpected exception: " + e.getMessage()); 364 } 365 366 try { 367 res.close(); 368 res.getBytes("TextVal"); 369 fail("Should get Exception"); 370 } catch (SQLException e) { 371 //ok 372 } 373 */ 374 } 375 376 /** 377 * Test method for {@link java.sql.ResultSet#getConcurrency()}. 378 */ 379 @TestTargetNew( 380 level = TestLevel.SUFFICIENT, 381 notes = "PARTIAL_OKly supported: CONCUR_UPDATABLE not supported", 382 method = "getConcurrency", 383 args = {} 384 ) 385 public void testGetConcurrency() { 386 try { 387 assertEquals(ResultSet.CONCUR_READ_ONLY, res.getConcurrency()); 388 } catch (SQLException e) { 389 fail("Unexpected exception: " + e.getMessage()); 390 } 391 392 } 393 394 /** 395 * Test method for {@link java.sql.ResultSet#getDate(int)}. 396 */ 397 @TestTargetNew( 398 level = TestLevel.COMPLETE, 399 notes = "", 400 method = "getDate", 401 args = {int.class} 402 ) 403 public void testGetDateInt() { 404 try { 405 406 GregorianCalendar testCal = new GregorianCalendar(1799, Calendar.MAY, 26, 0, 0); 407 Date input = new Date(testCal.getTimeInMillis()); 408 Date d = res.getDate(15); 409 assertEquals(input.toString(),"1799-05-26"); 410 assertEquals(input,d); 411 412 } catch (SQLException e) { 413 fail("Unexpected exception: " + e.getMessage()); 414 } 415 try { 416 Date d = res.getDate(500); 417 fail("Should get exception"); 418 } catch (SQLException e) { 419 //ok 420 } catch (Exception e) { 421 fail("Got unspecified Exception "+ e.getMessage()); 422 } 423 424 // null value 425 try { 426 assertTrue(res.next()); 427 Date d = res.getDate(15); 428 assertNull(d); 429 } catch (SQLException e) { 430 fail("Unexpected exception: " + e.getMessage()); 431 } 432 } 433 434 /** 435 * Test method for {@link java.sql.ResultSet#getDate(int, java.util.Calendar)}. 436 */ 437 @TestTargetNew( 438 level = TestLevel.COMPLETE, 439 notes = "Not fully supported", 440 method = "getDate", 441 args = {int.class, java.util.Calendar.class} 442 ) 443 public void testGetDateIntCalendar() { 444 GregorianCalendar testCal = new GregorianCalendar(1799, Calendar.MAY, 26, 0, 0); 445 try { 446 447 Date input = new Date(testCal.getTimeInMillis()); 448 Date d = res.getDate(15, testCal); 449 450 assertEquals(input.toString(),"1799-05-26"); 451 assertEquals(input,d); 452 453 } catch (SQLException e) { 454 fail("Unexpected exception: " + e.getMessage()); 455 } 456 try { 457 Date d = res.getDate(500, testCal); 458 fail("Should get exception"); 459 } catch (SQLException e) { 460 //ok 461 } catch (Exception e) { 462 fail("Got unspecified Exception "+ e.getMessage()); 463 } 464 465 466 // null value 467 try { 468 assertTrue(res.next()); 469 Date d = res.getDate(15,testCal); 470 assertNull(d); 471 } catch (SQLException e) { 472 fail("Unexpected exception: " + e.getMessage()); 473 } 474 } 475 476 /** 477 * Test method for {@link java.sql.ResultSet#getDate(java.lang.String)}. 478 */ 479 @TestTargetNew( 480 level = TestLevel.COMPLETE, 481 notes = "Not fully supported", 482 method = "getDate", 483 args = {java.lang.String.class} 484 ) 485 public void testGetDateString() { 486 try { 487 GregorianCalendar testCal = new GregorianCalendar(1799, Calendar.MAY, 26, 0, 0); 488 Date input = new Date(testCal.getTimeInMillis()); 489 Date d = res.getDate("dateVal"); 490 assertEquals(input.toString(),"1799-05-26"); 491 assertEquals(input,d); 492 493 } catch (SQLException e) { 494 fail("Unexpected exception: " + e.getMessage()); 495 } 496 try { 497 Date d = res.getDate("bla"); 498 fail("Should get exception"); 499 } catch (SQLException e) { 500 //ok 501 } 502 503 // null value 504 try { 505 assertTrue(res.next()); 506 Date d = res.getDate("dateVal"); 507 assertNull(d); 508 } catch (SQLException e) { 509 fail("Unexpected exception: " + e.getMessage()); 510 } 511 } 512 513 /** 514 * Test method for {@link java.sql.ResultSet#getDate(java.lang.String, java.util.Calendar)}. 515 */ 516 @TestTargetNew( 517 level = TestLevel.COMPLETE, 518 notes = "", 519 method = "getDate", 520 args = {java.lang.String.class, java.util.Calendar.class} 521 ) 522 public void testGetDateStringCalendar() { 523 GregorianCalendar testCal = new GregorianCalendar(1799, Calendar.MAY, 26, 0, 0); 524 try { 525 Date input = new Date(testCal.getTimeInMillis()); 526 Date d = res.getDate("dateVal", testCal); 527 528 assertEquals(input.toString(),"1799-05-26"); 529 assertEquals(input,d); 530 531 } catch (SQLException e) { 532 fail("Unexpected exception: " + e.getMessage()); 533 } 534 try { 535 Date d = res.getDate("bla", testCal); 536 fail("Should get exception"); 537 } catch (SQLException e) { 538 //ok 539 } 540 541 // null value 542 try { 543 assertTrue(res.next()); 544 Date d = res.getDate("dateVal",testCal); 545 assertNull(d); 546 } catch (SQLException e) { 547 fail("Unexpected exception: " + e.getMessage()); 548 } 549 } 550 551 /** 552 * Test method for {@link java.sql.ResultSet#getDouble(int)}. 553 */ 554 @TestTargetNew( 555 level = TestLevel.COMPLETE, 556 notes = "", 557 method = "getDouble", 558 args = {int.class} 559 ) 560 public void testGetDoubleInt() { 561 562 double output = 0.0; 563 try { 564 double[] input = {2.0, 3.9 , 23.2}; 565 566 output = res.getDouble(8); 567 assertEquals(input[0],output); 568 569 output = res.getDouble(9); 570 assertEquals(input[1],output); 571 572 output = res.getDouble(10); 573 assertEquals(input[2],output); 574 575 } catch (SQLException e) { 576 fail("Unexpected exception: " + e.getMessage()); 577 } 578 579 try { 580 res.getDouble(500); 581 } catch (SQLException e) { 582 //ok 583 } 584 585 // null value 586 try { 587 res.next(); 588 output = res.getDouble(8); 589 assertEquals(0.0,output); 590 591 output = res.getDouble(9); 592 assertEquals(0.0,output); 593 594 output = res.getDouble(10); 595 assertEquals(0.0,output); 596 597 } catch (SQLException e) { 598 fail("Unexpected exception: " + e.getMessage()); 599 } 600 601 } 602 603 /** 604 * Test method for {@link java.sql.ResultSet#getDouble(java.lang.String)}. 605 */ 606 @TestTargetNew( 607 level = TestLevel.SUFFICIENT, 608 notes = "Not fully supported: eg. getDouble from TinyInt ", 609 method = "getDouble", 610 args = {java.lang.String.class} 611 ) 612 public void testGetDoubleString() { 613 double input = 23.2; 614 double output = 0.0; 615 616 try{ 617 output = res.getDouble("DoubleVal"); 618 assertEquals (input,output); 619 } catch (SQLException e) { 620 fail("Unexpected exception: " + e.getMessage()); 621 } 622 623 try{ 624 output = res.getDouble("bla"); 625 fail("Exception expected"); 626 } catch (SQLException e) { 627 // ok 628 } 629 630 // null value 631 try{ 632 assertTrue(res.next()); 633 output = res.getDouble("DoubleVal"); 634 assertEquals (0.0 , output); 635 } catch (SQLException e) { 636 fail("Unexpected exception: " + e.getMessage()); 637 } 638 } 639 640 /** 641 * Test method for {@link java.sql.ResultSet#getFloat(int)}. 642 */ 643 @TestTargetNew( 644 level = TestLevel.SUFFICIENT, 645 notes = "Not fully supported: eg.: getFloat from TinyInt according to JDBC 1.0 spec", 646 method = "getFloat", 647 args = {int.class} 648 ) 649 public void testGetFloatInt() { 650 float defaultF = 0.0f; 651 try { 652 float[] input = {3.9f, 23.2f, 33.3f}; 653 654 655 float output = res.getFloat(9); 656 assertEquals(input[0], output); 657 658 output = res.getFloat(10); 659 assertEquals(input[1], output); 660 661 output = res.getFloat(11); 662 assertEquals(input[2], output); 663 664 } catch (SQLException e) { 665 fail("Unexpected exception: " + e.getMessage()); 666 } 667 668 try { 669 res.getFloat(500); 670 fail("Exception expected"); 671 } catch (SQLException e) { 672 //ok 673 } 674 675 try { 676 res.next(); 677 float output = res.getFloat(8); 678 assertEquals(defaultF, output); 679 680 output = res.getFloat(9); 681 assertEquals(defaultF, output); 682 683 output = res.getFloat(10); 684 assertEquals(defaultF, output); 685 686 } catch (SQLException e) { 687 fail("Unexpected exception: " + e.getMessage()); 688 } 689 } 690 691 /** 692 * Test method for {@link java.sql.ResultSet#getFloat(java.lang.String)}. 693 */ 694 @TestTargetNew( 695 level = TestLevel.SUFFICIENT, 696 notes = "Not fully supported", 697 method = "getFloat", 698 args = {java.lang.String.class} 699 ) 700 public void testGetFloatString() { 701 float defaultF = 0.0f; 702 try { 703 String[] input = {"RealVal", "DoubleVal", "FloatVal"}; 704 float[] inputF = {3.9f, 23.2f, 33.3f}; 705 706 707 float output = res.getFloat(input[0]); 708 assertEquals(inputF[0], output); 709 710 output = res.getFloat(input[1]); 711 assertEquals(inputF[1], output); 712 713 output = res.getFloat(input[2]); 714 assertEquals(inputF[2], output); 715 716 } catch (SQLException e) { 717 fail("Unexpected exception: " + e.getMessage()); 718 } 719 720 try { 721 res.getFloat(500); 722 fail("Exception expected"); 723 } catch (SQLException e) { 724 //ok 725 } 726 727 try { 728 res.next(); 729 float output = res.getFloat(8); 730 assertEquals(defaultF, output); 731 732 output = res.getFloat(9); 733 assertEquals(defaultF, output); 734 735 output = res.getFloat(10); 736 assertEquals(defaultF, output); 737 738 } catch (SQLException e) { 739 fail("Unexpected exception: " + e.getMessage()); 740 } 741 } 742 743 /** 744 * Test method for {@link java.sql.ResultSet#getInt(int)}. 745 */ 746 @TestTargetNew( 747 level = TestLevel.COMPLETE, 748 notes = "", 749 method = "getInt", 750 args = {int.class} 751 ) 752 public void testGetIntInt() { 753 754 // real input val -1, 22, 2, 33,3, 1, 2 755 List<Integer> input = Arrays.asList(1, -1, 22, 2, 33,3, 1, 2); 756 ListIterator<Integer> it = input.listIterator(); 757 Double test2 = new Double(23.2); 758 try { 759 for (int i = 1;i<9;i++ ) { 760 assertEquals(it.next().intValue(),res.getInt(i)); 761 } 762 } catch (SQLException e) { 763 fail("Unexpected exception: " + e.getMessage()); 764 } 765 766 try { 767 res.getInt(500); 768 fail("Exception expected"); 769 } catch (SQLException e) { 770 //ok 771 } 772 773 try { 774 res.next(); 775 for (int i = 2;i<11;i++ ) { 776 assertEquals(0,res.getInt(i)); 777 } 778 779 } catch (SQLException e) { 780 fail("Unexpected exception: " + e.getMessage()); 781 } 782 } 783 784 /** 785 * Test method for {@link java.sql.ResultSet#getInt(java.lang.String)}. 786 */ 787 @TestTargetNew( 788 level = TestLevel.COMPLETE, 789 notes = "", 790 method = "getInt", 791 args = {java.lang.String.class} 792 ) 793 public void testGetIntString() { 794 List<String> inputS = Arrays.asList("BoolVal", "IntVal", "LongVal", 795 "Bint", "Tint", "Sint", "Mint", "IntegerVal"); 796 ListIterator<String> itS = inputS.listIterator(); 797 List<Integer> input = Arrays.asList(1, -1, 22, 2, 33, 3, 1, 2); 798 ListIterator<Integer> it = input.listIterator(); 799 try { 800 while (it.hasNext()) { 801 assertEquals(it.next().intValue(), res.getInt(itS.next())); 802 } 803 } catch (SQLException e) { 804 fail("Unexpected exception: " + e.getMessage()); 805 } 806 807 try { 808 res.getInt("bla"); 809 fail("Exception expected"); 810 } catch (SQLException e) { 811 //ok 812 } 813 814 try { 815 res.next(); 816 for (String s : inputS) { 817 assertEquals(0, res.getInt(s)); 818 } 819 820 } catch (SQLException e) { 821 fail("Unexpected exception: " + e.getMessage()); 822 } 823 } 824 825 /** 826 * Test method for {@link java.sql.ResultSet#getLong(int)}. 827 */ 828 @TestTargetNew( 829 level = TestLevel.COMPLETE, 830 notes = "", 831 method = "getLong", 832 args = {int.class} 833 ) 834 public void testGetLongInt() { 835 long maxVal = Long.MAX_VALUE; 836 long minVal = Long.MIN_VALUE; 837 838 try { 839 assertEquals(maxVal, res.getLong(27)); 840 assertEquals(minVal, res.getLong(28)); 841 } catch (SQLException e) { 842 fail("Unexpected exception: " + e.getMessage()); 843 } 844 845 try { 846 res.getInt(500); 847 fail("Exception expected"); 848 } catch (SQLException e) { 849 //ok 850 } 851 852 try { 853 res.next(); 854 855 assertEquals(0,res.getLong(27)); 856 assertEquals(0,res.getLong(28)); 857 858 859 } catch (SQLException e) { 860 fail("Unexpected exception: " + e.getMessage()); 861 } 862 863 } 864 865 /** 866 * Test method for {@link java.sql.ResultSet#getLong(java.lang.String)}. 867 */ 868 @TestTargetNew( 869 level = TestLevel.COMPLETE, 870 notes = "", 871 method = "getLong", 872 args = {java.lang.String.class} 873 ) 874 public void testGetLongString() { 875 long maxVal = Long.MAX_VALUE; 876 long minVal = Long.MIN_VALUE; 877 878 try { 879 assertEquals(maxVal, res.getLong("MaxLongVal")); 880 assertEquals(minVal, res.getLong("MinLongVal")); 881 } catch (SQLException e) { 882 fail("Unexpected exception: " + e.getMessage()); 883 } 884 885 try { 886 res.getInt("bla"); 887 fail("Exception expected"); 888 } catch (SQLException e) { 889 //ok 890 } 891 892 try { 893 res.next(); 894 895 assertEquals(0,res.getLong("MaxLongVal")); 896 assertEquals(0,res.getLong("MinLongVal")); 897 898 899 } catch (SQLException e) { 900 fail("Unexpected exception: " + e.getMessage()); 901 } 902 } 903 904 /** 905 * Test method for {@link java.sql.ResultSet#getMetaData()}. 906 * type mappings according to 907 * http://java.sun.com/j2se/1.3/docs/guide/jdbc/spec/jdbc-spec.frame8.html 908 * Not supported datatypes are not checked. 909 */ 910 @TestTargets({ 911 @TestTargetNew( 912 level = TestLevel.SUFFICIENT, 913 notes = "checks supported data types ,not supported types are not checked.", 914 method = "getMetaData", 915 args = {} 916 ) 917 }) 918 public void testGetMetaData() { 919 /* 920 * List<String> types = Arrays.asList("BOOLEAN", "INT", "LONG", 921 * "BIGINT", "TINYINT", "SMALLINT", "MEDIUMINT", "INTEGER", "REAL", 922 * "DOUBLE", "FLOAT", "DECIMAL", "NUMERIC", "CHAR(20)", "DATE", "TIME", 923 * "TIMESTAMP", "DATETIME", "TINYBLOB", "BLOB", "MEDIUMBLOB", 924 * "LONGBLOB", "TINYTEXT", "TEXT", "MEDIUMTEXT", "LONGTEXT", "BIGINT", 925 * "BIGINT","URL","URL"); 926 */ 927 List<String> types = Arrays.asList("VARCHAR", "INTEGER", "VARCHAR", 928 "BIGINT", "SMALLINT", "SHORT", "INTEGER", "INTEGER", "FLOAT", 929 "DOUBLE", "DOUBLE", "DECIMAL", "NUMERIC", "VARCHAR", "DATE", 930 "TIME", "TIMESTAMP", "DATETIME", "BLOB", "BLOB", "BLOB", 931 "BLOB", "VARCHAR", "VARCHAR", "VARCHAR", "VARCHAR", "BIGINT", 932 "BIGINT", "URL", "URL"); 933 934 935 936 ListIterator<String> it = types.listIterator(); 937 ListIterator<String> colNameIt = colNames.listIterator(); 938 try { 939 ResultSetMetaData meta = res.getMetaData(); 940 assertNotNull(meta); 941 assertEquals("Error in test setup. Columns do not match", types 942 .size(), meta.getColumnCount()); 943 for (int i = 1; i < 31; i++) { 944 String colName = colNameIt.next(); 945 String type = it.next(); 946 if (supported[i - 1]) { 947 assertTrue("Wrong column name at " + i, colName 948 .equalsIgnoreCase(meta.getColumnName(i))); 949 assertTrue("Wrong type at " + i, type.equalsIgnoreCase(meta 950 .getColumnTypeName(i))); 951 } 952 } 953 } catch (SQLException e) { 954 fail("Unexpected exception: " + e.getMessage()); 955 } 956 } 957 958 /** 959 * Test method for {@link java.sql.ResultSet#getObject(int)}. 960 */ 961 @TestTargetNew( 962 level = TestLevel.SUFFICIENT, 963 notes = "not supported types BIT,VARBINARY, LONGVARBINARY, BINARY, VARCHAR, LONGVARCHAR", 964 method = "getObject", 965 args = {int.class} 966 ) 967 public void testGetObjectInt() { 968 969 try { 970 for (int i = 1; i <= typeMap.length; i++) { 971 if (supported[i-1]) { 972 Object value = res.getObject(i); 973 assertTrue("value " + value.getClass().getName() 974 + " does not correspond " + typeMap[i-1] + "at "+i, value 975 .getClass().equals(typeMap[i-1])); 976 } 977 } 978 } catch (SQLException e) { 979 fail("Unexpected exception: " + e.getMessage()); 980 } 981 982 try { 983 res.getObject(500); 984 fail("Exception expected"); 985 } catch (SQLException e) { 986 //ok 987 } 988 989 try { 990 res.next(); 991 for (int i = 1; i <= typeMap.length; i++) { 992 Object value = res.getObject(i); 993 assertNull(value); 994 } 995 } catch (SQLException e) { 996 fail("Unexpected exception: " + e.getMessage()); 997 } 998 999 1000 } 1001 1002 1003 /** 1004 * Test method for {@link java.sql.ResultSet#getObject(java.lang.String)}. 1005 */ 1006 @TestTargetNew( 1007 level = TestLevel.COMPLETE, 1008 notes = "not fully supported", 1009 method = "getObject", 1010 args = {java.lang.String.class} 1011 ) 1012 public void testGetObjectString() { 1013 ListIterator<String> colNameIt = colNames.listIterator(); 1014 try { 1015 for (int i = 1; i <= typeMap.length; i++) { 1016 String name = colNameIt.next(); 1017 if (supported[i-1]) { 1018 Object value = res.getObject(name); 1019 assertTrue("value " + value.getClass().getName() 1020 + " does not correspond " + typeMap[i-1] + "at "+i, value 1021 .getClass().equals(typeMap[i-1])); 1022 } 1023 } 1024 } catch (SQLException e) { 1025 fail("Unexpected exception: " + e.getMessage()); 1026 } 1027 1028 try { 1029 res.getObject("bla"); 1030 fail("Exception expected"); 1031 } catch (SQLException e) { 1032 //ok 1033 } 1034 1035 1036 try { 1037 colNameIt = colNames.listIterator(); 1038 res.next(); 1039 for (int i = 1; i <= typeMap.length; i++) { 1040 Object value = res.getObject(colNameIt.next()); 1041 assertNull(value); 1042 } 1043 } catch (SQLException e) { 1044 fail("Unexpected exception: " + e.getMessage()); 1045 } 1046 1047 } 1048 1049 1050 /** 1051 * Test method for {@link java.sql.ResultSet#getRow()}. 1052 */ 1053 @TestTargetNew( 1054 level = TestLevel.COMPLETE, 1055 notes = "Exception testing missed, test fails. According to spec afterlast row is 0 but returns 3", 1056 method = "getRow", 1057 args = {} 1058 ) 1059 @KnownFailure("If there is no current row 0 must be returned. res.close() does not wrap up") 1060 public void testGetRow() { 1061 try { 1062 assertEquals(1, res.getRow()); 1063 assertTrue(res.isFirst()); 1064 res.next(); 1065 assertEquals(2, res.getRow()); 1066 assertTrue(res.isLast()); 1067 res.next(); 1068 assertTrue(res.isAfterLast()); 1069 assertEquals(0, res.getRow()); 1070 } catch (SQLException e) { 1071 fail("Unexpected exception: " + e.getMessage()); 1072 } 1073 1074 try { 1075 res.close(); 1076 res.getRow(); 1077 } catch (SQLException e) { 1078 // ok 1079 } 1080 } 1081 1082 /** 1083 * Test method for {@link java.sql.ResultSet#getShort(int)}. 1084 */ 1085 @TestTargetNew( 1086 level = TestLevel.COMPLETE, 1087 notes = "", 1088 method = "getShort", 1089 args = {int.class} 1090 ) 1091 public void testGetShortInt() { 1092 try { 1093 short shorty = res.getShort(6); 1094 assertEquals(3,shorty); 1095 } catch (SQLException e) { 1096 fail("Unexpected exception: " + e.getMessage()); 1097 } 1098 1099 try { 1100 res.next(); 1101 short shorty = res.getShort(6); 1102 assertEquals(0,shorty); 1103 } catch (SQLException e) { 1104 fail("Unexpected exception: " + e.getMessage()); 1105 } 1106 1107 1108 try { 1109 res.getShort(500); 1110 fail("Exception expected"); 1111 } catch (SQLException e) { 1112 //ok 1113 } 1114 } 1115 1116 /** 1117 * Test method for {@link java.sql.ResultSet#getShort(java.lang.String)}. 1118 */ 1119 @TestTargetNew( 1120 level = TestLevel.COMPLETE, 1121 notes = "", 1122 method = "getShort", 1123 args = {java.lang.String.class} 1124 ) 1125 public void testGetShortString() { 1126 try { 1127 short shorty = res.getShort("Sint"); 1128 assertEquals(3,shorty); 1129 } catch (SQLException e) { 1130 fail("Unexpected exception: " + e.getMessage()); 1131 } 1132 1133 try { 1134 res.next(); 1135 short shorty = res.getShort("Sint"); 1136 assertEquals(0,shorty); 1137 } catch (SQLException e) { 1138 fail("Unexpected exception: " + e.getMessage()); 1139 } 1140 1141 1142 try { 1143 res.getShort("bla"); 1144 fail("Exception expected"); 1145 } catch (SQLException e) { 1146 //ok 1147 } 1148 } 1149 1150 /** 1151 * Test method for {@link java.sql.ResultSet#getStatement()}. 1152 */ 1153 @TestTargetNew( 1154 level = TestLevel.COMPLETE, 1155 notes = "test fails. According to spec info.getStatement should return"+ 1156 " null but an exception is thrown: stale result set.", 1157 method = "getStatement", 1158 args = {} 1159 ) 1160 @KnownFailure("According to spec info.getStatement should return null"+ 1161 " but an exception is thrown: stale result set.") 1162 public void testGetStatement() { 1163 try { 1164 DatabaseMetaData meta = conn.getMetaData(); 1165 ResultSet info = meta.getTypeInfo(); 1166 Statement statement2 = info.getStatement(); 1167 assertNull(statement2); 1168 } catch(SQLException e) { 1169 fail("Unexpected exception: " + e.getMessage()); 1170 } 1171 1172 try { 1173 Statement statement2 = res.getStatement(); 1174 assertEquals(st, statement2); 1175 } catch(SQLException e) { 1176 fail("Unexpected exception: " + e.getMessage()); 1177 } 1178 1179 // exception testing 1180 try { 1181 res.close(); 1182 res.getStatement(); 1183 fail("Exception expected"); 1184 } catch (SQLException e) { 1185 //ok 1186 } 1187 } 1188 1189 /** 1190 * Test method for {@link java.sql.ResultSet#getString(int)}. 1191 */ 1192 @TestTargetNew( 1193 level = TestLevel.COMPLETE, 1194 notes = "", 1195 method = "getString", 1196 args = {int.class} 1197 ) 1198 public void testGetStringInt() { 1199 List<String> texts = Arrays.asList("Test text message tiny", 1200 "Test text", "Test text message medium", 1201 "Test text message long"); 1202 int i = 23; 1203 1204 //text and exception testing 1205 try { 1206 for (String t : texts) { 1207 assertEquals(t, res.getString(i)); 1208 i++; 1209 } 1210 } catch (SQLException e) { 1211 fail("Unexpected exception: " + e.getMessage()); 1212 } 1213 1214 // the rest: everything should work with getString 1215 1216 texts = Arrays.asList("1", "-1", "22", "2", "33", 1217 "3","1","2","3.9","23.2","33.3","44", 1218 "5", "test string", "1799-05-26", "12:35:45", "2007-10-09 14:28:02.0", 1219 "1221-09-22 10:11:55","1","2","3","4"); 1220 i= 1; 1221 1222 try { 1223 for (String t : texts) { 1224 assertEquals(t, res.getString(i)); 1225 i++; 1226 } 1227 } catch (SQLException e) { 1228 fail("Unexpected exception: " + e.getMessage()); 1229 } 1230 1231 //null testing 1232 1233 try { 1234 i = 1; 1235 res.next(); 1236 for (String t : values) { 1237 assertNull(res.getString(i)); 1238 i++; 1239 } 1240 } catch (SQLException e) { 1241 fail("Unexpected exception: " + e.getMessage()); 1242 } 1243 1244 // exception testing 1245 try { 1246 res.getString(500); 1247 fail("Exception expected"); 1248 } catch (SQLException e) { 1249 //ok 1250 } 1251 1252 } 1253 1254 /** 1255 * Test method for {@link java.sql.ResultSet#getString(java.lang.String)}. 1256 */ 1257 @TestTargetNew( 1258 level = TestLevel.COMPLETE, 1259 notes = "exception test missed", 1260 method = "getString", 1261 args = {java.lang.String.class} 1262 ) 1263 public void testGetStringString() { 1264 1265 ListIterator<String> colNameIt = colNames.listIterator(); 1266 try { 1267 for (String t : values) { 1268 assertEquals(t, res.getString(colNameIt.next())); 1269 } 1270 } catch (SQLException e) { 1271 fail("Unexpected exception: " + e.getMessage()); 1272 } 1273 1274 try { 1275 res.next(); 1276 1277 for (String name: colNames) { 1278 assertNull(res.getString(name)); 1279 } 1280 } catch (SQLException e) { 1281 fail("Unexpected exception: " + e.getMessage()); 1282 } 1283 1284 try { 1285 res.getString("bla"); 1286 fail("Exception expected"); 1287 } catch (SQLException e) { 1288 //ok 1289 } 1290 } 1291 1292 /** 1293 * Test method for {@link java.sql.ResultSet#getTime(int)}. 1294 */ 1295 @TestTargetNew( 1296 level = TestLevel.COMPLETE, 1297 notes = "", 1298 method = "getTime", 1299 args = {int.class} 1300 ) 1301 public void testGetTimeInt() { 1302 List<Time> times = new LinkedList<Time>(); 1303 // values "12:35:45", "2007-10-09 14:28:02.0", "1221-09-22 10:11:55" 1304 1305 Calendar cal = new GregorianCalendar(); 1306 cal.clear(); 1307 cal.set(Calendar.HOUR_OF_DAY, 12); 1308 cal.set(Calendar.MINUTE, 35); 1309 cal.set(Calendar.SECOND, 45); 1310 cal.set(Calendar.MILLISECOND, 0); 1311 // set with calendar value (correct init time: since epoch) 1312 long millis = cal.getTime().getTime(); 1313 Time t1 = new java.sql.Time(millis); 1314 assertNotNull("t1", t1); 1315 times.add(t1); 1316 1317 int i = 16; 1318 1319 try { 1320 Time resTime = res.getTime(i); 1321 assertNotNull("Pos " + i + " null", resTime); 1322 assertEquals(t1.toString(), resTime.toString()); 1323 assertEquals(t1.getTime(), resTime.getTime()); 1324 assertEquals(t1, resTime); 1325 } catch (SQLException e) { 1326 fail("Unexpected exception: " + e.getMessage()); 1327 } 1328 1329 try { 1330 i = 16; 1331 res.next(); 1332 assertNull(res.getTime(i)); 1333 } catch (SQLException e) { 1334 fail("Unexpected exception: " + e.getMessage()); 1335 } 1336 1337 try { 1338 res.getTime(500); 1339 fail("Exception expected"); 1340 } catch (SQLException e) { 1341 // ok 1342 } 1343 } 1344 1345 /** 1346 * Test method for {@link java.sql.ResultSet#getTime(int, java.util.Calendar)}. 1347 */ 1348 @TestTargetNew( 1349 level = TestLevel.COMPLETE, 1350 notes = "", 1351 method = "getTime", 1352 args = {int.class, java.util.Calendar.class} 1353 ) 1354 public void testGetTimeIntCalendar() { 1355 List<Time> times = new LinkedList<Time>(); 1356 List<Calendar> cals = new LinkedList<Calendar>(); 1357 // Arrays.asList("12:35:45", "2007-10-09 14:28:02.0", 1358 // "1221-09-22 10:11:55"); 1359 1360 Calendar cal1 = new GregorianCalendar(); 1361 cal1.clear(); 1362 cal1.set(Calendar.HOUR_OF_DAY, 12); 1363 cal1.set(Calendar.MINUTE, 35); 1364 cal1.set(Calendar.SECOND, 45); 1365 cal1.set(Calendar.MILLISECOND, 0); 1366 1367 long millis = cal1.getTime().getTime(); 1368 Time t1 = new java.sql.Time(millis); 1369 1370 int i = 16; 1371 1372 try { 1373 Time timeRes = res.getTime(i,new GregorianCalendar()); 1374 assertNotNull(timeRes); 1375 assertEquals(t1.toString(), timeRes.toString()); 1376 assertEquals(t1.getTime(), timeRes.getTime()); 1377 assertEquals(t1, timeRes); 1378 } catch (SQLException e) { 1379 fail("Unexpected exception: " + e.getMessage()); 1380 } 1381 1382 try { 1383 res.next(); 1384 1385 for (Calendar c : cals) { 1386 assertNull(res.getTime(16,c)); 1387 i++; 1388 } 1389 } catch (SQLException e) { 1390 fail("Unexpected exception: " + e.getMessage()); 1391 } 1392 1393 try { 1394 res.getTime(500,Calendar.getInstance()); 1395 fail("Exception expected"); 1396 } catch (SQLException e) { 1397 //ok 1398 } 1399 } 1400 1401 /** 1402 * Test method for {@link java.sql.ResultSet#getTime(java.lang.String)}. 1403 */ 1404 @TestTargetNew( 1405 level = TestLevel.SUFFICIENT, 1406 notes = "", 1407 method = "getTime", 1408 args = {java.lang.String.class} 1409 ) 1410// @KnownFailure("Type Time not supported. test fails") 1411 public void testGetTimeString() { 1412 List<Time> times = new LinkedList<Time>(); 1413 1414 List<String> stringTimes = Arrays.asList("timeVal", "TS", "DT"); 1415 Iterator<String> it = stringTimes.iterator(); 1416 1417 // Arrays.asList("12:35:45", "2007-10-09 14:28:02.0", 1418 // "1221-09-22 10:11:55"); 1419 1420 Calendar cal = new GregorianCalendar(); 1421 cal.clear(); 1422 cal.set(Calendar.HOUR_OF_DAY, 12); 1423 cal.set(Calendar.MINUTE, 35); 1424 cal.set(Calendar.SECOND, 45); 1425 cal.set(Calendar.MILLISECOND, 0); 1426 1427 long millis = cal.getTime().getTime(); 1428 Time t1 = new java.sql.Time(millis); 1429 1430 String col = it.next(); 1431 1432 try { 1433 Time timeRes = res.getTime(col); 1434 assertNotNull(timeRes); 1435 assertEquals(t1.toString(), timeRes.toString()); 1436 assertEquals(t1.getTime(), timeRes.getTime()); 1437 assertEquals(t1, timeRes); 1438 } catch (SQLException e) { 1439 fail("Unexpected exception: " + e.getMessage()); 1440 } 1441 1442 try { 1443 res.next(); 1444 1445 assertNull(res.getTime(col)); 1446 } catch (SQLException e) { 1447 fail("Unexpected exception: " + e.getMessage()); 1448 } 1449 1450 try { 1451 res.getTime("bla"); 1452 fail("Exception expected"); 1453 } catch (SQLException e) { 1454 //ok 1455 } 1456 } 1457 1458 /** 1459 * Test method for {@link java.sql.ResultSet#getTime(java.lang.String, java.util.Calendar)}. 1460 */ 1461 @TestTargetNew( 1462 level = TestLevel.COMPLETE, 1463 notes = "type Time not supported. Test fails", 1464 method = "getTime", 1465 args = {java.lang.String.class, java.util.Calendar.class} 1466 ) 1467// @KnownFailure("type Time not supported. Test fails") 1468 public void testGetTimeStringCalendar() { 1469 List<Time> times = new LinkedList<Time>(); 1470 1471 List<String> stringTimes = Arrays.asList("timeVal", "TS", "DT"); 1472 Iterator<String> it = stringTimes.iterator(); 1473 List<Calendar> cals = new LinkedList<Calendar>(); 1474 1475 // Arrays.asList("12:35:45", "2007-10-09 14:28:02.0", 1476 // "1221-09-22 10:11:55"); 1477 1478 Calendar cal1 = new GregorianCalendar(); 1479 cal1.clear(); 1480 cal1.set(Calendar.HOUR_OF_DAY, 12); 1481 cal1.set(Calendar.MINUTE, 35); 1482 cal1.set(Calendar.SECOND, 45); 1483 cal1.set(Calendar.MILLISECOND, 0); 1484 1485 long millis = cal1.getTime().getTime(); 1486 Time t1 = new java.sql.Time(millis); 1487 1488 Calendar cal2 = new GregorianCalendar(); 1489 cal2.set(Calendar.YEAR, 2007); 1490 cal2.set(Calendar.MONTH, Calendar.OCTOBER); 1491 cal2.set(Calendar.DATE, 9); 1492 cal2.set(Calendar.HOUR_OF_DAY, 14); 1493 cal2.set(Calendar.MINUTE, 28); 1494 cal2.set(Calendar.SECOND, 02); 1495 cal2.set(Calendar.MILLISECOND, 0); 1496 1497 long millis2 = cal2.getTime().getTime(); 1498 Time t2 = new java.sql.Time(millis2); 1499 1500// ListIterator<Calendar> calIt = cals.listIterator(); 1501 String col = it.next(); 1502 1503 try { 1504 Time timeRes = res.getTime(col, new GregorianCalendar()); 1505 assertNotNull(timeRes); 1506 assertEquals(t1.toString(), timeRes.toString()); 1507 assertEquals(t1.getTime(), timeRes.getTime()); 1508 assertEquals(t1, res.getTime(col)); 1509 } catch (SQLException e) { 1510 fail("Unexpected exception: " + e.getMessage()); 1511 } 1512 1513 col = it.next(); 1514 System.out.println("ResultSetGetterTests.testGetTimeStringCalendar() "+col); 1515 1516 try { 1517 Time timeRes = res.getTime(col, new GregorianCalendar()); 1518 assertNotNull(timeRes); 1519 assertEquals(t2.toString(), timeRes.toString()); 1520 assertEquals(t2.getTime(), timeRes.getTime()); 1521 assertEquals(t2, res.getTime(col)); 1522 } catch (SQLException e) { 1523 fail("Unexpected exception: " + e.getMessage()); 1524 } 1525 1526 1527 1528 try { 1529 res.next(); 1530 assertNull(res.getTime(stringTimes.get(0), new GregorianCalendar())); 1531 } catch (SQLException e) { 1532 fail("Unexpected exception: " + e.getMessage()); 1533 } 1534 1535 try { 1536 res.getTime("bla"); 1537 fail("Exception expected"); 1538 } catch (SQLException e) { 1539 // ok 1540 } 1541 } 1542 1543 /** 1544 * Test method for {@link java.sql.ResultSet#getTimestamp(int)}. 1545 */ 1546 @TestTargetNew( 1547 level = TestLevel.COMPLETE, 1548 notes = "", 1549 method = "getTimestamp", 1550 args = {int.class} 1551 ) 1552 public void testGetTimestampInt() { 1553 List<Timestamp> times = new LinkedList<Timestamp>(); 1554 1555 List<String> stringTimes = Arrays.asList("timeVal", "TS", "DT"); 1556 Iterator<String> it = stringTimes.iterator(); 1557 List<Calendar> cals = new LinkedList<Calendar>(); 1558 1559 Calendar cal2 = new GregorianCalendar(); 1560 cal2.set(Calendar.YEAR, 2007); 1561 cal2.set(Calendar.MONTH, Calendar.OCTOBER); 1562 cal2.set(Calendar.DATE, 9); 1563 cal2.set(Calendar.HOUR_OF_DAY, 14); 1564 cal2.set(Calendar.MINUTE, 28); 1565 cal2.set(Calendar.SECOND, 02); 1566 cal2.set(Calendar.MILLISECOND, 0); 1567 1568 long millis = cal2.getTime().getTime(); 1569 Timestamp t2 = new Timestamp(millis); 1570 times.add(t2); 1571 // 1572 Calendar cal3 = new GregorianCalendar(); 1573 cal3.set(Calendar.YEAR, 1221); 1574 cal3.set(Calendar.MONTH, Calendar.SEPTEMBER); 1575 cal3.set(Calendar.DATE, 22); 1576 cal3.set(Calendar.HOUR_OF_DAY, 10); 1577 cal3.set(Calendar.MINUTE, 11); 1578 cal3.set(Calendar.SECOND, 55); 1579 cal3.set(Calendar.MILLISECOND, 0); 1580 1581 millis = cal3.getTime().getTime(); 1582 Timestamp t3 = new Timestamp(millis); 1583 times.add(t3); 1584 1585// cals.add(cal1); 1586 cals.add(cal2); 1587 cals.add(cal3); 1588 1589 // ListIterator<Calendar> calIt = cals.listIterator(); 1590 1591 int i = 17; 1592 1593 try { 1594 // String col = it.next(); 1595 Timestamp timeRes = res.getTimestamp(i); 1596 assertEquals(t2.toString(), timeRes.toString()); 1597 assertEquals(t2.getTime(), timeRes.getTime()); 1598 // assertEquals(t, res.getTime(col)); 1599 } catch (SQLException e) { 1600 fail("Unexpected exception: " + e.getMessage()); 1601 } 1602 1603 // calIt = cals.listIterator(); 1604 1605 try { 1606 res.next(); 1607 assertNull(res.getTime(i)); 1608 } catch (SQLException e) { 1609 fail("Unexpected exception: " + e.getMessage()); 1610 } 1611 1612 try { 1613 res.getTime(500); 1614 fail("Exception expected"); 1615 } catch (SQLException e) { 1616 // ok 1617 } 1618 } 1619 1620 /** 1621 * Test method for {@link java.sql.ResultSet#getTimestamp(int, java.util.Calendar)}. 1622 */ 1623 @TestTargetNew( 1624 level = TestLevel.COMPLETE, 1625 notes = "", 1626 method = "getTimestamp", 1627 args = {int.class, java.util.Calendar.class} 1628 ) 1629 public void testGetTimestampIntCalendar() { 1630 List<Timestamp> times = new LinkedList<Timestamp>(); 1631 1632 List<String> stringTimes = Arrays.asList("timeVal", "TS", "DT"); 1633 Iterator<String> it = stringTimes.iterator(); 1634// List<Calendar> cals = new LinkedList<Calendar>(); 1635 1636 Calendar cal2 = new GregorianCalendar(); 1637 cal2.set(Calendar.YEAR, 2007); 1638 cal2.set(Calendar.MONTH, Calendar.OCTOBER); 1639 cal2.set(Calendar.DATE, 9); 1640 cal2.set(Calendar.HOUR_OF_DAY, 14); 1641 cal2.set(Calendar.MINUTE, 28); 1642 cal2.set(Calendar.SECOND, 02); 1643 cal2.set(Calendar.MILLISECOND, 0); 1644 1645 long millis = cal2.getTime().getTime(); 1646 Timestamp t2 = new Timestamp(millis); 1647 times.add(t2); 1648 // 1649 Calendar cal3 = new GregorianCalendar(); 1650 cal3.set(Calendar.YEAR, 1221); 1651 cal3.set(Calendar.MONTH, Calendar.SEPTEMBER); 1652 cal3.set(Calendar.DATE, 22); 1653 cal3.set(Calendar.HOUR_OF_DAY, 10); 1654 cal3.set(Calendar.MINUTE, 11); 1655 cal3.set(Calendar.SECOND, 55); 1656 cal3.set(Calendar.MILLISECOND, 0); 1657 1658 millis = cal3.getTime().getTime(); 1659 Timestamp t3 = new Timestamp(millis); 1660 times.add(t3); 1661 1662// cals.add(cal1); 1663// cals.add(cal2); 1664// cals.add(cal3); 1665// 1666// ListIterator<Calendar> calIt = cals.listIterator(); 1667 1668 int i = 17; 1669 1670 try { 1671 // String col = it.next(); 1672 Timestamp timeRes = res.getTimestamp(i,cal2); 1673 assertEquals(t2.toString(), timeRes.toString()); 1674 timeRes = res.getTimestamp(i+1,cal3); 1675 assertEquals(t3.toString(), timeRes.toString()); 1676 assertEquals(t3.getTime(), timeRes.getTime()); 1677 // assertEquals(t, res.getTime(col)); 1678 } catch (SQLException e) { 1679 fail("Unexpected exception: " + e.getMessage()); 1680 } 1681 1682 // calIt = cals.listIterator(); 1683 1684 try { 1685 res.next(); 1686 assertNull(res.getTime(17,cal2)); 1687 assertNull(res.getTime(18,cal3)); 1688 } catch (SQLException e) { 1689 fail("Unexpected exception: " + e.getMessage()); 1690 } 1691 1692 try { 1693 res.getTime(500); 1694 fail("Exception expected"); 1695 } catch (SQLException e) { 1696 // ok 1697 } 1698 } 1699 1700 /** 1701 * Test method for {@link java.sql.ResultSet#getTimestamp(java.lang.String)}. 1702 */ 1703 @TestTargetNew( 1704 level = TestLevel.COMPLETE, 1705 notes = "", 1706 method = "getTimestamp", 1707 args = {java.lang.String.class} 1708 ) 1709 public void testGetTimestampString() { 1710 List<Timestamp> times = new LinkedList<Timestamp>(); 1711 1712 List<String> stringTimes = Arrays.asList( "TS", "DT"); 1713 Iterator<String> it = stringTimes.iterator(); 1714// List<Calendar> cals = new LinkedList<Calendar>(); 1715 1716 Calendar cal2 = new GregorianCalendar(); 1717 cal2.set(Calendar.YEAR, 2007); 1718 cal2.set(Calendar.MONTH, Calendar.OCTOBER); 1719 cal2.set(Calendar.DATE, 9); 1720 cal2.set(Calendar.HOUR_OF_DAY, 14); 1721 cal2.set(Calendar.MINUTE, 28); 1722 cal2.set(Calendar.SECOND, 02); 1723 cal2.set(Calendar.MILLISECOND, 0); 1724 1725 long millis = cal2.getTime().getTime(); 1726 Timestamp t2 = new Timestamp(millis); 1727 times.add(t2); 1728 // 1729 Calendar cal3 = new GregorianCalendar(); 1730 cal3.set(Calendar.YEAR, 1221); 1731 cal3.set(Calendar.MONTH, Calendar.SEPTEMBER); 1732 cal3.set(Calendar.DATE, 22); 1733 cal3.set(Calendar.HOUR_OF_DAY, 10); 1734 cal3.set(Calendar.MINUTE, 11); 1735 cal3.set(Calendar.SECOND, 55); 1736 cal3.set(Calendar.MILLISECOND, 0); 1737 1738 millis = cal3.getTime().getTime(); 1739 Timestamp t3 = new Timestamp(millis); 1740 times.add(t3); 1741 1742// cals.add(cal1); 1743// cals.add(cal2); 1744// cals.add(cal3); 1745// 1746// ListIterator<Calendar> calIt = cals.listIterator(); 1747 1748 try { 1749 Timestamp timeRes = res.getTimestamp(stringTimes.get(0)); 1750 assertEquals(t2.toString(), timeRes.toString()); 1751 timeRes = res.getTimestamp(stringTimes.get(1)); 1752 assertEquals(t3.toString(), timeRes.toString()); 1753 assertEquals(t3.getTime(), timeRes.getTime()); 1754 // assertEquals(t, res.getTime(col)); 1755 } catch (SQLException e) { 1756 fail("Unexpected exception: " + e.getMessage()); 1757 } 1758 1759 // calIt = cals.listIterator(); 1760 1761 try { 1762 res.next(); 1763 assertNull(res.getTime(stringTimes.get(0))); 1764 assertNull(res.getTime(stringTimes.get(1))); 1765 } catch (SQLException e) { 1766 fail("Unexpected exception: " + e.getMessage()); 1767 } 1768 1769 try { 1770 res.getTime(500); 1771 fail("Exception expected"); 1772 } catch (SQLException e) { 1773 // ok 1774 } 1775 } 1776 1777 /** 1778 * Test method for {@link java.sql.ResultSet#getTimestamp(java.lang.String, java.util.Calendar)}. 1779 */ 1780 @TestTargetNew( 1781 level = TestLevel.COMPLETE, 1782 notes = "", 1783 method = "getTimestamp", 1784 args = {java.lang.String.class, java.util.Calendar.class} 1785 ) 1786 public void testGetTimestampStringCalendar() { 1787 List<Timestamp> times = new LinkedList<Timestamp>(); 1788 1789 List<String> stringTimes = Arrays.asList( "TS", "DT"); 1790 Iterator<String> it = stringTimes.iterator(); 1791 1792 Calendar cal2 = new GregorianCalendar(); 1793 cal2.set(Calendar.YEAR, 2007); 1794 cal2.set(Calendar.MONTH, Calendar.OCTOBER); 1795 cal2.set(Calendar.DATE, 9); 1796 cal2.set(Calendar.HOUR_OF_DAY, 14); 1797 cal2.set(Calendar.MINUTE, 28); 1798 cal2.set(Calendar.SECOND, 02); 1799 cal2.set(Calendar.MILLISECOND, 0); 1800 1801 long millis = cal2.getTime().getTime(); 1802 Timestamp t2 = new Timestamp(millis); 1803 times.add(t2); 1804 // 1805 Calendar cal3 = new GregorianCalendar(); 1806 cal3.set(Calendar.YEAR, 1221); 1807 cal3.set(Calendar.MONTH, Calendar.SEPTEMBER); 1808 cal3.set(Calendar.DATE, 22); 1809 cal3.set(Calendar.HOUR_OF_DAY, 10); 1810 cal3.set(Calendar.MINUTE, 11); 1811 cal3.set(Calendar.SECOND, 55); 1812 cal3.set(Calendar.MILLISECOND, 0); 1813 1814 millis = cal3.getTime().getTime(); 1815 Timestamp t3 = new Timestamp(millis); 1816 times.add(t3); 1817 1818 try { 1819 Timestamp timeRes = res.getTimestamp(stringTimes.get(0),cal2); 1820 assertEquals(t2.toString(), timeRes.toString()); 1821 timeRes = res.getTimestamp(stringTimes.get(1),cal3); 1822 assertEquals(t3.toString(), timeRes.toString()); 1823 assertEquals(t3.getTime(), timeRes.getTime()); 1824 // assertEquals(t, res.getTime(col)); 1825 } catch (SQLException e) { 1826 fail("Unexpected exception: " + e.getMessage()); 1827 } 1828 1829 // calIt = cals.listIterator(); 1830 1831 try { 1832 res.next(); 1833 assertNull(res.getTime(stringTimes.get(0),cal2)); 1834 assertNull(res.getTime(stringTimes.get(1),cal3)); 1835 } catch (SQLException e) { 1836 fail("Unexpected exception: " + e.getMessage()); 1837 } 1838 1839 try { 1840 res.getTime(500); 1841 fail("Exception expected"); 1842 } catch (SQLException e) { 1843 // ok 1844 } 1845 } 1846 1847 /** 1848 * Test method for {@link java.sql.ResultSet#getType()}. 1849 */ 1850 @TestTargetNew( 1851 level = TestLevel.SUFFICIENT, 1852 notes = "SQLException checking missed. Only one ResultSet type supported: default values, Test fails.Not fully supported. Always returns ResultSet.TYPE_SCROLL_INSENSITIVE. Wrong default value.", 1853 method = "getType", 1854 args = {} 1855 ) 1856 @KnownFailure("res.close() does not wrap up") 1857 public void testGetType() { 1858 try { 1859 assertEquals(ResultSet.TYPE_FORWARD_ONLY, res.getType()); 1860 } catch (SQLException e) { 1861 fail("Unexpected exception " + e.getMessage()); 1862 } 1863 1864 try { 1865 st.close(); 1866 res.getType(); 1867 fail("Exception not thrown."); 1868 } catch (SQLException e) { 1869 //ok 1870 } 1871 1872 } 1873 1874 1875 /** 1876 * Test method for {@link java.sql.ResultSet#getURL(int)}. 1877 */ 1878 @TestTargetNew( 1879 level = TestLevel.SUFFICIENT, 1880 notes = "not fully supported type", 1881 method = "getURL", 1882 args = {int.class} 1883 ) 1884 public void testGetURLInt() { 1885 try { 1886 URL input = new URL("http://www.android.com"); 1887 URL validURL = res.getURL(29); 1888 assertEquals(input, validURL); 1889 } catch (SQLException e) { 1890 fail("Unexpected exception " + e.getMessage()); 1891 } catch (MalformedURLException e) { 1892 fail("Unexpected exception " + e.getMessage()); 1893 } 1894 1895 try { 1896 URL invalidURL = res.getURL(30); 1897 assertNull(invalidURL); 1898 } catch (SQLException e) { 1899 // ok 1900 } 1901 1902 try { 1903 res.next(); 1904 assertNull(res.getURL(29)); 1905 assertNull(res.getURL(30)); 1906 } catch (SQLException e) { 1907 fail("Unexpected exception " + e.getMessage()); 1908 } 1909 1910 try { 1911 res.getURL(500); 1912 fail("Exception expected"); 1913 } catch (SQLException e) { 1914 // ok 1915 } 1916 } 1917 1918 /** 1919 * Test method for {@link java.sql.ResultSet#getURL(java.lang.String)}. 1920 */ 1921 @TestTargetNew( 1922 level = TestLevel.SUFFICIENT, 1923 notes = "not fully supported type", 1924 method = "getURL", 1925 args = {java.lang.String.class} 1926 ) 1927 public void testGetURLString() { 1928 try { 1929 URL input = new URL("http://www.android.com"); 1930 URL validURL = res.getURL("validURL"); 1931 assertEquals(input, validURL); 1932 } catch (SQLException e) { 1933 fail("Unexpected exception " + e.getMessage()); 1934 } catch (MalformedURLException e) { 1935 fail("Unexpected exception " + e.getMessage()); 1936 } 1937 1938 try { 1939 URL invalidURL = res.getURL("invalidURL"); 1940 assertNull(invalidURL); 1941 } catch (SQLException e) { 1942 // ok 1943 } 1944 1945 try { 1946 res.next(); 1947 assertNull(res.getURL("validURL")); 1948 assertNull(res.getURL("invalidURL")); 1949 } catch (SQLException e) { 1950 fail("Unexpected exception " + e.getMessage()); 1951 } 1952 1953 try { 1954 res.getURL("bla"); 1955 fail("Exception expected"); 1956 } catch (SQLException e) { 1957 // ok 1958 } 1959 } 1960} 1961