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@776 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.alibaba.druid.bvt.pool.basic;
|
||||
|
||||
import java.io.Reader;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
|
||||
@@ -28,10 +29,10 @@ public class PoolableCallableStatementTest extends TestCase {
|
||||
};
|
||||
|
||||
Assert.assertEquals(0, raw.getParameters().size());
|
||||
raw.registerOutParameter(1, Types.INTEGER);
|
||||
stmt.registerOutParameter(1, Types.INTEGER);
|
||||
Assert.assertEquals(1, raw.getParameters().size());
|
||||
|
||||
raw.registerOutParameter(2, Types.DECIMAL, 10);
|
||||
stmt.registerOutParameter(2, Types.DECIMAL, 10);
|
||||
Assert.assertEquals(2, raw.getParameters().size());
|
||||
}
|
||||
|
||||
@@ -241,7 +242,7 @@ public class PoolableCallableStatementTest extends TestCase {
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
@@ -403,7 +404,7 @@ public class PoolableCallableStatementTest extends TestCase {
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
@@ -415,4 +416,134 @@ public class PoolableCallableStatementTest extends TestCase {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void test_getNClob() throws Exception {
|
||||
|
||||
stmt.getNClob(1);
|
||||
stmt.getNClob("1");
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
stmt.getNClob("0");
|
||||
} catch (SQLException ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
stmt.getNClob("0");
|
||||
} catch (SQLException ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
public void test_getNString() throws Exception {
|
||||
|
||||
stmt.getNString(1);
|
||||
stmt.getNString("1");
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
stmt.getNString("0");
|
||||
} catch (SQLException ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
stmt.getNString("0");
|
||||
} catch (SQLException ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
public void test_getNCharacterStream() throws Exception {
|
||||
|
||||
stmt.getNCharacterStream(1);
|
||||
stmt.getNCharacterStream("1");
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
stmt.getNCharacterStream("0");
|
||||
} catch (SQLException ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
stmt.getNCharacterStream("0");
|
||||
} catch (SQLException ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
public void test_getCharacterStream() throws Exception {
|
||||
|
||||
stmt.getCharacterStream(1);
|
||||
stmt.getCharacterStream("1");
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
stmt.getCharacterStream("0");
|
||||
} catch (SQLException ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
stmt.getCharacterStream("0");
|
||||
} catch (SQLException ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
public void test_updateCharacterStream_2() throws Exception {
|
||||
|
||||
stmt.setCharacterStream(1, (Reader) null, 1L);
|
||||
stmt.setCharacterStream("1", (Reader) null, 1L);
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
stmt.setCharacterStream("0", (Reader) null, 1L);
|
||||
} catch (SQLException ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
stmt.setCharacterStream(0, (Reader) null, 1L);
|
||||
} catch (SQLException ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.alibaba.druid.bvt.pool.basic;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Date;
|
||||
import java.sql.SQLException;
|
||||
@@ -33,6 +34,11 @@ public class PoolablePreparedStatementTest extends TestCase {
|
||||
};
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
stmt.clearParameters();
|
||||
Assert.assertEquals(0, raw.getParameters().size());
|
||||
}
|
||||
|
||||
public void test_basic() throws Exception {
|
||||
Assert.assertEquals(raw, stmt.getRawPreparedStatement());
|
||||
Assert.assertEquals(raw, stmt.getRawStatement());
|
||||
@@ -101,12 +107,12 @@ public class PoolablePreparedStatementTest extends TestCase {
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void test_setInt() throws Exception {
|
||||
stmt.setInt(1, Integer.MAX_VALUE);
|
||||
|
||||
|
||||
Assert.assertEquals(new Integer(Integer.MAX_VALUE), raw.getParameters().get(0));
|
||||
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
@@ -117,12 +123,12 @@ public class PoolablePreparedStatementTest extends TestCase {
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void test_setLong() throws Exception {
|
||||
stmt.setLong(1, Long.MAX_VALUE);
|
||||
|
||||
|
||||
Assert.assertEquals(new Long(Long.MAX_VALUE), raw.getParameters().get(0));
|
||||
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
@@ -133,12 +139,12 @@ public class PoolablePreparedStatementTest extends TestCase {
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void test_setFloat() throws Exception {
|
||||
stmt.setFloat(1, Float.MAX_VALUE);
|
||||
|
||||
|
||||
Assert.assertEquals(new Float(Float.MAX_VALUE), raw.getParameters().get(0));
|
||||
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
@@ -149,12 +155,12 @@ public class PoolablePreparedStatementTest extends TestCase {
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void test_setDouble() throws Exception {
|
||||
stmt.setDouble(1, Double.MAX_VALUE);
|
||||
|
||||
|
||||
Assert.assertEquals(new Double(Double.MAX_VALUE), raw.getParameters().get(0));
|
||||
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
@@ -165,12 +171,12 @@ public class PoolablePreparedStatementTest extends TestCase {
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void test_setBigDecimal() throws Exception {
|
||||
stmt.setBigDecimal(1, BigDecimal.TEN);
|
||||
|
||||
|
||||
Assert.assertEquals(BigDecimal.TEN, raw.getParameters().get(0));
|
||||
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
@@ -181,12 +187,12 @@ public class PoolablePreparedStatementTest extends TestCase {
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void test_setString() throws Exception {
|
||||
stmt.setString(1, "中国");
|
||||
|
||||
|
||||
Assert.assertEquals("中国", raw.getParameters().get(0));
|
||||
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
@@ -197,13 +203,13 @@ public class PoolablePreparedStatementTest extends TestCase {
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void test_setBytes() throws Exception {
|
||||
byte[] bytes = "中国".getBytes();
|
||||
stmt.setBytes(1, bytes);
|
||||
|
||||
|
||||
Assert.assertEquals(true, Arrays.equals(bytes, (byte[]) raw.getParameters().get(0)));
|
||||
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
@@ -214,13 +220,13 @@ public class PoolablePreparedStatementTest extends TestCase {
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void test_setDate() throws Exception {
|
||||
Date value = new Date(System.currentTimeMillis());
|
||||
stmt.setDate(1, value);
|
||||
|
||||
|
||||
Assert.assertEquals(value, raw.getParameters().get(0));
|
||||
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
@@ -231,13 +237,13 @@ public class PoolablePreparedStatementTest extends TestCase {
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void test_setTimestamp() throws Exception {
|
||||
Timestamp value = new Timestamp(System.currentTimeMillis());
|
||||
stmt.setTimestamp(1, value);
|
||||
|
||||
|
||||
Assert.assertEquals(value, raw.getParameters().get(0));
|
||||
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
@@ -248,13 +254,13 @@ public class PoolablePreparedStatementTest extends TestCase {
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void test_setAsciiStream() throws Exception {
|
||||
InputStream value = null;
|
||||
stmt.setAsciiStream(1, value);
|
||||
|
||||
|
||||
Assert.assertEquals(value, raw.getParameters().get(0));
|
||||
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
@@ -265,14 +271,14 @@ public class PoolablePreparedStatementTest extends TestCase {
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public void test_setUnicodeStream() throws Exception {
|
||||
InputStream value = null;
|
||||
stmt.setUnicodeStream(1, value, 0);
|
||||
|
||||
|
||||
Assert.assertEquals(value, raw.getParameters().get(0));
|
||||
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
@@ -283,14 +289,14 @@ public class PoolablePreparedStatementTest extends TestCase {
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public void test_setBinaryStream() throws Exception {
|
||||
InputStream value = null;
|
||||
stmt.setBinaryStream(1, value, 0);
|
||||
|
||||
|
||||
Assert.assertEquals(value, raw.getParameters().get(0));
|
||||
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
@@ -301,4 +307,20 @@ public class PoolablePreparedStatementTest extends TestCase {
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void test_updateCharacterStream_2() throws Exception {
|
||||
|
||||
stmt.setCharacterStream(1, (Reader) null, 1L);
|
||||
|
||||
{
|
||||
SQLException error = null;
|
||||
try {
|
||||
stmt.setCharacterStream(0, (Reader) null, 1L);
|
||||
} catch (SQLException ex) {
|
||||
error = ex;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user