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();