mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
add testcase
This commit is contained in:
@@ -972,6 +972,10 @@ public class FilterChainImpl implements FilterChain {
|
||||
|
||||
Object obj = resultSet.getResultSetRaw().getObject(columnIndex);
|
||||
|
||||
if (obj instanceof ResultSet) {
|
||||
return wrap(resultSet.getStatementProxy(), (ResultSet) obj);
|
||||
}
|
||||
|
||||
if (obj instanceof Clob) {
|
||||
return wrap(resultSet.getStatementProxy().getConnectionProxy(), (Clob) obj);
|
||||
}
|
||||
@@ -987,6 +991,10 @@ public class FilterChainImpl implements FilterChain {
|
||||
|
||||
Object obj = resultSet.getResultSetRaw().getObject(columnLabel);
|
||||
|
||||
if (obj instanceof ResultSet) {
|
||||
return wrap(resultSet.getStatementProxy(), (ResultSet) obj);
|
||||
}
|
||||
|
||||
if (obj instanceof Clob) {
|
||||
return wrap(resultSet.getStatementProxy().getConnectionProxy(), (Clob) obj);
|
||||
}
|
||||
@@ -1640,6 +1648,10 @@ public class FilterChainImpl implements FilterChain {
|
||||
|
||||
Object obj = resultSet.getResultSetRaw().getObject(columnIndex, map);
|
||||
|
||||
if (obj instanceof ResultSet) {
|
||||
return wrap(resultSet.getStatementProxy(), (ResultSet) obj);
|
||||
}
|
||||
|
||||
if (obj instanceof Clob) {
|
||||
return wrap(resultSet.getStatementProxy().getConnectionProxy(), (Clob) obj);
|
||||
}
|
||||
@@ -1691,9 +1703,13 @@ public class FilterChainImpl implements FilterChain {
|
||||
if (this.pos < filterSize) {
|
||||
return nextFilter().resultSet_getObject(this, resultSet, columnLabel, map);
|
||||
}
|
||||
|
||||
|
||||
Object obj = resultSet.getResultSetRaw().getObject(columnLabel, map);
|
||||
|
||||
if (obj instanceof ResultSet) {
|
||||
return wrap(resultSet.getStatementProxy(), (ResultSet) obj);
|
||||
}
|
||||
|
||||
if (obj instanceof Clob) {
|
||||
return wrap(resultSet.getStatementProxy().getConnectionProxy(), (Clob) obj);
|
||||
}
|
||||
@@ -3416,7 +3432,7 @@ public class FilterChainImpl implements FilterChain {
|
||||
if (obj instanceof ResultSet) {
|
||||
return wrap(statement, (ResultSet) obj);
|
||||
}
|
||||
|
||||
|
||||
if (obj instanceof Clob) {
|
||||
return wrap(statement.getConnectionProxy(), (Clob) obj);
|
||||
}
|
||||
@@ -3436,7 +3452,7 @@ public class FilterChainImpl implements FilterChain {
|
||||
if (obj instanceof ResultSet) {
|
||||
return wrap(statement, (ResultSet) obj);
|
||||
}
|
||||
|
||||
|
||||
if (obj instanceof Clob) {
|
||||
return wrap(statement.getConnectionProxy(), (Clob) obj);
|
||||
}
|
||||
@@ -4458,7 +4474,7 @@ public class FilterChainImpl implements FilterChain {
|
||||
if (clob == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
if (clob instanceof NClob) {
|
||||
return wrap(connection, (NClob) clob);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.alibaba.druid.bvt.filter;
|
||||
|
||||
import java.sql.Clob;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collections;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.filter.FilterChainImpl;
|
||||
import com.alibaba.druid.mock.MockResultSet;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.proxy.jdbc.ResultSetProxy;
|
||||
import com.alibaba.druid.proxy.jdbc.ResultSetProxyImpl;
|
||||
import com.alibaba.druid.proxy.jdbc.StatementProxy;
|
||||
import com.alibaba.druid.proxy.jdbc.StatementProxyImpl;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
public class FilterChainTest_ResultSet extends TestCase {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
private StatementProxy statement;
|
||||
private MockResultSet mockResultSet;
|
||||
|
||||
private int invokeCount = 0;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSource = new DruidDataSource();
|
||||
statement = new StatementProxyImpl(null, null, 1);
|
||||
|
||||
mockResultSet = new MockResultSet(null) {
|
||||
|
||||
public Object getObject(int columnIndex) throws SQLException {
|
||||
invokeCount++;
|
||||
return new MockResultSet(null);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
JdbcUtils.close(dataSource);
|
||||
|
||||
invokeCount = 0;
|
||||
}
|
||||
|
||||
public void test_resultSet_getObject() throws Exception {
|
||||
FilterChainImpl chain = new FilterChainImpl(dataSource);
|
||||
|
||||
ResultSet clob = (ResultSet) chain.resultSet_getObject(new ResultSetProxyImpl(statement, mockResultSet, 1, null), 1);
|
||||
|
||||
Assert.assertTrue(clob instanceof ResultSetProxy);
|
||||
Assert.assertEquals(1, invokeCount);
|
||||
}
|
||||
|
||||
public void test_resultSet_getObject_1() throws Exception {
|
||||
FilterChainImpl chain = new FilterChainImpl(dataSource);
|
||||
|
||||
ResultSet clob = (ResultSet) chain.resultSet_getObject(new ResultSetProxyImpl(statement, mockResultSet, 1, null), "1");
|
||||
|
||||
Assert.assertTrue(clob instanceof ResultSetProxy);
|
||||
Assert.assertEquals(1, invokeCount);
|
||||
}
|
||||
|
||||
public void test_resultSet_getObject_2() throws Exception {
|
||||
FilterChainImpl chain = new FilterChainImpl(dataSource);
|
||||
|
||||
ResultSet clob = (ResultSet) chain.resultSet_getObject(new ResultSetProxyImpl(statement, mockResultSet, 1, null), 1, Collections.<String, Class<?>>emptyMap());
|
||||
|
||||
Assert.assertTrue(clob instanceof ResultSetProxy);
|
||||
Assert.assertEquals(1, invokeCount);
|
||||
}
|
||||
|
||||
public void test_resultSet_getObject_3() throws Exception {
|
||||
FilterChainImpl chain = new FilterChainImpl(dataSource);
|
||||
|
||||
ResultSet clob = (ResultSet) chain.resultSet_getObject(new ResultSetProxyImpl(statement, mockResultSet, 1, null), "1", Collections.<String, Class<?>>emptyMap());
|
||||
|
||||
Assert.assertTrue(clob instanceof ResultSetProxy);
|
||||
Assert.assertEquals(1, invokeCount);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package com.alibaba.druid.bvt.filter;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collections;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.druid.filter.FilterChainImpl;
|
||||
import com.alibaba.druid.mock.MockCallableStatement;
|
||||
import com.alibaba.druid.mock.MockResultSet;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.proxy.jdbc.CallableStatementProxy;
|
||||
import com.alibaba.druid.proxy.jdbc.CallableStatementProxyImpl;
|
||||
import com.alibaba.druid.proxy.jdbc.ClobProxy;
|
||||
import com.alibaba.druid.proxy.jdbc.ResultSetProxy;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
public class FilterChainTest_ResultSet_2 extends TestCase {
|
||||
|
||||
private DruidDataSource dataSource;
|
||||
private CallableStatementProxy statement;
|
||||
|
||||
private int invokeCount = 0;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSource = new DruidDataSource();
|
||||
|
||||
MockCallableStatement mockStmt = new MockCallableStatement(null, "") {
|
||||
|
||||
@Override
|
||||
public Object getObject(int parameterIndex) throws SQLException {
|
||||
invokeCount++;
|
||||
return new MockResultSet(null);
|
||||
}
|
||||
};
|
||||
|
||||
statement = new CallableStatementProxyImpl(null, mockStmt, "", 1);
|
||||
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
JdbcUtils.close(dataSource);
|
||||
|
||||
invokeCount = 0;
|
||||
}
|
||||
|
||||
public void test_getObject() throws Exception {
|
||||
FilterChainImpl chain = new FilterChainImpl(dataSource);
|
||||
|
||||
ResultSet clob = (ResultSet) chain.callableStatement_getObject(statement, 1);
|
||||
|
||||
Assert.assertTrue(clob instanceof ResultSetProxy);
|
||||
Assert.assertEquals(1, invokeCount);
|
||||
}
|
||||
|
||||
public void test_getObject_1() throws Exception {
|
||||
FilterChainImpl chain = new FilterChainImpl(dataSource);
|
||||
|
||||
ResultSet clob = (ResultSet) chain.callableStatement_getObject(statement, "1");
|
||||
|
||||
Assert.assertTrue(clob instanceof ResultSetProxy);
|
||||
Assert.assertEquals(1, invokeCount);
|
||||
}
|
||||
|
||||
public void test_getObject_2() throws Exception {
|
||||
FilterChainImpl chain = new FilterChainImpl(dataSource);
|
||||
|
||||
ResultSet clob = (ResultSet) chain.callableStatement_getObject(statement, 1, Collections.<String, Class<?>> emptyMap());
|
||||
|
||||
Assert.assertTrue(clob instanceof ResultSetProxy);
|
||||
Assert.assertEquals(1, invokeCount);
|
||||
}
|
||||
|
||||
public void test_getObject_3() throws Exception {
|
||||
FilterChainImpl chain = new FilterChainImpl(dataSource);
|
||||
|
||||
ResultSet clob = (ResultSet) chain.callableStatement_getObject(statement, "1", Collections.<String, Class<?>> emptyMap());
|
||||
|
||||
Assert.assertTrue(clob instanceof ResultSetProxy);
|
||||
Assert.assertEquals(1, invokeCount);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user