1 package org.cacert.gigi.pages.orga;
3 import static org.junit.Assert.*;
5 import java.io.IOException;
6 import java.net.URLEncoder;
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;
15 public class TestOrgDomain extends ClientTest {
17 public TestOrgDomain() throws IOException {
18 makeAssurer(u.getId());
19 u.grantGroup(u, Group.ORGASSURER);
21 cookie = login(email, TEST_PASSWORD);
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());
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);
45 public void testBusinessAddWhileUser() throws IOException, GigiApiException {
46 Organisation o1 = createUniqueOrg();
47 String dom = createUniqueName() + ".de";
48 new Domain(u, u, dom);
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());
56 assertEquals(0, o1.getDomains().length);
57 assertEquals(1, u.getDomains().length);
61 public void testBusinessAddWhileOtherOrg() throws IOException, GigiApiException {
62 Organisation o1 = createUniqueOrg();
63 Organisation o2 = createUniqueOrg();
65 String dom = createUniqueName() + ".de";
66 new Domain(u, o1, dom);
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());
74 assertEquals(1, o1.getDomains().length);
75 assertEquals(0, o2.getDomains().length);
76 assertEquals(0, u.getDomains().length);
79 private Organisation createUniqueOrg() throws GigiApiException {
80 Organisation o1 = new Organisation(createUniqueName(), "st", "pr", "city", "test@example.com", "", "", u);
85 public void testBusinessAddInvalid() throws IOException, GigiApiException {
86 Organisation o1 = createUniqueOrg();
87 String dom = createUniqueName() + ".invalid-tld";
89 new Domain(u, o1, dom);
90 fail("Was able to add invalid domain.");
91 } catch (GigiApiException e) {
94 assertEquals(0, o1.getDomains().length);
95 assertEquals(0, u.getDomains().length);