import org.cacert.gigi.Language;
import org.cacert.gigi.User;
import org.cacert.gigi.testUtils.ManagedTest;
-import org.cacert.gigi.testUtils.TestEmailReciever.TestMail;
import org.junit.Test;
public class TestMailManagement extends ManagedTest {
@Test
public void testMailAddInternal() throws InterruptedException, GigiApiException {
- EmailAddress adrr = new EmailAddress(createUniqueName() + "test@test.tld", u);
- adrr.insert(Language.getInstance("en"));
- TestMail testMail = getMailReciever().recieve();
- assertTrue(adrr.getAddress().equals(testMail.getTo()));
- String hash = testMail.extractLink().substring(testMail.extractLink().lastIndexOf('=') + 1);
- adrr.verify(hash);
- getMailReciever().clearMails();
+ createVerifiedEmail(u);
}
@Test
@Test
public void testMailSetDefaultWeb() throws MalformedURLException, UnsupportedEncodingException, IOException,
InterruptedException, GigiApiException {
- EmailAddress adrr = new EmailAddress(createUniqueName() + "test@test.tld", u);
- adrr.insert(Language.getInstance("en"));
- TestMail testMail = getMailReciever().recieve();
- assertTrue(adrr.getAddress().equals(testMail.getTo()));
- String hash = testMail.extractLink().substring(testMail.extractLink().lastIndexOf('=') + 1);
- adrr.verify(hash);
+ EmailAddress adrr = createVerifiedEmail(u);
assertNull(executeBasicWebInteraction(cookie, path, "makedefault&emailid=" + adrr.getId()));
assertEquals(User.getById(u.getId()).getEmail(), adrr.getAddress());
- getMailReciever().clearMails();
}
@Test
assertNotEquals(User.getById(u.getId()).getEmail(), u2.getEmail());
getMailReciever().clearMails();
}
+
+ @Test
+ public void testMailDeleteWeb() throws InterruptedException, GigiApiException, MalformedURLException,
+ UnsupportedEncodingException, IOException {
+ EmailAddress addr = createVerifiedEmail(u);
+ assertNull(executeBasicWebInteraction(cookie, path, "delete&delid[]=" + addr.getId(), 0));
+ User u = User.getById(this.u.getId());
+ EmailAddress[] addresses = u.getEmails();
+ for (int i = 0; i < addresses.length; i++) {
+ assertNotEquals(addresses[i].getAddress(), addr.getAddress());
+ }
+ }
+
+ @Test
+ public void testMailDeleteWebMulti() throws InterruptedException, GigiApiException, MalformedURLException,
+ UnsupportedEncodingException, IOException {
+ EmailAddress[] addr = new EmailAddress[] { createVerifiedEmail(u), createVerifiedEmail(u) };
+ assertNull(executeBasicWebInteraction(cookie, path,
+ "delete&delid[]=" + addr[0].getId() + "&delid[]="
+ + addr[1].getId(), 0));
+ User u = User.getById(this.u.getId());
+ EmailAddress[] addresses = u.getEmails();
+ for (int i = 0; i < addresses.length; i++) {
+ assertNotEquals(addresses[i].getAddress(), addr[0].getAddress());
+ assertNotEquals(addresses[i].getAddress(), addr[1].getAddress());
+ }
+ }
}