]> WPIA git - gigi.git/blobdiff - tests/org/cacert/gigi/testUtils/PingTest.java
Fix: various coverity charset issues.
[gigi.git] / tests / org / cacert / gigi / testUtils / PingTest.java
index 6c57d76dcd80d30173f6b00f4c2ff133e7a1e18c..20395878fb4411dc7251bd0166f8cfb2df0eef44 100644 (file)
@@ -1,34 +1,43 @@
 package org.cacert.gigi.testUtils;
 
 import static org.junit.Assert.*;
+import static org.junit.Assume.*;
 
 import java.io.IOException;
 import java.net.HttpURLConnection;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLConnection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import org.cacert.gigi.database.DatabaseConnection;
-import org.cacert.gigi.pages.account.DomainOverview;
-import org.junit.Before;
+import org.cacert.gigi.database.GigiPreparedStatement;
+import org.cacert.gigi.database.GigiResultSet;
+import org.cacert.gigi.pages.account.domain.DomainOverview;
+import org.junit.After;
 
+/**
+ * Base class for test suites that check extensively if the domain-ping
+ * functionality wroks as expected.
+ */
 public abstract class PingTest extends ClientTest {
 
+    protected String csrf;
+
     protected static void updateService(String token, String value, String action) throws IOException, MalformedURLException {
         String manage = getTestProps().getProperty("domain.manage");
+        assumeNotNull(manage);
         String url = manage + "t1=" + token + "&t2=" + value + "&action=" + action;
         assertEquals(200, ((HttpURLConnection) new URL(url).openConnection()).getResponseCode());
     }
 
     protected void waitForPings(int count) throws SQLException, InterruptedException {
-        PreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT COUNT(*) FROM domainPinglog");
-        while (true) {
-            ResultSet rs = ps.executeQuery();
+        GigiPreparedStatement ps = DatabaseConnection.getInstance().prepare("SELECT COUNT(*) FROM domainPinglog");
+        long start = System.currentTimeMillis();
+        while (System.currentTimeMillis() - start < 10000) {
+            GigiResultSet rs = ps.executeQuery();
             rs.next();
             if (rs.getInt(1) >= count) {
                 break;
@@ -41,13 +50,15 @@ public abstract class PingTest extends ClientTest {
         URLConnection openConnection = u.openConnection();
         openConnection.setRequestProperty("Cookie", cookie);
         openConnection.setDoOutput(true);
-        openConnection.getOutputStream().write(content.getBytes());
+        openConnection.getOutputStream().write(content.getBytes("UTF-8"));
         openConnection.getHeaderField("Location");
 
         String newcontent = IOUtils.readURL(cookie(u.openConnection(), cookie));
         Pattern dlink = Pattern.compile(DomainOverview.PATH + "([0-9]+)'>");
         Matcher m1 = dlink.matcher(newcontent);
-        m1.find();
+        if ( !m1.find()) {
+            throw new Error(newcontent);
+        }
         URL u2 = new URL(u.toString() + m1.group(1));
         return u2;
     }
@@ -64,14 +75,8 @@ public abstract class PingTest extends ClientTest {
         return m;
     }
 
-    private static boolean first = true;
-
-    @Before
+    @After
     public void purgeDbAfterTest() throws SQLException, IOException {
-        if (first) {
-            first = false;
-            return;
-        }
         purgeDatabase();
     }