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