]> WPIA git - gigi.git/blob - tests/club/wpia/gigi/pages/orga/TestOrgDomain.java
Merge "upd: remove 'browser install'"
[gigi.git] / tests / club / wpia / gigi / pages / orga / TestOrgDomain.java
1 package club.wpia.gigi.pages.orga;
2
3 import static org.hamcrest.CoreMatchers.*;
4 import static org.junit.Assert.*;
5
6 import java.io.IOException;
7 import java.net.URLConnection;
8 import java.net.URLEncoder;
9
10 import org.junit.Test;
11
12 import club.wpia.gigi.GigiApiException;
13 import club.wpia.gigi.dbObjects.CATS.CATSType;
14 import club.wpia.gigi.dbObjects.Domain;
15 import club.wpia.gigi.dbObjects.Organisation;
16 import club.wpia.gigi.dbObjects.User;
17 import club.wpia.gigi.pages.account.domain.DomainOverview;
18 import club.wpia.gigi.testUtils.IOUtils;
19 import club.wpia.gigi.testUtils.OrgTest;
20
21 public class TestOrgDomain extends OrgTest {
22
23     public TestOrgDomain() throws IOException, GigiApiException {
24
25     }
26
27     @Test
28     public void testAdd() throws IOException, GigiApiException {
29         Organisation o1 = createUniqueOrg();
30         String dom = createUniqueName() + ".de";
31         assertNull(executeBasicWebInteraction(cookie, ViewOrgPage.DEFAULT_PATH + "/" + o1.getId(), "addDomain&domain=" + URLEncoder.encode(dom, "UTF-8"), 3));
32         Domain[] d = o1.getDomains();
33         assertEquals(1, d.length);
34         assertEquals(dom, d[0].getSuffix());
35     }
36
37     @Test
38     public void testDel() throws IOException, GigiApiException {
39         Organisation o1 = createUniqueOrg();
40         String dom = createUniqueName() + ".de";
41         Domain d = new Domain(u, o1, dom);
42         assertEquals(1, o1.getDomains().length);
43         assertNull(executeBasicWebInteraction(cookie, ViewOrgPage.DEFAULT_PATH + "/" + o1.getId(), "delete=" + d.getId(), 2));
44         assertEquals(0, o1.getDomains().length);
45     }
46
47     @Test
48     public void testBusinessAddWhileUser() throws IOException, GigiApiException {
49         Organisation o1 = createUniqueOrg();
50         String dom = createUniqueName() + ".de";
51         new Domain(u, u, dom);
52         try {
53             new Domain(u, o1, dom);
54             fail("Was able to add domain twice.");
55         } catch (GigiApiException e) {
56             assertEquals("Domain could not be inserted. Domain is already known to the system.", e.getMessage());
57             // expected
58         }
59         assertEquals(0, o1.getDomains().length);
60         assertEquals(1, u.getDomains().length);
61     }
62
63     @Test
64     public void testBusinessAddWhileOtherOrg() throws IOException, GigiApiException {
65         Organisation o1 = createUniqueOrg();
66         Organisation o2 = createUniqueOrg();
67
68         String dom = createUniqueName() + ".de";
69         new Domain(u, o1, dom);
70         try {
71             new Domain(u, o2, dom);
72             fail("Was able to add domain twice.");
73         } catch (GigiApiException e) {
74             assertEquals("Domain could not be inserted. Domain is already known to the system.", e.getMessage());
75             // expected
76         }
77         assertEquals(1, o1.getDomains().length);
78         assertEquals(0, o2.getDomains().length);
79         assertEquals(0, u.getDomains().length);
80     }
81
82     @Test
83     public void testBusinessAddInvalid() throws IOException, GigiApiException {
84         Organisation o1 = createUniqueOrg();
85         String dom = createUniqueName() + ".invalid-tld";
86         try {
87             new Domain(u, o1, dom);
88             fail("Was able to add invalid domain.");
89         } catch (GigiApiException e) {
90             // expected
91         }
92         assertEquals(0, o1.getDomains().length);
93         assertEquals(0, u.getDomains().length);
94     }
95
96     @Test
97     public void testDelAsAdmin() throws IOException, GigiApiException {
98         Organisation o = createUniqueOrg();
99         String dom = createUniqueName() + ".de";
100         Domain d = new Domain(u, o, dom);
101         assertEquals(1, o.getDomains().length);
102         User admin = createOrgAdmin(o);
103         addChallenge(admin.getId(), CATSType.ORG_ADMIN_DP_CHALLENGE_NAME);
104         String adminCookie = cookieWithCertificateLogin(admin);
105         assertNull(executeBasicWebInteraction(adminCookie, SwitchOrganisation.PATH, "org:" + o.getId() + "=y", 0));
106
107         // test that delete button is not displayed
108         URLConnection uc = get(adminCookie, DomainOverview.PATH);
109         uc.setDoOutput(true);
110         String res = IOUtils.readURL(uc);
111         assertThat(res, not(containsString("Delete")));
112
113         // test that domain cannot be deleted by organisation administrator
114         assertNull(executeBasicWebInteraction(adminCookie, SwitchOrganisation.PATH, "org:" + o.getId() + "=y", 0));
115         uc = post(adminCookie, DomainOverview.PATH, "delete=" + d.getId(), 0);
116         res = IOUtils.readURL(uc);
117         assertThat(res, containsString("You are not allowed to delete a domain."));
118
119         // verify that domain still belongs to organisation
120         assertEquals(1, o.getDomains().length);
121
122     }
123 }