1 /*
   2  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package test.rowset;
  24 
  25 import java.io.InputStream;
  26 import java.io.Reader;
  27 import java.io.StringBufferInputStream;
  28 import java.io.StringReader;
  29 import java.math.BigDecimal;
  30 import java.sql.Array;
  31 import java.sql.Blob;
  32 import java.sql.Clob;
  33 import java.sql.Connection;
  34 import java.sql.ResultSet;
  35 import java.sql.SQLException;
  36 import java.sql.Date;
  37 import java.sql.Ref;
  38 import java.sql.RowId;
  39 import java.sql.SQLFeatureNotSupportedException;
  40 import java.sql.Time;
  41 import java.sql.Timestamp;
  42 import java.sql.Types;
  43 import java.time.LocalDate;
  44 import java.time.LocalDateTime;
  45 import java.time.LocalTime;
  46 import java.util.Calendar;
  47 import java.util.HashMap;
  48 import java.util.Map;
  49 import java.util.logging.Level;
  50 import java.util.logging.Logger;
  51 import javax.sql.rowset.serial.SerialArray;
  52 import javax.sql.rowset.serial.SerialBlob;
  53 import javax.sql.rowset.serial.SerialClob;
  54 import javax.sql.rowset.serial.SerialRef;
  55 import static org.testng.Assert.*;
  56 import org.testng.annotations.BeforeMethod;
  57 import org.testng.annotations.DataProvider;
  58 import org.testng.annotations.Test;
  59 import util.BaseTest;
  60 import util.StubArray;
  61 import util.StubBaseRowSet;
  62 import util.StubBlob;
  63 import util.StubClob;
  64 import util.StubNClob;
  65 import util.StubRef;
  66 import util.StubRowId;
  67 import util.StubSQLXML;
  68 import util.TestRowSetListener;
  69 
  70 public class BaseRowSetTests extends BaseTest {
  71 
  72     private StubBaseRowSet brs;
  73     private StubBaseRowSet brs1;
  74     private final String query = "SELECT * FROM SUPERHEROS";
  75     private final String url = "jdbc:derby://localhost:1527/myDB";
  76     private final String dsName = "jdbc/myDB";
  77     private final String user = "Bruce Wayne";
  78     private final String password = "The Dark Knight";
  79     private final Date aDate = Date.valueOf(LocalDate.now());
  80     private final Time aTime = Time.valueOf(LocalTime.now());
  81     private final Timestamp ts = Timestamp.valueOf(LocalDateTime.now());
  82     private final Calendar cal = Calendar.getInstance();
  83     private final byte[] bytes = new byte[10];
  84     private RowId aRowid;
  85     private Ref aRef;
  86     private Blob aBlob;
  87     private Clob aClob;
  88     private Array aArray;
  89     private InputStream is;
  90     private Reader rdr;
  91     private Map<String, Class<?>> map = new HashMap<>();
  92 
  93     public BaseRowSetTests() {
  94         brs1 = new StubBaseRowSet();
  95         is = new StringBufferInputStream(query);
  96         rdr = new StringReader(query);
  97         aRowid = new StubRowId();
  98         try {
  99             aBlob = new SerialBlob(new StubBlob());
 100             aClob = new SerialClob(new StubClob());
 101             aRef = new SerialRef(new StubRef("INTEGER", query));
 102             aArray = new SerialArray(new StubArray("INTEGER", new Object[1]));
 103             map.put("SUPERHERO", Class.forName("util.SuperHero"));
 104         } catch (SQLException | ClassNotFoundException ex) {
 105             Logger.getLogger(BaseRowSetTests.class.getName()).log(Level.SEVERE, null, ex);
 106         }
 107     }
 108 
 109     @BeforeMethod
 110     @Override
 111     public void setUpMethod() throws Exception {
 112         brs = new StubBaseRowSet();
 113     }
 114 
 115     /*
 116      * Validate that getCommand() returns null by default
 117      */
 118     @Test
 119     public void test() {
 120         assertTrue(brs.getCommand() == null);
 121     }
 122 
 123     /*
 124      * Validate that getCommand() returns command specified to setCommand
 125      */
 126     @Test
 127     public void test01() throws Exception {
 128         brs.setCommand(query);
 129         assertTrue(brs.getCommand().equals(query));
 130     }
 131 
 132     /*
 133      * Validate that getCurrency() returns the correct default value
 134      */
 135     @Test
 136     public void test02() throws Exception {
 137         assertTrue(brs.getConcurrency() == ResultSet.CONCUR_UPDATABLE);
 138     }
 139 
 140     /*
 141      * Validate that getCurrency() returns the correct value
 142      * after a call to setConcurrency())
 143      */
 144     @Test(dataProvider = "concurTypes")
 145     public void test03(int concurType) throws Exception {
 146         brs.setConcurrency(concurType);
 147         assertTrue(brs.getConcurrency() == concurType);
 148     }
 149 
 150     /*
 151      * Validate that getCurrency() throws a SQLException for an invalid value
 152      */
 153     @Test(expectedExceptions = SQLException.class)
 154     public void test04() throws Exception {
 155         brs.setConcurrency(ResultSet.CLOSE_CURSORS_AT_COMMIT);
 156     }
 157 
 158     /*
 159      * Validate that getDataSourceName() returns null by default
 160      */
 161     @Test
 162     public void test05() throws Exception {
 163         assertTrue(brs.getDataSourceName() == null);
 164     }
 165 
 166     /*
 167      * Validate that getDataSourceName() returns the value specified
 168      * by setDataSourceName() and getUrl() returns null
 169      */
 170     @Test
 171     public void test06() throws Exception {
 172         brs.setUrl(url);
 173         brs.setDataSourceName(dsName);
 174         assertTrue(brs.getDataSourceName().equals(dsName));
 175         assertTrue(brs.getUrl() == null);
 176     }
 177 
 178     /*
 179      * Validate that setDataSourceName() throws a SQLException for an empty
 180      * String specified for the data source name
 181      */
 182     @Test(expectedExceptions = SQLException.class)
 183     public void test07() throws Exception {
 184         String dsname = "";
 185         brs.setDataSourceName(dsname);
 186     }
 187 
 188     /*
 189      * Validate that getEscapeProcessing() returns true by default
 190      */
 191     @Test
 192     public void test08() throws Exception {
 193         assertTrue(brs.getEscapeProcessing());
 194     }
 195 
 196     /*
 197      * Validate that getEscapeProcessing() returns value set by
 198      * setEscapeProcessing()
 199      */
 200     @Test(dataProvider = "trueFalse")
 201     public void test09(boolean val) throws Exception {
 202         brs.setEscapeProcessing(val);
 203         assertTrue(brs.getEscapeProcessing() == val);
 204     }
 205 
 206     /*
 207      * Validate that getFetchDirection() returns the correct default value
 208      */
 209     @Test
 210     public void test10() throws Exception {
 211         assertTrue(brs.getFetchDirection() == ResultSet.FETCH_FORWARD);
 212     }
 213 
 214     /*
 215      * Validate that getFetchDirection() returns the value set by
 216      * setFetchDirection()
 217      */
 218     @Test(dataProvider = "fetchDirection")
 219     public void test11(int direction) throws Exception {
 220         brs.setFetchDirection(direction);
 221         assertTrue(brs.getFetchDirection() == direction);
 222     }
 223 
 224     /*
 225      * Validate that setConcurrency() throws a SQLException for an invalid value
 226      */
 227     @Test(expectedExceptions = SQLException.class)
 228     public void test12() throws Exception {
 229         brs.setConcurrency(ResultSet.CLOSE_CURSORS_AT_COMMIT);
 230     }
 231 
 232     /*
 233      * Validate that setFetchSize() throws a SQLException for an invalid value
 234      */
 235     @Test(expectedExceptions = SQLException.class)
 236     public void test13() throws Exception {
 237         brs.setFetchSize(-1);
 238     }
 239 
 240     /*
 241      * Validate that setFetchSize() throws a SQLException for a
 242      * value greater than getMaxRows()
 243      */
 244     @Test(expectedExceptions = SQLException.class)
 245     public void test14() throws Exception {
 246         brs.setMaxRows(5);
 247         brs.setFetchSize(brs.getMaxRows() + 1);
 248     }
 249 
 250     /*
 251      * Validate that getFetchSize() returns the correct value after
 252      * setFetchSize() has been called
 253      */
 254     @Test
 255     public void test15() throws Exception {
 256         int maxRows = 150;
 257         brs.setFetchSize(0);
 258         assertTrue(brs.getFetchSize() == 0);
 259         brs.setFetchSize(100);
 260         assertTrue(brs.getFetchSize() == 100);
 261         brs.setMaxRows(maxRows);
 262         brs.setFetchSize(maxRows);
 263         assertTrue(brs.getFetchSize() == maxRows);
 264     }
 265 
 266     /*
 267      * Validate that setMaxFieldSize() throws a SQLException for an invalid value
 268      */
 269     @Test(expectedExceptions = SQLException.class)
 270     public void test16() throws Exception {
 271         brs.setMaxFieldSize(-1);
 272     }
 273 
 274     /*
 275      * Validate that getMaxFieldSize() returns the value set by
 276      * setMaxFieldSize()
 277      */
 278     @Test
 279     public void test17() throws Exception {
 280         brs.setMaxFieldSize(0);
 281         assertTrue(brs.getMaxFieldSize() == 0);
 282         brs.setMaxFieldSize(100);
 283         assertTrue(brs.getMaxFieldSize() == 100);
 284         brs.setMaxFieldSize(50);
 285         assertTrue(brs.getMaxFieldSize() == 50);
 286     }
 287 
 288     /*
 289      * Validate that isReadOnly() returns value set by
 290      * setReadOnly()
 291      */
 292     @Test(dataProvider = "trueFalse")
 293     public void test18(boolean val) throws Exception {
 294         brs.setReadOnly(val);
 295         assertTrue(brs.isReadOnly() == val);
 296     }
 297 
 298     /*
 299      * Validate that getTransactionIsolation() returns value set by
 300      * setTransactionIsolation()
 301      */
 302     @Test(dataProvider = "isolationTypes")
 303     public void test19(int val) throws Exception {
 304         brs.setTransactionIsolation(val);
 305         assertTrue(brs.getTransactionIsolation() == val);
 306     }
 307 
 308     /*
 309      * Validate that getType() returns value set by setType()
 310      */
 311     @Test(dataProvider = "scrollTypes")
 312     public void test20(int val) throws Exception {
 313         brs.setType(val);
 314         assertTrue(brs.getType() == val);
 315     }
 316 
 317     /*
 318      * Validate that getEscapeProcessing() returns value set by
 319      * setEscapeProcessing()
 320      */
 321     @Test(dataProvider = "trueFalse")
 322     public void test21(boolean val) throws Exception {
 323         brs.setShowDeleted(val);
 324         assertTrue(brs.getShowDeleted() == val);
 325     }
 326 
 327     /*
 328      * Validate that getTypeMap() returns same value set by
 329      * setTypeMap()
 330      */
 331     @Test()
 332     public void test22() throws Exception {
 333         brs.setTypeMap(map);
 334         assertTrue(brs.getTypeMap().equals(map));
 335     }
 336 
 337     /*
 338      * Validate that getUsername() returns same value set by
 339      * setUsername()
 340      */
 341     @Test()
 342     public void test23() throws Exception {
 343         brs.setUsername(user);
 344         assertTrue(brs.getUsername().equals(user));
 345     }
 346 
 347     /*
 348      * Validate that getPassword() returns same password set by
 349      * setPassword()
 350      */
 351     @Test()
 352     public void test24() throws Exception {
 353         brs.setPassword(password);
 354         assertTrue(brs.getPassword().equals(password));
 355     }
 356 
 357     /*
 358      * Validate that getQueryTimeout() returns same value set by
 359      * setQueryTimeout() and that 0 is a valid timeout value
 360      */
 361     @Test()
 362     public void test25() throws Exception {
 363         int timeout = 0;
 364         brs.setQueryTimeout(timeout);
 365         assertTrue(brs.getQueryTimeout() == timeout);
 366     }
 367 
 368     /*
 369      * Validate that getQueryTimeout() returns same value set by
 370      * setQueryTimeout() and that 0 is a valid timeout value
 371      */
 372     @Test()
 373     public void test26() throws Exception {
 374         int timeout = 10000;
 375         brs.setQueryTimeout(timeout);
 376         assertTrue(brs.getQueryTimeout() == timeout);
 377     }
 378 
 379     /*
 380      * Validate that setQueryTimeout() throws a SQLException for a timeout
 381      * value < 0
 382      */
 383     @Test(expectedExceptions = SQLException.class)
 384     public void test27() throws Exception {
 385         brs.setQueryTimeout(-1);
 386     }
 387 
 388     /*
 389      * Create a RowSetListener and validate that notifyRowSetChanged is called
 390      */
 391     @Test()
 392     public void test28() throws Exception {
 393         TestRowSetListener rsl = new TestRowSetListener();
 394         brs.addRowSetListener(rsl);
 395         brs.notifyRowSetChanged();
 396         assertTrue(rsl.isNotified(TestRowSetListener.ROWSET_CHANGED));
 397     }
 398 
 399     /*
 400      * Create a RowSetListener and validate that notifyRowChanged is called
 401      */
 402     @Test()
 403     public void test29() throws Exception {
 404         TestRowSetListener rsl = new TestRowSetListener();
 405         brs.addRowSetListener(rsl);
 406         brs.notifyRowChanged();
 407         assertTrue(rsl.isNotified(TestRowSetListener.ROW_CHANGED));
 408     }
 409 
 410     /*
 411      * Create a RowSetListener and validate that notifyCursorMoved is called
 412      */
 413     @Test()
 414     public void test30() throws Exception {
 415         TestRowSetListener rsl = new TestRowSetListener();
 416         brs.addRowSetListener(rsl);
 417         brs.notifyCursorMoved();
 418         assertTrue(rsl.isNotified(TestRowSetListener.CURSOR_MOVED));
 419     }
 420 
 421     /*
 422      * Create a RowSetListener and validate that notifyRowSetChanged,
 423      * notifyRowChanged() and notifyCursorMoved are called
 424      */
 425     @Test()
 426     public void test31() throws Exception {
 427         TestRowSetListener rsl = new TestRowSetListener();
 428         brs.addRowSetListener(rsl);
 429         brs.notifyRowSetChanged();
 430         brs.notifyRowChanged();
 431         brs.notifyCursorMoved();
 432         assertTrue(rsl.isNotified(
 433                 TestRowSetListener.CURSOR_MOVED | TestRowSetListener.ROWSET_CHANGED
 434                 | TestRowSetListener.ROW_CHANGED));
 435     }
 436 
 437     /*
 438      * Create multiple RowSetListeners and validate that notifyRowSetChanged
 439      * is called on all listeners
 440      */
 441     @Test()
 442     public void test32() throws Exception {
 443         TestRowSetListener rsl = new TestRowSetListener();
 444         TestRowSetListener rsl2 = new TestRowSetListener();
 445         brs.addRowSetListener(rsl);
 446         brs.addRowSetListener(rsl2);
 447         brs.notifyRowSetChanged();
 448         assertTrue(rsl.isNotified(TestRowSetListener.ROWSET_CHANGED));
 449         assertTrue(rsl2.isNotified(TestRowSetListener.ROWSET_CHANGED));
 450     }
 451 
 452     /*
 453      * Create multiple RowSetListeners and validate that notifyRowChanged
 454      * is called on all listeners
 455      */
 456     @Test()
 457     public void test33() throws Exception {
 458         TestRowSetListener rsl = new TestRowSetListener();
 459         TestRowSetListener rsl2 = new TestRowSetListener();
 460         brs.addRowSetListener(rsl);
 461         brs.addRowSetListener(rsl2);
 462         brs.notifyRowChanged();
 463         assertTrue(rsl.isNotified(TestRowSetListener.ROW_CHANGED));
 464         assertTrue(rsl2.isNotified(TestRowSetListener.ROW_CHANGED));
 465     }
 466 
 467     /*
 468      * Create multiple RowSetListeners and validate that notifyCursorMoved
 469      * is called on all listeners
 470      */
 471     @Test()
 472     public void test34() throws Exception {
 473         TestRowSetListener rsl = new TestRowSetListener();
 474         TestRowSetListener rsl2 = new TestRowSetListener();
 475         brs.addRowSetListener(rsl);
 476         brs.addRowSetListener(rsl2);
 477         brs.notifyCursorMoved();
 478         assertTrue(rsl.isNotified(TestRowSetListener.CURSOR_MOVED));
 479         assertTrue(rsl2.isNotified(TestRowSetListener.CURSOR_MOVED));
 480     }
 481 
 482     /*
 483      * Create multiple RowSetListeners and validate that notifyRowSetChanged,
 484      * notifyRowChanged() and notifyCursorMoved are called on all listeners
 485      */
 486     @Test()
 487     public void test35() throws Exception {
 488         TestRowSetListener rsl = new TestRowSetListener();
 489         TestRowSetListener rsl2 = new TestRowSetListener();
 490         brs.addRowSetListener(rsl);
 491         brs.addRowSetListener(rsl2);
 492         brs.notifyRowSetChanged();
 493         brs.notifyRowChanged();
 494         brs.notifyCursorMoved();
 495         assertTrue(rsl.isNotified(
 496                 TestRowSetListener.CURSOR_MOVED | TestRowSetListener.ROWSET_CHANGED
 497                 | TestRowSetListener.ROW_CHANGED));
 498         assertTrue(rsl2.isNotified(
 499                 TestRowSetListener.CURSOR_MOVED | TestRowSetListener.ROWSET_CHANGED
 500                 | TestRowSetListener.ROW_CHANGED));
 501     }
 502 
 503     /*
 504      * Create a RowSetListener and validate that notifyRowSetChanged is called,
 505      * remove the listener, invoke notifyRowSetChanged again and verify the
 506      * listner is not called
 507      */
 508     @Test()
 509     public void test36() throws Exception {
 510         TestRowSetListener rsl = new TestRowSetListener();
 511         brs.addRowSetListener(rsl);
 512         brs.notifyRowSetChanged();
 513         assertTrue(rsl.isNotified(TestRowSetListener.ROWSET_CHANGED));
 514         // Clear the flag indicating the listener has been called
 515         rsl.resetFlag();
 516         brs.removeRowSetListener(rsl);
 517         brs.notifyRowSetChanged();
 518         assertFalse(rsl.isNotified(TestRowSetListener.ROWSET_CHANGED));
 519     }
 520 
 521     /*
 522      * Validate addRowSetListener does not throw an Exception when null is
 523      * passed as the parameter
 524      */
 525     @Test()
 526     public void test37() throws Exception {
 527         brs.addRowSetListener(null);
 528     }
 529 
 530     /*
 531      * Validate removeRowSetListener does not throw an Exception when null is
 532      * passed as the parameter
 533      */
 534     @Test()
 535     public void test38() throws Exception {
 536         brs.removeRowSetListener(null);
 537     }
 538 
 539     /*
 540      * Set two parameters and then validate clearParameters() will clear them
 541      */
 542     @Test()
 543     public void test39() throws Exception {
 544         brs.setInt(1, 1);
 545         brs.setString(2, query);
 546         assertTrue(brs.getParams().length == 2);
 547         brs.clearParameters();
 548         assertTrue(brs.getParams().length == 0);
 549     }
 550 
 551     /*
 552      * Set the base parameters and validate that the value set is
 553      * the correct type and value
 554      */
 555     @Test(dataProvider = "testBaseParameters")
 556     public void test40(int pos, Object o) throws Exception {
 557         assertTrue(getParam(pos, o).getClass().isInstance(o));
 558         assertTrue(o.equals(getParam(pos, o)));
 559     }
 560 
 561     /*
 562      * Set the complex parameters and validate that the value set is
 563      * the correct type
 564      */
 565     @Test(dataProvider = "testAdvancedParameters")
 566     public void test41(int pos, Object o) throws Exception {
 567         assertTrue(getParam(pos, o).getClass().isInstance(o));
 568     }
 569 
 570     /*
 571      * Validate setNull specifying the supported type values
 572      */
 573     @Test(dataProvider = "jdbcTypes")
 574     public void test42(Integer type) throws Exception {
 575         brs.setNull(1, type);
 576         assertTrue(checkNullParam(1, type, null));
 577     }
 578 
 579     /*
 580      * Validate setNull specifying the supported type values and that
 581      * typeName is set internally
 582      */
 583     @Test(dataProvider = "jdbcTypes")
 584     public void test43(Integer type) throws Exception {
 585         brs.setNull(1, type, "SUPERHERO");
 586         assertTrue(checkNullParam(1, type, "SUPERHERO"));
 587     }
 588 
 589     /*
 590      *  Validate that setDate sets the specified Calendar internally
 591      */
 592     @Test()
 593     public void test44() throws Exception {
 594         brs.setDate(1, aDate, cal);
 595         assertTrue(checkCalendarParam(1, cal));
 596     }
 597 
 598     /*
 599      *  Validate that setTime sets the specified Calendar internally
 600      */
 601     @Test()
 602     public void test45() throws Exception {
 603         brs.setTime(1, aTime, cal);
 604         assertTrue(checkCalendarParam(1, cal));
 605     }
 606 
 607     /*
 608      *  Validate that setTimestamp sets the specified Calendar internally
 609      */
 610     @Test()
 611     public void test46() throws Exception {
 612         brs.setTimestamp(1, ts, cal);
 613         assertTrue(checkCalendarParam(1, cal));
 614     }
 615 
 616     /*
 617      * Validate that getURL() returns same value set by
 618      * setURL()
 619      */
 620     @Test()
 621     public void test47() throws Exception {
 622         brs.setUrl(url);
 623         assertTrue(brs.getUrl().equals(url));
 624     }
 625 
 626     /*
 627      * Validate that initParams() initializes the parameters
 628      */
 629     @Test()
 630     public void test48() throws Exception {
 631         brs.setInt(1, 1);
 632         brs.initParams();
 633         assertTrue(brs.getParams().length == 0);
 634     }
 635 
 636     /*
 637      * This method is currently not implemented in BaseRowSet and will
 638      * throw a SQLFeatureNotSupportedException
 639      */
 640 
 641     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
 642     public void test100() throws Exception {
 643         brs1.setAsciiStream(1, is);
 644     }
 645 
 646     /*
 647      * This method is currently not implemented in BaseRowSet and will
 648      * throw a SQLFeatureNotSupportedException
 649      */
 650     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
 651     public void test101() throws Exception {
 652         brs1.setAsciiStream("one", is);
 653     }
 654 
 655     /*
 656      * This method is currently not implemented in BaseRowSet and will
 657      * throw a SQLFeatureNotSupportedException
 658      */
 659     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
 660     public void test102() throws Exception {
 661         brs1.setAsciiStream("one", is, query.length());
 662     }
 663 
 664     /*
 665      * This method is currently not implemented in BaseRowSet and will
 666      * throw a SQLFeatureNotSupportedException
 667      */
 668     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
 669     public void test103() throws Exception {
 670         brs1.setBinaryStream(1, is);
 671     }
 672 
 673     /*
 674      * This method is currently not implemented in BaseRowSet and will
 675      * throw a SQLFeatureNotSupportedException
 676      */
 677     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
 678     public void test104() throws Exception {
 679         brs1.setBinaryStream("one", is);
 680     }
 681 
 682     /*
 683      * This method is currently not implemented in BaseRowSet and will
 684      * throw a SQLFeatureNotSupportedException
 685      */
 686     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
 687     public void test105() throws Exception {
 688         brs1.setBinaryStream("one", is, query.length());
 689     }
 690 
 691     /*
 692      * This method is currently not implemented in BaseRowSet and will
 693      * throw a SQLFeatureNotSupportedException
 694      */
 695     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
 696     public void test106() throws Exception {
 697         brs1.setBigDecimal("one", BigDecimal.ONE);
 698     }
 699 
 700     /*
 701      * This method is currently not implemented in BaseRowSet and will
 702      * throw a SQLFeatureNotSupportedException
 703      */
 704     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
 705     public void test107() throws Exception {
 706         brs1.setBlob(1, is);
 707     }
 708 
 709     /*
 710      * This method is currently not implemented in BaseRowSet and will
 711      * throw a SQLFeatureNotSupportedException
 712      */
 713     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
 714     public void test108() throws Exception {
 715         brs1.setBlob("one", is);
 716     }
 717 
 718     /*
 719      * This method is currently not implemented in BaseRowSet and will
 720      * throw a SQLFeatureNotSupportedException
 721      */
 722     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
 723     public void test109() throws Exception {
 724         brs1.setBlob("one", is, query.length());
 725     }
 726 
 727     /*
 728      * This method is currently not implemented in BaseRowSet and will
 729      * throw a SQLFeatureNotSupportedException
 730      */
 731     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
 732     public void test110() throws Exception {
 733         brs1.setBlob("one", aBlob);
 734     }
 735 
 736     /*
 737      * This method is currently not implemented in BaseRowSet and will
 738      * throw a SQLFeatureNotSupportedException
 739      */
 740     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
 741     public void test111() throws Exception {
 742         brs1.setBoolean("one", true);
 743     }
 744 
 745     /*
 746      * This method is currently not implemented in BaseRowSet and will
 747      * throw a SQLFeatureNotSupportedException
 748      */
 749     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
 750     public void test112() throws Exception {
 751         byte b = 1;
 752         brs1.setByte("one", b);
 753     }
 754 
 755     /*
 756      * This method is currently not implemented in BaseRowSet and will
 757      * throw a SQLFeatureNotSupportedException
 758      */
 759     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
 760     public void test113() throws Exception {
 761         byte b = 1;
 762         brs1.setBytes("one", bytes);
 763     }
 764 
 765     /*
 766      * This method is currently not implemented in BaseRowSet and will
 767      * throw a SQLFeatureNotSupportedException
 768      */
 769     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
 770     public void test114() throws Exception {
 771         brs1.setCharacterStream("one", rdr, query.length());
 772     }
 773 
 774     /*
 775      * This method is currently not implemented in BaseRowSet and will
 776      * throw a SQLFeatureNotSupportedException
 777      */
 778     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
 779     public void test115() throws Exception {
 780         brs1.setCharacterStream("one", rdr);
 781     }
 782 
 783     /*
 784      * This method is currently not implemented in BaseRowSet and will
 785      * throw a SQLFeatureNotSupportedException
 786      */
 787     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
 788     public void test116() throws Exception {
 789         brs1.setCharacterStream(1, rdr);
 790     }
 791 
 792     /*
 793      * This method is currently not implemented in BaseRowSet and will
 794      * throw a SQLFeatureNotSupportedException
 795      */
 796     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
 797     public void test117() throws Exception {
 798         brs1.setClob(1, rdr);
 799     }
 800 
 801     /*
 802      * This method is currently not implemented in BaseRowSet and will
 803      * throw a SQLFeatureNotSupportedException
 804      */
 805     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
 806     public void test118() throws Exception {
 807         brs1.setClob("one", rdr);
 808     }
 809 
 810     /*
 811      * This method is currently not implemented in BaseRowSet and will
 812      * throw a SQLFeatureNotSupportedException
 813      */
 814     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
 815     public void test119() throws Exception {
 816         brs1.setClob("one", rdr, query.length());
 817     }
 818 
 819     /*
 820      * This method is currently not implemented in BaseRowSet and will
 821      * throw a SQLFeatureNotSupportedException
 822      */
 823     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
 824     public void test120() throws Exception {
 825         brs1.setClob("one", aClob);
 826     }
 827 
 828     /*
 829      * This method is currently not implemented in BaseRowSet and will
 830      * throw a SQLFeatureNotSupportedException
 831      */
 832     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
 833     public void test121() throws Exception {
 834         brs1.setDate("one", aDate);
 835     }
 836 
 837     /*
 838      * This method is currently not implemented in BaseRowSet and will
 839      * throw a SQLFeatureNotSupportedException
 840      */
 841     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
 842     public void test122() throws Exception {
 843         brs1.setDate("one", aDate, cal);
 844     }
 845 
 846     /*
 847      * This method is currently not implemented in BaseRowSet and will
 848      * throw a SQLFeatureNotSupportedException
 849      */
 850     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
 851     public void test123() throws Exception {
 852         brs1.setTime("one", aTime);
 853     }
 854 
 855     /*
 856      * This method is currently not implemented in BaseRowSet and will
 857      * throw a SQLFeatureNotSupportedException
 858      */
 859     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
 860     public void test124() throws Exception {
 861         brs1.setTime("one", aTime, cal);
 862     }
 863 
 864     /*
 865      * This method is currently not implemented in BaseRowSet and will
 866      * throw a SQLFeatureNotSupportedException
 867      */
 868     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
 869     public void test125() throws Exception {
 870         brs1.setTimestamp("one", ts);
 871     }
 872 
 873     /*
 874      * This method is currently not implemented in BaseRowSet and will
 875      * throw a SQLFeatureNotSupportedException
 876      */
 877     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
 878     public void test126() throws Exception {
 879         brs1.setTimestamp("one", ts, cal);
 880     }
 881 
 882     /*
 883      * This method is currently not implemented in BaseRowSet and will
 884      * throw a SQLFeatureNotSupportedException
 885      */
 886     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
 887     public void test127() throws Exception {
 888         brs1.setDouble("one", 2.0d);
 889     }
 890 
 891     /*
 892      * This method is currently not implemented in BaseRowSet and will
 893      * throw a SQLFeatureNotSupportedException
 894      */
 895     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
 896     public void test128() throws Exception {
 897         brs1.setFloat("one", 2.0f);
 898     }
 899 
 900     /*
 901      * This method is currently not implemented in BaseRowSet and will
 902      * throw a SQLFeatureNotSupportedException
 903      */
 904     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
 905     public void test129() throws Exception {
 906         brs1.setInt("one", 21);
 907     }
 908 
 909     /*
 910      * This method is currently not implemented in BaseRowSet and will
 911      * throw a SQLFeatureNotSupportedException
 912      */
 913     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
 914     public void test130() throws Exception {
 915         brs1.setLong("one", 21l);
 916     }
 917 
 918     /*
 919      * This method is currently not implemented in BaseRowSet and will
 920      * throw a SQLFeatureNotSupportedException
 921      */
 922     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
 923     public void test131() throws Exception {
 924         brs1.setNCharacterStream("one", rdr, query.length());
 925     }
 926 
 927     /*
 928      * This method is currently not implemented in BaseRowSet and will
 929      * throw a SQLFeatureNotSupportedException
 930      */
 931     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
 932     public void test132() throws Exception {
 933         brs1.setNCharacterStream("one", rdr);
 934     }
 935 
 936     /*
 937      * This method is currently not implemented in BaseRowSet and will
 938      * throw a SQLFeatureNotSupportedException
 939      */
 940     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
 941     public void test133() throws Exception {
 942         brs1.setNCharacterStream(1, rdr);
 943     }
 944 
 945     /*
 946      * This method is currently not implemented in BaseRowSet and will
 947      * throw a SQLFeatureNotSupportedException
 948      */
 949     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
 950     public void test134() throws Exception {
 951         brs1.setNCharacterStream(1, rdr, query.length());
 952     }
 953 
 954     /*
 955      * This method is currently not implemented in BaseRowSet and will
 956      * throw a SQLFeatureNotSupportedException
 957      */
 958     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
 959     public void test135() throws Exception {
 960         brs1.setClob("one", rdr);
 961     }
 962 
 963     /*
 964      * This method is currently not implemented in BaseRowSet and will
 965      * throw a SQLFeatureNotSupportedException
 966      */
 967     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
 968     public void test136() throws Exception {
 969         brs1.setClob("one", rdr, query.length());
 970     }
 971 
 972     /*
 973      * This method is currently not implemented in BaseRowSet and will
 974      * throw a SQLFeatureNotSupportedException
 975      */
 976     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
 977     public void test137() throws Exception {
 978         brs1.setNClob("one", new StubNClob());
 979     }
 980 
 981     /*
 982      * This method is currently not implemented in BaseRowSet and will
 983      * throw a SQLFeatureNotSupportedException
 984      */
 985     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
 986     public void test138() throws Exception {
 987         brs1.setNClob(1, rdr);
 988     }
 989 
 990     /*
 991      * This method is currently not implemented in BaseRowSet and will
 992      * throw a SQLFeatureNotSupportedException
 993      */
 994     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
 995     public void test139() throws Exception {
 996         brs1.setNClob(1, rdr, query.length());
 997     }
 998 
 999     /*
1000      * This method is currently not implemented in BaseRowSet and will
1001      * throw a SQLFeatureNotSupportedException
1002      */
1003     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
1004     public void test140() throws Exception {
1005         brs1.setNClob(1, new StubNClob());
1006     }
1007 
1008     /*
1009      * This method is currently not implemented in BaseRowSet and will
1010      * throw a SQLFeatureNotSupportedException
1011      */
1012     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
1013     public void test141() throws Exception {
1014         brs1.setNString(1, query);
1015     }
1016 
1017     /*
1018      * This method is currently not implemented in BaseRowSet and will
1019      * throw a SQLFeatureNotSupportedException
1020      */
1021     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
1022     public void test142() throws Exception {
1023         brs1.setNull("one", Types.INTEGER);
1024     }
1025 
1026     /*
1027      * This method is currently not implemented in BaseRowSet and will
1028      * throw a SQLFeatureNotSupportedException
1029      */
1030     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
1031     public void test143() throws Exception {
1032         brs1.setNull("one", Types.INTEGER, "my.type");
1033     }
1034 
1035     /*
1036      * This method is currently not implemented in BaseRowSet and will
1037      * throw a SQLFeatureNotSupportedException
1038      */
1039     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
1040     public void test144() throws Exception {
1041         brs1.setObject("one", query, Types.VARCHAR);
1042     }
1043 
1044     /*
1045      * This method is currently not implemented in BaseRowSet and will
1046      * throw a SQLFeatureNotSupportedException
1047      */
1048     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
1049     public void test145() throws Exception {
1050         brs1.setObject("one", query, Types.VARCHAR, 0);
1051     }
1052 
1053     /*
1054      * This method is currently not implemented in BaseRowSet and will
1055      * throw a SQLFeatureNotSupportedException
1056      */
1057     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
1058     public void test146() throws Exception {
1059         brs1.setObject("one", query);
1060     }
1061 
1062     /*
1063      * This method is currently not implemented in BaseRowSet and will
1064      * throw a SQLFeatureNotSupportedException
1065      */
1066     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
1067     public void test147() throws Exception {
1068         brs1.setRowId("one", aRowid);
1069     }
1070 
1071     /*
1072      * This method is currently not implemented in BaseRowSet and will
1073      * throw a SQLFeatureNotSupportedException
1074      */
1075     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
1076     public void test148() throws Exception {
1077         brs1.setSQLXML("one", new StubSQLXML());
1078     }
1079 
1080     /*
1081      * This method is currently not implemented in BaseRowSet and will
1082      * throw a SQLFeatureNotSupportedException
1083      */
1084     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
1085     public void test149() throws Exception {
1086         brs1.setSQLXML(1, new StubSQLXML());
1087     }
1088 
1089     /*
1090      * This method is currently not implemented in BaseRowSet and will
1091      * throw a SQLFeatureNotSupportedException
1092      */
1093     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
1094     public void test150() throws Exception {
1095         brs1.setNString(1, query);
1096     }
1097 
1098     /*
1099      * This method is currently not implemented in BaseRowSet and will
1100      * throw a SQLFeatureNotSupportedException
1101      */
1102     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
1103     public void test151() throws Exception {
1104         brs1.setNString("one", query);
1105     }
1106 
1107     /*
1108      * This method is currently not implemented in BaseRowSet and will
1109      * throw a SQLFeatureNotSupportedException
1110      */
1111     @Test(expectedExceptions = SQLFeatureNotSupportedException.class)
1112     public void test152() throws Exception {
1113         short val = 21;
1114         brs1.setShort("one", val);
1115     }
1116 
1117     /*
1118      * DataProvider used to specify the value to set and check for
1119      * methods using transaction isolation types
1120      */
1121     @DataProvider(name = "isolationTypes")
1122     private Object[][] isolationTypes() {
1123         return new Object[][]{
1124             {Connection.TRANSACTION_NONE},
1125             {Connection.TRANSACTION_READ_COMMITTED},
1126             {Connection.TRANSACTION_READ_UNCOMMITTED},
1127             {Connection.TRANSACTION_REPEATABLE_READ},
1128             {Connection.TRANSACTION_SERIALIZABLE}
1129         };
1130     }
1131 
1132     /*
1133      * DataProvider used to specify the value to set and check for the
1134      * methods for fetch direction
1135      */
1136     @DataProvider(name = "fetchDirection")
1137     private Object[][] fetchDirection() {
1138         return new Object[][]{
1139             {ResultSet.FETCH_FORWARD},
1140             {ResultSet.FETCH_REVERSE},
1141             {ResultSet.FETCH_UNKNOWN}
1142         };
1143     }
1144 
1145     /*
1146      * DataProvider used to specify the value to set and check for the
1147      * methods for Concurrency
1148      */
1149     @DataProvider(name = "concurTypes")
1150     private Object[][] concurTypes() {
1151         return new Object[][]{
1152             {ResultSet.CONCUR_READ_ONLY},
1153             {ResultSet.CONCUR_UPDATABLE}
1154         };
1155     }
1156 
1157     /*
1158      * DataProvider used to specify the value to set and check for the
1159      * methods for Cursor Scroll Type
1160      */
1161     @DataProvider(name = "scrollTypes")
1162     private Object[][] scrollTypes() {
1163         return new Object[][]{
1164             {ResultSet.TYPE_FORWARD_ONLY},
1165             {ResultSet.TYPE_SCROLL_INSENSITIVE},
1166             {ResultSet.TYPE_SCROLL_SENSITIVE}
1167         };
1168     }
1169 
1170     /*
1171      * DataProvider used to set parameters for basic types that are supported
1172      */
1173     @DataProvider(name = "testBaseParameters")
1174     private Object[][] testBaseParameters() throws SQLException {
1175         Integer aInt = 1;
1176         Long aLong = Long.MAX_VALUE;
1177         Short aShort = Short.MIN_VALUE;
1178         BigDecimal bd = BigDecimal.ONE;
1179         Double aDouble = Double.MAX_VALUE;
1180         Boolean aBoolean = true;
1181         Float aFloat = 1.5f;
1182         Byte aByte = 1;
1183 
1184         brs1.clearParameters();
1185         brs1.setInt(1, aInt);
1186         brs1.setString(2, query);
1187         brs1.setLong(3, aLong);
1188         brs1.setBoolean(4, aBoolean);
1189         brs1.setShort(5, aShort);
1190         brs1.setDouble(6, aDouble);
1191         brs1.setBigDecimal(7, bd);
1192         brs1.setFloat(8, aFloat);
1193         brs1.setByte(9, aByte);
1194         brs1.setDate(10, aDate);
1195         brs1.setTime(11, aTime);
1196         brs1.setTimestamp(12, ts);
1197         brs1.setDate(13, aDate, cal);
1198         brs1.setTime(14, aTime, cal);
1199         brs1.setTimestamp(15, ts);
1200         brs1.setObject(16, query);
1201         brs1.setObject(17, query, Types.CHAR);
1202         brs1.setObject(18, query, Types.CHAR, 0);
1203 
1204         return new Object[][]{
1205             {1, aInt},
1206             {2, query},
1207             {3, aLong},
1208             {4, aBoolean},
1209             {5, aShort},
1210             {6, aDouble},
1211             {7, bd},
1212             {8, aFloat},
1213             {9, aByte},
1214             {10, aDate},
1215             {11, aTime},
1216             {12, ts},
1217             {13, aDate},
1218             {14, aTime},
1219             {15, ts},
1220             {16, query},
1221             {17, query},
1222             {18, query}
1223 
1224         };
1225     }
1226 
1227     /*
1228      * DataProvider used to set advanced parameters for types that are supported
1229      */
1230     @DataProvider(name = "testAdvancedParameters")
1231     private Object[][] testAdvancedParameters() throws SQLException {
1232 
1233         brs1.clearParameters();
1234         brs1.setBytes(1, bytes);
1235         brs1.setAsciiStream(2, is, query.length());
1236         brs1.setRef(3, aRef);
1237         brs1.setArray(4, aArray);
1238         brs1.setBlob(5, aBlob);
1239         brs1.setClob(6, aClob);
1240         brs1.setBinaryStream(7, is, query.length());
1241         brs1.setUnicodeStream(8, is, query.length());
1242         brs1.setCharacterStream(9, rdr, query.length());
1243 
1244         return new Object[][]{
1245             {1, bytes},
1246             {2, is},
1247             {3, aRef},
1248             {4, aArray},
1249             {5, aBlob},
1250             {6, aClob},
1251             {7, is},
1252             {8, is},
1253             {9, rdr}
1254         };
1255     }
1256 
1257     /*
1258      *  Method that returns the specified parameter instance that was set via setXXX
1259      *  Note non-basic types are stored as an Object[] where the 1st element
1260      *  is the object instnace
1261      */
1262     @SuppressWarnings("unchecked")
1263     private <T> T getParam(int pos, T o) throws SQLException {
1264         Object[] params = brs1.getParams();
1265         if (params[pos - 1] instanceof Object[]) {
1266             Object[] param = (Object[]) params[pos - 1];
1267             return (T) param[0];
1268         } else {
1269             return (T) params[pos - 1];
1270         }
1271     }
1272 
1273     /*
1274      * Utility method to validate parameters when the param is an Object[]
1275      */
1276     private boolean checkParam(int pos, int type, Object val) throws SQLException {
1277         boolean result = false;
1278         Object[] params = brs.getParams();
1279         if (params[pos - 1] instanceof Object[]) {
1280             Object[] param = (Object[]) params[pos - 1];
1281 
1282             if (param[0] == null) {
1283                 // setNull was used
1284                 if (param.length == 2 && (Integer) param[1] == type) {
1285                     result = true;
1286                 } else {
1287                     if (param.length == 3 && (Integer) param[1] == type
1288                             && val.equals(param[2])) {
1289                         result = true;
1290                     }
1291                 }
1292 
1293             } else if (param[0] instanceof java.util.Date) {
1294                 // setDate/Time/Timestamp with a Calendar object
1295                 if (param[1] instanceof Calendar && val.equals(param[1])) {
1296                     result = true;
1297                 }
1298             }
1299         }
1300         return result;
1301     }
1302 
1303     /*
1304      * Wrapper method for validating that a null was set and the appropriate
1305      * type and typeName if applicable
1306      */
1307     private boolean checkNullParam(int pos, int type, String typeName) throws SQLException {
1308         return checkParam(pos, type, typeName);
1309     }
1310 
1311     /*
1312      *  Wrapper method for validating that a Calander was set
1313      */
1314     private boolean checkCalendarParam(int pos, Calendar cal) throws SQLException {
1315         // 2nd param is ignored when instanceof java.util.Date
1316         return checkParam(pos, Types.DATE, cal);
1317     }
1318 }