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.Organisation;
11 import org.cacert.gigi.testUtils.OrgTest;
12 import org.junit.Test;
14 public class TestOrgDomain extends OrgTest {
16 public TestOrgDomain() throws IOException, GigiApiException {
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());
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);
41 public void testBusinessAddWhileUser() throws IOException, GigiApiException {
42 Organisation o1 = createUniqueOrg();
43 String dom = createUniqueName() + ".de";
44 new Domain(u, u, dom);
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());
52 assertEquals(0, o1.getDomains().length);
53 assertEquals(1, u.getDomains().length);
57 public void testBusinessAddWhileOtherOrg() throws IOException, GigiApiException {
58 Organisation o1 = createUniqueOrg();
59 Organisation o2 = createUniqueOrg();
61 String dom = createUniqueName() + ".de";
62 new Domain(u, o1, dom);
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());
70 assertEquals(1, o1.getDomains().length);
71 assertEquals(0, o2.getDomains().length);
72 assertEquals(0, u.getDomains().length);
76 public void testBusinessAddInvalid() throws IOException, GigiApiException {
77 Organisation o1 = createUniqueOrg();
78 String dom = createUniqueName() + ".invalid-tld";
80 new Domain(u, o1, dom);
81 fail("Was able to add invalid domain.");
82 } catch (GigiApiException e) {
85 assertEquals(0, o1.getDomains().length);
86 assertEquals(0, u.getDomains().length);