]> WPIA git - gigi.git/blobdiff - tests/org/cacert/gigi/testUtils/ManagedTest.java
Fix Cache punging for local tests.
[gigi.git] / tests / org / cacert / gigi / testUtils / ManagedTest.java
index da1aca399418d92e99b2105228a5c0a7bd2d0a1c..6cccdae1132d80364bd83c346969f3956b6f0be5 100644 (file)
@@ -45,10 +45,11 @@ import javax.net.ssl.SSLContext;
 import javax.net.ssl.X509KeyManager;
 
 import org.cacert.gigi.DevelLauncher;
-import org.cacert.gigi.EmailAddress;
 import org.cacert.gigi.GigiApiException;
-import org.cacert.gigi.User;
 import org.cacert.gigi.database.DatabaseConnection;
+import org.cacert.gigi.dbObjects.EmailAddress;
+import org.cacert.gigi.dbObjects.ObjectCache;
+import org.cacert.gigi.dbObjects.User;
 import org.cacert.gigi.localisation.Language;
 import org.cacert.gigi.pages.account.MyDetails;
 import org.cacert.gigi.pages.main.RegisterPage;
@@ -78,6 +79,12 @@ public class ManagedTest {
 
     private static String url = "localhost:4443";
 
+    private static String acceptLanguage = null;
+
+    public static void setAcceptLanguage(String acceptLanguage) {
+        ManagedTest.acceptLanguage = acceptLanguage;
+    }
+
     public static String getServerName() {
         return url;
     }
@@ -165,6 +172,12 @@ public class ManagedTest {
             e.printStackTrace();
         }
         System.out.println(" in " + (System.currentTimeMillis() - ms) + " ms");
+        String type = testProps.getProperty("type");
+        ObjectCache.clearAllCaches();
+        if (type.equals("local")) {
+            URL u = new URL("https://" + getServerName() + "/manage");
+            u.openConnection().getHeaderField("Location");
+        }
     }
 
     private static Properties generateMainProps() {
@@ -207,6 +220,11 @@ public class ManagedTest {
         ter.reset();
     }
 
+    @After
+    public void clearAcceptLanguage() {
+        acceptLanguage = null;
+    }
+
     public TestMail waitForMail() {
         try {
             return ter.recieve();
@@ -223,6 +241,10 @@ public class ManagedTest {
         URL regist = new URL("https://" + getServerName() + RegisterPage.PATH);
         HttpURLConnection uc = (HttpURLConnection) regist.openConnection();
         HttpURLConnection csrfConn = (HttpURLConnection) regist.openConnection();
+        if (acceptLanguage != null) {
+            csrfConn.setRequestProperty("Accept-Language", acceptLanguage);
+            uc.setRequestProperty("Accept-Language", acceptLanguage);
+        }
 
         String headerField = csrfConn.getHeaderField("Set-Cookie");
         headerField = stripCookie(headerField);
@@ -491,10 +513,10 @@ public class ManagedTest {
     }
 
     public static EmailAddress createVerifiedEmail(User u) throws InterruptedException, GigiApiException {
-        EmailAddress adrr = new EmailAddress(createUniqueName() + "test@test.tld", u);
+        EmailAddress adrr = new EmailAddress(u, createUniqueName() + "test@test.tld");
         adrr.insert(Language.getInstance(Locale.ENGLISH));
         TestMail testMail = getMailReciever().recieve();
-        assertTrue(adrr.getAddress().equals(testMail.getTo()));
+        assertEquals(adrr.getAddress(), testMail.getTo());
         String hash = testMail.extractLink().substring(testMail.extractLink().lastIndexOf('=') + 1);
         adrr.verify(hash);
         getMailReciever().clearMails();