mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
add testcase
This commit is contained in:
@@ -546,7 +546,7 @@ public class BasicTypeTest extends TestCase {
|
||||
}
|
||||
try {
|
||||
cstmt.getBlob(12).free();
|
||||
} catch (SQLFeatureNotSupportedException ex) {
|
||||
} catch (SQLException ex) {
|
||||
|
||||
}
|
||||
try {
|
||||
|
||||
@@ -288,7 +288,7 @@ public class PrecallTest extends TestCase {
|
||||
|
||||
try {
|
||||
cstmt.getClob(1);
|
||||
} catch (SQLFeatureNotSupportedException ex) {
|
||||
} catch (SQLException ex) {
|
||||
|
||||
}
|
||||
try {
|
||||
|
||||
@@ -54,7 +54,7 @@ public class WrapImplTest extends TestCase {
|
||||
Assert.assertEquals(url, dataSource.getUrl());
|
||||
Assert.assertEquals("jdbc:derby:classpath:petstore-db", dataSource.getRawUrl());
|
||||
Assert.assertEquals(10, dataSource.getRawDriverMajorVersion());
|
||||
Assert.assertEquals(6, dataSource.getRawDriverMinorVersion());
|
||||
Assert.assertEquals(8, dataSource.getRawDriverMinorVersion());
|
||||
|
||||
Assert.assertFalse(connection.isWrapperFor(com.mysql.jdbc.Connection.class));
|
||||
Assert.assertTrue(connection.isWrapperFor(ConnectionProxyImpl.class));
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.alibaba.druid.bvt.spring;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.Statement;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.mock.MockConnection;
|
||||
import com.alibaba.druid.mock.MockPreparedStatement;
|
||||
import com.alibaba.druid.mock.MockStatement;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.spring.DruidJdbcExtractor;
|
||||
|
||||
public class DruidJdbcExtractorTest extends TestCase {
|
||||
|
||||
public void test_spring() throws Exception {
|
||||
DruidDataSource dataSource = new DruidDataSource();
|
||||
|
||||
try {
|
||||
DruidJdbcExtractor extractor = new DruidJdbcExtractor();
|
||||
|
||||
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();
|
||||
|
||||
conn.close();
|
||||
} finally {
|
||||
dataSource.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void test_spring_filter() throws Exception {
|
||||
DruidDataSource dataSource = new DruidDataSource();
|
||||
|
||||
try {
|
||||
DruidJdbcExtractor extractor = new DruidJdbcExtractor();
|
||||
|
||||
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();
|
||||
|
||||
conn.close();
|
||||
} finally {
|
||||
dataSource.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user