]> WPIA git - gigi.git/blobdiff - tests/club/wpia/gigi/testUtils/ManagedTest.java
Merge "add: show more certificates on the "roots" page"
[gigi.git] / tests / club / wpia / gigi / testUtils / ManagedTest.java
index f4ad8522899d4bc34c4c559658db86ecfe41a94e..a2eb449fb988b083d2369c9e6ef6b028be5e7c07 100644 (file)
@@ -101,11 +101,11 @@ public class ManagedTest extends ConfiguredTest {
                 return mainProps;
             }
             inited = true;
+            url = testProps.getProperty("name.www") + ":" + testProps.getProperty("serverPort.https");
             purgeDatabase();
             String type = testProps.getProperty("type");
             generateMainProps(mainProps);
             if (type.equals("local")) {
-                url = testProps.getProperty("name.www") + ":" + testProps.getProperty("serverPort.https");
                 String[] parts = testProps.getProperty("mail").split(":", 2);
                 ter = new TestEmailReceiver(new InetSocketAddress(parts[0], Integer.parseInt(parts[1])));
                 ter.start();
@@ -114,7 +114,6 @@ public class ManagedTest extends ConfiguredTest {
                 }
                 return mainProps;
             }
-            url = testProps.getProperty("name.www") + ":" + testProps.getProperty("serverPort.https");
             gigi = Runtime.getRuntime().exec(testProps.getProperty("java"));
             DataOutputStream toGigi = new DataOutputStream(gigi.getOutputStream());
             System.out.println("... starting server");
@@ -168,14 +167,18 @@ public class ManagedTest extends ConfiguredTest {
 
     public static void purgeDatabase() throws SQLException, IOException {
         purgeOnlyDB();
-        clearCaches();
+        if (gigi != null) {
+            clearCaches();
+        }
     }
 
     public static void clearCaches() throws IOException {
         ObjectCache.clearAllCaches();
         // String type = testProps.getProperty("type");
         URL u = new URL("https://" + getServerName() + "/manage");
-        u.openConnection().getHeaderField("Location");
+        URLConnection connection = u.openConnection();
+        connection.getHeaderField("Location");
+        connection.getInputStream().close();
     }
 
     private static void generateMainProps(Properties mainProps) {
@@ -196,6 +199,14 @@ public class ManagedTest extends ConfiguredTest {
         String type = testProps.getProperty("type");
         ter.destroy();
         if (type.equals("local")) {
+            if (testProps.getProperty("withSigner", "false").equals("true")) {
+                try {
+                    SimpleSigner.stopSigner();
+                } catch (InterruptedException e) {
+                    e.printStackTrace();
+                }
+            }
+            inited = false;
             return;
         }
         gigi.destroy();
@@ -204,6 +215,7 @@ public class ManagedTest extends ConfiguredTest {
         } catch (InterruptedException e) {
             e.printStackTrace();
         }
+        inited = false;
     }
 
     public final String uniq = createUniqueName();
@@ -279,7 +291,7 @@ public class ManagedTest extends ConfiguredTest {
     public static int createVerifiedUser(String firstName, String lastName, String email, String password) {
         registerUser(firstName, lastName, email, password);
         try {
-            ter.receive().verify();
+            ter.receive(email).verify();
 
             try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT `id` FROM `users` WHERE `email`=?")) {
                 ps.setString(1, email);
@@ -484,11 +496,10 @@ public class ManagedTest extends ConfiguredTest {
 
     public EmailAddress createVerifiedEmail(User u, String email) throws InterruptedException, GigiApiException {
         EmailAddress addr = new EmailAddress(u, email, Locale.ENGLISH);
-        TestMail testMail = getMailReceiver().receive();
-        assertEquals(addr.getAddress(), testMail.getTo());
+        TestMail testMail = getMailReceiver().receive(addr.getAddress());
         String hash = testMail.extractLink().substring(testMail.extractLink().lastIndexOf('=') + 1);
         addr.verify(hash);
-        getMailReceiver().clearMails();
+        getMailReceiver().assertEmpty();
         return addr;
     }