mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
add testcase
This commit is contained in:
@@ -21,6 +21,8 @@ public class DruidPooledCallableStatementTest extends TestCase {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
private boolean throwError = true;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSource = new DruidDataSource();
|
||||
|
||||
@@ -32,7 +34,11 @@ public class DruidPooledCallableStatementTest extends TestCase {
|
||||
|
||||
public boolean callableStatement_wasNull(FilterChain chain, CallableStatementProxy statement)
|
||||
throws SQLException {
|
||||
if (throwError) {
|
||||
throw new SQLException();
|
||||
} else {
|
||||
return chain.callableStatement_wasNull(statement);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -41,11 +47,27 @@ public class DruidPooledCallableStatementTest extends TestCase {
|
||||
dataSource.close();
|
||||
}
|
||||
|
||||
public void test_wasNull() throws Exception {
|
||||
public void test_wasNull_noerror() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
CallableStatement stmt = conn.prepareCall("select 1");
|
||||
stmt.execute();
|
||||
|
||||
throwError = false;
|
||||
stmt.wasNull();
|
||||
|
||||
Assert.assertEquals(0, dataSource.getErrorCount());
|
||||
|
||||
stmt.close();
|
||||
conn.close();
|
||||
|
||||
Assert.assertEquals(1, dataSource.getPoolingCount());
|
||||
}
|
||||
|
||||
public void test_wasNull_error() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
CallableStatement stmt = conn.prepareCall("select 1");
|
||||
stmt.execute();
|
||||
|
||||
Assert.assertEquals(0, dataSource.getErrorCount());
|
||||
|
||||
Exception error = null;
|
||||
@@ -63,14 +85,14 @@ public class DruidPooledCallableStatementTest extends TestCase {
|
||||
|
||||
Assert.assertEquals(1, dataSource.getPoolingCount());
|
||||
}
|
||||
|
||||
|
||||
public void test_getObject() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
DruidPooledCallableStatement stmt = (DruidPooledCallableStatement) conn.prepareCall("select 1");
|
||||
stmt.execute();
|
||||
|
||||
Assert.assertEquals(0, dataSource.getErrorCount());
|
||||
|
||||
|
||||
Exception error = null;
|
||||
try {
|
||||
stmt.getObject(1, String.class);
|
||||
@@ -78,22 +100,22 @@ public class DruidPooledCallableStatementTest extends TestCase {
|
||||
error = e;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
|
||||
|
||||
Assert.assertEquals(0, dataSource.getErrorCount());
|
||||
|
||||
|
||||
stmt.close();
|
||||
conn.close();
|
||||
|
||||
|
||||
Assert.assertEquals(1, dataSource.getPoolingCount());
|
||||
}
|
||||
|
||||
|
||||
public void test_getObject_1() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
DruidPooledCallableStatement stmt = (DruidPooledCallableStatement) conn.prepareCall("select 1");
|
||||
stmt.execute();
|
||||
|
||||
|
||||
Assert.assertEquals(0, dataSource.getErrorCount());
|
||||
|
||||
|
||||
Exception error = null;
|
||||
try {
|
||||
stmt.getObject("1", String.class);
|
||||
@@ -101,48 +123,48 @@ public class DruidPooledCallableStatementTest extends TestCase {
|
||||
error = e;
|
||||
}
|
||||
Assert.assertNotNull(error);
|
||||
|
||||
|
||||
Assert.assertEquals(0, dataSource.getErrorCount());
|
||||
|
||||
|
||||
stmt.close();
|
||||
conn.close();
|
||||
|
||||
|
||||
Assert.assertEquals(1, dataSource.getPoolingCount());
|
||||
}
|
||||
|
||||
|
||||
public void test_wrap() throws Exception {
|
||||
|
||||
|
||||
Connection conn = dataSource.getConnection();
|
||||
CallableStatement stmt = conn.prepareCall("select 1");
|
||||
|
||||
|
||||
Assert.assertNotNull(stmt.unwrap(CallableStatement.class));
|
||||
Assert.assertEquals(MockCallableStatement.class, stmt.unwrap(CallableStatement.class).getClass());
|
||||
|
||||
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
|
||||
public void test_wrap_1() throws Exception {
|
||||
|
||||
|
||||
Connection conn = dataSource.getConnection();
|
||||
CallableStatement stmt = conn.prepareCall("select 1");
|
||||
|
||||
|
||||
Assert.assertNotNull(stmt.unwrap(PreparedStatement.class));
|
||||
Assert.assertEquals(MockCallableStatement.class, stmt.unwrap(CallableStatement.class).getClass());
|
||||
|
||||
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
|
||||
public void test_wrap_2() throws Exception {
|
||||
dataSource.getProxyFilters().clear();
|
||||
|
||||
|
||||
Connection conn = dataSource.getConnection();
|
||||
CallableStatement stmt = conn.prepareCall("select 1");
|
||||
|
||||
|
||||
Assert.assertNotNull(stmt.unwrap(PreparedStatement.class));
|
||||
Assert.assertEquals(MockCallableStatement.class, stmt.unwrap(CallableStatement.class).getClass());
|
||||
|
||||
|
||||
stmt.close();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user