]> WPIA git - gigi.git/blob - tests/org/cacert/gigi/pages/orga/TestOrgDomain.java
Adding new fields to organisation account
[gigi.git] / tests / org / cacert / gigi / pages / orga / TestOrgDomain.java
1 package org.cacert.gigi.pages.orga;
2
3 import static org.junit.Assert.*;
4
5 import java.io.IOException;
6 import java.net.URLEncoder;
7
8 import org.cacert.gigi.GigiApiException;
9 import org.cacert.gigi.dbObjects.Domain;
10 import org.cacert.gigi.dbObjects.Group;
11 import org.cacert.gigi.dbObjects.Organisation;
12 import org.cacert.gigi.testUtils.ClientTest;
13 import org.junit.Test;
14
15 public class TestOrgDomain extends ClientTest {
16
17     public TestOrgDomain() throws IOException {
18         makeAssurer(u.getId());
19         u.grantGroup(u, Group.ORGASSURER);
20         clearCaches();
21         cookie = login(email, TEST_PASSWORD);
22     }
23
24     @Test
25     public void testAdd() throws IOException, GigiApiException {
26         Organisation o1 = createUniqueOrg();
27         String dom = createUniqueName() + ".de";
28         assertNull(executeBasicWebInteraction(cookie, ViewOrgPage.DEFAULT_PATH + "/" + o1.getId(), "addDomain&domain=" + URLEncoder.encode(dom, "UTF-8"), 3));
29         Domain[] d = o1.getDomains();
30         assertEquals(1, d.length);
31         assertEquals(dom, d[0].getSuffix());
32     }
33
34     @Test
35     public void testDel() throws IOException, GigiApiException {
36         Organisation o1 = createUniqueOrg();
37         String dom = createUniqueName() + ".de";
38         Domain d = new Domain(u, o1, dom);
39         assertEquals(1, o1.getDomains().length);
40         assertNull(executeBasicWebInteraction(cookie, ViewOrgPage.DEFAULT_PATH + "/" + o1.getId(), "delete=" + d.getId(), 2));
41         assertEquals(0, o1.getDomains().length);
42     }
43
44     @Test
45     public void testBusinessAddWhileUser() throws IOException, GigiApiException {
46         Organisation o1 = createUniqueOrg();
47         String dom = createUniqueName() + ".de";
48         new Domain(u, u, dom);
49         try {
50             new Domain(u, o1, dom);
51             fail("Was able to add domain twice.");
52         } catch (GigiApiException e) {
53             assertEquals("Domain could not be inserted. Domain is already known to the system.", e.getMessage());
54             // expected
55         }
56         assertEquals(0, o1.getDomains().length);
57         assertEquals(1, u.getDomains().length);
58     }
59
60     @Test
61     public void testBusinessAddWhileOtherOrg() throws IOException, GigiApiException {
62         Organisation o1 = createUniqueOrg();
63         Organisation o2 = createUniqueOrg();
64
65         String dom = createUniqueName() + ".de";
66         new Domain(u, o1, dom);
67         try {
68             new Domain(u, o2, dom);
69             fail("Was able to add domain twice.");
70         } catch (GigiApiException e) {
71             assertEquals("Domain could not be inserted. Domain is already known to the system.", e.getMessage());
72             // expected
73         }
74         assertEquals(1, o1.getDomains().length);
75         assertEquals(0, o2.getDomains().length);
76         assertEquals(0, u.getDomains().length);
77     }
78
79     private Organisation createUniqueOrg() throws GigiApiException {
80         Organisation o1 = new Organisation(createUniqueName(), "st", "pr", "city", "test@example.com", "", "", u);
81         return o1;
82     }
83
84     @Test
85     public void testBusinessAddInvalid() throws IOException, GigiApiException {
86         Organisation o1 = createUniqueOrg();
87         String dom = createUniqueName() + ".invalid-tld";
88         try {
89             new Domain(u, o1, dom);
90             fail("Was able to add invalid domain.");
91         } catch (GigiApiException e) {
92             // expected
93         }
94         assertEquals(0, o1.getDomains().length);
95         assertEquals(0, u.getDomains().length);
96     }
97 }