mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
完善mock和测试
git-svn-id: http://code.alibabatech.com/svn/druid/trunk@771 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
+219
-135
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user