Skip to content

Commit

Permalink
net-sf-ucanaccess-fork: Unit test review
Browse files Browse the repository at this point in the history
  • Loading branch information
spannm committed Nov 27, 2023
1 parent a49f68d commit 0b9c948
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 36 deletions.
39 changes: 20 additions & 19 deletions src/test/java/net/ucanaccess/jdbc/ParametersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,16 @@ void testParameters(AccessVersion _accessVersion) throws SQLException {
dumpQueryResult("SELECT * FROM [queryWithParameters]");
dumpQueryResult("SELECT * FROM table(queryWithParameters(#1971-03-13#,'hi babe'))");
checkQuery("SELECT COUNT(*) FROM [ab\"\"\"xxx]", singleRec(3));

CallableStatement cs = ucanaccess.prepareCall("{call Insert_from_select_abxxx(?,?,?)}");
cs.setString(1, "2");
cs.setString(2, "YeaH!!!!");
cs.setString(3, "u can see it works");
cs.executeUpdate();

dumpQueryResult("SELECT * FROM [ab\"\"\"xxx]");
checkQuery("SELECT COUNT(*) FROM [ab\"\"\"xxx]", singleRec(6));
// metaData();
cs = ucanaccess.prepareCall("{call InsertWithFewParameters(?,?,?)}");

cs = ucanaccess.prepareCall("{call InsertWithFewParameters(?,?,?)}");
cs.setString(1, "555");
cs.setString(2, "YeaH!ddd!!!");
cs.setDate(3, new java.sql.Date(System.currentTimeMillis()));
Expand All @@ -55,6 +54,7 @@ void testParameters(AccessVersion _accessVersion) throws SQLException {
cs.setInt(2, 1);
cs.executeUpdate();
dumpQueryResult("SELECT * FROM Membership");

// same again, but with space after the procedure name
cs = ucanaccess.prepareCall("{call UpdateMembershipLevel (?,?)}");
cs.setString(1, "Platinum");
Expand All @@ -70,6 +70,7 @@ void testParameters(AccessVersion _accessVersion) throws SQLException {
checkQuery("SELECT @@IDENTITY", singleRec(2)); // verify that we can retrieve the AutoNumber ID
cs.executeUpdate();
checkQuery("SELECT @@IDENTITY", singleRec(3)); // and again, just to be sure

cs = ucanaccess.prepareCall("{call UpdateWhere(?,?)}");
cs.setString(1, "updated");
cs.setString(2, "3x");
Expand All @@ -82,22 +83,22 @@ void testParameters(AccessVersion _accessVersion) throws SQLException {
void testLocalTimeParameters(AccessVersion _accessVersion) throws SQLException {
init(_accessVersion);

final LocalTime desiredTime = LocalTime.of(12, 0, 1);
final String expectedText = "one second past noon";

ResultSet rs = null;

PreparedStatement ps = ucanaccess.prepareStatement("SELECT Description FROM TimeValues WHERE TimeValue=?");
ps.setObject(1, desiredTime);
rs = ps.executeQuery();
rs.next();
assertEquals(expectedText, rs.getString("Description"));

CallableStatement cs = ucanaccess.prepareCall("{CALL SelectTimeValueUsingParameter(?)}");
cs.setObject(1, desiredTime);
rs = cs.executeQuery();
rs.next();
assertEquals(expectedText, rs.getString("Description"));
LocalTime desiredTime = LocalTime.of(12, 0, 1);
String expectedText = "one second past noon";

try (PreparedStatement ps = ucanaccess.prepareStatement("SELECT Description FROM TimeValues WHERE TimeValue=?")) {
ps.setObject(1, desiredTime);
ResultSet rs1 = ps.executeQuery();
rs1.next();
assertEquals(expectedText, rs1.getString("Description"));
}

try (CallableStatement cs = ucanaccess.prepareCall("{CALL SelectTimeValueUsingParameter(?)}")) {
cs.setObject(1, desiredTime);
ResultSet rs2 = cs.executeQuery();
rs2.next();
assertEquals(expectedText, rs2.getString("Description"));
}
}

}
16 changes: 8 additions & 8 deletions src/test/java/net/ucanaccess/jdbc/PhysicalRollbackTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected String getAccessPath() {
@Override
protected void init(AccessVersion _accessVersion) throws SQLException {
super.init(_accessVersion);
executeStatements("CREATE TABLE T4 (id LONG, descr VARCHAR(400))");
executeStatements("CREATE TABLE t_pr (id LONG, descr VARCHAR(400))");
}

@ParameterizedTest(name = "[{index}] {0}")
Expand All @@ -37,22 +37,22 @@ void testCommit(AccessVersion _accessVersion) throws SQLException {
ucanaccess.setAutoCommit(false);

try (UcanaccessStatement st = ucanaccess.createStatement()) {
st.execute("INSERT INTO T4 (id, descr) VALUES(6666554, 'nel mezzo del cammin di nostra vita')");
st.execute("INSERT INTO T4 (id, descr) VALUES(77666554, 'nel mezzo del cammin di nostra vita')");
st.execute("UPDATE T4 SET ID=0 WHERE id=77666554");
st.execute("INSERT INTO t_pr (id, descr) VALUES(6666554, 'nel mezzo del cammin di nostra vita')");
st.execute("INSERT INTO t_pr (id, descr) VALUES(77666554, 'nel mezzo del cammin di nostra vita')");
st.execute("UPDATE t_pr SET ID=0 WHERE id=77666554");

st.execute("INSERT INTO T4 (id, descr) VALUES(4, 'nel mezzo del cammin di nostra vita')");
st.execute("INSERT INTO t_pr (id, descr) VALUES(4, 'nel mezzo del cammin di nostra vita')");

st.execute("DELETE FROM T4 WHERE id=4");
st.execute("DELETE FROM t_pr WHERE id=4");
}
assertThatThrownBy(ucanaccess::commit)
.isInstanceOf(SQLException.class)
.hasMessageContaining(getClass().getSimpleName());

ucanaccess = createUcanaccessConnection();
dumpQueryResult("SELECT * FROM T4");
dumpQueryResult("SELECT * FROM t_pr");

assertEquals(0, getVerifyCount("SELECT COUNT(*) FROM T4"));
assertEquals(0, getVerifyCount("SELECT COUNT(*) FROM t_pr"));
}

}
14 changes: 8 additions & 6 deletions src/test/java/net/ucanaccess/jdbc/PivotTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ protected String getAccessPath() {
@EnumSource(value = AccessVersion.class)
void testPivot(AccessVersion _accessVersion) throws SQLException {
init(_accessVersion);

try (UcanaccessStatement st = ucanaccess.createStatement()) {
dumpQueryResult("SELECT * FROM Table1_trim");
dumpQueryResult("SELECT * FROM q_trim");
executeStatements(st,
"INSERT INTO TABLE1(COD,VALUE,DT) VALUES ('O SOLE',1234.56,#2003-12-03# )",
"INSERT INTO TABLE1(COD,VALUE,DT) VALUES ('O SOLE MIO',134.46,#2003-12-03# )",
"INSERT INTO TABLE1(COD,VALUE,DT) VALUES ('STA IN FRUNTE A MEEE',1344.46,#2003-12-05# )");
"INSERT INTO t_pivot(c_cod, c_val, c_dt) VALUES('O SOLE', 1234.56, #2003-12-03#)",
"INSERT INTO t_pivot(c_cod, c_val, c_dt) VALUES('O SOLE MIO', 134.46, #2003-12-03#)",
"INSERT INTO t_pivot(c_cod, c_val, c_dt) VALUES('STA IN FRUNTE A MEEE', 1344.46, #2003-12-05#)");
initVerifyConnection();
dumpQueryResult("SELECT * FROM Table1_trim");
checkQuery("SELECT * FROM Table1_trim");

dumpQueryResult("SELECT * FROM q_trim");
checkQuery("SELECT * FROM q_trim");
}
}
}
6 changes: 3 additions & 3 deletions src/test/java/net/ucanaccess/jdbc/RegexTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class RegexTest extends UcanaccessBaseTest {
@Override
protected void init(AccessVersion _accessVersion) throws SQLException {
super.init(_accessVersion);
executeStatements("CREATE TABLE reg (id COUNTER, descr MEMO) ");
executeStatements("CREATE TABLE t_regex (id COUNTER, descr MEMO) ");
}

@ParameterizedTest(name = "[{index}] {0}")
Expand All @@ -41,12 +41,12 @@ void testRegex(AccessVersion _accessVersion) throws SQLException {
k++;
}
}
checkQuery("SELECT descr FROM reg ORDER BY id ASC", out);
checkQuery("SELECT descr FROM t_regex ORDER BY id ASC", out);
}
}

private String getStatement(CharSequence _s, CharSequence _dlm) {
return "INSERT INTO reg (descr) VALUES( " + _dlm + _s + _dlm + ")";
return "INSERT INTO t_regex (descr) VALUES( " + _dlm + _s + _dlm + ")";
}

}
Binary file modified src/test/resources/testdbs/pivot.mdb
Binary file not shown.

0 comments on commit 0b9c948

Please sign in to comment.