]> WPIA git - gigi.git/blob - tests/org/cacert/gigi/TestDomain.java
de494f2b2702dd6d5268c7323b86117466088059
[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         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, "del.example.org");
69         d.insert();
70         d.delete();
71         Domain d2 = new Domain(us, "del.example.org");
72         d2.insert();
73     }
74
75     @Test
76     public void testDoubleDomainPrefix() throws InterruptedException, GigiApiException {
77         Domain d = new Domain(us, "pref.aexample.org");
78         d.insert();
79         Domain d2 = new Domain(us, "a.pref.aexample.org");
80         try {
81             d2.insert();
82             fail("expected exception");
83         } catch (GigiApiException e) {
84             // expected
85         }
86         Domain d3 = new Domain(us, "aexample.org");
87         try {
88             d3.insert();
89             fail("expected exception");
90         } catch (GigiApiException e) {
91             // expected
92         }
93     }
94
95     @Test
96     public void testDoubleInsertDomain() throws InterruptedException, GigiApiException {
97         Domain d = new Domain(us, "dins.example.org");
98         d.insert();
99         try {
100             d.insert();
101             fail("expected exception");
102         } catch (GigiApiException e) {
103             // expected
104         }
105     }
106
107 }