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(createUniqueName() + "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);
37 getMailReciever().clearMails();
41 public void testMailAddInternalFaulty() {
43 new EmailAddress("kurti ", u);
45 } catch (IllegalArgumentException e) {
51 public void testMailAddWeb() throws MalformedURLException, UnsupportedEncodingException, IOException {
52 String newMail = createUniqueName() + "uni@example.org";
53 assertNull(executeBasicWebInteraction(cookie, path, "addmail&newemail=" + URLEncoder.encode(newMail, "UTF-8"),
55 EmailAddress[] addrs = u.getEmails();
56 for (int i = 0; i < addrs.length; i++) {
57 if (addrs[i].getAddress().equals(newMail)) {
65 public void testMailAddWebFaulty() throws MalformedURLException, UnsupportedEncodingException, IOException {
66 String newMail = createUniqueName() + "uniexample.org";
67 assertNotNull(executeBasicWebInteraction(cookie, path,
68 "addmail&newemail=" + URLEncoder.encode(newMail, "UTF-8"), 1));
69 EmailAddress[] addrs = u.getEmails();
70 for (int i = 0; i < addrs.length; i++) {
71 if (addrs[i].getAddress().equals(newMail)) {
78 public void testMailSetDefaultWeb() throws MalformedURLException, UnsupportedEncodingException, IOException,
79 InterruptedException, GigiApiException {
80 EmailAddress adrr = new EmailAddress(createUniqueName() + "test@test.tld", u);
81 adrr.insert(Language.getInstance("en"));
82 TestMail testMail = getMailReciever().recieve();
83 assertTrue(adrr.getAddress().equals(testMail.getTo()));
84 String hash = testMail.extractLink().substring(testMail.extractLink().lastIndexOf('=') + 1);
86 assertNull(executeBasicWebInteraction(cookie, path, "makedefault&emailid=" + adrr.getId()));
87 assertEquals(User.getById(u.getId()).getEmail(), adrr.getAddress());
88 getMailReciever().clearMails();
92 public void testMailSetDefaultWebUnverified() throws MalformedURLException, UnsupportedEncodingException,
93 IOException, InterruptedException, GigiApiException {
94 EmailAddress adrr = new EmailAddress(createUniqueName() + "test@test.tld", u);
95 adrr.insert(Language.getInstance("en"));
96 assertNotNull(executeBasicWebInteraction(cookie, path, "makedefault&emailid=" + adrr.getId()));
97 assertNotEquals(User.getById(u.getId()).getEmail(), adrr.getAddress());
98 getMailReciever().clearMails();
102 public void testMailSetDefaultWebInvalidID() throws MalformedURLException, UnsupportedEncodingException,
103 IOException, InterruptedException, GigiApiException {
104 User u2 = User.getById(createVerifiedUser("fn", "ln", createUniqueName() + "uni@example.org", TEST_PASSWORD));
106 EmailAddress[] emails = u2.getEmails();
107 for (int i = 0; i < emails.length; i++) {
108 if (emails[i].getAddress().equals(u2.getEmail())) {
109 id = emails[i].getId();
112 assertNotEquals(id, -1);
113 assertNotNull(executeBasicWebInteraction(cookie, path, "makedefault&emailid=" + id));
114 assertNotEquals(User.getById(u.getId()).getEmail(), u2.getEmail());
115 getMailReciever().clearMails();