From 62b2c1dc0d9488557da097d36b1168aa34b1b558 Mon Sep 17 00:00:00 2001 From: wenshao Date: Thu, 15 Sep 2011 21:59:43 +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@771 b9813039-fb51-4c41-a8b9-e21c2acb5095 --- .../druid/mock/MockCallableStatement.java | 60 +-- .../PoolableCallableStatementTest.java | 354 +++++++++++------- 2 files changed, 239 insertions(+), 175 deletions(-) rename src/test/java/com/alibaba/druid/bvt/pool/{ => basic}/PoolableCallableStatementTest.java (78%) diff --git a/src/main/java/com/alibaba/druid/mock/MockCallableStatement.java b/src/main/java/com/alibaba/druid/mock/MockCallableStatement.java index 7d9f50d52b..aaa79e9bd0 100644 --- a/src/main/java/com/alibaba/druid/mock/MockCallableStatement.java +++ b/src/main/java/com/alibaba/druid/mock/MockCallableStatement.java @@ -248,50 +248,42 @@ public class MockCallableStatement extends MockPreparedStatement implements Call @Override public Object getObject(int parameterIndex, Map> map) throws SQLException { - - return null; + return getObject(parameterIndex); } @Override public Ref getRef(int parameterIndex) throws SQLException { - - return null; + return (Ref) getObject(parameterIndex); } @Override public Blob getBlob(int parameterIndex) throws SQLException { - - return null; + return (Blob) getObject(parameterIndex); } @Override public Clob getClob(int parameterIndex) throws SQLException { - - return null; + return (Clob) getObject(parameterIndex); } @Override public Array getArray(int parameterIndex) throws SQLException { - - return null; + return (Array) getObject(parameterIndex); } @Override public Date getDate(int parameterIndex, Calendar cal) throws SQLException { - - return null; + return (Date) getObject(parameterIndex); } @Override public Time getTime(int parameterIndex, Calendar cal) throws SQLException { - - return null; + return (Time) getObject(parameterIndex); } @Override public Timestamp getTimestamp(int parameterIndex, Calendar cal) throws SQLException { - - return null; + return (Timestamp) getObject(parameterIndex); } @Override @@ -447,8 +439,7 @@ public class MockCallableStatement extends MockPreparedStatement implements Call @Override public Object getObject(String parameterName) throws SQLException { - - return null; + return getObject(Integer.parseInt(parameterName)); } @Override @@ -458,68 +449,57 @@ public class MockCallableStatement extends MockPreparedStatement implements Call @Override public Object getObject(String parameterName, Map> map) throws SQLException { - - return null; + return getObject(parameterName); } @Override public Ref getRef(String parameterName) throws SQLException { - - return null; + return (Ref) getObject(parameterName); } @Override public Blob getBlob(String parameterName) throws SQLException { - - return null; + return (Blob) getObject(parameterName); } @Override public Clob getClob(String parameterName) throws SQLException { - - return null; + return (Clob) getObject(parameterName); } @Override public Array getArray(String parameterName) throws SQLException { - - return null; + return (Array) getObject(parameterName); } @Override public Date getDate(String parameterName, Calendar cal) throws SQLException { - - return null; + return (Date) getObject(parameterName); } @Override public Time getTime(String parameterName, Calendar cal) throws SQLException { - - return null; + return (Time) getObject(parameterName); } @Override public Timestamp getTimestamp(String parameterName, Calendar cal) throws SQLException { - - return null; + return (Timestamp) getObject(parameterName); } @Override public URL getURL(String parameterName) throws SQLException { - - return null; + return (URL) getObject(parameterName); } @Override public RowId getRowId(int parameterIndex) throws SQLException { - - return null; + return (RowId) getObject(parameterIndex); } @Override public RowId getRowId(String parameterName) throws SQLException { - - return null; + return (RowId) getObject(parameterName); } @Override diff --git a/src/test/java/com/alibaba/druid/bvt/pool/PoolableCallableStatementTest.java b/src/test/java/com/alibaba/druid/bvt/pool/basic/PoolableCallableStatementTest.java similarity index 78% rename from src/test/java/com/alibaba/druid/bvt/pool/PoolableCallableStatementTest.java rename to src/test/java/com/alibaba/druid/bvt/pool/basic/PoolableCallableStatementTest.java index bba984fe08..ef4d7fb39f 100644 --- a/src/test/java/com/alibaba/druid/bvt/pool/PoolableCallableStatementTest.java +++ b/src/test/java/com/alibaba/druid/bvt/pool/basic/PoolableCallableStatementTest.java @@ -1,4 +1,4 @@ -package com.alibaba.druid.bvt.pool; +package com.alibaba.druid.bvt.pool.basic; import java.sql.SQLException; import java.sql.Types; @@ -11,9 +11,13 @@ import com.alibaba.druid.pool.PoolableCallableStatement; public class PoolableCallableStatementTest extends TestCase { - public void test_callableStmt() throws Exception { - MockCallableStatement raw = new MockCallableStatement(null, null); - PoolableCallableStatement stmt = new PoolableCallableStatement(null, raw, null) { + protected MockCallableStatement raw; + protected PoolableCallableStatement stmt; + + protected void setUp() throws Exception { + raw = new MockCallableStatement(null, null); + stmt = new PoolableCallableStatement(null, raw, null) { + protected SQLException checkException(Throwable error) throws SQLException { if (error instanceof SQLException) { return (SQLException) error; @@ -22,11 +26,21 @@ public class PoolableCallableStatementTest extends TestCase { return new SQLException(error); } }; - + Assert.assertEquals(0, raw.getParameters().size()); raw.registerOutParameter(1, Types.INTEGER); Assert.assertEquals(1, raw.getParameters().size()); + raw.registerOutParameter(2, Types.DECIMAL, 10); + Assert.assertEquals(2, raw.getParameters().size()); + } + + public void test_basic() throws Exception { + Assert.assertEquals(raw, stmt.getRawPreparedStatement()); + } + + public void test_callableStmt() throws Exception { + Assert.assertTrue(stmt.wasNull() == false); stmt.getString(1); Assert.assertTrue(stmt.wasNull()); @@ -43,6 +57,9 @@ public class PoolableCallableStatementTest extends TestCase { stmt.getDate(1); stmt.getTime(1); stmt.getTimestamp(1); + stmt.getObject(1); + stmt.getRef(1); + stmt.getBlob(1); stmt.getString("1"); stmt.getBoolean("1"); @@ -57,137 +74,12 @@ public class PoolableCallableStatementTest extends TestCase { stmt.getDate("1"); stmt.getTime("1"); stmt.getTimestamp("1"); + stmt.getObject("1"); + stmt.getRef("1"); + stmt.getBlob("1"); + } - { - SQLException error = null; - try { - stmt.getString(0); - } catch (SQLException ex) { - error = ex; - } - Assert.assertNotNull(error); - } - - { - SQLException error = null; - try { - stmt.getBoolean(0); - } catch (SQLException ex) { - error = ex; - } - Assert.assertNotNull(error); - } - - { - SQLException error = null; - try { - stmt.getByte(0); - } catch (SQLException ex) { - error = ex; - } - Assert.assertNotNull(error); - } - - { - SQLException error = null; - try { - stmt.getShort(0); - } catch (SQLException ex) { - error = ex; - } - Assert.assertNotNull(error); - } - - { - SQLException error = null; - try { - stmt.getInt(0); - } catch (SQLException ex) { - error = ex; - } - Assert.assertNotNull(error); - } - - { - SQLException error = null; - try { - stmt.getLong(0); - } catch (SQLException ex) { - error = ex; - } - Assert.assertNotNull(error); - } - - { - SQLException error = null; - try { - stmt.getFloat(0); - } catch (SQLException ex) { - error = ex; - } - Assert.assertNotNull(error); - } - - { - SQLException error = null; - try { - stmt.getDouble(0); - } catch (SQLException ex) { - error = ex; - } - Assert.assertNotNull(error); - } - - { - SQLException error = null; - try { - stmt.getBigDecimal(0); - } catch (SQLException ex) { - error = ex; - } - Assert.assertNotNull(error); - } - - { - SQLException error = null; - try { - stmt.getBigDecimal(0, 1); - } catch (SQLException ex) { - error = ex; - } - Assert.assertNotNull(error); - } - - { - SQLException error = null; - try { - stmt.getBytes(0); - } catch (SQLException ex) { - error = ex; - } - Assert.assertNotNull(error); - } - - { - SQLException error = null; - try { - stmt.getDate(0); - } catch (SQLException ex) { - error = ex; - } - Assert.assertNotNull(error); - } - - { - SQLException error = null; - try { - stmt.getTime(0); - } catch (SQLException ex) { - error = ex; - } - Assert.assertNotNull(error); - } - + public void test_getByLabel_error() { { SQLException error = null; try { @@ -330,5 +222,197 @@ public class PoolableCallableStatementTest extends TestCase { Assert.assertNotNull(error); } + { + SQLException error = null; + try { + stmt.getObject("0"); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + + { + SQLException error = null; + try { + stmt.getRef("0"); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + + { + SQLException error = null; + try { + stmt.getBlob("0"); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + } + + public void test_get_error() { + { + SQLException error = null; + try { + stmt.getString(0); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + + { + SQLException error = null; + try { + stmt.getBoolean(0); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + + { + SQLException error = null; + try { + stmt.getByte(0); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + + { + SQLException error = null; + try { + stmt.getShort(0); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + + { + SQLException error = null; + try { + stmt.getInt(0); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + + { + SQLException error = null; + try { + stmt.getLong(0); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + + { + SQLException error = null; + try { + stmt.getFloat(0); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + + { + SQLException error = null; + try { + stmt.getDouble(0); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + + { + SQLException error = null; + try { + stmt.getBigDecimal(0); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + + { + SQLException error = null; + try { + stmt.getBigDecimal(0, 1); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + + { + SQLException error = null; + try { + stmt.getBytes(0); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + + { + SQLException error = null; + try { + stmt.getDate(0); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + + { + SQLException error = null; + try { + stmt.getTime(0); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + + { + SQLException error = null; + try { + stmt.getObject(0); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + + { + SQLException error = null; + try { + stmt.getRef(0); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + + { + SQLException error = null; + try { + stmt.getBlob(0); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + } }