]> WPIA git - gigi.git/blob - tests/org/cacert/gigi/TestDomain.java
Merge "Suggestions to enhance the SQL call pattern."
[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, us, "v1example.org");
23         Domain[] domains = us.getDomains();
24         assertEquals(1, domains.length);
25         assertEquals("v1example.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         new Domain(us, us, "v2-example.org");
32
33         domains = us.getDomains();
34         assertEquals(2, domains.length);
35         if ( !domains[1].getSuffix().equals("v2-example.org")) {
36             Domain d1 = domains[0];
37             domains[0] = domains[1];
38             domains[1] = d1;
39         }
40         assertEquals("v2-example.org", domains[1].getSuffix());
41         assertEquals(domains[0].getOwner().getId(), us.getId());
42         assertEquals(domains[1].getOwner().getId(), us.getId());
43         assertNotEquals(0, domains[0].getId());
44         assertNotEquals(0, d.getId());
45         assertEquals(d.getId(), domains[0].getId());
46
47     }
48
49     @Test
50     public void testDoubleDomain() throws InterruptedException, GigiApiException {
51         new Domain(us, us, "dub-example.org");
52         try {
53             new Domain(us, us, "dub-example.org");
54             fail("expected exception, was able to insert domain (with different case) a second time");
55         } catch (GigiApiException e) {
56             // expected
57         }
58     }
59
60     @Test
61     public void testDoubleDomainCase() throws InterruptedException, GigiApiException {
62         Domain d = new Domain(us, us, "dub2-ExaMple.Org");
63         assertEquals("dub2-example.org", d.getSuffix());
64         try {
65             new Domain(us, us, "duB2-eXample.oRG");
66             fail("expected exception, was able to insert domain (with different case) a second time");
67         } catch (GigiApiException e) {
68             // expected
69         }
70     }
71
72     @Test
73     public void testDoubleDomainDelete() throws InterruptedException, GigiApiException {
74         Domain d = new Domain(us, us, "delexample.org");
75         d.delete();
76         new Domain(us, us, "delexample.org");
77     }
78
79 }