]> WPIA git - gigi.git/blob - tests/org/cacert/gigi/pages/orga/TestOrgDomain.java
d1b930db2edc0627b502d213492d2b393a0cdb24
[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.Organisation;
11 import org.cacert.gigi.testUtils.OrgTest;
12 import org.junit.Test;
13
14 public class TestOrgDomain extends OrgTest {
15
16     public TestOrgDomain() throws IOException {
17
18     }
19
20     @Test
21     public void testAdd() throws IOException, GigiApiException {
22         Organisation o1 = createUniqueOrg();
23         String dom = createUniqueName() + ".de";
24         assertNull(executeBasicWebInteraction(cookie, ViewOrgPage.DEFAULT_PATH + "/" + o1.getId(), "addDomain&domain=" + URLEncoder.encode(dom, "UTF-8"), 3));
25         Domain[] d = o1.getDomains();
26         assertEquals(1, d.length);
27         assertEquals(dom, d[0].getSuffix());
28     }
29
30     @Test
31     public void testDel() throws IOException, GigiApiException {
32         Organisation o1 = createUniqueOrg();
33         String dom = createUniqueName() + ".de";
34         Domain d = new Domain(u, o1, dom);
35         assertEquals(1, o1.getDomains().length);
36         assertNull(executeBasicWebInteraction(cookie, ViewOrgPage.DEFAULT_PATH + "/" + o1.getId(), "delete=" + d.getId(), 2));
37         assertEquals(0, o1.getDomains().length);
38     }
39
40     @Test
41     public void testBusinessAddWhileUser() throws IOException, GigiApiException {
42         Organisation o1 = createUniqueOrg();
43         String dom = createUniqueName() + ".de";
44         new Domain(u, u, dom);
45         try {
46             new Domain(u, o1, dom);
47             fail("Was able to add domain twice.");
48         } catch (GigiApiException e) {
49             assertEquals("Domain could not be inserted. Domain is already known to the system.", e.getMessage());
50             // expected
51         }
52         assertEquals(0, o1.getDomains().length);
53         assertEquals(1, u.getDomains().length);
54     }
55
56     @Test
57     public void testBusinessAddWhileOtherOrg() throws IOException, GigiApiException {
58         Organisation o1 = createUniqueOrg();
59         Organisation o2 = createUniqueOrg();
60
61         String dom = createUniqueName() + ".de";
62         new Domain(u, o1, dom);
63         try {
64             new Domain(u, o2, dom);
65             fail("Was able to add domain twice.");
66         } catch (GigiApiException e) {
67             assertEquals("Domain could not be inserted. Domain is already known to the system.", e.getMessage());
68             // expected
69         }
70         assertEquals(1, o1.getDomains().length);
71         assertEquals(0, o2.getDomains().length);
72         assertEquals(0, u.getDomains().length);
73     }
74
75     @Test
76     public void testBusinessAddInvalid() throws IOException, GigiApiException {
77         Organisation o1 = createUniqueOrg();
78         String dom = createUniqueName() + ".invalid-tld";
79         try {
80             new Domain(u, o1, dom);
81             fail("Was able to add invalid domain.");
82         } catch (GigiApiException e) {
83             // expected
84         }
85         assertEquals(0, o1.getDomains().length);
86         assertEquals(0, u.getDomains().length);
87     }
88 }