]> WPIA git - gigi.git/blobdiff - tests/org/cacert/gigi/testUtils/ConfiguredTest.java
Merge "Suggestions to enhance the SQL call pattern."
[gigi.git] / tests / org / cacert / gigi / testUtils / ConfiguredTest.java
index 207aa006e2cc3f85b77d30eccb0d32a7545680a4..90b3468291d4695dc00e4b829633c4fef80a09e0 100644 (file)
@@ -12,8 +12,11 @@ import java.security.KeyPairGenerator;
 import java.security.Signature;
 import java.util.Properties;
 import java.util.TimeZone;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import org.cacert.gigi.database.DatabaseConnection;
+import org.cacert.gigi.database.DatabaseConnection.Link;
 import org.cacert.gigi.util.PEM;
 import org.junit.BeforeClass;
 
@@ -42,9 +45,16 @@ public abstract class ConfiguredTest {
             return;
         }
         envInited = true;
-        testProps.load(new FileInputStream("config/test.properties"));
+        try (FileInputStream inStream = new FileInputStream("config/test.properties")) {
+            testProps.load(inStream);
+        }
         if ( !DatabaseConnection.isInited()) {
             DatabaseConnection.init(testProps);
+            try {
+                l = DatabaseConnection.newLink(false);
+            } catch (InterruptedException e) {
+                throw new Error(e);
+            }
         }
     }
 
@@ -91,8 +101,19 @@ public abstract class ConfiguredTest {
 
     static int count = 0;
 
+    private static Link l;
+
     public static String createUniqueName() {
         return "test" + System.currentTimeMillis() + "a" + (count++) + "u";
     }
 
+    public static int countRegex(String text, String pattern) {
+        Pattern p = Pattern.compile(pattern);
+        Matcher m = p.matcher(text);
+        int i = 0;
+        while (m.find()) {
+            i++;
+        }
+        return i;
+    }
 }