X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=tests%2Forg%2Fcacert%2Fgigi%2FtestUtils%2FConfiguredTest.java;h=90b3468291d4695dc00e4b829633c4fef80a09e0;hp=a6bbed85be7c6684a6dfabeaaa3370f952aecd96;hb=d7be034f96e06985f57d86d2779c434276b5bd4d;hpb=3ad63175cc8309ab090f2df24b593e61da421bbe diff --git a/tests/org/cacert/gigi/testUtils/ConfiguredTest.java b/tests/org/cacert/gigi/testUtils/ConfiguredTest.java index a6bbed85..90b34682 100644 --- a/tests/org/cacert/gigi/testUtils/ConfiguredTest.java +++ b/tests/org/cacert/gigi/testUtils/ConfiguredTest.java @@ -11,8 +11,12 @@ import java.security.KeyPair; 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; @@ -20,7 +24,11 @@ import sun.security.pkcs10.PKCS10; import sun.security.pkcs10.PKCS10Attributes; import sun.security.x509.X500Name; -public class ConfiguredTest { +/** + * Base class for a Testsuite that makes use of the config variables that define + * the environment. + */ +public abstract class ConfiguredTest { static Properties testProps = new Properties(); @@ -32,13 +40,21 @@ public class ConfiguredTest { @BeforeClass public static void initEnvironment() throws IOException { + TimeZone.setDefault(TimeZone.getTimeZone("UTC")); if (envInited) { 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); + } } } @@ -85,8 +101,19 @@ public 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; + } }