]> WPIA git - gigi.git/blob - tests/org/cacert/gigi/pages/account/TestMailManagement.java
Merge branch 'janis_work'
[gigi.git] / tests / org / cacert / gigi / pages / account / TestMailManagement.java
1 package org.cacert.gigi.pages.account;
2
3 import static org.junit.Assert.*;
4
5 import java.io.IOException;
6 import java.io.UnsupportedEncodingException;
7 import java.net.MalformedURLException;
8 import java.net.URLEncoder;
9
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;
17
18 public class TestMailManagement extends ManagedTest {
19         private User u = User
20                 .getById(createVerifiedUser("fn", "ln", createUniqueName() + "uni@example.org", TEST_PASSWORD));
21         private String cookie;
22         private String path = MailOverview.DEFAULT_PATH;
23
24         public TestMailManagement() throws IOException {
25                 cookie = login(u.getEmail(), TEST_PASSWORD);
26                 assertTrue(isLoggedin(cookie));
27         }
28
29         @Test
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);
36                 adrr.verify(hash);
37                 try {
38                         new EmailAddress("kurti ", u);
39                 } catch (IllegalArgumentException e) {
40                         // Intended.
41                         return;
42                 }
43                 fail();
44         }
45
46         @Test
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"),
50                         1));
51                 EmailAddress[] addrs = u.getEmails();
52                 for (int i = 0; i < addrs.length; i++) {
53                         if (addrs[i].getAddress().equals(newMail)) {
54                                 return;
55                         }
56                 }
57                 fail();
58         }
59
60         @Test
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)) {
68                                 fail();
69                         }
70                 }
71         }
72 }