]> WPIA git - gigi.git/blob - tests/org/cacert/gigi/TestDomain.java
ADD: more advanced domain name verification (public suffix, punycode)
[gigi.git] / tests / org / cacert / gigi / TestDomain.java
1 package org.cacert.gigi;
2
3 import static org.junit.Assert.*;
4
5 import org.cacert.gigi.dbObjects.Domain;
6 import org.cacert.gigi.dbObjects.User;
7 import org.cacert.gigi.testUtils.ManagedTest;
8 import org.junit.Test;
9
10 public class TestDomain extends ManagedTest {
11
12     private User us;
13
14     public TestDomain() {
15         int uid = createVerifiedUser("fn", "ln", createUniqueName() + "pr@test-email.de", TEST_PASSWORD);
16         us = User.getById(uid);
17     }
18
19     @Test
20     public void testDomain() throws InterruptedException, GigiApiException {
21         assertEquals(0, us.getDomains().length);
22         Domain d = new Domain(us, "v1example.org");
23         assertEquals(0, d.getId());
24         d.insert();
25         Domain[] domains = us.getDomains();
26         assertEquals(1, domains.length);
27         assertEquals("v1example.org", domains[0].getSuffix());
28         assertEquals(domains[0].getOwner().getId(), us.getId());
29         assertNotEquals(0, domains[0].getId());
30         assertNotEquals(0, d.getId());
31         assertEquals(d.getId(), domains[0].getId());
32
33         Domain d2 = new Domain(us, "v2-example.org");
34         assertEquals(0, d2.getId());
35         d2.insert();
36
37         domains = us.getDomains();
38         assertEquals(2, domains.length);
39         if ( !domains[1].getSuffix().equals("v2-example.org")) {
40             Domain d1 = domains[0];
41             domains[0] = domains[1];
42             domains[1] = d1;
43         }
44         assertEquals("v2-example.org", domains[1].getSuffix());
45         assertEquals(domains[0].getOwner().getId(), us.getId());
46         assertEquals(domains[1].getOwner().getId(), us.getId());
47         assertNotEquals(0, domains[0].getId());
48         assertNotEquals(0, d.getId());
49         assertEquals(d.getId(), domains[0].getId());
50
51     }
52
53     @Test
54     public void testDoubleDomain() throws InterruptedException, GigiApiException {
55         Domain d = new Domain(us, "dub-example.org");
56         d.insert();
57         try {
58             Domain d2 = new Domain(us, "dub-example.org");
59             d2.insert();
60             fail("expected exception");
61         } catch (GigiApiException e) {
62             // expected
63         }
64     }
65
66     @Test
67     public void testDoubleDomainDelete() throws InterruptedException, GigiApiException {
68         Domain d = new Domain(us, "delexample.org");
69         d.insert();
70         d.delete();
71         Domain d2 = new Domain(us, "delexample.org");
72         d2.insert();
73     }
74
75     @Test
76     public void testDoubleInsertDomain() throws InterruptedException, GigiApiException {
77         Domain d = new Domain(us, "dins-example.org");
78         d.insert();
79         try {
80             d.insert();
81             fail("expected exception");
82         } catch (GigiApiException e) {
83             // expected
84         }
85     }
86
87 }