X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=tests%2Forg%2Fcacert%2Fgigi%2Fpages%2Forga%2FTestOrgDomain.java;h=b24bb83e9caa1ea6072b323d0c7b438a76cef89d;hp=0ee3b4094ece94ab7c2106271a9c096af0bc85c4;hb=d0470c5987aaecbc444c7100319df69b6f740680;hpb=63bda8ada49680a55380847ab120724e7d377f7b diff --git a/tests/org/cacert/gigi/pages/orga/TestOrgDomain.java b/tests/org/cacert/gigi/pages/orga/TestOrgDomain.java index 0ee3b409..b24bb83e 100644 --- a/tests/org/cacert/gigi/pages/orga/TestOrgDomain.java +++ b/tests/org/cacert/gigi/pages/orga/TestOrgDomain.java @@ -7,23 +7,19 @@ import java.net.URLEncoder; import org.cacert.gigi.GigiApiException; import org.cacert.gigi.dbObjects.Domain; -import org.cacert.gigi.dbObjects.Group; import org.cacert.gigi.dbObjects.Organisation; -import org.cacert.gigi.testUtils.ClientTest; +import org.cacert.gigi.testUtils.OrgTest; import org.junit.Test; -public class TestOrgDomain extends ClientTest { +public class TestOrgDomain extends OrgTest { + + public TestOrgDomain() throws IOException, GigiApiException { - public TestOrgDomain() throws IOException { - makeAssurer(u.getId()); - u.grantGroup(u, Group.ORGASSURER); - clearCaches(); - cookie = login(email, TEST_PASSWORD); } @Test public void testAdd() throws IOException, GigiApiException { - Organisation o1 = new Organisation(createUniqueName(), "st", "pr", "city", "test@example.com", u); + Organisation o1 = createUniqueOrg(); String dom = createUniqueName() + ".de"; assertNull(executeBasicWebInteraction(cookie, ViewOrgPage.DEFAULT_PATH + "/" + o1.getId(), "addDomain&domain=" + URLEncoder.encode(dom, "UTF-8"), 3)); Domain[] d = o1.getDomains(); @@ -33,11 +29,60 @@ public class TestOrgDomain extends ClientTest { @Test public void testDel() throws IOException, GigiApiException { - Organisation o1 = new Organisation(createUniqueName(), "st", "pr", "city", "test@example.com", u); + Organisation o1 = createUniqueOrg(); String dom = createUniqueName() + ".de"; Domain d = new Domain(u, o1, dom); assertEquals(1, o1.getDomains().length); assertNull(executeBasicWebInteraction(cookie, ViewOrgPage.DEFAULT_PATH + "/" + o1.getId(), "delete=" + d.getId(), 2)); assertEquals(0, o1.getDomains().length); } + + @Test + public void testBusinessAddWhileUser() throws IOException, GigiApiException { + Organisation o1 = createUniqueOrg(); + String dom = createUniqueName() + ".de"; + new Domain(u, u, dom); + try { + new Domain(u, o1, dom); + fail("Was able to add domain twice."); + } catch (GigiApiException e) { + assertEquals("Domain could not be inserted. Domain is already known to the system.", e.getMessage()); + // expected + } + assertEquals(0, o1.getDomains().length); + assertEquals(1, u.getDomains().length); + } + + @Test + public void testBusinessAddWhileOtherOrg() throws IOException, GigiApiException { + Organisation o1 = createUniqueOrg(); + Organisation o2 = createUniqueOrg(); + + String dom = createUniqueName() + ".de"; + new Domain(u, o1, dom); + try { + new Domain(u, o2, dom); + fail("Was able to add domain twice."); + } catch (GigiApiException e) { + assertEquals("Domain could not be inserted. Domain is already known to the system.", e.getMessage()); + // expected + } + assertEquals(1, o1.getDomains().length); + assertEquals(0, o2.getDomains().length); + assertEquals(0, u.getDomains().length); + } + + @Test + public void testBusinessAddInvalid() throws IOException, GigiApiException { + Organisation o1 = createUniqueOrg(); + String dom = createUniqueName() + ".invalid-tld"; + try { + new Domain(u, o1, dom); + fail("Was able to add invalid domain."); + } catch (GigiApiException e) { + // expected + } + assertEquals(0, o1.getDomains().length); + assertEquals(0, u.getDomains().length); + } }