use of com.alibaba.druid.mock.MockResultSet in project druid by alibaba.
the class JdbcUtilsTest method test_print.
public void test_print() throws Exception {
final AtomicInteger nextCount = new AtomicInteger(2);
final MockResultSetMetaData rsMeta = new MockResultSetMetaData() {
private int[] types = new int[] { Types.DATE, Types.BIT, Types.BOOLEAN, Types.TINYINT, Types.SMALLINT, Types.INTEGER, Types.CLOB, Types.LONGVARCHAR, Types.OTHER, Types.VARCHAR, Types.CHAR, Types.NVARCHAR, Types.NCHAR };
@Override
public int getColumnCount() throws SQLException {
return types.length;
}
@Override
public int getColumnType(int column) throws SQLException {
return types[column - 1];
}
@Override
public String getColumnName(int column) throws SQLException {
return "C" + column;
}
};
MockResultSet rs = new MockResultSet(null) {
@Override
public boolean next() throws SQLException {
return nextCount.getAndDecrement() > 0;
}
@Override
public ResultSetMetaData getMetaData() throws SQLException {
return rsMeta;
}
@Override
public java.sql.Date getDate(int columnIndex) throws SQLException {
return new java.sql.Date(System.currentTimeMillis());
}
@Override
public boolean wasNull() throws SQLException {
if (nextCount.get() == 1) {
return true;
}
return false;
}
public Object getObject(int columnIndex) throws SQLException {
return null;
}
};
JdbcUtils.printResultSet(rs);
}
use of com.alibaba.druid.mock.MockResultSet in project druid by alibaba.
the class JdbcUtilsTest method test_close.
public void test_close() throws Exception {
JdbcUtils.close((Connection) null);
JdbcUtils.close((Statement) null);
JdbcUtils.close((ResultSet) null);
JdbcUtils.close(new MockConnection() {
@Override
public void close() throws SQLException {
throw new SQLException();
}
});
JdbcUtils.close(new MockStatement(null) {
@Override
public void close() throws SQLException {
throw new SQLException();
}
});
JdbcUtils.close(new MockResultSet(null) {
@Override
public void close() throws SQLException {
throw new SQLException();
}
});
JdbcUtils.close(new Closeable() {
@Override
public void close() throws IOException {
throw new IOException();
}
});
JdbcUtils.close(new Closeable() {
@Override
public void close() throws IOException {
}
});
JdbcUtils.close((Closeable) null);
new JdbcUtils();
}
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 MySqlMockExecuteHandlerImpl method showStatus.
public ResultSet showStatus(MockStatementBase statement) throws SQLException {
MockResultSet rs = new MockResultSet(statement);
MockResultSetMetaData metaData = rs.getMockMetaData();
Object[] row = new Object[] { "on" };
ColumnMetaData column = new ColumnMetaData();
column.setColumnType(Types.NVARCHAR);
metaData.getColumns().add(column);
rs.getRows().add(row);
return rs;
}
use of com.alibaba.druid.mock.MockResultSet in project druid by alibaba.
the class ResultSetTest2 method test_closeError.
public void test_closeError() throws Exception {
MockResultSet mock = new MockResultSet(null) {
public void close() throws SQLException {
throw new SQLException();
}
};
DruidPooledResultSet rs = new DruidPooledResultSet(stmt, mock);
SQLException error = null;
try {
rs.close();
} catch (SQLException ex) {
error = ex;
}
Assert.assertNotNull(error);
}
Aggregations