]> WPIA git - gigi.git/blobdiff - tests/org/cacert/gigi/testUtils/ManagedTest.java
fix: SQL change database call pattern
[gigi.git] / tests / org / cacert / gigi / testUtils / ManagedTest.java
index 3bc32ca728e26bbdd69b6b171a3d641cc8cb69fc..96b4e61b06886d689ebf3d0b6d867f80005ae2b1 100644 (file)
@@ -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, 0);
-        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,6 +474,12 @@ public class ManagedTest extends ConfiguredTest {
         return (HttpURLConnection) uc;
     }
 
+    public HttpURLConnection get(String cookie, String path) throws IOException {
+        URLConnection uc = new URL("https://" + getServerName() + path).openConnection();
+        uc.addRequestProperty("Cookie", cookie);
+        return (HttpURLConnection) uc;
+    }
+
     public static EmailAddress createVerifiedEmail(User u) throws InterruptedException, GigiApiException {
         EmailAddress adrr = new EmailAddress(u, createUniqueName() + "test@test.tld", Locale.ENGLISH);
         TestMail testMail = getMailReciever().receive();