]> WPIA git - gigi.git/blob - tests/org/cacert/gigi/TestDomain.java
UPD: add timeouts to testssl so that we could try to debug.
[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, "v1.example.org");
23         assertEquals(0, d.getId());
24         d.insert();
25         Domain[] domains = us.getDomains();
26         assertEquals(1, domains.length);
27         assertEquals("v1.example.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         assertEquals("v2.example.org", domains[1].getSuffix());
40         assertEquals(domains[0].getOwner().getId(), us.getId());
41         assertEquals(domains[1].getOwner().getId(), us.getId());
42         assertNotEquals(0, domains[0].getId());
43         assertNotEquals(0, d.getId());
44         assertEquals(d.getId(), domains[0].getId());
45
46     }
47
48     @Test
49     public void testDoubleDomain() throws InterruptedException, GigiApiException {
50         Domain d = new Domain(us, "dub.example.org");
51         d.insert();
52         try {
53             Domain d2 = new Domain(us, "dub.example.org");
54             d2.insert();
55             fail("expected exception");
56         } catch (GigiApiException e) {
57             // expected
58         }
59     }
60
61     @Test
62     public void testDoubleDomainDelete() throws InterruptedException, GigiApiException {
63         Domain d = new Domain(us, "del.example.org");
64         d.insert();
65         d.delete();
66         Domain d2 = new Domain(us, "del.example.org");
67         d2.insert();
68     }
69
70     @Test
71     public void testDoubleDomainPrefix() throws InterruptedException, GigiApiException {
72         Domain d = new Domain(us, "pref.aexample.org");
73         d.insert();
74         Domain d2 = new Domain(us, "a.pref.aexample.org");
75         try {
76             d2.insert();
77             fail("expected exception");
78         } catch (GigiApiException e) {
79             // expected
80         }
81         Domain d3 = new Domain(us, "aexample.org");
82         try {
83             d3.insert();
84             fail("expected exception");
85         } catch (GigiApiException e) {
86             // expected
87         }
88     }
89
90     @Test
91     public void testDoubleInsertDomain() throws InterruptedException, GigiApiException {
92         Domain d = new Domain(us, "dins.example.org");
93         d.insert();
94         try {
95             d.insert();
96             fail("expected exception");
97         } catch (GigiApiException e) {
98             // expected
99         }
100     }
101
102 }