X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;ds=sidebyside;f=tests%2Forg%2Fcacert%2Fgigi%2FtestUtils%2FConfiguredTest.java;h=9010a5975ef802619338311cc7073dc2bbd59e30;hb=753aae17442cbcdfcbce2d720b7b5dfd13918294;hp=207aa006e2cc3f85b77d30eccb0d32a7545680a4;hpb=6d092b2ec03985863aea4854e45035f9e5cdf718;p=gigi.git diff --git a/tests/org/cacert/gigi/testUtils/ConfiguredTest.java b/tests/org/cacert/gigi/testUtils/ConfiguredTest.java index 207aa006..9010a597 100644 --- a/tests/org/cacert/gigi/testUtils/ConfiguredTest.java +++ b/tests/org/cacert/gigi/testUtils/ConfiguredTest.java @@ -12,8 +12,12 @@ 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.DomainAssessment; import org.cacert.gigi.util.PEM; import org.junit.BeforeClass; @@ -36,16 +40,45 @@ public abstract class ConfiguredTest { private static boolean envInited = false; @BeforeClass - public static void initEnvironment() throws IOException { + public static void initEnvironmentHook() throws IOException { + initEnvironment(); + } + + public static Properties initEnvironment() throws IOException { TimeZone.setDefault(TimeZone.getTimeZone("UTC")); + Properties props = generateProps(); if (envInited) { - return; + return props; } envInited = true; - testProps.load(new FileInputStream("config/test.properties")); + DomainAssessment.init(props); + 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); + } } + return props; + + } + + private static Properties generateProps() throws Error { + Properties mainProps = new Properties(); + File out = new File("financial.dat"); + if ( !out.exists()) { + try (FileOutputStream fos = new FileOutputStream(out)) { + fos.write("google.com\ntwitter.com\n".getBytes("UTF-8")); + } catch (IOException e) { + throw new Error(e); + } + } + mainProps.setProperty("highFinancialValue", out.getAbsolutePath()); + return mainProps; } public static KeyPair generateKeypair() throws GeneralSecurityException { @@ -91,8 +124,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; + } }