use of com.alibaba.druid.mock.MockConnection in project druid by alibaba.
the class MSSQLValidConnectionCheckerTest method test_closed.
public void test_closed() throws Exception {
MSSQLValidConnectionChecker checker = new MSSQLValidConnectionChecker();
MockConnection conn = new MockConnection();
conn.close();
Assert.assertFalse(checker.isValidConnection(conn, "select 1", 10));
}
use of com.alibaba.druid.mock.MockConnection in project druid by alibaba.
the class MSSQLValidConnectionCheckerTest method test_error.
public void test_error() throws Exception {
MSSQLValidConnectionChecker checker = new MSSQLValidConnectionChecker();
MockConnection conn = new MockConnection();
conn.setError(new SQLException());
SQLException error = null;
try {
checker.isValidConnection(conn, "select 1", 10);
} catch (SQLException ex) {
error = ex;
}
Assert.assertNotNull(error);
Assert.assertSame(error, conn.getError());
}
use of com.alibaba.druid.mock.MockConnection 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.MockConnection 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.MockConnection 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();
}
}
Aggregations