use of com.alibaba.druid.mock.MockResultSet in project druid by alibaba.
the class FilterChainTest_ResultSet_2 method setUp.
protected void setUp() throws Exception {
dataSource = new DruidDataSource();
ConnectionProxyImpl conn = new ConnectionProxyImpl(dataSource, null, new Properties(), 0);
MockCallableStatement mockStmt = new MockCallableStatement(null, "") {
@Override
public Object getObject(int parameterIndex) throws SQLException {
invokeCount++;
return new MockResultSet(null);
}
};
statement = new CallableStatementProxyImpl(conn, mockStmt, "", 1);
}
use of com.alibaba.druid.mock.MockResultSet in project druid by alibaba.
the class CallableStatmentTest method test_connect.
public void test_connect() throws Exception {
MockCallableStatement rawStmt = null;
MockResultSet rawRs = null;
{
Connection conn = dataSource.getConnection();
CallableStatement stmt = conn.prepareCall("select 1");
stmt.execute();
rawStmt = stmt.unwrap(MockCallableStatement.class);
ResultSet rs = (ResultSet) stmt.getObject(0);
rawRs = rs.unwrap(MockResultSet.class);
rs.next();
rs.close();
stmt.close();
Assert.assertFalse(rawStmt.isClosed());
Assert.assertTrue(rawRs.isClosed());
rawRs = rs.unwrap(MockResultSet.class);
Assert.assertNotNull(rawRs);
conn.close();
}
{
Connection conn = dataSource.getConnection();
CallableStatement stmt = conn.prepareCall("select 1");
stmt.execute();
Assert.assertSame(rawStmt, stmt.unwrap(MockCallableStatement.class));
Assert.assertFalse(rawStmt.isClosed());
stmt.getObject(0);
ResultSet rs = (ResultSet) stmt.getObject(0);
rs.next();
rs.close();
stmt.close();
conn.close();
}
}
use of com.alibaba.druid.mock.MockResultSet in project druid by alibaba.
the class DruidDataSourceTest6 method setUp.
protected void setUp() throws Exception {
returnEmptyCount.set(0);
dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setTestOnBorrow(true);
dataSource.setInitialSize(1);
dataSource.setValidationQuery("select 1");
dataSource.setValidationQueryTimeout(10);
dataSource.setQueryTimeout(100);
dataSource.setUserCallback(new NameCallback("xx") {
});
dataSource.setPasswordCallback(new DruidPasswordCallback() {
@Override
public char[] getPassword() {
return "xx".toCharArray();
}
});
dataSource.getProxyFilters().add(new FilterAdapter() {
public ResultSetProxy statement_executeQuery(FilterChain chain, StatementProxy statement, String sql) throws SQLException {
if (errorCount.get() > 0) {
errorCount.decrementAndGet();
throw new RuntimeException();
}
if (returnEmptyCount.get() > 0) {
returnEmptyCount.decrementAndGet();
return new ResultSetProxyImpl(statement, new MockResultSet(statement), 0, sql);
}
return chain.statement_executeQuery(statement, sql);
}
});
}
use of com.alibaba.druid.mock.MockResultSet in project druid by alibaba.
the class DruidPooledResultSetTest method testWrap.
public void testWrap() throws Exception {
String sql = "select ?";
Connection conn = dataSource.getConnection();
PreparedStatement stmt = conn.prepareStatement(sql);
stmt.setString(1, "xxx");
ResultSet rs = stmt.executeQuery();
ResultSet raw = rs.unwrap(ResultSet.class);
Assert.assertTrue(raw instanceof MockResultSet);
rs.close();
conn.close();
}
use of com.alibaba.druid.mock.MockResultSet in project druid by alibaba.
the class ResultSetTest method setUp.
protected void setUp() throws Exception {
stmt = new DruidPooledStatement(null, null) {
protected SQLException checkException(Throwable error) throws SQLException {
if (error instanceof SQLException) {
return (SQLException) error;
}
return new SQLException(error);
}
};
raw = new MockResultSet(null);
raw.getRows().add(new Object[] { null });
resultSet = new DruidPooledResultSet(stmt, raw);
}
Aggregations