From 4dfc06eb1f4747eb6e5b554bb0be6215886c0870 Mon Sep 17 00:00:00 2001 From: wenshao Date: Fri, 16 Sep 2011 05:31:08 +0000 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84mock=E5=92=8C=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://code.alibabatech.com/svn/druid/trunk@798 b9813039-fb51-4c41-a8b9-e21c2acb5095 --- .../druid/mock/MockCallableStatement.java | 24 +-- .../druid/mock/MockPreparedStatement.java | 4 +- .../basic/PoolableCallableStatementTest.java | 170 ++++++++++++++---- 3 files changed, 151 insertions(+), 47 deletions(-) diff --git a/src/main/java/com/alibaba/druid/mock/MockCallableStatement.java b/src/main/java/com/alibaba/druid/mock/MockCallableStatement.java index 8541914b41..d73d741257 100644 --- a/src/main/java/com/alibaba/druid/mock/MockCallableStatement.java +++ b/src/main/java/com/alibaba/druid/mock/MockCallableStatement.java @@ -503,36 +503,36 @@ public class MockCallableStatement extends MockPreparedStatement implements Call @Override public void setRowId(String parameterName, RowId x) throws SQLException { - + setObject(parameterName, x); } @Override - public void setNString(String parameterName, String value) throws SQLException { - + public void setNString(String parameterName, String x) throws SQLException { + setObject(parameterName, x); } @Override - public void setNCharacterStream(String parameterName, Reader value, long length) throws SQLException { - + public void setNCharacterStream(String parameterName, Reader x, long length) throws SQLException { + setObject(parameterName, x); } @Override - public void setNClob(String parameterName, NClob value) throws SQLException { - + public void setNClob(String parameterName, NClob x) throws SQLException { + setObject(parameterName, x); } @Override - public void setClob(String parameterName, Reader reader, long length) throws SQLException { - + public void setClob(String parameterName, Reader x, long length) throws SQLException { + setObject(parameterName, x); } @Override - public void setBlob(String parameterName, InputStream inputStream, long length) throws SQLException { - + public void setBlob(String parameterName, InputStream x, long length) throws SQLException { + setObject(parameterName, x); } @Override - public void setNClob(String parameterName, Reader reader, long length) throws SQLException { + public void setNClob(String parameterName, Reader x, long length) throws SQLException { } diff --git a/src/main/java/com/alibaba/druid/mock/MockPreparedStatement.java b/src/main/java/com/alibaba/druid/mock/MockPreparedStatement.java index ae29e4cce7..33ab05a289 100644 --- a/src/main/java/com/alibaba/druid/mock/MockPreparedStatement.java +++ b/src/main/java/com/alibaba/druid/mock/MockPreparedStatement.java @@ -268,8 +268,8 @@ public class MockPreparedStatement extends MockStatement implements PreparedStat } @Override - public void setClob(int parameterIndex, Reader reader, long length) throws SQLException { - + public void setClob(int parameterIndex, Reader value, long length) throws SQLException { + parameters.add(parameterIndex - 1, value); } @Override diff --git a/src/test/java/com/alibaba/druid/bvt/pool/basic/PoolableCallableStatementTest.java b/src/test/java/com/alibaba/druid/bvt/pool/basic/PoolableCallableStatementTest.java index 749823bb9e..1b2fc17d07 100644 --- a/src/test/java/com/alibaba/druid/bvt/pool/basic/PoolableCallableStatementTest.java +++ b/src/test/java/com/alibaba/druid/bvt/pool/basic/PoolableCallableStatementTest.java @@ -2,6 +2,7 @@ package com.alibaba.druid.bvt.pool.basic; import java.io.InputStream; import java.io.Reader; +import java.sql.Clob; import java.sql.SQLException; import java.sql.Types; @@ -547,12 +548,12 @@ public class PoolableCallableStatementTest extends TestCase { Assert.assertNotNull(error); } } - + public void test_setNClob() throws Exception { - + stmt.setNClob(1, (Reader) null); stmt.setNClob("1", (Reader) null); - + { SQLException error = null; try { @@ -562,7 +563,7 @@ public class PoolableCallableStatementTest extends TestCase { } Assert.assertNotNull(error); } - + { SQLException error = null; try { @@ -573,12 +574,12 @@ public class PoolableCallableStatementTest extends TestCase { Assert.assertNotNull(error); } } - + public void test_setClob() throws Exception { - + stmt.setClob(1, (Reader) null); stmt.setClob("1", (Reader) null); - + { SQLException error = null; try { @@ -588,7 +589,7 @@ public class PoolableCallableStatementTest extends TestCase { } Assert.assertNotNull(error); } - + { SQLException error = null; try { @@ -599,12 +600,12 @@ public class PoolableCallableStatementTest extends TestCase { Assert.assertNotNull(error); } } - + public void test_setNCharacterStream() throws Exception { - + stmt.setNCharacterStream(1, (Reader) null); stmt.setNCharacterStream("1", (Reader) null); - + { SQLException error = null; try { @@ -614,7 +615,7 @@ public class PoolableCallableStatementTest extends TestCase { } Assert.assertNotNull(error); } - + { SQLException error = null; try { @@ -625,12 +626,12 @@ public class PoolableCallableStatementTest extends TestCase { Assert.assertNotNull(error); } } - + public void test_setCharacterStream() throws Exception { - + stmt.setCharacterStream(1, (Reader) null); stmt.setCharacterStream("1", (Reader) null); - + { SQLException error = null; try { @@ -640,7 +641,7 @@ public class PoolableCallableStatementTest extends TestCase { } Assert.assertNotNull(error); } - + { SQLException error = null; try { @@ -651,12 +652,12 @@ public class PoolableCallableStatementTest extends TestCase { Assert.assertNotNull(error); } } - + public void test_setBinaryStream() throws Exception { - + stmt.setBinaryStream(1, (InputStream) null); stmt.setBinaryStream("1", (InputStream) null); - + { SQLException error = null; try { @@ -666,7 +667,7 @@ public class PoolableCallableStatementTest extends TestCase { } Assert.assertNotNull(error); } - + { SQLException error = null; try { @@ -677,12 +678,12 @@ public class PoolableCallableStatementTest extends TestCase { Assert.assertNotNull(error); } } - + public void test_setBinaryStream_1() throws Exception { - + stmt.setBinaryStream(1, (InputStream) null, 1); stmt.setBinaryStream("1", (InputStream) null, 1); - + { SQLException error = null; try { @@ -692,7 +693,7 @@ public class PoolableCallableStatementTest extends TestCase { } Assert.assertNotNull(error); } - + { SQLException error = null; try { @@ -703,13 +704,12 @@ public class PoolableCallableStatementTest extends TestCase { Assert.assertNotNull(error); } } - - + public void test_setBinaryStream_2() throws Exception { - + stmt.setBinaryStream(1, (InputStream) null, 1L); stmt.setBinaryStream("1", (InputStream) null, 1L); - + { SQLException error = null; try { @@ -719,7 +719,7 @@ public class PoolableCallableStatementTest extends TestCase { } Assert.assertNotNull(error); } - + { SQLException error = null; try { @@ -730,12 +730,12 @@ public class PoolableCallableStatementTest extends TestCase { Assert.assertNotNull(error); } } - + public void test_setAsciiStream() throws Exception { - + stmt.setAsciiStream(1, (InputStream) null); stmt.setAsciiStream("1", (InputStream) null); - + { SQLException error = null; try { @@ -745,7 +745,7 @@ public class PoolableCallableStatementTest extends TestCase { } Assert.assertNotNull(error); } - + { SQLException error = null; try { @@ -756,4 +756,108 @@ public class PoolableCallableStatementTest extends TestCase { Assert.assertNotNull(error); } } + + public void test_setBlob() throws Exception { + + stmt.setBlob(1, (InputStream) null); + stmt.setBlob("1", (InputStream) null); + + { + SQLException error = null; + try { + stmt.setBlob("0", (InputStream) null); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + + { + SQLException error = null; + try { + stmt.setBlob(0, (InputStream) null); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + } + + public void test_setClob_1() throws Exception { + + stmt.setClob(1, (Clob) null); + stmt.setClob("1", (Clob) null); + + { + SQLException error = null; + try { + stmt.setClob("0", (Clob) null); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + + { + SQLException error = null; + try { + stmt.setClob(0, (Clob) null); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + } + + public void test_setClob_2() throws Exception { + + stmt.setClob(1, (Reader) null, 1L); + stmt.setClob("1", (Reader) null, 1L); + + { + SQLException error = null; + try { + stmt.setClob("0", (Reader) null, 1L); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + + { + SQLException error = null; + try { + stmt.setClob(0, (Reader) null, 1L); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + } + + public void test_setAsciiStream_1() throws Exception { + + stmt.setAsciiStream(1, (InputStream) null, 1L); + stmt.setAsciiStream("1", (InputStream) null, 1L); + + { + SQLException error = null; + try { + stmt.setAsciiStream("0", (InputStream) null, 1L); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + + { + SQLException error = null; + try { + stmt.setAsciiStream(0, (InputStream) null, 1L); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + } }