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