0001: /*
0002: * HA-JDBC: High-Availability JDBC
0003: * Copyright (c) 2004-2007 Paul Ferraro
0004: *
0005: * This library is free software; you can redistribute it and/or modify it
0006: * under the terms of the GNU Lesser General Public License as published by the
0007: * Free Software Foundation; either version 2.1 of the License, or (at your
0008: * option) any later version.
0009: *
0010: * This library is distributed in the hope that it will be useful, but WITHOUT
0011: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0012: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
0013: * for more details.
0014: *
0015: * You should have received a copy of the GNU Lesser General Public License
0016: * along with this library; if not, write to the Free Software Foundation,
0017: * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0018: *
0019: * Contact: ferraro@users.sourceforge.net
0020: */
0021: package net.sf.hajdbc.sql;
0022:
0023: import java.io.ByteArrayInputStream;
0024: import java.io.CharArrayReader;
0025: import java.io.File;
0026: import java.io.InputStream;
0027: import java.io.Reader;
0028: import java.io.StringReader;
0029: import java.lang.reflect.Proxy;
0030: import java.math.BigDecimal;
0031: import java.net.MalformedURLException;
0032: import java.net.URL;
0033: import java.sql.Array;
0034: import java.sql.Blob;
0035: import java.sql.Clob;
0036: import java.sql.Date;
0037: import java.sql.NClob;
0038: import java.sql.ParameterMetaData;
0039: import java.sql.PreparedStatement;
0040: import java.sql.Ref;
0041: import java.sql.ResultSet;
0042: import java.sql.ResultSetMetaData;
0043: import java.sql.RowId;
0044: import java.sql.SQLException;
0045: import java.sql.SQLXML;
0046: import java.sql.Time;
0047: import java.sql.Timestamp;
0048: import java.util.Calendar;
0049: import java.util.Map;
0050: import java.util.TreeMap;
0051:
0052: import javax.sql.rowset.serial.SerialBlob;
0053: import javax.sql.rowset.serial.SerialClob;
0054:
0055: import net.sf.hajdbc.Database;
0056: import net.sf.hajdbc.util.reflect.ProxyFactory;
0057:
0058: import org.easymock.EasyMock;
0059: import org.testng.annotations.DataProvider;
0060: import org.testng.annotations.Test;
0061:
0062: /**
0063: * Unit test for {@link PreparedStatement}
0064: * @author Paul Ferraro
0065: */
0066: @Test
0067: @SuppressWarnings({"unchecked","nls"})
0068: public class TestPreparedStatement extends TestStatement implements
0069: java.sql.PreparedStatement {
0070: protected String sql = "sql";
0071:
0072: protected Blob blob1 = EasyMock.createMock(Blob.class);
0073: protected Blob blob2 = EasyMock.createMock(Blob.class);
0074: protected Clob clob1 = EasyMock.createMock(Clob.class);
0075: protected Clob clob2 = EasyMock.createMock(Clob.class);
0076: protected NClob nClob1 = EasyMock.createMock(NClob.class);
0077: protected NClob nClob2 = EasyMock.createMock(NClob.class);
0078:
0079: @Override
0080: protected Class<? extends java.sql.Statement> getStatementClass() {
0081: return java.sql.PreparedStatement.class;
0082: }
0083:
0084: protected Class<? extends java.sql.PreparedStatement> getPreparedStatementClass() {
0085: return java.sql.PreparedStatement.class;
0086: }
0087:
0088: private PreparedStatement getStatement() {
0089: return PreparedStatement.class.cast(this .statement);
0090: }
0091:
0092: private PreparedStatement getStatement1() {
0093: return PreparedStatement.class.cast(this .statement1);
0094: }
0095:
0096: private PreparedStatement getStatement2() {
0097: return PreparedStatement.class.cast(this .statement2);
0098: }
0099:
0100: @Override
0101: protected AbstractStatementInvocationHandler getInvocationHandler(
0102: Map map) throws Exception {
0103: return new PreparedStatementInvocationHandler(this .connection,
0104: this .parent, EasyMock.createMock(Invoker.class), map,
0105: this .transactionContext, this .fileSupport, this .sql);
0106: }
0107:
0108: /**
0109: * @see net.sf.hajdbc.sql.TestStatement#recordConstructor()
0110: */
0111: @Override
0112: protected void recordConstructor() throws SQLException {
0113: this .parent.addChild(EasyMock
0114: .isA(PreparedStatementInvocationHandler.class));
0115:
0116: this .expectIdentifiers(this .sql, null, null);
0117: this .expectSelectForUpdateCheck(this .sql, false);
0118: }
0119:
0120: /**
0121: * @see java.sql.PreparedStatement#addBatch()
0122: */
0123: @Test
0124: public void addBatch() throws SQLException {
0125: EasyMock.expect(this .cluster.isActive()).andReturn(true);
0126:
0127: this .getStatement1().addBatch();
0128: this .getStatement2().addBatch();
0129:
0130: this .replay();
0131:
0132: this .getStatement().addBatch();
0133:
0134: this .verify();
0135: }
0136:
0137: /**
0138: * @see java.sql.PreparedStatement#clearParameters()
0139: */
0140: @Test
0141: public void clearParameters() throws SQLException {
0142: EasyMock.expect(this .cluster.isActive()).andReturn(true);
0143:
0144: EasyMock.expect(this .cluster.getBalancer()).andReturn(
0145: this .balancer);
0146: EasyMock.expect(this .balancer.all())
0147: .andReturn(this .databaseSet);
0148:
0149: this .getStatement1().addBatch();
0150: this .getStatement2().addBatch();
0151:
0152: this .replay();
0153:
0154: this .getStatement().addBatch();
0155: }
0156:
0157: /**
0158: * @see java.sql.PreparedStatement#execute()
0159: */
0160: @Test
0161: public boolean execute() throws SQLException {
0162: EasyMock.expect(this .cluster.isActive()).andReturn(true);
0163:
0164: EasyMock.expect(this .cluster.getTransactionalExecutor())
0165: .andReturn(this .executor);
0166:
0167: EasyMock.expect(
0168: this .transactionContext.start(EasyMock
0169: .isA(InvocationStrategy.class), EasyMock
0170: .same(this .connection))).andAnswer(this .anwser);
0171:
0172: EasyMock.expect(this .cluster.getBalancer()).andReturn(
0173: this .balancer);
0174: EasyMock.expect(this .balancer.all())
0175: .andReturn(this .databaseSet);
0176:
0177: EasyMock.expect(this .parent.getRoot()).andReturn(this .root);
0178:
0179: this .root.retain(this .databaseSet);
0180:
0181: EasyMock.expect(this .getStatement1().execute()).andReturn(true);
0182: EasyMock.expect(this .getStatement2().execute()).andReturn(true);
0183:
0184: this .replay();
0185:
0186: boolean result = this .getStatement().execute();
0187:
0188: this .verify();
0189:
0190: assert result;
0191:
0192: return result;
0193: }
0194:
0195: /**
0196: * @see java.sql.PreparedStatement#executeQuery()
0197: */
0198: @Test
0199: public ResultSet executeQuery() throws SQLException {
0200: ResultSet resultSet = EasyMock.createMock(ResultSet.class);
0201:
0202: EasyMock.expect(this .cluster.isActive()).andReturn(true).times(
0203: 2);
0204:
0205: // Read-only
0206: EasyMock.expect(this .getStatement1().getResultSetConcurrency())
0207: .andReturn(ResultSet.CONCUR_READ_ONLY);
0208:
0209: EasyMock.expect(this .cluster.getBalancer()).andReturn(
0210: this .balancer);
0211: EasyMock.expect(this .balancer.next()).andReturn(this .database2);
0212:
0213: this .balancer.beforeInvocation(this .database2);
0214:
0215: EasyMock.expect(this .getStatement2().executeQuery()).andReturn(
0216: resultSet);
0217:
0218: this .balancer.afterInvocation(this .database2);
0219:
0220: this .replay();
0221:
0222: ResultSet results = this .getStatement().executeQuery();
0223:
0224: this .verify();
0225:
0226: assert results == resultSet;
0227:
0228: this .reset();
0229:
0230: ResultSet resultSet1 = EasyMock.createMock(ResultSet.class);
0231: ResultSet resultSet2 = EasyMock.createMock(ResultSet.class);
0232:
0233: EasyMock.expect(this .cluster.isActive()).andReturn(true).times(
0234: 2);
0235:
0236: // Updatable
0237: EasyMock.expect(this .getStatement1().getResultSetConcurrency())
0238: .andReturn(ResultSet.CONCUR_UPDATABLE);
0239:
0240: EasyMock.expect(this .cluster.getTransactionalExecutor())
0241: .andReturn(this .executor);
0242:
0243: EasyMock.expect(this .cluster.getBalancer()).andReturn(
0244: this .balancer);
0245: EasyMock.expect(this .balancer.all())
0246: .andReturn(this .databaseSet);
0247:
0248: EasyMock.expect(this .parent.getRoot()).andReturn(this .root);
0249:
0250: this .root.retain(this .databaseSet);
0251:
0252: EasyMock.expect(this .getStatement1().executeQuery()).andReturn(
0253: resultSet1);
0254: EasyMock.expect(this .getStatement2().executeQuery()).andReturn(
0255: resultSet2);
0256:
0257: this .replay();
0258:
0259: results = this .getStatement().executeQuery();
0260:
0261: this .verify();
0262:
0263: assert Proxy.isProxyClass(results.getClass());
0264: assert SQLProxy.class.cast(Proxy.getInvocationHandler(results))
0265: .getObject(this .database1) == resultSet1;
0266: assert SQLProxy.class.cast(Proxy.getInvocationHandler(results))
0267: .getObject(this .database2) == resultSet2;
0268:
0269: return results;
0270: }
0271:
0272: /**
0273: * @see java.sql.PreparedStatement#executeUpdate()
0274: */
0275: @Test
0276: public int executeUpdate() throws SQLException {
0277: EasyMock.expect(this .cluster.isActive()).andReturn(true);
0278:
0279: EasyMock.expect(this .cluster.getTransactionalExecutor())
0280: .andReturn(this .executor);
0281:
0282: EasyMock.expect(
0283: this .transactionContext.start(EasyMock
0284: .isA(InvocationStrategy.class), EasyMock
0285: .same(this .connection))).andAnswer(this .anwser);
0286:
0287: EasyMock.expect(this .cluster.getBalancer()).andReturn(
0288: this .balancer);
0289: EasyMock.expect(this .balancer.all())
0290: .andReturn(this .databaseSet);
0291:
0292: EasyMock.expect(this .parent.getRoot()).andReturn(this .root);
0293:
0294: this .root.retain(this .databaseSet);
0295:
0296: EasyMock.expect(this .getStatement1().executeUpdate())
0297: .andReturn(1);
0298: EasyMock.expect(this .getStatement2().executeUpdate())
0299: .andReturn(1);
0300:
0301: this .replay();
0302:
0303: int result = this .getStatement().executeUpdate();
0304:
0305: this .verify();
0306:
0307: assert result == 1;
0308:
0309: return result;
0310: }
0311:
0312: /**
0313: * @see java.sql.PreparedStatement#getMetaData()
0314: */
0315: @Test
0316: public ResultSetMetaData getMetaData() throws SQLException {
0317: ResultSetMetaData metaData = EasyMock
0318: .createMock(ResultSetMetaData.class);
0319:
0320: EasyMock.expect(this .cluster.isActive()).andReturn(true);
0321:
0322: EasyMock.expect(this .cluster.getBalancer()).andReturn(
0323: this .balancer);
0324: EasyMock.expect(this .balancer.next()).andReturn(this .database2);
0325:
0326: this .balancer.beforeInvocation(this .database2);
0327:
0328: EasyMock.expect(this .getStatement2().getMetaData()).andReturn(
0329: metaData);
0330:
0331: this .balancer.afterInvocation(this .database2);
0332:
0333: this .replay();
0334:
0335: ResultSetMetaData result = this .getStatement().getMetaData();
0336:
0337: this .verify();
0338:
0339: assert result == metaData;
0340:
0341: return result;
0342: }
0343:
0344: /**
0345: * @see java.sql.PreparedStatement#getParameterMetaData()
0346: */
0347: @Test
0348: public ParameterMetaData getParameterMetaData() throws SQLException {
0349: ParameterMetaData metaData = EasyMock
0350: .createMock(ParameterMetaData.class);
0351:
0352: EasyMock.expect(this .cluster.isActive()).andReturn(true);
0353:
0354: EasyMock.expect(this .cluster.getBalancer()).andReturn(
0355: this .balancer);
0356: EasyMock.expect(this .balancer.next()).andReturn(this .database2);
0357:
0358: this .balancer.beforeInvocation(this .database2);
0359:
0360: EasyMock.expect(this .getStatement2().getParameterMetaData())
0361: .andReturn(metaData);
0362:
0363: this .balancer.afterInvocation(this .database2);
0364:
0365: this .replay();
0366:
0367: ParameterMetaData result = this .getStatement()
0368: .getParameterMetaData();
0369:
0370: this .verify();
0371:
0372: assert result == metaData;
0373:
0374: return result;
0375: }
0376:
0377: @DataProvider(name="int-array")
0378: Object[][] intArrayProvider() {
0379: return new Object[][] { new Object[] { 1,
0380: EasyMock.createMock(Array.class) } };
0381: }
0382:
0383: /**
0384: * @see java.sql.PreparedStatement#setArray(int, java.sql.Array)
0385: */
0386: @Test(dataProvider="int-array")
0387: public void setArray(int index, Array array) throws SQLException {
0388: EasyMock.expect(this .cluster.isActive()).andReturn(true);
0389:
0390: this .getStatement1().setArray(index, array);
0391: this .getStatement2().setArray(index, array);
0392:
0393: this .replay();
0394:
0395: this .getStatement().setArray(index, array);
0396:
0397: this .verify();
0398: }
0399:
0400: @DataProvider(name="int-inputStream-int")
0401: Object[][] intInputStreamIntProvider() {
0402: return new Object[][] { new Object[] { 1,
0403: new ByteArrayInputStream(new byte[0]), 0 } };
0404: }
0405:
0406: /**
0407: * @see java.sql.PreparedStatement#setAsciiStream(int, java.io.InputStream, int)
0408: */
0409: @Test(dataProvider="int-inputStream-int")
0410: public void setAsciiStream(int index, InputStream inputStream,
0411: int length) throws SQLException {
0412: File file = new File("");
0413: InputStream input1 = new ByteArrayInputStream(new byte[0]);
0414: InputStream input2 = new ByteArrayInputStream(new byte[0]);
0415:
0416: EasyMock.expect(this .cluster.isActive()).andReturn(true);
0417:
0418: EasyMock.expect(this .fileSupport.createFile(inputStream))
0419: .andReturn(file);
0420:
0421: EasyMock.expect(this .fileSupport.getInputStream(file))
0422: .andReturn(input1);
0423:
0424: this .getStatement1().setAsciiStream(index, input1, length);
0425:
0426: EasyMock.expect(this .fileSupport.getInputStream(file))
0427: .andReturn(input2);
0428:
0429: this .getStatement2().setAsciiStream(index, input2, length);
0430:
0431: this .replay();
0432:
0433: this .getStatement().setAsciiStream(index, inputStream, length);
0434:
0435: this .verify();
0436: }
0437:
0438: @DataProvider(name="int-bigDecimal")
0439: Object[][] intBigDecimalProvider() {
0440: return new Object[][] { new Object[] { 1, new BigDecimal(10) } };
0441: }
0442:
0443: /**
0444: * @see java.sql.PreparedStatement#setBigDecimal(int, java.math.BigDecimal)
0445: */
0446: @Test(dataProvider="int-bigDecimal")
0447: public void setBigDecimal(int index, BigDecimal value)
0448: throws SQLException {
0449: EasyMock.expect(this .cluster.isActive()).andReturn(true);
0450:
0451: this .getStatement1().setBigDecimal(index, value);
0452: this .getStatement2().setBigDecimal(index, value);
0453:
0454: this .replay();
0455:
0456: this .getStatement().setBigDecimal(index, value);
0457:
0458: this .verify();
0459: }
0460:
0461: /**
0462: * @see java.sql.PreparedStatement#setBinaryStream(int, java.io.InputStream, int)
0463: */
0464: @Test(dataProvider="int-inputStream-int")
0465: public void setBinaryStream(int index, InputStream inputStream,
0466: int length) throws SQLException {
0467: File file = new File("");
0468: InputStream input1 = new ByteArrayInputStream(new byte[0]);
0469: InputStream input2 = new ByteArrayInputStream(new byte[0]);
0470:
0471: EasyMock.expect(this .cluster.isActive()).andReturn(true);
0472:
0473: EasyMock.expect(this .fileSupport.createFile(inputStream))
0474: .andReturn(file);
0475:
0476: EasyMock.expect(this .fileSupport.getInputStream(file))
0477: .andReturn(input1);
0478:
0479: this .getStatement1().setBinaryStream(index, input1, length);
0480:
0481: EasyMock.expect(this .fileSupport.getInputStream(file))
0482: .andReturn(input2);
0483:
0484: this .getStatement2().setBinaryStream(index, input2, length);
0485:
0486: this .replay();
0487:
0488: this .getStatement().setBinaryStream(index, inputStream, length);
0489:
0490: this .verify();
0491: }
0492:
0493: @DataProvider(name="int-blob")
0494: Object[][] intBlobProvider() throws Exception {
0495: Map<Database, Blob> map = new TreeMap<Database, Blob>();
0496:
0497: map.put(this .database1, this .blob1);
0498: map.put(this .database2, this .blob2);
0499:
0500: Blob blob = ProxyFactory
0501: .createProxy(Blob.class, new BlobInvocationHandler(
0502: null, this .handler, null, map));
0503:
0504: return new Object[][] { new Object[] { 1, new MockBlob() },
0505: new Object[] { 1, blob } };
0506: }
0507:
0508: /**
0509: * @see java.sql.PreparedStatement#setBlob(int, java.sql.Blob)
0510: */
0511: @Test(dataProvider="int-blob")
0512: public void setBlob(int index, Blob value) throws SQLException {
0513: EasyMock.expect(this .cluster.isActive()).andReturn(true);
0514:
0515: if (Proxy.isProxyClass(value.getClass())) {
0516: this .getStatement1().setBlob(index, this .blob1);
0517: this .getStatement2().setBlob(index, this .blob2);
0518: } else {
0519: this .getStatement1().setBlob(EasyMock.eq(index),
0520: EasyMock.isA(SerialBlob.class));
0521: this .getStatement2().setBlob(EasyMock.eq(index),
0522: EasyMock.isA(SerialBlob.class));
0523: }
0524:
0525: this .replay();
0526:
0527: this .getStatement().setBlob(index, value);
0528:
0529: this .verify();
0530: }
0531:
0532: @DataProvider(name="int-boolean")
0533: Object[][] intBooleanProvider() {
0534: return new Object[][] { new Object[] { 1, true } };
0535: }
0536:
0537: /**
0538: * @see java.sql.PreparedStatement#setBoolean(int, boolean)
0539: */
0540: @Test(dataProvider="int-boolean")
0541: public void setBoolean(int index, boolean value)
0542: throws SQLException {
0543: EasyMock.expect(this .cluster.isActive()).andReturn(true);
0544:
0545: this .getStatement1().setBoolean(index, value);
0546: this .getStatement2().setBoolean(index, value);
0547:
0548: this .replay();
0549:
0550: this .getStatement().setBoolean(index, value);
0551:
0552: this .verify();
0553: }
0554:
0555: @DataProvider(name="int-byte")
0556: Object[][] intByteProvider() {
0557: return new Object[][] { new Object[] { 1,
0558: Integer.valueOf(1).byteValue() } };
0559: }
0560:
0561: /**
0562: * @see java.sql.PreparedStatement#setByte(int, byte)
0563: */
0564: @Test(dataProvider="int-byte")
0565: public void setByte(int index, byte value) throws SQLException {
0566: EasyMock.expect(this .cluster.isActive()).andReturn(true);
0567:
0568: this .getStatement1().setByte(index, value);
0569: this .getStatement2().setByte(index, value);
0570:
0571: this .replay();
0572:
0573: this .getStatement().setByte(index, value);
0574:
0575: this .verify();
0576: }
0577:
0578: @DataProvider(name="int-bytes")
0579: Object[][] intBytesProvider() {
0580: return new Object[][] { new Object[] { 1, new byte[0] } };
0581: }
0582:
0583: /**
0584: * @see java.sql.PreparedStatement#setBytes(int, byte[])
0585: */
0586: @Test(dataProvider="int-bytes")
0587: public void setBytes(int index, byte[] value) throws SQLException {
0588: EasyMock.expect(this .cluster.isActive()).andReturn(true);
0589:
0590: this .getStatement1().setBytes(index, value);
0591: this .getStatement2().setBytes(index, value);
0592:
0593: this .replay();
0594:
0595: this .getStatement().setBytes(index, value);
0596:
0597: this .verify();
0598: }
0599:
0600: @DataProvider(name="int-reader-int")
0601: Object[][] intReaderIntProvider() {
0602: return new Object[][] { new Object[] { 1,
0603: new CharArrayReader(new char[0]), 0 } };
0604: }
0605:
0606: /**
0607: * @see java.sql.PreparedStatement#setCharacterStream(int, java.io.Reader, int)
0608: */
0609: @Test(dataProvider="int-reader-int")
0610: public void setCharacterStream(int index, Reader reader, int length)
0611: throws SQLException {
0612: File file = new File("");
0613: Reader reader1 = new CharArrayReader(new char[0]);
0614: Reader reader2 = new CharArrayReader(new char[0]);
0615:
0616: EasyMock.expect(this .cluster.isActive()).andReturn(true);
0617:
0618: EasyMock.expect(this .fileSupport.createFile(reader)).andReturn(
0619: file);
0620:
0621: EasyMock.expect(this .fileSupport.getReader(file)).andReturn(
0622: reader1);
0623:
0624: this .getStatement1().setCharacterStream(index, reader1, length);
0625:
0626: EasyMock.expect(this .fileSupport.getReader(file)).andReturn(
0627: reader2);
0628:
0629: this .getStatement2().setCharacterStream(index, reader2, length);
0630:
0631: this .replay();
0632:
0633: this .getStatement().setCharacterStream(index, reader, length);
0634:
0635: this .verify();
0636: }
0637:
0638: @DataProvider(name="int-clob")
0639: Object[][] intClobProvider() throws Exception {
0640: Map<Database, Clob> map = new TreeMap<Database, Clob>();
0641:
0642: map.put(this .database1, this .clob1);
0643: map.put(this .database2, this .clob2);
0644:
0645: Clob clob = ProxyFactory
0646: .createProxy(Clob.class, new ClobInvocationHandler(
0647: null, this .handler, null, map));
0648:
0649: return new Object[][] { new Object[] { 1, new MockClob() },
0650: new Object[] { 1, clob } };
0651: }
0652:
0653: /**
0654: * @see java.sql.PreparedStatement#setClob(int, java.sql.Clob)
0655: */
0656: @Test(dataProvider="int-clob")
0657: public void setClob(int index, Clob value) throws SQLException {
0658: EasyMock.expect(this .cluster.isActive()).andReturn(true);
0659:
0660: if (Proxy.isProxyClass(value.getClass())) {
0661: this .getStatement1().setClob(index, this .clob1);
0662: this .getStatement2().setClob(index, this .clob2);
0663: } else {
0664: this .getStatement1().setClob(EasyMock.eq(index),
0665: EasyMock.isA(SerialClob.class));
0666: this .getStatement2().setClob(EasyMock.eq(index),
0667: EasyMock.isA(SerialClob.class));
0668: }
0669:
0670: this .replay();
0671:
0672: this .getStatement().setClob(index, value);
0673:
0674: this .verify();
0675: }
0676:
0677: @DataProvider(name="int-date")
0678: Object[][] intDateProvider() {
0679: return new Object[][] { new Object[] { 1,
0680: new Date(System.currentTimeMillis()) } };
0681: }
0682:
0683: /**
0684: * @see java.sql.PreparedStatement#setDate(int, java.sql.Date)
0685: */
0686: @Test(dataProvider="int-date")
0687: public void setDate(int index, Date date) throws SQLException {
0688: EasyMock.expect(this .cluster.isActive()).andReturn(true);
0689:
0690: this .getStatement1().setDate(index, date);
0691: this .getStatement2().setDate(index, date);
0692:
0693: this .replay();
0694:
0695: this .getStatement().setDate(index, date);
0696:
0697: this .verify();
0698: }
0699:
0700: @DataProvider(name="int-date-calendar")
0701: Object[][] intDateCalendarProvider() {
0702: return new Object[][] { new Object[] { 1,
0703: new Date(System.currentTimeMillis()),
0704: Calendar.getInstance() } };
0705: }
0706:
0707: /**
0708: * @see java.sql.PreparedStatement#setDate(int, java.sql.Date, java.util.Calendar)
0709: */
0710: @Test(dataProvider="int-date-calendar")
0711: public void setDate(int index, Date date, Calendar calendar)
0712: throws SQLException {
0713: EasyMock.expect(this .cluster.isActive()).andReturn(true);
0714:
0715: this .getStatement1().setDate(index, date, calendar);
0716: this .getStatement2().setDate(index, date, calendar);
0717:
0718: this .replay();
0719:
0720: this .getStatement().setDate(index, date, calendar);
0721:
0722: this .verify();
0723: }
0724:
0725: @DataProvider(name="int-double")
0726: Object[][] intDoubleProvider() {
0727: return new Object[][] { new Object[] { 1, 1.0 } };
0728: }
0729:
0730: /**
0731: * @see java.sql.PreparedStatement#setDouble(int, double)
0732: */
0733: @Test(dataProvider="int-double")
0734: public void setDouble(int index, double value) throws SQLException {
0735: EasyMock.expect(this .cluster.isActive()).andReturn(true);
0736:
0737: this .getStatement1().setDouble(index, value);
0738: this .getStatement2().setDouble(index, value);
0739:
0740: this .replay();
0741:
0742: this .getStatement().setDouble(index, value);
0743:
0744: this .verify();
0745: }
0746:
0747: @DataProvider(name="int-float")
0748: Object[][] intFloatProvider() {
0749: return new Object[][] { new Object[] { 1, 1.0f } };
0750: }
0751:
0752: /**
0753: * @see java.sql.PreparedStatement#setFloat(int, float)
0754: */
0755: @Test(dataProvider="int-float")
0756: public void setFloat(int index, float value) throws SQLException {
0757: EasyMock.expect(this .cluster.isActive()).andReturn(true);
0758:
0759: this .getStatement1().setFloat(index, value);
0760: this .getStatement2().setFloat(index, value);
0761:
0762: this .replay();
0763:
0764: this .getStatement().setFloat(index, value);
0765:
0766: this .verify();
0767: }
0768:
0769: @DataProvider(name="int-int")
0770: Object[][] intIntProvider() {
0771: return new Object[][] { new Object[] { 1, 1 } };
0772: }
0773:
0774: /**
0775: * @see java.sql.PreparedStatement#setInt(int, int)
0776: */
0777: @Test(dataProvider="int-int")
0778: public void setInt(int index, int value) throws SQLException {
0779: EasyMock.expect(this .cluster.isActive()).andReturn(true);
0780:
0781: this .getStatement1().setInt(index, value);
0782: this .getStatement2().setInt(index, value);
0783:
0784: this .replay();
0785:
0786: this .getStatement().setInt(index, value);
0787:
0788: this .verify();
0789: }
0790:
0791: @DataProvider(name="int-long")
0792: Object[][] intLongProvider() {
0793: return new Object[][] { new Object[] { 1, 1L } };
0794: }
0795:
0796: /**
0797: * @see java.sql.PreparedStatement#setLong(int, long)
0798: */
0799: @Test(dataProvider="int-long")
0800: public void setLong(int index, long value) throws SQLException {
0801: EasyMock.expect(this .cluster.isActive()).andReturn(true);
0802:
0803: this .getStatement1().setLong(index, value);
0804: this .getStatement2().setLong(index, value);
0805:
0806: this .replay();
0807:
0808: this .getStatement().setLong(index, value);
0809:
0810: this .verify();
0811: }
0812:
0813: /**
0814: * @see java.sql.PreparedStatement#setNull(int, int)
0815: */
0816: @Test(dataProvider="int-int")
0817: public void setNull(int index, int sqlType) throws SQLException {
0818: EasyMock.expect(this .cluster.isActive()).andReturn(true);
0819:
0820: this .getStatement1().setNull(index, sqlType);
0821: this .getStatement2().setNull(index, sqlType);
0822:
0823: this .replay();
0824:
0825: this .getStatement().setNull(index, sqlType);
0826:
0827: this .verify();
0828: }
0829:
0830: @DataProvider(name="int-int-string")
0831: Object[][] intIntStringProvider() {
0832: return new Object[][] { new Object[] { 1, 1, "" } };
0833: }
0834:
0835: /**
0836: * @see java.sql.PreparedStatement#setNull(int, int, java.lang.String)
0837: */
0838: @Test(dataProvider="int-int-string")
0839: public void setNull(int index, int sqlType, String typeName)
0840: throws SQLException {
0841: EasyMock.expect(this .cluster.isActive()).andReturn(true);
0842:
0843: this .getStatement1().setNull(index, sqlType, typeName);
0844: this .getStatement2().setNull(index, sqlType, typeName);
0845:
0846: this .replay();
0847:
0848: this .getStatement().setNull(index, sqlType, typeName);
0849:
0850: this .verify();
0851: }
0852:
0853: @DataProvider(name="int-object")
0854: Object[][] intObjectProvider() {
0855: return new Object[][] { new Object[] { 1, new Object() } };
0856: }
0857:
0858: /**
0859: * @see java.sql.PreparedStatement#setObject(int, java.lang.Object)
0860: */
0861: @Test(dataProvider="int-object")
0862: public void setObject(int index, Object value) throws SQLException {
0863: EasyMock.expect(this .cluster.isActive()).andReturn(true);
0864:
0865: this .getStatement1().setObject(index, value);
0866: this .getStatement2().setObject(index, value);
0867:
0868: this .replay();
0869:
0870: this .getStatement().setObject(index, value);
0871:
0872: this .verify();
0873: }
0874:
0875: @DataProvider(name="int-object-int")
0876: Object[][] intObjectIntProvider() {
0877: return new Object[][] { new Object[] { 1, new Object(), 1 } };
0878: }
0879:
0880: /**
0881: * @see java.sql.PreparedStatement#setObject(int, java.lang.Object, int)
0882: */
0883: @Test(dataProvider="int-object-int")
0884: public void setObject(int index, Object value, int targetSqlType)
0885: throws SQLException {
0886: EasyMock.expect(this .cluster.isActive()).andReturn(true);
0887:
0888: this .getStatement1().setObject(index, value, targetSqlType);
0889: this .getStatement2().setObject(index, value, targetSqlType);
0890:
0891: this .replay();
0892:
0893: this .getStatement().setObject(index, value, targetSqlType);
0894:
0895: this .verify();
0896: }
0897:
0898: @DataProvider(name="int-object-int-int")
0899: Object[][] intObjectIntIntProvider() {
0900: return new Object[][] { new Object[] { 1, new Object(), 1, 1 } };
0901: }
0902:
0903: /**
0904: * @see java.sql.PreparedStatement#setObject(int, java.lang.Object, int, int)
0905: */
0906: @Test(dataProvider="int-object-int-int")
0907: public void setObject(int index, Object value, int targetSqlType,
0908: int scale) throws SQLException {
0909: EasyMock.expect(this .cluster.isActive()).andReturn(true);
0910:
0911: this .getStatement1().setObject(index, value, targetSqlType,
0912: scale);
0913: this .getStatement2().setObject(index, value, targetSqlType,
0914: scale);
0915:
0916: this .replay();
0917:
0918: this .getStatement().setObject(index, value, targetSqlType,
0919: scale);
0920:
0921: this .verify();
0922: }
0923:
0924: @DataProvider(name="int-ref")
0925: Object[][] intRefProvider() {
0926: return new Object[][] { new Object[] { 1,
0927: EasyMock.createMock(Ref.class) } };
0928: }
0929:
0930: /**
0931: * @see java.sql.PreparedStatement#setRef(int, java.sql.Ref)
0932: */
0933: @Test(dataProvider="int-ref")
0934: public void setRef(int index, Ref value) throws SQLException {
0935: EasyMock.expect(this .cluster.isActive()).andReturn(true);
0936:
0937: this .getStatement1().setRef(index, value);
0938: this .getStatement2().setRef(index, value);
0939:
0940: this .replay();
0941:
0942: this .getStatement().setRef(index, value);
0943:
0944: this .verify();
0945: }
0946:
0947: @DataProvider(name="int-short")
0948: Object[][] intShortProvider() {
0949: return new Object[][] { new Object[] { 1,
0950: Integer.valueOf(1).shortValue() } };
0951: }
0952:
0953: /**
0954: * @see java.sql.PreparedStatement#setShort(int, short)
0955: */
0956: @Test(dataProvider="int-short")
0957: public void setShort(int index, short value) throws SQLException {
0958: EasyMock.expect(this .cluster.isActive()).andReturn(true);
0959:
0960: this .getStatement1().setShort(index, value);
0961: this .getStatement2().setShort(index, value);
0962:
0963: this .replay();
0964:
0965: this .getStatement().setShort(index, value);
0966:
0967: this .verify();
0968: }
0969:
0970: @DataProvider(name="int-string")
0971: Object[][] intStringProvider() {
0972: return new Object[][] { new Object[] { 1, "" } };
0973: }
0974:
0975: /**
0976: * @see java.sql.PreparedStatement#setString(int, java.lang.String)
0977: */
0978: @Test(dataProvider="int-string")
0979: public void setString(int index, String value) throws SQLException {
0980: EasyMock.expect(this .cluster.isActive()).andReturn(true);
0981:
0982: this .getStatement1().setString(index, value);
0983: this .getStatement2().setString(index, value);
0984:
0985: this .replay();
0986:
0987: this .getStatement().setString(index, value);
0988:
0989: this .verify();
0990: }
0991:
0992: @DataProvider(name="int-time")
0993: Object[][] intTimeProvider() {
0994: return new Object[][] { new Object[] { 1,
0995: new Time(System.currentTimeMillis()) } };
0996: }
0997:
0998: /**
0999: * @see java.sql.PreparedStatement#setTime(int, java.sql.Time)
1000: */
1001: @Test(dataProvider="int-time")
1002: public void setTime(int index, Time value) throws SQLException {
1003: EasyMock.expect(this .cluster.isActive()).andReturn(true);
1004:
1005: this .getStatement1().setTime(index, value);
1006: this .getStatement2().setTime(index, value);
1007:
1008: this .replay();
1009:
1010: this .getStatement().setTime(index, value);
1011:
1012: this .verify();
1013: }
1014:
1015: @DataProvider(name="int-time-calendar")
1016: Object[][] intTimeCalendarProvider() {
1017: return new Object[][] { new Object[] { 1,
1018: new Time(System.currentTimeMillis()),
1019: Calendar.getInstance() } };
1020: }
1021:
1022: /**
1023: * @see java.sql.PreparedStatement#setTime(int, java.sql.Time, java.util.Calendar)
1024: */
1025: @Test(dataProvider="int-time-calendar")
1026: public void setTime(int index, Time value, Calendar calendar)
1027: throws SQLException {
1028: EasyMock.expect(this .cluster.isActive()).andReturn(true);
1029:
1030: this .getStatement1().setTime(index, value, calendar);
1031: this .getStatement2().setTime(index, value, calendar);
1032:
1033: this .replay();
1034:
1035: this .getStatement().setTime(index, value, calendar);
1036:
1037: this .verify();
1038: }
1039:
1040: @DataProvider(name="int-timestamp")
1041: Object[][] intTimestampProvider() {
1042: return new Object[][] { new Object[] { 1,
1043: new Timestamp(System.currentTimeMillis()) } };
1044: }
1045:
1046: /**
1047: * @see java.sql.PreparedStatement#setTimestamp(int, java.sql.Timestamp)
1048: */
1049: @Test(dataProvider="int-timestamp")
1050: public void setTimestamp(int index, Timestamp value)
1051: throws SQLException {
1052: EasyMock.expect(this .cluster.isActive()).andReturn(true);
1053:
1054: this .getStatement1().setTimestamp(index, value);
1055: this .getStatement2().setTimestamp(index, value);
1056:
1057: this .replay();
1058:
1059: this .getStatement().setTimestamp(index, value);
1060:
1061: this .verify();
1062: }
1063:
1064: @DataProvider(name="int-timestamp-calendar")
1065: Object[][] intTimestampCalendarProvider() {
1066: return new Object[][] { new Object[] { 1,
1067: new Timestamp(System.currentTimeMillis()),
1068: Calendar.getInstance() } };
1069: }
1070:
1071: /**
1072: * @see java.sql.PreparedStatement#setTimestamp(int, java.sql.Timestamp, java.util.Calendar)
1073: */
1074: @Test(dataProvider="int-timestamp-calendar")
1075: public void setTimestamp(int index, Timestamp value,
1076: Calendar calendar) throws SQLException {
1077: EasyMock.expect(this .cluster.isActive()).andReturn(true);
1078:
1079: this .getStatement1().setTimestamp(index, value, calendar);
1080: this .getStatement2().setTimestamp(index, value, calendar);
1081:
1082: this .replay();
1083:
1084: this .getStatement().setTimestamp(index, value, calendar);
1085:
1086: this .verify();
1087: }
1088:
1089: /**
1090: * @see java.sql.PreparedStatement#setUnicodeStream(int, java.io.InputStream, int)
1091: */
1092: @SuppressWarnings("deprecation")
1093: @Test(dataProvider="int-inputStream-int")
1094: @Deprecated
1095: public void setUnicodeStream(int index, InputStream inputStream,
1096: int length) throws SQLException {
1097: File file = new File("");
1098: InputStream input1 = new ByteArrayInputStream(new byte[0]);
1099: InputStream input2 = new ByteArrayInputStream(new byte[0]);
1100:
1101: EasyMock.expect(this .cluster.isActive()).andReturn(true);
1102:
1103: EasyMock.expect(this .fileSupport.createFile(inputStream))
1104: .andReturn(file);
1105:
1106: EasyMock.expect(this .fileSupport.getInputStream(file))
1107: .andReturn(input1);
1108:
1109: this .getStatement1().setUnicodeStream(index, input1, length);
1110:
1111: EasyMock.expect(this .fileSupport.getInputStream(file))
1112: .andReturn(input2);
1113:
1114: this .getStatement2().setUnicodeStream(index, input2, length);
1115:
1116: this .replay();
1117:
1118: this .getStatement()
1119: .setUnicodeStream(index, inputStream, length);
1120:
1121: this .verify();
1122: }
1123:
1124: @DataProvider(name="int-url")
1125: Object[][] intURLProvider() throws MalformedURLException {
1126: return new Object[][] { new Object[] { 1,
1127: new URL("http://ha-jdbc.sf.net") } };
1128: }
1129:
1130: /**
1131: * @see java.sql.PreparedStatement#setURL(int, java.net.URL)
1132: */
1133: @Test(dataProvider="int-url")
1134: public void setURL(int index, URL value) throws SQLException {
1135: EasyMock.expect(this .cluster.isActive()).andReturn(true);
1136:
1137: this .getStatement1().setURL(index, value);
1138: this .getStatement2().setURL(index, value);
1139:
1140: this .replay();
1141:
1142: this .getStatement().setURL(index, value);
1143:
1144: this .verify();
1145: }
1146:
1147: @DataProvider(name="int-inputStream")
1148: Object[][] intInputStreamProvider() {
1149: return new Object[][] { new Object[] { 1,
1150: new ByteArrayInputStream(new byte[0]) } };
1151: }
1152:
1153: /**
1154: * @see java.sql.PreparedStatement#setAsciiStream(int, java.io.InputStream)
1155: */
1156: @Test(dataProvider="int-inputStream")
1157: public void setAsciiStream(int index, InputStream value)
1158: throws SQLException {
1159: File file = new File("");
1160: InputStream input1 = new ByteArrayInputStream(new byte[0]);
1161: InputStream input2 = new ByteArrayInputStream(new byte[0]);
1162:
1163: EasyMock.expect(this .cluster.isActive()).andReturn(true);
1164:
1165: EasyMock.expect(this .fileSupport.createFile(value)).andReturn(
1166: file);
1167:
1168: EasyMock.expect(this .fileSupport.getInputStream(file))
1169: .andReturn(input1);
1170:
1171: this .getStatement1().setAsciiStream(index, input1);
1172:
1173: EasyMock.expect(this .fileSupport.getInputStream(file))
1174: .andReturn(input2);
1175:
1176: this .getStatement2().setAsciiStream(index, input2);
1177:
1178: this .replay();
1179:
1180: this .getStatement().setAsciiStream(index, value);
1181:
1182: this .verify();
1183: }
1184:
1185: @DataProvider(name="int-inputStream-long")
1186: Object[][] intInputStreamLongProvider() {
1187: return new Object[][] { new Object[] { 1,
1188: new ByteArrayInputStream(new byte[0]), 1L } };
1189: }
1190:
1191: /**
1192: * @see java.sql.PreparedStatement#setAsciiStream(int, java.io.InputStream, long)
1193: */
1194: @Test(dataProvider="int-inputStream-long")
1195: public void setAsciiStream(int index, InputStream value, long length)
1196: throws SQLException {
1197: File file = new File("");
1198: InputStream input1 = new ByteArrayInputStream(new byte[0]);
1199: InputStream input2 = new ByteArrayInputStream(new byte[0]);
1200:
1201: EasyMock.expect(this .cluster.isActive()).andReturn(true);
1202:
1203: EasyMock.expect(this .fileSupport.createFile(value)).andReturn(
1204: file);
1205:
1206: EasyMock.expect(this .fileSupport.getInputStream(file))
1207: .andReturn(input1);
1208:
1209: this .getStatement1().setAsciiStream(index, input1, length);
1210:
1211: EasyMock.expect(this .fileSupport.getInputStream(file))
1212: .andReturn(input2);
1213:
1214: this .getStatement2().setAsciiStream(index, input2, length);
1215:
1216: this .replay();
1217:
1218: this .getStatement().setAsciiStream(index, value, length);
1219:
1220: this .verify();
1221: }
1222:
1223: /**
1224: * @see java.sql.PreparedStatement#setBinaryStream(int, java.io.InputStream)
1225: */
1226: @Test(dataProvider="int-inputStream")
1227: public void setBinaryStream(int index, InputStream value)
1228: throws SQLException {
1229: File file = new File("");
1230: InputStream input1 = new ByteArrayInputStream(new byte[0]);
1231: InputStream input2 = new ByteArrayInputStream(new byte[0]);
1232:
1233: EasyMock.expect(this .cluster.isActive()).andReturn(true);
1234:
1235: EasyMock.expect(this .fileSupport.createFile(value)).andReturn(
1236: file);
1237:
1238: EasyMock.expect(this .fileSupport.getInputStream(file))
1239: .andReturn(input1);
1240:
1241: this .getStatement1().setBinaryStream(index, input1);
1242:
1243: EasyMock.expect(this .fileSupport.getInputStream(file))
1244: .andReturn(input2);
1245:
1246: this .getStatement2().setBinaryStream(index, input2);
1247:
1248: this .replay();
1249:
1250: this .getStatement().setBinaryStream(index, value);
1251:
1252: this .verify();
1253: }
1254:
1255: /**
1256: * @see java.sql.PreparedStatement#setBinaryStream(int, java.io.InputStream, long)
1257: */
1258: @Test(dataProvider="int-inputStream-long")
1259: public void setBinaryStream(int index, InputStream value,
1260: long length) throws SQLException {
1261: File file = new File("");
1262: InputStream input1 = new ByteArrayInputStream(new byte[0]);
1263: InputStream input2 = new ByteArrayInputStream(new byte[0]);
1264:
1265: EasyMock.expect(this .cluster.isActive()).andReturn(true);
1266:
1267: EasyMock.expect(this .fileSupport.createFile(value)).andReturn(
1268: file);
1269:
1270: EasyMock.expect(this .fileSupport.getInputStream(file))
1271: .andReturn(input1);
1272:
1273: this .getStatement1().setBinaryStream(index, input1, length);
1274:
1275: EasyMock.expect(this .fileSupport.getInputStream(file))
1276: .andReturn(input2);
1277:
1278: this .getStatement2().setBinaryStream(index, input2, length);
1279:
1280: this .replay();
1281:
1282: this .getStatement().setBinaryStream(index, value, length);
1283:
1284: this .verify();
1285: }
1286:
1287: /**
1288: * @see java.sql.PreparedStatement#setBlob(int, java.io.InputStream)
1289: */
1290: @Test(dataProvider="int-inputStream")
1291: public void setBlob(int index, InputStream value)
1292: throws SQLException {
1293: File file = new File("");
1294: InputStream input1 = new ByteArrayInputStream(new byte[0]);
1295: InputStream input2 = new ByteArrayInputStream(new byte[0]);
1296:
1297: EasyMock.expect(this .cluster.isActive()).andReturn(true);
1298:
1299: EasyMock.expect(this .fileSupport.createFile(value)).andReturn(
1300: file);
1301:
1302: EasyMock.expect(this .fileSupport.getInputStream(file))
1303: .andReturn(input1);
1304:
1305: this .getStatement1().setBlob(index, input1);
1306:
1307: EasyMock.expect(this .fileSupport.getInputStream(file))
1308: .andReturn(input2);
1309:
1310: this .getStatement2().setBlob(index, input2);
1311:
1312: this .replay();
1313:
1314: this .getStatement().setBlob(index, value);
1315:
1316: this .verify();
1317: }
1318:
1319: /**
1320: * @see java.sql.PreparedStatement#setBlob(int, java.io.InputStream, long)
1321: */
1322: @Test(dataProvider="int-inputStream-long")
1323: public void setBlob(int index, InputStream value, long length)
1324: throws SQLException {
1325: File file = new File("");
1326: InputStream input1 = new ByteArrayInputStream(new byte[0]);
1327: InputStream input2 = new ByteArrayInputStream(new byte[0]);
1328:
1329: EasyMock.expect(this .cluster.isActive()).andReturn(true);
1330:
1331: EasyMock.expect(this .fileSupport.createFile(value)).andReturn(
1332: file);
1333:
1334: EasyMock.expect(this .fileSupport.getInputStream(file))
1335: .andReturn(input1);
1336:
1337: this .getStatement1().setBlob(index, input1, length);
1338:
1339: EasyMock.expect(this .fileSupport.getInputStream(file))
1340: .andReturn(input2);
1341:
1342: this .getStatement2().setBlob(index, input2, length);
1343:
1344: this .replay();
1345:
1346: this .getStatement().setBlob(index, value, length);
1347:
1348: this .verify();
1349: }
1350:
1351: /**
1352: * @see java.sql.PreparedStatement#setCharacterStream(int, java.io.Reader)
1353: */
1354: @Test(dataProvider="int-reader")
1355: public void setCharacterStream(int index, Reader value)
1356: throws SQLException {
1357: File file = new File("");
1358: Reader reader1 = new CharArrayReader(new char[0]);
1359: Reader reader2 = new CharArrayReader(new char[0]);
1360:
1361: EasyMock.expect(this .cluster.isActive()).andReturn(true);
1362:
1363: EasyMock.expect(this .fileSupport.createFile(value)).andReturn(
1364: file);
1365:
1366: EasyMock.expect(this .fileSupport.getReader(file)).andReturn(
1367: reader1);
1368:
1369: this .getStatement1().setCharacterStream(index, reader1);
1370:
1371: EasyMock.expect(this .fileSupport.getReader(file)).andReturn(
1372: reader2);
1373:
1374: this .getStatement2().setCharacterStream(index, reader2);
1375:
1376: this .replay();
1377:
1378: this .getStatement().setCharacterStream(index, value);
1379:
1380: this .verify();
1381: }
1382:
1383: @DataProvider(name="int-reader-long")
1384: Object[][] intReaderLongProvider() {
1385: return new Object[][] { new Object[] { 1, new StringReader(""),
1386: 1L } };
1387: }
1388:
1389: /**
1390: * @see java.sql.PreparedStatement#setCharacterStream(int, java.io.Reader, long)
1391: */
1392: @Test(dataProvider="int-reader-long")
1393: public void setCharacterStream(int index, Reader value, long length)
1394: throws SQLException {
1395: File file = new File("");
1396: Reader reader1 = new CharArrayReader(new char[0]);
1397: Reader reader2 = new CharArrayReader(new char[0]);
1398:
1399: EasyMock.expect(this .cluster.isActive()).andReturn(true);
1400:
1401: EasyMock.expect(this .fileSupport.createFile(value)).andReturn(
1402: file);
1403:
1404: EasyMock.expect(this .fileSupport.getReader(file)).andReturn(
1405: reader1);
1406:
1407: this .getStatement1().setCharacterStream(index, reader1, length);
1408:
1409: EasyMock.expect(this .fileSupport.getReader(file)).andReturn(
1410: reader2);
1411:
1412: this .getStatement2().setCharacterStream(index, reader2, length);
1413:
1414: this .replay();
1415:
1416: this .getStatement().setCharacterStream(index, value, length);
1417:
1418: this .verify();
1419: }
1420:
1421: @DataProvider(name="int-reader")
1422: Object[][] intReaderProvider() {
1423: return new Object[][] { new Object[] { 1, new StringReader("") } };
1424: }
1425:
1426: /**
1427: * @see java.sql.PreparedStatement#setClob(int, java.io.Reader)
1428: */
1429: @Test(dataProvider="int-reader")
1430: public void setClob(int index, Reader value) throws SQLException {
1431: File file = new File("");
1432: Reader reader1 = new CharArrayReader(new char[0]);
1433: Reader reader2 = new CharArrayReader(new char[0]);
1434:
1435: EasyMock.expect(this .cluster.isActive()).andReturn(true);
1436:
1437: EasyMock.expect(this .fileSupport.createFile(value)).andReturn(
1438: file);
1439:
1440: EasyMock.expect(this .fileSupport.getReader(file)).andReturn(
1441: reader1);
1442:
1443: this .getStatement1().setClob(index, reader1);
1444:
1445: EasyMock.expect(this .fileSupport.getReader(file)).andReturn(
1446: reader2);
1447:
1448: this .getStatement2().setClob(index, reader2);
1449:
1450: this .replay();
1451:
1452: this .getStatement().setClob(index, value);
1453:
1454: this .verify();
1455: }
1456:
1457: /**
1458: * @see java.sql.PreparedStatement#setClob(int, java.io.Reader, long)
1459: */
1460: @Test(dataProvider="int-reader-long")
1461: public void setClob(int index, Reader value, long length)
1462: throws SQLException {
1463: File file = new File("");
1464: Reader reader1 = new CharArrayReader(new char[0]);
1465: Reader reader2 = new CharArrayReader(new char[0]);
1466:
1467: EasyMock.expect(this .cluster.isActive()).andReturn(true);
1468:
1469: EasyMock.expect(this .fileSupport.createFile(value)).andReturn(
1470: file);
1471:
1472: EasyMock.expect(this .fileSupport.getReader(file)).andReturn(
1473: reader1);
1474:
1475: this .getStatement1().setClob(index, reader1, length);
1476:
1477: EasyMock.expect(this .fileSupport.getReader(file)).andReturn(
1478: reader2);
1479:
1480: this .getStatement2().setClob(index, reader2, length);
1481:
1482: this .replay();
1483:
1484: this .getStatement().setClob(index, value, length);
1485:
1486: this .verify();
1487: }
1488:
1489: /**
1490: * @see java.sql.PreparedStatement#setNCharacterStream(int, java.io.Reader)
1491: */
1492: @Test(dataProvider="int-reader")
1493: public void setNCharacterStream(int index, Reader value)
1494: throws SQLException {
1495: File file = new File("");
1496: Reader reader1 = new CharArrayReader(new char[0]);
1497: Reader reader2 = new CharArrayReader(new char[0]);
1498:
1499: EasyMock.expect(this .cluster.isActive()).andReturn(true);
1500:
1501: EasyMock.expect(this .fileSupport.createFile(value)).andReturn(
1502: file);
1503:
1504: EasyMock.expect(this .fileSupport.getReader(file)).andReturn(
1505: reader1);
1506:
1507: this .getStatement1().setNCharacterStream(index, reader1);
1508:
1509: EasyMock.expect(this .fileSupport.getReader(file)).andReturn(
1510: reader2);
1511:
1512: this .getStatement2().setNCharacterStream(index, reader2);
1513:
1514: this .replay();
1515:
1516: this .getStatement().setNCharacterStream(index, value);
1517:
1518: this .verify();
1519: }
1520:
1521: /**
1522: * @see java.sql.PreparedStatement#setNCharacterStream(int, java.io.Reader, long)
1523: */
1524: @Test(dataProvider="int-reader-long")
1525: public void setNCharacterStream(int index, Reader value, long length)
1526: throws SQLException {
1527: File file = new File("");
1528: Reader reader1 = new CharArrayReader(new char[0]);
1529: Reader reader2 = new CharArrayReader(new char[0]);
1530:
1531: EasyMock.expect(this .cluster.isActive()).andReturn(true);
1532:
1533: EasyMock.expect(this .fileSupport.createFile(value)).andReturn(
1534: file);
1535:
1536: EasyMock.expect(this .fileSupport.getReader(file)).andReturn(
1537: reader1);
1538:
1539: this .getStatement1()
1540: .setNCharacterStream(index, reader1, length);
1541:
1542: EasyMock.expect(this .fileSupport.getReader(file)).andReturn(
1543: reader2);
1544:
1545: this .getStatement2()
1546: .setNCharacterStream(index, reader2, length);
1547:
1548: this .replay();
1549:
1550: this .getStatement().setNCharacterStream(index, value, length);
1551:
1552: this .verify();
1553: }
1554:
1555: @DataProvider(name="int-nclob")
1556: Object[][] intNClobProvider() throws Exception {
1557: Map<Database, NClob> map = new TreeMap<Database, NClob>();
1558:
1559: map.put(this .database1, this .nClob1);
1560: map.put(this .database2, this .nClob2);
1561:
1562: NClob nClob = ProxyFactory
1563: .createProxy(NClob.class, new ClobInvocationHandler(
1564: null, this .handler, null, map));
1565:
1566: return new Object[][] { new Object[] { 1, new MockClob() },
1567: new Object[] { 1, nClob } };
1568: }
1569:
1570: /**
1571: * @see java.sql.PreparedStatement#setNClob(int, java.sql.NClob)
1572: */
1573: @Test(dataProvider="int-nclob")
1574: public void setNClob(int index, NClob value) throws SQLException {
1575: EasyMock.expect(this .cluster.isActive()).andReturn(true);
1576:
1577: if (Proxy.isProxyClass(value.getClass())) {
1578: this .getStatement1().setNClob(index, this .nClob1);
1579: this .getStatement2().setNClob(index, this .nClob2);
1580: } else {
1581: this .getStatement1().setNClob(EasyMock.eq(index),
1582: EasyMock.isA(NClob.class));
1583: this .getStatement2().setNClob(EasyMock.eq(index),
1584: EasyMock.isA(NClob.class));
1585: }
1586:
1587: this .replay();
1588:
1589: this .getStatement().setNClob(index, value);
1590:
1591: this .verify();
1592: }
1593:
1594: /**
1595: * @see java.sql.PreparedStatement#setNClob(int, java.io.Reader)
1596: */
1597: @Test(dataProvider="int-reader")
1598: public void setNClob(int index, Reader value) throws SQLException {
1599: File file = new File("");
1600: Reader reader1 = new CharArrayReader(new char[0]);
1601: Reader reader2 = new CharArrayReader(new char[0]);
1602:
1603: EasyMock.expect(this .cluster.isActive()).andReturn(true);
1604:
1605: EasyMock.expect(this .fileSupport.createFile(value)).andReturn(
1606: file);
1607:
1608: EasyMock.expect(this .fileSupport.getReader(file)).andReturn(
1609: reader1);
1610:
1611: this .getStatement1().setNClob(index, reader1);
1612:
1613: EasyMock.expect(this .fileSupport.getReader(file)).andReturn(
1614: reader2);
1615:
1616: this .getStatement2().setNClob(index, reader2);
1617:
1618: this .replay();
1619:
1620: this .getStatement().setNClob(index, value);
1621:
1622: this .verify();
1623: }
1624:
1625: /**
1626: * @see java.sql.PreparedStatement#setNClob(int, java.io.Reader, long)
1627: */
1628: @Test(dataProvider="int-reader-long")
1629: public void setNClob(int index, Reader value, long length)
1630: throws SQLException {
1631: File file = new File("");
1632: Reader reader1 = new CharArrayReader(new char[0]);
1633: Reader reader2 = new CharArrayReader(new char[0]);
1634:
1635: EasyMock.expect(this .cluster.isActive()).andReturn(true);
1636:
1637: EasyMock.expect(this .fileSupport.createFile(value)).andReturn(
1638: file);
1639:
1640: EasyMock.expect(this .fileSupport.getReader(file)).andReturn(
1641: reader1);
1642:
1643: this .getStatement1().setNClob(index, reader1, length);
1644:
1645: EasyMock.expect(this .fileSupport.getReader(file)).andReturn(
1646: reader2);
1647:
1648: this .getStatement2().setNClob(index, reader2, length);
1649:
1650: this .replay();
1651:
1652: this .getStatement().setNClob(index, value, length);
1653:
1654: this .verify();
1655: }
1656:
1657: /**
1658: * @see java.sql.PreparedStatement#setNString(int, java.lang.String)
1659: */
1660: @Test(dataProvider="int-string")
1661: public void setNString(int index, String value) throws SQLException {
1662: EasyMock.expect(this .cluster.isActive()).andReturn(true);
1663:
1664: this .getStatement1().setNString(index, value);
1665: this .getStatement2().setNString(index, value);
1666:
1667: this .replay();
1668:
1669: this .getStatement().setNString(index, value);
1670:
1671: this .verify();
1672: }
1673:
1674: @DataProvider(name="int-rowId")
1675: Object[][] intRowIdProvider() {
1676: return new Object[][] { new Object[] { 1,
1677: EasyMock.createMock(RowId.class) } };
1678: }
1679:
1680: /**
1681: * @see java.sql.PreparedStatement#setRowId(int, java.sql.RowId)
1682: */
1683: @Test(dataProvider="int-rowId")
1684: public void setRowId(int index, RowId value) throws SQLException {
1685: EasyMock.expect(this .cluster.isActive()).andReturn(true);
1686:
1687: this .getStatement1().setRowId(index, value);
1688: this .getStatement2().setRowId(index, value);
1689:
1690: this .replay();
1691:
1692: this .getStatement().setRowId(index, value);
1693:
1694: this .verify();
1695: }
1696:
1697: @DataProvider(name="int-xml")
1698: Object[][] intSQLXMLProvider() {
1699: return new Object[][] { new Object[] { 1,
1700: EasyMock.createMock(SQLXML.class) } };
1701: }
1702:
1703: /**
1704: * @see java.sql.PreparedStatement#setSQLXML(int, java.sql.SQLXML)
1705: */
1706: @Test(dataProvider="int-xml")
1707: public void setSQLXML(int index, SQLXML value) throws SQLException {
1708: EasyMock.expect(this .cluster.isActive()).andReturn(true);
1709:
1710: this.getStatement1().setSQLXML(index, value);
1711: this.getStatement2().setSQLXML(index, value);
1712:
1713: this.replay();
1714:
1715: this.getStatement().setSQLXML(index, value);
1716:
1717: this.verify();
1718: }
1719: }
|