use of com.alibaba.druid.mock.MockStatement in project druid by alibaba.
the class PoolableStatementTest method setUp.
protected void setUp() throws Exception {
raw = new MockStatement(null);
stmt = new DruidPooledStatement(null, raw) {
protected SQLException checkException(Throwable error) throws SQLException {
if (error instanceof SQLException) {
return (SQLException) error;
}
return new SQLException(error);
}
};
}
use of com.alibaba.druid.mock.MockStatement 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.MockStatement in project druid by alibaba.
the class DruidJdbcExtractorTest method test_spring.
public void test_spring() throws Exception {
DruidDataSource dataSource = new DruidDataSource();
try {
DruidNativeJdbcExtractor extractor = new DruidNativeJdbcExtractor();
dataSource.setUrl("jdbc:mock:xx1");
Connection conn = dataSource.getConnection();
Assert.assertEquals(true, extractor.getNativeConnection(conn) instanceof MockConnection);
Statement stmt = conn.createStatement();
Assert.assertEquals(true, extractor.getNativeConnectionFromStatement(stmt) instanceof MockConnection);
Assert.assertEquals(true, extractor.getNativeStatement(stmt) instanceof MockStatement);
stmt.close();
PreparedStatement preStmt = conn.prepareStatement("select 1");
Assert.assertEquals(true, extractor.getNativeConnectionFromStatement(preStmt) instanceof MockConnection);
Assert.assertEquals(true, extractor.getNativeStatement(preStmt) instanceof MockPreparedStatement);
Assert.assertEquals(true, extractor.getNativePreparedStatement(preStmt) instanceof MockPreparedStatement);
preStmt.close();
PreparedStatement callStmt = conn.prepareCall("select 1");
Assert.assertEquals(true, extractor.getNativeConnectionFromStatement(callStmt) instanceof MockConnection);
Assert.assertEquals(true, extractor.getNativeStatement(callStmt) instanceof MockCallableStatement);
Assert.assertEquals(true, extractor.getNativePreparedStatement(callStmt) instanceof MockCallableStatement);
callStmt.close();
conn.close();
} finally {
dataSource.close();
}
}
use of com.alibaba.druid.mock.MockStatement in project druid by alibaba.
the class DruidJdbcExtractorTest method test_spring_filter.
public void test_spring_filter() throws Exception {
DruidDataSource dataSource = new DruidDataSource();
try {
DruidNativeJdbcExtractor extractor = new DruidNativeJdbcExtractor();
dataSource.setUrl("jdbc:mock:xx1");
dataSource.setFilters("stat");
Connection conn = dataSource.getConnection();
Assert.assertEquals(true, extractor.getNativeConnection(conn) instanceof MockConnection);
Statement stmt = conn.createStatement();
Assert.assertEquals(true, extractor.getNativeConnectionFromStatement(stmt) instanceof MockConnection);
Assert.assertEquals(true, extractor.getNativeStatement(stmt) instanceof MockStatement);
stmt.close();
PreparedStatement preStmt = conn.prepareStatement("select 1");
Assert.assertEquals(true, extractor.getNativeConnectionFromStatement(preStmt) instanceof MockConnection);
Assert.assertEquals(true, extractor.getNativeStatement(preStmt) instanceof MockPreparedStatement);
Assert.assertEquals(true, extractor.getNativePreparedStatement(preStmt) instanceof MockPreparedStatement);
preStmt.close();
PreparedStatement callStmt = conn.prepareCall("select 1");
Assert.assertEquals(true, extractor.getNativeConnectionFromStatement(callStmt) instanceof MockConnection);
Assert.assertEquals(true, extractor.getNativeStatement(callStmt) instanceof MockCallableStatement);
Assert.assertEquals(true, extractor.getNativePreparedStatement(callStmt) instanceof MockCallableStatement);
callStmt.close();
conn.close();
} finally {
dataSource.close();
}
}
use of com.alibaba.druid.mock.MockStatement in project druid by alibaba.
the class Bug_for_happyday517 method test_for_happyday517_1.
public void test_for_happyday517_1() throws Exception {
Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, ResultSet.CLOSE_CURSORS_AT_COMMIT);
MockStatement mockStmt = stmt.unwrap(MockStatement.class);
Assert.assertEquals(ResultSet.TYPE_SCROLL_SENSITIVE, mockStmt.getResultSetType());
Assert.assertEquals(ResultSet.CONCUR_UPDATABLE, mockStmt.getResultSetConcurrency());
Assert.assertEquals(ResultSet.CLOSE_CURSORS_AT_COMMIT, mockStmt.getResultSetHoldability());
stmt.close();
conn.close();
}
Aggregations