]> WPIA git - gigi.git/blob - tests/org/cacert/gigi/TestDomain.java
936395db3dc193b1d6740786b1fd3a07537796c9
[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.testUtils.ManagedTest;
6 import org.junit.Test;
7
8 public class TestDomain extends ManagedTest {
9
10     private User us;
11
12     public TestDomain() {
13         int uid = createVerifiedUser("fn", "ln", createUniqueName() + "pr@test-email.de", TEST_PASSWORD);
14         us = User.getById(uid);
15     }
16
17     @Test
18     public void testDomain() throws InterruptedException, GigiApiException {
19         assertEquals(0, us.getDomains().length);
20         Domain d = new Domain(us, "v1.example.org");
21         assertEquals(0, d.getId());
22         d.insert();
23         Domain[] domains = us.getDomains();
24         assertEquals(1, domains.length);
25         assertEquals("v1.example.org", domains[0].getSuffix());
26         assertEquals(domains[0].getOwner().getId(), us.getId());
27         assertNotEquals(0, domains[0].getId());
28         assertNotEquals(0, d.getId());
29         assertEquals(d.getId(), domains[0].getId());
30
31         Domain d2 = new Domain(us, "v2.example.org");
32         assertEquals(0, d2.getId());
33         d2.insert();
34
35         domains = us.getDomains();
36         assertEquals(2, domains.length);
37         assertEquals("v2.example.org", domains[1].getSuffix());
38         assertEquals(domains[0].getOwner().getId(), us.getId());
39         assertEquals(domains[1].getOwner().getId(), us.getId());
40         assertNotEquals(0, domains[0].getId());
41         assertNotEquals(0, d.getId());
42         assertEquals(d.getId(), domains[0].getId());
43
44     }
45
46     @Test
47     public void testDoubleDomain() throws InterruptedException, GigiApiException {
48         Domain d = new Domain(us, "dub.example.org");
49         d.insert();
50         try {
51             Domain d2 = new Domain(us, "dub.example.org");
52             d2.insert();
53             fail("expected exception");
54         } catch (GigiApiException e) {
55             // expected
56         }
57     }
58
59     @Test
60     public void testDoubleDomainDelete() throws InterruptedException, GigiApiException {
61         Domain d = new Domain(us, "del.example.org");
62         d.insert();
63         d.delete();
64         Domain d2 = new Domain(us, "del.example.org");
65         d2.insert();
66     }
67
68     @Test
69     public void testDoubleDomainPrefix() throws InterruptedException, GigiApiException {
70         Domain d = new Domain(us, "pref.aexample.org");
71         d.insert();
72         Domain d2 = new Domain(us, "a.pref.aexample.org");
73         try {
74             d2.insert();
75             fail("expected exception");
76         } catch (GigiApiException e) {
77             // expected
78         }
79         Domain d3 = new Domain(us, "aexample.org");
80         try {
81             d3.insert();
82             fail("expected exception");
83         } catch (GigiApiException e) {
84             // expected
85         }
86     }
87
88     @Test
89     public void testDoubleInsertDomain() throws InterruptedException, GigiApiException {
90         Domain d = new Domain(us, "dins.example.org");
91         d.insert();
92         try {
93             d.insert();
94             fail("expected exception");
95         } catch (GigiApiException e) {
96             // expected
97         }
98     }
99
100 }