1 package org.cacert.gigi;
3 import static org.hamcrest.CoreMatchers.*;
4 import static org.junit.Assert.*;
6 import java.sql.SQLException;
7 import java.util.Calendar;
8 import java.util.Locale;
10 import org.cacert.gigi.dbObjects.Domain;
11 import org.cacert.gigi.dbObjects.EmailAddress;
12 import org.cacert.gigi.dbObjects.User;
13 import org.cacert.gigi.testUtils.ClientBusinessTest;
14 import org.junit.Test;
16 public class TestObjectCache extends ClientBusinessTest {
19 public void testUserCache() throws SQLException, GigiApiException {
20 assertThat(User.getById(id), is(sameInstance(User.getById(id))));
22 Calendar c = Calendar.getInstance();
23 c.set(1950, 1, 1, 0, 0, 0);
24 c.set(Calendar.MILLISECOND, 0);
25 User u = createUser("fname", "lname", createUniqueName() + "@example.org", TEST_PASSWORD);
27 assertThat(u, is(sameInstance(User.getById(u.getId()))));
28 assertThat(User.getById(u.getId()), is(sameInstance(User.getById(u.getId()))));
33 public void testDomainCache() throws GigiApiException {
34 Domain d = new Domain(u, u, "example.org");
36 assertThat(d, is(sameInstance(Domain.getById(d.getId()))));
37 assertThat(Domain.getById(d.getId()), is(sameInstance(Domain.getById(d.getId()))));
41 public void testEmailCache() throws GigiApiException {
42 EmailAddress em = new EmailAddress(u, createUniqueName() + "@example.org", Locale.ENGLISH);
44 assertThat(em, is(sameInstance(EmailAddress.getById(em.getId()))));
45 assertThat(EmailAddress.getById(em.getId()), is(sameInstance(EmailAddress.getById(em.getId()))));