1 package org.cacert.gigi.pages.account;
3 import static org.junit.Assert.*;
5 import java.io.IOException;
6 import java.io.UnsupportedEncodingException;
7 import java.net.MalformedURLException;
8 import java.net.URLEncoder;
10 import org.cacert.gigi.EmailAddress;
11 import org.cacert.gigi.GigiApiException;
12 import org.cacert.gigi.Language;
13 import org.cacert.gigi.User;
14 import org.cacert.gigi.testUtils.ManagedTest;
15 import org.cacert.gigi.testUtils.TestEmailReciever.TestMail;
16 import org.junit.Test;
18 public class TestMailManagement extends ManagedTest {
20 .getById(createVerifiedUser("fn", "ln", createUniqueName() + "uni@example.org", TEST_PASSWORD));
21 private String cookie;
22 private String path = MailOverview.DEFAULT_PATH;
24 public TestMailManagement() throws IOException {
25 cookie = login(u.getEmail(), TEST_PASSWORD);
26 assertTrue(isLoggedin(cookie));
30 public void testMailAddInternal() throws InterruptedException, GigiApiException {
31 EmailAddress adrr = new EmailAddress("test@test.tld", u);
32 adrr.insert(Language.getInstance("en"));
33 TestMail testMail = getMailReciever().recieve();
34 assertTrue(adrr.getAddress().equals(testMail.getTo()));
35 String hash = testMail.extractLink().substring(testMail.extractLink().lastIndexOf('=') + 1);
38 new EmailAddress("kurti ", u);
39 } catch (IllegalArgumentException e) {
47 public void testMailAddWeb() throws MalformedURLException, UnsupportedEncodingException, IOException {
48 String newMail = createUniqueName() + "uni@example.org";
49 assertNull(executeBasicWebInteraction(cookie, path, "addmail&newemail=" + URLEncoder.encode(newMail, "UTF-8"),
51 EmailAddress[] addrs = u.getEmails();
52 for (int i = 0; i < addrs.length; i++) {
53 if (addrs[i].getAddress().equals(newMail)) {
61 public void testMailAddWebFaulty() throws MalformedURLException, UnsupportedEncodingException, IOException {
62 String newMail = createUniqueName() + "uniexample.org";
63 assertNotNull(executeBasicWebInteraction(cookie, path,
64 "addmail&newemail=" + URLEncoder.encode(newMail, "UTF-8"), 1));
65 EmailAddress[] addrs = u.getEmails();
66 for (int i = 0; i < addrs.length; i++) {
67 if (addrs[i].getAddress().equals(newMail)) {