Methods Summary |
---|
private void | assertAllFromTbl1(java.sql.Statement stmt, java.lang.String[] ones, short[] twos)Asserts that the expected values can be selected from the test table.
ResultSet rs = stmt.executeQuery("select * from tbl1");
int i = 0;
for (; rs.next(); i++) {
assertTrue(i < ones.length);
assertEquals(ones[i], rs.getString("one"));
assertEquals(twos[i], rs.getShort("two"));
}
assertTrue(i == ones.length);
|
private void | autoCommitInsertSelect()Adds some rows to the test table and asserts that the rows can be
retrieved again.
firstStmt.getConnection().setAutoCommit(true);
for (int i = 0; i < ones.length; i++) {
firstStmt.execute("insert into tbl1 values('" + ones[i] + "',"
+ twos[i] + ")");
}
assertAllFromTbl1(firstStmt, ones, twos);
|
protected abstract java.lang.String | getConnectionURL()
|
protected abstract java.lang.String | getDriverClassName()
|
protected abstract int | getTransactionIsolation()
|
protected void | setUp()Sets up a unit test, by creating two statements from two connections and
creating a test table.
Class.forName(getDriverClassName()).newInstance();
firstConnection = DriverManager.getConnection(getConnectionURL());
firstConnection.setTransactionIsolation(getTransactionIsolation());
secondConnection = DriverManager.getConnection(getConnectionURL());
secondConnection.setTransactionIsolation(getTransactionIsolation());
firstStmt = firstConnection.createStatement();
firstStmt.execute("create table tbl1(one varchar(10), two smallint)");
secondStmt = secondConnection.createStatement();
|
protected void | tearDown()Tears down a unit test, by setting the auto commit property of the first
connection back to true, dropping the test table and closing the two
connections.
firstStmt.close();
secondStmt.close();
firstConnection.setAutoCommit(true);
firstStmt = firstConnection.createStatement();
firstStmt.execute("drop table tbl1");
firstStmt.close();
firstConnection.close();
secondConnection.close();
|
public void | testAutoCommitInsertSelect()
autoCommitInsertSelect();
|
public void | testUpdateSelectCommitSelect()Tests the following sequence after successful insertion of some test
data:
- update data from connection one
- select data from connection two (-> should have the old values)
- commit data from connection one
- select data from connection two (-> should have the new values)
autoCommitInsertSelect();
firstStmt.getConnection().setAutoCommit(false);
updateOnes(firstStmt, ones_updated, twos);
assertAllFromTbl1(secondStmt, ones, twos);
firstStmt.getConnection().commit();
assertAllFromTbl1(secondStmt, ones_updated, twos);
|
public void | testUpdateSelectRollbackSelect()Tests the following sequence after successful insertion of some test
data:
- update data from connection one
- select data from connection two (-> should have the old values)
- rollback data from connection one
- select data from connection two (-> should still have the old values)
autoCommitInsertSelect();
firstStmt.getConnection().setAutoCommit(false);
updateOnes(firstStmt, ones_updated, twos);
assertAllFromTbl1(secondStmt, ones, twos);
firstStmt.getConnection().rollback();
assertAllFromTbl1(secondStmt, ones, twos);
|
private void | updateOnes(java.sql.Statement stmt, java.lang.String[] ones_updated, short[] twos)Updates the values in column 'one'
for (int i = 0; i < ones_updated.length; i++) {
stmt.execute("UPDATE tbl1 SET one = '" + ones_updated[i]
+ "' WHERE two = " + twos[i]);
}
|