1 package org.cacert.gigi;
3 import static org.hamcrest.CoreMatchers.*;
4 import static org.junit.Assert.*;
7 import java.sql.SQLException;
8 import java.util.Calendar;
9 import java.util.Locale;
11 import org.cacert.gigi.localisation.Language;
12 import org.cacert.gigi.testUtils.ManagedTest;
13 import org.junit.Test;
15 public class TestObjectCache extends ManagedTest {
17 int uid = createVerifiedUser("fname", "lname", createUniqueName() + "@example.com", TEST_PASSWORD);
20 public void testUserCache() throws SQLException {
21 assertThat(User.getById(uid), is(sameInstance(User.getById(uid))));
26 u.setSuffix("suffix");
28 u.setEmail(createUniqueName() + "@example.org");
29 Calendar c = Calendar.getInstance();
31 u.setDob(new Date(c.getTime().getTime()));
32 u.setPreferredLocale(Locale.ENGLISH);
33 u.insert(TEST_PASSWORD);
35 assertThat(u, is(sameInstance(User.getById(u.getId()))));
36 assertThat(User.getById(u.getId()), is(sameInstance(User.getById(u.getId()))));
41 public void testDomainCache() throws GigiApiException {
42 Domain d = new Domain(User.getById(uid), "example.org");
45 assertThat(d, is(sameInstance(Domain.getById(d.getId()))));
46 assertThat(Domain.getById(d.getId()), is(sameInstance(Domain.getById(d.getId()))));
50 public void testEmailCache() {
51 EmailAddress em = new EmailAddress(createUniqueName() + "@example.org", User.getById(uid));
52 em.insert(Language.getInstance(Locale.ENGLISH));
54 assertThat(em, is(sameInstance(EmailAddress.getById(em.getId()))));
55 assertThat(EmailAddress.getById(em.getId()), is(sameInstance(EmailAddress.getById(em.getId()))));