]> WPIA git - gigi.git/commitdiff
Fix Cache punging for local tests.
authorFelix Dörre <felix@dogcraft.de>
Sat, 6 Sep 2014 19:37:15 +0000 (21:37 +0200)
committerFelix Dörre <felix@dogcraft.de>
Sat, 6 Sep 2014 19:37:15 +0000 (21:37 +0200)
src/org/cacert/gigi/DevelLauncher.java
src/org/cacert/gigi/dbObjects/ObjectCache.java
tests/org/cacert/gigi/pages/account/TestMailManagement.java
tests/org/cacert/gigi/testUtils/ManagedTest.java

index e83ae4145f3d47d955c5b087a9e23b27479eb882..44a949c8b2654e72538c2a2529e15413e8b5ec72 100644 (file)
@@ -10,10 +10,17 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
+import java.lang.reflect.Field;
 import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.nio.file.Files;
 import java.nio.file.Paths;
+import java.util.HashMap;
 import java.util.Properties;
 
 import java.util.Properties;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.cacert.gigi.dbObjects.ObjectCache;
+import org.cacert.gigi.pages.Page;
 import org.kamranzafar.jtar.TarEntry;
 import org.kamranzafar.jtar.TarHeader;
 import org.kamranzafar.jtar.TarOutputStream;
 import org.kamranzafar.jtar.TarEntry;
 import org.kamranzafar.jtar.TarHeader;
 import org.kamranzafar.jtar.TarOutputStream;
@@ -42,6 +49,7 @@ public class DevelLauncher {
         InputStream oldin = System.in;
         System.setIn(new ByteArrayInputStream(chunkConfig.toByteArray()));
         Launcher.main(args);
         InputStream oldin = System.in;
         System.setIn(new ByteArrayInputStream(chunkConfig.toByteArray()));
         Launcher.main(args);
+        addDevelPage();
         System.setIn(oldin);
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         System.out.println("Cacert-gigi system sucessfully started.");
         System.setIn(oldin);
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         System.out.println("Cacert-gigi system sucessfully started.");
@@ -50,6 +58,34 @@ public class DevelLauncher {
         System.exit(0);
     }
 
         System.exit(0);
     }
 
+    private static void addDevelPage() {
+        try {
+            Field instF = Gigi.class.getDeclaredField("instance");
+            Field pageF = Gigi.class.getDeclaredField("pages");
+            instF.setAccessible(true);
+            pageF.setAccessible(true);
+            Object gigi = instF.get(null);
+            HashMap<String, Page> pages = (HashMap<String, Page>) pageF.get(gigi);
+            pages.put("/manage", new Page("Page-manger") {
+
+                @Override
+                public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
+                    ObjectCache.clearAllCaches();
+                    resp.getWriter().println("All caches cleared.");
+                    System.out.println("Caches cleared.");
+
+                }
+
+                @Override
+                public boolean needsLogin() {
+                    return false;
+                }
+            });
+        } catch (ReflectiveOperationException e) {
+            e.printStackTrace();
+        }
+    }
+
     public static void writeGigiConfig(OutputStream target, byte[] keystorepw, byte[] truststorepw, Properties mainprop, byte[] cacerts, byte[] keystore) throws IOException {
         TarOutputStream tos = new TarOutputStream(target);
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
     public static void writeGigiConfig(OutputStream target, byte[] keystorepw, byte[] truststorepw, Properties mainprop, byte[] cacerts, byte[] keystore) throws IOException {
         TarOutputStream tos = new TarOutputStream(target);
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
index e06f84f84a57fd0fde3bafe5d8066b9d6efc08d0..2a5d297b96652d3c2b07cbd9fa402bb87297c361 100644 (file)
@@ -26,7 +26,7 @@ public class ObjectCache<T extends IdCachable> {
         return null;
     }
 
         return null;
     }
 
-    public static void clearAllCashes() {
+    public static void clearAllCaches() {
         for (ObjectCache<?> objectCache : caches) {
             objectCache.hashmap.clear();
         }
         for (ObjectCache<?> objectCache : caches) {
             objectCache.hashmap.clear();
         }
index 5ad75a60ee23af66323dce418a27a9b74457766c..9c8ce391eb905dfffb4acea727ab07e19818c468 100644 (file)
@@ -71,9 +71,9 @@ public class TestMailManagement extends ManagedTest {
 
     @Test
     public void testMailSetDefaultWeb() throws MalformedURLException, UnsupportedEncodingException, IOException, InterruptedException, GigiApiException {
 
     @Test
     public void testMailSetDefaultWeb() throws MalformedURLException, UnsupportedEncodingException, IOException, InterruptedException, GigiApiException {
-        ObjectCache.clearAllCashes();
         EmailAddress adrr = createVerifiedEmail(u);
         assertNull(executeBasicWebInteraction(cookie, path, "makedefault&emailid=" + adrr.getId()));
         EmailAddress adrr = createVerifiedEmail(u);
         assertNull(executeBasicWebInteraction(cookie, path, "makedefault&emailid=" + adrr.getId()));
+        ObjectCache.clearAllCaches();
         assertEquals(User.getById(u.getId()).getEmail(), adrr.getAddress());
     }
 
         assertEquals(User.getById(u.getId()).getEmail(), adrr.getAddress());
     }
 
index 0c81e370a2e6119d9381215f0225904531c9df92..6cccdae1132d80364bd83c346969f3956b6f0be5 100644 (file)
@@ -48,6 +48,7 @@ import org.cacert.gigi.DevelLauncher;
 import org.cacert.gigi.GigiApiException;
 import org.cacert.gigi.database.DatabaseConnection;
 import org.cacert.gigi.dbObjects.EmailAddress;
 import org.cacert.gigi.GigiApiException;
 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.dbObjects.User;
 import org.cacert.gigi.localisation.Language;
 import org.cacert.gigi.pages.account.MyDetails;
@@ -171,6 +172,12 @@ public class ManagedTest {
             e.printStackTrace();
         }
         System.out.println(" in " + (System.currentTimeMillis() - ms) + " ms");
             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() {
     }
 
     private static Properties generateMainProps() {