]> WPIA git - gigi.git/blobdiff - tests/org/cacert/gigi/pages/wot/TestAssurance.java
add: test case for user opt-in notification for RA Agents
[gigi.git] / tests / org / cacert / gigi / pages / wot / TestAssurance.java
index 84cd6dc44ae12bfd37890d931572a6bd8a81ce41..0af859ccc979ad664a0cc47a682ae9365ce25bba 100644 (file)
@@ -16,11 +16,15 @@ import java.util.Calendar;
 import java.util.Date;
 import java.util.regex.Pattern;
 
+import org.cacert.gigi.GigiApiException;
 import org.cacert.gigi.database.GigiPreparedStatement;
+import org.cacert.gigi.dbObjects.Country;
+import org.cacert.gigi.dbObjects.Group;
 import org.cacert.gigi.dbObjects.User;
 import org.cacert.gigi.pages.account.MyDetails;
 import org.cacert.gigi.testUtils.IOUtils;
 import org.cacert.gigi.testUtils.ManagedTest;
+import org.cacert.gigi.testUtils.TestEmailReceiver.TestMail;
 import org.cacert.gigi.util.DayDate;
 import org.cacert.gigi.util.Notary;
 import org.hamcrest.Matcher;
@@ -225,7 +229,7 @@ public class TestAssurance extends ManagedTest {
     }
 
     @Test
-    public void testAssureListingValid() throws IOException {
+    public void testAssureListingValid() throws IOException, GigiApiException {
         String uniqueLoc = createUniqueName();
         execute("date=" + validVerificationDateString() + "&location=" + uniqueLoc + "&countryCode=DE&certify=1&rules=1&assertion=1&points=10");
 
@@ -234,10 +238,11 @@ public class TestAssurance extends ManagedTest {
         String resp = IOUtils.readURL(url);
         resp = resp.split(Pattern.quote("</table>"))[1];
         assertThat(resp, containsString(uniqueLoc));
+        assertThat(resp, containsString(Country.getCountryByCode("DE", Country.CountryCodeType.CODE_2_CHARS).getName()));
     }
 
     @Test
-    public void testAssurerListingValid() throws IOException {
+    public void testAssurerListingValid() throws IOException, GigiApiException {
         String uniqueLoc = createUniqueName();
         executeSuccess("date=" + validVerificationDateString() + "&location=" + uniqueLoc + "&countryCode=DE&certify=1&rules=1&assertion=1&points=10");
         String cookie = login(assurerM, TEST_PASSWORD);
@@ -245,6 +250,7 @@ public class TestAssurance extends ManagedTest {
         String resp = IOUtils.readURL(url);
         resp = resp.split(Pattern.quote("</table>"))[2];
         assertThat(resp, containsString(uniqueLoc));
+        assertThat(resp, containsString(Country.getCountryByCode("DE", Country.CountryCodeType.CODE_2_CHARS).getName()));
     }
 
     private void executeFails(String query) throws MalformedURLException, IOException {
@@ -313,4 +319,58 @@ public class TestAssurance extends ManagedTest {
         assertThat(IOUtils.readURL(uc), hasError());
 
     }
+
+    @Test
+    public void testAssureFormNoCountry() throws IOException {
+        executeFails("date=" + validVerificationDateString() + "&location=testcase&countryCode=&certify=1&rules=1&assertion=1&points=10");
+    }
+
+    @Test
+    public void testRANotificationSet() throws IOException, GigiApiException {
+        getMailReceiver().clearMails();
+
+        User users[] = User.findByEmail(assurerM);
+        assertTrue("user RA Agent not found", users != null && users.length > 0);
+
+        User u = users[0];
+        u.grantGroup(u, Group.VERIFY_NOTIFICATION);
+        clearCaches();
+        cookie = login(assurerM, TEST_PASSWORD);
+
+        String targetMail = u.getEmail();
+
+        // enter verification
+        String uniqueLoc = createUniqueName();
+        executeSuccess("date=" + validVerificationDateString() + "&location=" + uniqueLoc + "&countryCode=DE&certify=1&rules=1&assertion=1&points=10");
+        TestMail tm;
+
+        do {
+            tm = getMailReceiver().receive();
+        } while ( !tm.getTo().equals(targetMail));
+        assertThat(tm.getMessage(), containsString("You entered a verification for the account with email address " + assureeM));
+
+    }
+
+    @Test
+    public void testRANotificationNotSet() throws IOException, GigiApiException {
+        getMailReceiver().clearMails();
+
+        User users[] = User.findByEmail(assurerM);
+        assertTrue("user RA Agent not found", users != null && users.length > 0);
+
+        User u = users[0];
+        u.revokeGroup(u, Group.VERIFY_NOTIFICATION);
+        clearCaches();
+        cookie = login(assurerM, TEST_PASSWORD);
+
+        // enter verification
+        String uniqueLoc = createUniqueName();
+        executeSuccess("date=" + validVerificationDateString() + "&location=" + uniqueLoc + "&countryCode=DE&certify=1&rules=1&assertion=1&points=10");
+
+        TestMail tm;
+
+        tm = getMailReceiver().receive();
+        assertThat(tm.getMessage(), not(containsString("You entered a verification for the account with email address " + assureeM)));
+
+    }
 }