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