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 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);
}
use of com.alibaba.druid.mock.MockResultSet in project druid by alibaba.
the class DruidLobHandlerTest method test_0.
public void test_0() throws Exception {
DruidLobHandler handler = new DruidLobHandler();
List<Object[]> rows = new ArrayList<Object[]>();
rows.add(new Object[] { null, new MockBlob(), new MockClob() });
MockResultSet rs = new MockResultSet(null, rows);
rs.next();
handler.getBlobAsBinaryStream(rs, 1);
handler.getBlobAsBinaryStream(rs, "1");
handler.getBlobAsBytes(rs, 1);
handler.getBlobAsBytes(rs, "1");
handler.getBlobAsBinaryStream(rs, 2);
handler.getBlobAsBinaryStream(rs, "2");
handler.getBlobAsBytes(rs, 2);
handler.getBlobAsBytes(rs, "2");
handler.getClobAsAsciiStream(rs, 1);
handler.getClobAsAsciiStream(rs, "1");
handler.getClobAsCharacterStream(rs, 1);
handler.getClobAsCharacterStream(rs, "1");
handler.getClobAsString(rs, 1);
handler.getClobAsString(rs, "1");
handler.getClobAsAsciiStream(rs, 3);
handler.getClobAsAsciiStream(rs, "3");
handler.getClobAsCharacterStream(rs, 3);
handler.getClobAsCharacterStream(rs, "3");
handler.getClobAsString(rs, 3);
handler.getClobAsString(rs, "3");
handler.getLobCreator();
}
use of com.alibaba.druid.mock.MockResultSet in project druid by alibaba.
the class FilterChainTest_Clob method setUp.
protected void setUp() throws Exception {
dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
ConnectionProxyImpl conn = new ConnectionProxyImpl(dataSource, null, new Properties(), 0);
statement = new StatementProxyImpl(conn, null, 1);
mockResultSet = new MockResultSet(null) {
public Object getObject(int columnIndex) throws SQLException {
invokeCount++;
return new MockClob();
}
};
}
use of com.alibaba.druid.mock.MockResultSet in project druid by alibaba.
the class MySqlMockExecuteHandlerImpl method executeQueryFromDual.
public ResultSet executeQueryFromDual(MockStatementBase statement, SQLSelectQueryBlock query) throws SQLException {
MockResultSet rs = statement.getConnection().getDriver().createMockResultSet(statement);
MockResultSetMetaData metaData = rs.getMockMetaData();
Object[] row = new Object[query.getSelectList().size()];
for (int i = 0, size = query.getSelectList().size(); i < size; ++i) {
ColumnMetaData column = new ColumnMetaData();
SQLSelectItem item = query.getSelectList().get(i);
SQLExpr expr = item.getExpr();
if (expr instanceof SQLIntegerExpr) {
row[i] = ((SQLNumericLiteralExpr) expr).getNumber();
column.setColumnType(Types.INTEGER);
} else if (expr instanceof SQLNumberExpr) {
row[i] = ((SQLNumericLiteralExpr) expr).getNumber();
column.setColumnType(Types.DECIMAL);
} else if (expr instanceof SQLCharExpr) {
row[i] = ((SQLCharExpr) expr).getText();
column.setColumnType(Types.VARCHAR);
} else if (expr instanceof SQLNCharExpr) {
row[i] = ((SQLNCharExpr) expr).getText();
column.setColumnType(Types.NVARCHAR);
} else if (expr instanceof SQLBooleanExpr) {
row[i] = ((SQLBooleanExpr) expr).getBooleanValue();
column.setColumnType(Types.NVARCHAR);
} else if (expr instanceof SQLNullExpr) {
row[i] = null;
} else if (expr instanceof SQLMethodInvokeExpr) {
SQLMethodInvokeExpr methodInvokeExpr = (SQLMethodInvokeExpr) expr;
if ("NOW".equalsIgnoreCase(methodInvokeExpr.getMethodName())) {
row[i] = new Timestamp(System.currentTimeMillis());
} else {
throw new SQLException("TODO");
}
} else if (expr instanceof SQLVariantRefExpr) {
SQLVariantRefExpr varExpr = (SQLVariantRefExpr) expr;
int varIndex = varExpr.getIndex();
if (statement instanceof MockPreparedStatement) {
MockPreparedStatement mockPstmt = (MockPreparedStatement) statement;
row[i] = mockPstmt.getParameters().get(varIndex);
} else {
row[i] = null;
}
} else {
row[i] = null;
}
metaData.getColumns().add(column);
}
rs.getRows().add(row);
return rs;
}
Aggregations