]> WPIA git - gigi.git/blob - tests/club/wpia/gigi/dbObjects/TestEmailAddress.java
add: check that new email address is not linked to organisation domain
[gigi.git] / tests / club / wpia / gigi / dbObjects / TestEmailAddress.java
1 package club.wpia.gigi.dbObjects;
2
3 import static org.junit.Assert.*;
4
5 import java.io.IOException;
6 import java.util.Locale;
7
8 import org.junit.Test;
9
10 import club.wpia.gigi.GigiApiException;
11 import club.wpia.gigi.testUtils.OrgTest;
12
13 public class TestEmailAddress extends OrgTest {
14
15     public TestEmailAddress() throws IOException, GigiApiException {
16
17     }
18
19     @Test
20     public void testAddEmail() {
21         String email = createUniqueName() + "@email.com";
22         assertNull(addEmailAddress(email));
23
24         // add known email address
25         assertEquals("The email address is already known to the system.", addEmailAddress(email));
26
27         // add invalid email address
28         email = createUniqueName();
29         assertEquals("Invalid email.", addEmailAddress(email));
30
31         // add invalid email address
32         email = createUniqueName() + "@email";
33         assertEquals("Invalid email.", addEmailAddress(email));
34
35         // add email address with organisation domain
36         String dom = createUniqueName() + ".de";
37         try {
38             Organisation o1 = createUniqueOrg();
39             new Domain(u, o1, dom);
40         } catch (GigiApiException e) {
41             // nothing to do
42         }
43         email = createUniqueName() + "@" + dom;
44         assertEquals("The entered email address belongs to a registered organisation. Please contact the organisation to issue certificates for this email address.", addEmailAddress(email));
45
46     }
47
48     private String addEmailAddress(String email) {
49         try {
50             EmailAddress addr = new EmailAddress(u, email, Locale.ENGLISH);
51             getMailReceiver().receive(addr.getAddress());
52         } catch (IllegalArgumentException e) {
53             return e.getMessage();
54         } catch (GigiApiException e) {
55             return e.getMessage();
56         }
57         return null;
58     }
59
60 }