mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
完善mock和测试
git-svn-id: http://code.alibabatech.com/svn/druid/trunk@851 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
@@ -247,10 +247,10 @@ public class MockConnection implements Connection {
|
||||
}
|
||||
|
||||
MockStatement stmt = new MockStatement(this);
|
||||
|
||||
|
||||
stmt.setResultSetType(resultSetType);
|
||||
stmt.setResultSetConcurrency(resultSetConcurrency);
|
||||
|
||||
|
||||
return stmt;
|
||||
}
|
||||
|
||||
@@ -261,7 +261,12 @@ public class MockConnection implements Connection {
|
||||
throw new MockConnectionClosedException();
|
||||
}
|
||||
|
||||
return new MockPreparedStatement(this, sql);
|
||||
MockPreparedStatement stmt = new MockPreparedStatement(this, sql);
|
||||
|
||||
stmt.setResultSetType(resultSetType);
|
||||
stmt.setResultSetConcurrency(resultSetConcurrency);
|
||||
|
||||
return stmt;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -270,7 +275,12 @@ public class MockConnection implements Connection {
|
||||
throw new MockConnectionClosedException();
|
||||
}
|
||||
|
||||
return new MockCallableStatement(this, sql);
|
||||
MockCallableStatement stmt = new MockCallableStatement(this, sql);
|
||||
|
||||
stmt.setResultSetType(resultSetType);
|
||||
stmt.setResultSetConcurrency(resultSetConcurrency);
|
||||
|
||||
return stmt;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -330,7 +340,13 @@ public class MockConnection implements Connection {
|
||||
throw new MockConnectionClosedException();
|
||||
}
|
||||
|
||||
return new MockStatement(this);
|
||||
MockStatement stmt = new MockStatement(this);
|
||||
|
||||
stmt.setResultSetType(resultSetType);
|
||||
stmt.setResultSetConcurrency(resultSetConcurrency);
|
||||
stmt.setResultSetHoldability(resultSetHoldability);
|
||||
|
||||
return stmt;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -340,7 +356,13 @@ public class MockConnection implements Connection {
|
||||
throw new MockConnectionClosedException();
|
||||
}
|
||||
|
||||
return new MockPreparedStatement(this, sql);
|
||||
MockPreparedStatement stmt = new MockPreparedStatement(this, sql);
|
||||
|
||||
stmt.setResultSetType(resultSetType);
|
||||
stmt.setResultSetConcurrency(resultSetConcurrency);
|
||||
stmt.setResultSetHoldability(resultSetHoldability);
|
||||
|
||||
return stmt;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -350,7 +372,13 @@ public class MockConnection implements Connection {
|
||||
throw new MockConnectionClosedException();
|
||||
}
|
||||
|
||||
return new MockCallableStatement(this, sql);
|
||||
MockCallableStatement stmt = new MockCallableStatement(this, sql);
|
||||
|
||||
stmt.setResultSetType(resultSetType);
|
||||
stmt.setResultSetConcurrency(resultSetConcurrency);
|
||||
stmt.setResultSetHoldability(resultSetHoldability);
|
||||
|
||||
return stmt;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -41,6 +41,7 @@ public class MockStatement implements Statement {
|
||||
|
||||
private int resultSetType;
|
||||
private int resultSetConcurrency;
|
||||
private int resultSetHoldability;
|
||||
|
||||
public MockStatement(Connection connection){
|
||||
super();
|
||||
@@ -55,7 +56,7 @@ public class MockStatement implements Statement {
|
||||
if (closed) {
|
||||
throw new SQLException("stmt closed.");
|
||||
}
|
||||
|
||||
|
||||
return resultSetType;
|
||||
}
|
||||
|
||||
@@ -66,7 +67,6 @@ public class MockStatement implements Statement {
|
||||
public void setResultSetConcurrency(int resultSetConcurrency) {
|
||||
this.resultSetConcurrency = resultSetConcurrency;
|
||||
}
|
||||
|
||||
|
||||
public MockConnection getMockConnection() {
|
||||
return mockConnection;
|
||||
@@ -323,7 +323,6 @@ public class MockStatement implements Statement {
|
||||
return resultSetConcurrency;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void addBatch(String sql) throws SQLException {
|
||||
if (closed) {
|
||||
@@ -423,7 +422,11 @@ public class MockStatement implements Statement {
|
||||
if (closed) {
|
||||
throw new SQLException("stmt closed.");
|
||||
}
|
||||
return 0;
|
||||
return resultSetHoldability;
|
||||
}
|
||||
|
||||
public void setResultSetHoldability(int resultSetHoldability) {
|
||||
this.resultSetHoldability = resultSetHoldability;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,7 +18,7 @@ public class Bug_for_happyday517 extends TestCase {
|
||||
protected void setUp() throws Exception {
|
||||
dataSource = new DruidDataSource();
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
dataSource.setFilters("stat");
|
||||
dataSource.setFilters("stat,trace,log");
|
||||
|
||||
}
|
||||
|
||||
@@ -27,10 +27,77 @@ public class Bug_for_happyday517 extends TestCase {
|
||||
Assert.assertEquals(0, DruidDataSourceStatManager.getInstance().getDataSourceList().size());
|
||||
}
|
||||
|
||||
public void test_for_happyday517() throws Exception {
|
||||
public void test_for_happyday517_0() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
|
||||
|
||||
MockStatement mockStmt = stmt.unwrap(MockStatement.class);
|
||||
|
||||
Assert.assertEquals(ResultSet.TYPE_SCROLL_SENSITIVE, mockStmt.getResultSetType());
|
||||
Assert.assertEquals(ResultSet.CONCUR_UPDATABLE, mockStmt.getResultSetConcurrency());
|
||||
|
||||
stmt.close();
|
||||
|
||||
conn.close();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
public void test_for_happyday517_2() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
String sql = "select 1";
|
||||
Statement stmt = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
|
||||
|
||||
MockStatement mockStmt = stmt.unwrap(MockStatement.class);
|
||||
|
||||
Assert.assertEquals(ResultSet.TYPE_SCROLL_SENSITIVE, mockStmt.getResultSetType());
|
||||
Assert.assertEquals(ResultSet.CONCUR_UPDATABLE, mockStmt.getResultSetConcurrency());
|
||||
|
||||
stmt.close();
|
||||
|
||||
conn.close();
|
||||
}
|
||||
|
||||
public void test_for_happyday517_3() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
String sql = "select 1";
|
||||
Statement stmt = conn.prepareStatement(sql, 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();
|
||||
}
|
||||
|
||||
public void test_for_happyday517_4() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
|
||||
String sql = "select 1";
|
||||
Statement stmt = conn.prepareCall(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
|
||||
|
||||
MockStatement mockStmt = stmt.unwrap(MockStatement.class);
|
||||
|
||||
@@ -38,7 +105,25 @@ public class Bug_for_happyday517 extends TestCase {
|
||||
Assert.assertEquals(ResultSet.CONCUR_UPDATABLE, mockStmt.getResultSetConcurrency());
|
||||
|
||||
stmt.close();
|
||||
|
||||
|
||||
conn.close();
|
||||
}
|
||||
|
||||
public void test_for_happyday517_5() throws Exception {
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
String sql = "select 1";
|
||||
Statement stmt = conn.prepareCall(sql, 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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user