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.junit.Test;
17 public class TestMailManagement extends ManagedTest {
19 .getById(createVerifiedUser("fn", "ln", createUniqueName() + "uni@example.org", TEST_PASSWORD));
20 private String cookie;
21 private String path = MailOverview.DEFAULT_PATH;
23 public TestMailManagement() throws IOException {
24 cookie = login(u.getEmail(), TEST_PASSWORD);
25 assertTrue(isLoggedin(cookie));
29 public void testMailAddInternal() throws InterruptedException, GigiApiException {
30 createVerifiedEmail(u);
34 public void testMailAddInternalFaulty() {
36 new EmailAddress("kurti ", u);
38 } catch (IllegalArgumentException e) {
44 public void testMailAddWeb() throws MalformedURLException, UnsupportedEncodingException, IOException {
45 String newMail = createUniqueName() + "uni@example.org";
46 assertNull(executeBasicWebInteraction(cookie, path, "addmail&newemail=" + URLEncoder.encode(newMail, "UTF-8"),
48 EmailAddress[] addrs = u.getEmails();
49 for (int i = 0; i < addrs.length; i++) {
50 if (addrs[i].getAddress().equals(newMail)) {
58 public void testMailAddWebFaulty() throws MalformedURLException, UnsupportedEncodingException, IOException {
59 String newMail = createUniqueName() + "uniexample.org";
60 assertNotNull(executeBasicWebInteraction(cookie, path,
61 "addmail&newemail=" + URLEncoder.encode(newMail, "UTF-8"), 1));
62 EmailAddress[] addrs = u.getEmails();
63 for (int i = 0; i < addrs.length; i++) {
64 if (addrs[i].getAddress().equals(newMail)) {
71 public void testMailSetDefaultWeb() throws MalformedURLException, UnsupportedEncodingException, IOException,
72 InterruptedException, GigiApiException {
73 EmailAddress adrr = createVerifiedEmail(u);
74 assertNull(executeBasicWebInteraction(cookie, path, "makedefault&emailid=" + adrr.getId()));
75 assertEquals(User.getById(u.getId()).getEmail(), adrr.getAddress());
79 public void testMailSetDefaultWebUnverified() throws MalformedURLException, UnsupportedEncodingException,
80 IOException, InterruptedException, GigiApiException {
81 EmailAddress adrr = new EmailAddress(createUniqueName() + "test@test.tld", u);
82 adrr.insert(Language.getInstance("en"));
83 assertNotNull(executeBasicWebInteraction(cookie, path, "makedefault&emailid=" + adrr.getId()));
84 assertNotEquals(User.getById(u.getId()).getEmail(), adrr.getAddress());
85 getMailReciever().clearMails();
89 public void testMailSetDefaultWebInvalidID() throws MalformedURLException, UnsupportedEncodingException,
90 IOException, InterruptedException, GigiApiException {
91 User u2 = User.getById(createVerifiedUser("fn", "ln", createUniqueName() + "uni@example.org", TEST_PASSWORD));
93 EmailAddress[] emails = u2.getEmails();
94 for (int i = 0; i < emails.length; i++) {
95 if (emails[i].getAddress().equals(u2.getEmail())) {
96 id = emails[i].getId();
99 assertNotEquals(id, -1);
100 assertNotNull(executeBasicWebInteraction(cookie, path, "makedefault&emailid=" + id));
101 assertNotEquals(User.getById(u.getId()).getEmail(), u2.getEmail());
102 getMailReciever().clearMails();
106 public void testMailDeleteWeb() throws InterruptedException, GigiApiException, MalformedURLException,
107 UnsupportedEncodingException, IOException {
108 EmailAddress addr = createVerifiedEmail(u);
109 assertNull(executeBasicWebInteraction(cookie, path, "delete&delid[]=" + addr.getId(), 0));
110 User u = User.getById(this.u.getId());
111 EmailAddress[] addresses = u.getEmails();
112 for (int i = 0; i < addresses.length; i++) {
113 assertNotEquals(addresses[i].getAddress(), addr.getAddress());
118 public void testMailDeleteWebMulti() throws InterruptedException, GigiApiException, MalformedURLException,
119 UnsupportedEncodingException, IOException {
120 EmailAddress[] addr = new EmailAddress[] { createVerifiedEmail(u), createVerifiedEmail(u) };
121 assertNull(executeBasicWebInteraction(cookie, path,
122 "delete&delid[]=" + addr[0].getId() + "&delid[]="
123 + addr[1].getId(), 0));
124 User u = User.getById(this.u.getId());
125 EmailAddress[] addresses = u.getEmails();
126 for (int i = 0; i < addresses.length; i++) {
127 assertNotEquals(addresses[i].getAddress(), addr[0].getAddress());
128 assertNotEquals(addresses[i].getAddress(), addr[1].getAddress());