X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=tests%2Forg%2Fcacert%2Fgigi%2FtestUtils%2FManagedTest.java;h=96b4e61b06886d689ebf3d0b6d867f80005ae2b1;hp=28628cb852b11374d50bcb2ee123817c0eefd4c8;hb=a0232b6e40e7e09767f0444d24e18bf12dafc362;hpb=a0cae0454cb03690ce318fa0fc8b4ca6d6cca4f1 diff --git a/tests/org/cacert/gigi/testUtils/ManagedTest.java b/tests/org/cacert/gigi/testUtils/ManagedTest.java index 28628cb8..96b4e61b 100644 --- a/tests/org/cacert/gigi/testUtils/ManagedTest.java +++ b/tests/org/cacert/gigi/testUtils/ManagedTest.java @@ -35,7 +35,6 @@ import javax.net.ssl.X509KeyManager; import org.cacert.gigi.DevelLauncher; import org.cacert.gigi.GigiApiException; -import org.cacert.gigi.database.DatabaseConnection; import org.cacert.gigi.database.GigiPreparedStatement; import org.cacert.gigi.database.GigiResultSet; import org.cacert.gigi.database.SQLFileManager.ImportType; @@ -274,10 +273,10 @@ public class ManagedTest extends ConfiguredTest { try { ter.receive().verify(); - GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT `id` FROM `users` WHERE `email`=?"); - ps.setString(1, email); + try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT `id` FROM `users` WHERE `email`=?")) { + ps.setString(1, email); - try (GigiResultSet rs = ps.executeQuery()) { + GigiResultSet rs = ps.executeQuery(); if (rs.next()) { return rs.getInt(1); } @@ -319,18 +318,20 @@ public class ManagedTest extends ConfiguredTest { } public static void makeAssurer(int uid) { - GigiPreparedStatement ps1 = DatabaseConnection.getInstance().prepare("INSERT INTO `cats_passed` SET `user_id`=?, `variant_id`=?"); - ps1.setInt(1, uid); - ps1.setInt(2, 1); - ps1.execute(); + try (GigiPreparedStatement ps1 = new GigiPreparedStatement("INSERT INTO `cats_passed` SET `user_id`=?, `variant_id`=?")) { + ps1.setInt(1, uid); + ps1.setInt(2, 1); + ps1.execute(); + } - GigiPreparedStatement ps2 = DatabaseConnection.getInstance().prepare("INSERT INTO `notary` SET `from`=?, `to`=?, points='100'"); - ps2.setInt(1, uid); - ps2.setInt(2, uid); - ps2.execute(); + try (GigiPreparedStatement ps2 = new GigiPreparedStatement("INSERT INTO `notary` SET `from`=?, `to`=?, points='100'")) { + ps2.setInt(1, uid); + ps2.setInt(2, uid); + ps2.execute(); + } } - static String stripCookie(String headerField) { + protected static String stripCookie(String headerField) { return headerField.substring(0, headerField.indexOf(';')); } @@ -473,7 +474,7 @@ public class ManagedTest extends ConfiguredTest { return (HttpURLConnection) uc; } - public HttpURLConnection get(String cookie, String path, int formIndex) throws IOException { + public HttpURLConnection get(String cookie, String path) throws IOException { URLConnection uc = new URL("https://" + getServerName() + path).openConnection(); uc.addRequestProperty("Cookie", cookie); return (HttpURLConnection) uc;