X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=tests%2Forg%2Fcacert%2Fgigi%2FtestUtils%2FManagedTest.java;h=1ea49cf404672be28a59b0175a91f36cc1cafe85;hb=16316c8617f9da0b1e20ad0f54ce33e381f4da39;hp=aad0ef02c52e5d7ab653cdb0ff4783f8a3d3062f;hpb=6d7ab9c4e2807bc40e7c583f899b5221cf44c8ea;p=gigi.git diff --git a/tests/org/cacert/gigi/testUtils/ManagedTest.java b/tests/org/cacert/gigi/testUtils/ManagedTest.java index aad0ef02..1ea49cf4 100644 --- a/tests/org/cacert/gigi/testUtils/ManagedTest.java +++ b/tests/org/cacert/gigi/testUtils/ManagedTest.java @@ -37,10 +37,6 @@ import org.cacert.gigi.DevelLauncher; import org.cacert.gigi.GigiApiException; import org.cacert.gigi.database.GigiPreparedStatement; import org.cacert.gigi.database.GigiResultSet; -import org.cacert.gigi.database.SQLFileManager.ImportType; -import org.cacert.gigi.dbObjects.CATS; -import org.cacert.gigi.dbObjects.Domain; -import org.cacert.gigi.dbObjects.DomainPingType; import org.cacert.gigi.dbObjects.EmailAddress; import org.cacert.gigi.dbObjects.Group; import org.cacert.gigi.dbObjects.Job; @@ -50,9 +46,8 @@ import org.cacert.gigi.pages.Manager; import org.cacert.gigi.pages.account.MyDetails; import org.cacert.gigi.pages.main.RegisterPage; import org.cacert.gigi.testUtils.TestEmailReceiver.TestMail; -import org.cacert.gigi.util.DatabaseManager; -import org.cacert.gigi.util.ServerConstants; import org.cacert.gigi.util.SimpleSigner; +import org.hamcrest.CoreMatchers; import org.junit.After; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -67,13 +62,6 @@ public class ManagedTest extends ConfiguredTest { System.setProperty("sun.net.http.allowRestrictedHeaders", "true"); } - /** - * Some password that fulfills the password criteria. - */ - public static final String TEST_PASSWORD = "xvXV12°§"; - - public static final String DIFFICULT_CHARS = "ÜÖÄß𐀀"; - private static TestEmailReceiver ter; private static Process gigi; @@ -96,14 +84,22 @@ public class ManagedTest extends ConfiguredTest { } @BeforeClass - public static void initEnvironment() { - try { - ConfiguredTest.initEnvironment(); + public static void initEnvironmentHook() { + initEnvironment(); + } + private static boolean inited = false; + + public static Properties initEnvironment() { + try { + Properties mainProps = ConfiguredTest.initEnvironment(); + if (inited) { + return mainProps; + } + inited = true; purgeDatabase(); String type = testProps.getProperty("type"); - Properties mainProps = generateMainProps(); - ServerConstants.init(mainProps); + generateMainProps(mainProps); if (type.equals("local")) { url = testProps.getProperty("name.www") + ":" + testProps.getProperty("serverPort.https"); String[] parts = testProps.getProperty("mail").split(":", 2); @@ -112,7 +108,7 @@ public class ManagedTest extends ConfiguredTest { if (testProps.getProperty("withSigner", "false").equals("true")) { SimpleSigner.runSigner(); } - return; + return mainProps; } url = testProps.getProperty("name.www") + ":" + testProps.getProperty("serverPort.https"); gigi = Runtime.getRuntime().exec(testProps.getProperty("java")); @@ -150,12 +146,13 @@ public class ManagedTest extends ConfiguredTest { ter = new TestEmailReceiver(new InetSocketAddress("localhost", 8473)); ter.start(); SimpleSigner.runSigner(); + return mainProps; } catch (IOException e) { throw new Error(e); } catch (SQLException e1) { - e1.printStackTrace(); + throw new Error(e1); } catch (InterruptedException e) { - e.printStackTrace(); + throw new Error(e); } } @@ -166,16 +163,7 @@ public class ManagedTest extends ConfiguredTest { } public static void purgeDatabase() throws SQLException, IOException { - System.out.print("... resetting Database"); - long ms = System.currentTimeMillis(); - try { - DatabaseManager.run(new String[] { - testProps.getProperty("sql.driver"), testProps.getProperty("sql.url"), testProps.getProperty("sql.user"), testProps.getProperty("sql.password") - }, ImportType.TRUNCATE); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } - System.out.println(" in " + (System.currentTimeMillis() - ms) + " ms"); + purgeOnlyDB(); clearCaches(); } @@ -186,17 +174,10 @@ public class ManagedTest extends ConfiguredTest { u.openConnection().getHeaderField("Location"); } - private static Properties generateMainProps() { - Properties mainProps = new Properties(); + private static void generateMainProps(Properties mainProps) { mainProps.setProperty("testrunner", "true"); mainProps.setProperty("host", "127.0.0.1"); - mainProps.setProperty("name.secure", testProps.getProperty("name.secure")); - mainProps.setProperty("name.www", testProps.getProperty("name.www")); - mainProps.setProperty("name.static", testProps.getProperty("name.static")); - mainProps.setProperty("name.api", testProps.getProperty("name.api")); - mainProps.setProperty("https.port", testProps.getProperty("serverPort.https")); - mainProps.setProperty("http.port", testProps.getProperty("serverPort.http")); mainProps.setProperty("emailProvider", "org.cacert.gigi.email.TestEmailProvider"); mainProps.setProperty("emailProvider.port", "8473"); mainProps.setProperty("sql.driver", testProps.getProperty("sql.driver")); @@ -204,7 +185,6 @@ public class ManagedTest extends ConfiguredTest { mainProps.setProperty("sql.user", testProps.getProperty("sql.user")); mainProps.setProperty("sql.password", testProps.getProperty("sql.password")); mainProps.setProperty("testing", "true"); - return mainProps; } @AfterClass @@ -234,7 +214,8 @@ public class ManagedTest extends ConfiguredTest { ManagedTest.setAcceptLanguage(null); } - public static TestEmailReceiver getMailReciever() { + @Override + public MailReceiver getMailReciever() { return ter; } @@ -258,13 +239,21 @@ public class ManagedTest extends ConfiguredTest { return d; } + public static org.hamcrest.Matcher hasError() { + return CoreMatchers.containsString("
"); + } + + public static org.hamcrest.Matcher hasNoError() { + return CoreMatchers.not(hasError()); + } + public static String fetchStartErrorMessage(String d) throws IOException { - String formFail = "
"; + String formFail = "
"; int idx = d.indexOf(formFail); if (idx == -1) { return null; } - String startError = d.substring(idx + formFail.length(), idx + 100).trim(); + String startError = d.substring(idx + formFail.length(), idx + formFail.length() + 150).trim(); return startError; } @@ -329,20 +318,6 @@ public class ManagedTest extends ConfiguredTest { return uid; } - public static void makeAssurer(int uid) { - try (GigiPreparedStatement ps1 = new GigiPreparedStatement("INSERT INTO cats_passed SET user_id=?, variant_id=?, language='en_EN', version=1")) { - ps1.setInt(1, uid); - ps1.setInt(2, CATS.ASSURER_CHALLENGE_ID); - ps1.execute(); - } - - try (GigiPreparedStatement ps2 = new GigiPreparedStatement("INSERT INTO `notary` SET `from`=?, `to`=?, points='100'")) { - ps2.setInt(1, uid); - ps2.setInt(2, uid); - ps2.execute(); - } - } - protected static String stripCookie(String headerField) { return headerField.substring(0, headerField.indexOf(';')); } @@ -492,7 +467,7 @@ public class ManagedTest extends ConfiguredTest { return (HttpURLConnection) uc; } - public static EmailAddress createVerifiedEmail(User u) throws InterruptedException, GigiApiException { + public EmailAddress createVerifiedEmail(User u) throws InterruptedException, GigiApiException { EmailAddress adrr = new EmailAddress(u, createUniqueName() + "test@test.tld", Locale.ENGLISH); TestMail testMail = getMailReciever().receive(); assertEquals(adrr.getAddress(), testMail.getTo()); @@ -507,18 +482,4 @@ public class ManagedTest extends ConfiguredTest { return openConnection; } - public static void verify(Domain d) { - try { - System.out.println(d.getId()); - d.addPing(DomainPingType.EMAIL, "admin"); - TestMail testMail = ter.receive(); - testMail.verify(); - assertTrue(d.isVerified()); - } catch (GigiApiException e) { - throw new Error(e); - } catch (IOException e) { - throw new Error(e); - } - } - }