Skip to content

Commit

Permalink
net-sf-ucanaccess-fork: Improvements to unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
spannm committed Sep 22, 2023
1 parent 0759441 commit c539f3d
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 40 deletions.
23 changes: 11 additions & 12 deletions src/test/java/net/ucanaccess/test/integration/MetaDataTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,35 @@ protected String getAccessPath() {
@Override
protected void init(AccessVersion _accessVersion) throws SQLException {
super.init(_accessVersion);
executeStatements("CREATE TABLE AAAn ( baaaa TEXT(3) PRIMARY KEY,A INTEGER , C TEXT(4)) ");
executeStatements("CREATE TABLE t_metadata ( baaaa TEXT(3) PRIMARY KEY, A INTEGER, C TEXT(4))");
}

@AfterEach
void afterEachTest() throws SQLException {
dropTable("AAAn");
dropTable("t_metadata");
}

void createSimple(String a, Object[][] ver) throws SQLException, IOException {
try (Statement st = ucanaccess.createStatement()) {
st.execute("INSERT INTO AAAn VALUES ('33A',11,'" + a + "' )");
st.execute("INSERT INTO AAAn VALUES ('33B',111,'" + a + "' )");
checkQuery("SELECT * FROM AAAn", ver);
st.execute("INSERT INTO t_metadata VALUES ('33A', 11, '" + a + "' )");
st.execute("INSERT INTO t_metadata VALUES ('33B', 111, '" + a + "' )");
}
checkQuery("SELECT * FROM t_metadata", ver);
}

@ParameterizedTest(name = "[{index}] {0}")
@MethodSource("net.ucanaccess.test.util.AccessVersion#getDefaultAccessVersion()")
void testDrop(AccessVersion _accessVersion) throws SQLException, IOException {
init(_accessVersion);
Statement st = null;
ucanaccess.setAutoCommit(false);
createSimple("a", new Object[][] {{"33A", 11, "a"}, {"33B", 111, "a"}});
st = ucanaccess.createStatement();
st.executeUpdate("DROP TABLE AAAn");
try (Statement st = ucanaccess.createStatement()) {
st.executeUpdate("DROP TABLE t_metadata");

st.execute("CREATE TABLE AAAn ( baaaa TEXT(3) PRIMARY KEY,A INTEGER , C TEXT(4)) ");
createSimple("b", new Object[][] {{"33A", 11, "b"}, {"33B", 111, "b"}});
st.execute("CREATE TABLE t_metadata (baaaa TEXT(3) PRIMARY KEY, A INTEGER, C TEXT(4))");
createSimple("b", new Object[][] {{"33A", 11, "b"}, {"33B", 111, "b"}});

ucanaccess.commit();
st.close();
ucanaccess.commit();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,16 @@ protected String getAccessPath() {
@EnumSource(value = AccessVersion.class)
void testNoRomanCharactersInColumnName(AccessVersion _accessVersion) throws Exception {
init(_accessVersion);
dumpQueryResult("SELECT * FROM NOROMAN");

Statement st = ucanaccess.createStatement();

st.execute("INSERT INTO NOROMAN ([end],[q3¹²³¼½¾ß€Ð×ÝÞðýþäüöß]) VALUES( 'the end','yeeep')");
st.execute("UPDATE NOROMAN SET [q3¹²³¼½¾ß€Ð×ÝÞðýþäüöß]='NOOOp' WHERE [end]='the end' ");
ResultSet rs = st.executeQuery("SELECT * FROM NOROMAN");
while (rs.next()) {
getLogger().info(rs.getString("q3¹²³¼½¾ß€Ð×ÝÞðýþäüöß"));
dumpQueryResult("SELECT * FROM t_noroman");

try (Statement st = ucanaccess.createStatement()) {
st.execute("INSERT INTO t_noroman ([end],[q3¹²³¼½¾ß€Ð×ÝÞðýþäüöß]) VALUES( 'the end','yeeep')");
st.execute("UPDATE t_noroman SET [q3¹²³¼½¾ß€Ð×ÝÞðýþäüöß]='NOOOp' WHERE [end]='the end' ");
ResultSet rs = st.executeQuery("SELECT * FROM t_noroman");
while (rs.next()) {
getLogger().debug(rs.getString("q3¹²³¼½¾ß€Ð×ÝÞðýþäüöß"));
}
}

checkQuery("SELECT * FROM NOROMAN");
st.close();
checkQuery("SELECT * FROM t_noroman");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ protected String getAccessPath() {
@MethodSource("net.ucanaccess.test.util.AccessVersion#getDefaultAccessVersion()")
void testNoRomanCharactersInColumnName(AccessVersion _accessVersion) throws Exception {
init(_accessVersion);
dumpQueryResult("SELECT * FROM NOROMAN");
getLogger().info("q3¹²³¼½¾ß€Ð×ÝÞðýþäüöß");
dumpQueryResult("SELECT * FROM t_noroman");
try (Statement st = ucanaccess.createStatement()) {
st.execute("INSERT INTO NOROMAN ([end],[q3¹²³¼½¾ß€Ð×ÝÞðýþäüöß]) VALUES('the end', 'yeeep')");
st.execute("UPDATE NOROMAN SET [q3¹²³¼½¾ß€Ð×ÝÞðýþäüöß]='NOOOp' WHERE [end]='the end' ");
st.execute("INSERT INTO t_noroman ([end],[q3¹²³¼½¾ß€Ð×ÝÞðýþäüöß]) VALUES('the end', 'yeeep')");
st.execute("UPDATE t_noroman SET [q3¹²³¼½¾ß€Ð×ÝÞðýþäüöß]='NOOOp' WHERE [end]='the end' ");
}
checkQuery("SELECT * FROM NOROMAN");
checkQuery("SELECT * FROM t_noroman");
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package net.ucanaccess.test.integration;

import static org.assertj.core.api.Assertions.assertThatThrownBy;

import net.ucanaccess.jdbc.UcanaccessSQLException;
import net.ucanaccess.test.util.AccessVersion;
import net.ucanaccess.test.util.UcanaccessBaseTest;
import org.junit.jupiter.params.ParameterizedTest;
Expand All @@ -19,19 +22,18 @@ protected String getAccessPath() {
@EnumSource(value = AccessVersion.class)
void testExecute(AccessVersion _accessVersion) throws Exception {
init(_accessVersion);
execute("INSERT INTO NOROMAN ([end],[q3¹²³¼½¾ß€Ð×ÝÞðýþäüöß]) VALUES( 'the end','yeeep')");
execute("UPDATE NOROMAN SET [ENd]='BLeah'");
execute("DELETE FROM NOROMAN");
execute("INSERT INTO t_noroman ([end],[q3¹²³¼½¾ß€Ð×ÝÞðýþäüöß]) VALUES('the end', 'yeeep')");
execute("UPDATE t_noroman SET [ENd]='BLeah'");
execute("DELETE FROM t_noroman");
}

private void execute(String s) throws SQLException {
Statement st = ucanaccess.createStatement();
try {
st.executeQuery(s);
fail("Should not get here");
} catch (Exception _ex) {
getLogger().info(_ex.getMessage());
private void execute(String _sql) throws SQLException {
try (Statement st = ucanaccess.createStatement()) {
assertThatThrownBy(() -> st.executeQuery(_sql))
.isInstanceOf(UcanaccessSQLException.class)
.hasMessageMatching("UCAExc:::[0-9\\.]+ General error");

assertDoesNotThrow(() -> st.execute(_sql));
}
st.execute(s);
}
}
Binary file modified src/test/resources/testdbs/noroman.mdb
Binary file not shown.

0 comments on commit c539f3d

Please sign in to comment.