1 package club.wpia.gigi.pages.orga;
3 import static org.junit.Assert.*;
5 import java.io.IOException;
6 import java.net.URLEncoder;
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;
16 public class TestOrgDomain extends OrgTest {
18 public TestOrgDomain() throws IOException, GigiApiException {
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());
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);
43 public void testBusinessAddWhileUser() throws IOException, GigiApiException {
44 Organisation o1 = createUniqueOrg();
45 String dom = createUniqueName() + ".de";
46 new Domain(u, u, dom);
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());
54 assertEquals(0, o1.getDomains().length);
55 assertEquals(1, u.getDomains().length);
59 public void testBusinessAddWhileOtherOrg() throws IOException, GigiApiException {
60 Organisation o1 = createUniqueOrg();
61 Organisation o2 = createUniqueOrg();
63 String dom = createUniqueName() + ".de";
64 new Domain(u, o1, dom);
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());
72 assertEquals(1, o1.getDomains().length);
73 assertEquals(0, o2.getDomains().length);
74 assertEquals(0, u.getDomains().length);
78 public void testBusinessAddInvalid() throws IOException, GigiApiException {
79 Organisation o1 = createUniqueOrg();
80 String dom = createUniqueName() + ".invalid-tld";
82 new Domain(u, o1, dom);
83 fail("Was able to add invalid domain.");
84 } catch (GigiApiException e) {
87 assertEquals(0, o1.getDomains().length);
88 assertEquals(0, u.getDomains().length);