1 package org.cacert.gigi.util;
3 import java.sql.PreparedStatement;
4 import java.sql.SQLException;
6 import org.cacert.gigi.User;
7 import org.cacert.gigi.database.DatabaseConnection;
8 import org.cacert.gigi.testUtils.ManagedTest;
9 import org.cacert.gigi.util.Notary.AssuranceResult;
10 import org.junit.Test;
12 import static org.junit.Assert.*;
14 public class TestNotary extends ManagedTest {
17 public void testNormalAssurance() throws SQLException {
18 User[] users = new User[30];
19 for (int i = 0; i < users.length; i++) {
20 int id = createVerifiedUser("fn" + i, "ln" + i, createUniqueName() + "@email.org", TEST_PASSWORD);
21 users[i] = new User(id);
23 User assurer = new User(createAssuranceUser("fn", "ln", createUniqueName() + "@email.org", TEST_PASSWORD));
24 int[] result = new int[] {
25 10, 10, 10, 10, 15, 15, 15, 15, 15, 20, 20, 20, 20, 20, 25, 25, 25, 25, 25, 30, 30, 30, 30, 30, 35, 35, 35, 35, 35, 35
28 assertNotEquals(AssuranceResult.ASSURANCE_SUCCEDED, Notary.assure(assurer, users[0], -1, "test-notary", "2014-01-01"));
29 for (int i = 0; i < result.length; i++) {
30 assertEquals(result[i], assurer.getMaxAssurePoints());
31 assertNotEquals(AssuranceResult.ASSURANCE_SUCCEDED, Notary.assure(assurer, users[i], result[i] + 1, "test-notary", "2014-01-01"));
32 assertEquals(AssuranceResult.ASSURANCE_SUCCEDED, Notary.assure(assurer, users[i], result[i], "test-notary", "2014-01-01"));
33 assertNotEquals(AssuranceResult.ASSURANCE_SUCCEDED, Notary.assure(assurer, users[i], result[i], "test-notary", "2014-01-01"));
36 assertEquals(35, assurer.getMaxAssurePoints());
38 assertEquals(2 + 60, assurer.getExperiencePoints());
43 public void testPoJam() throws SQLException {
44 User[] users = new User[30];
45 for (int i = 0; i < users.length; i++) {
46 int id = createVerifiedUser("fn" + i, "ln" + i, createUniqueName() + "@email.org", TEST_PASSWORD);
47 users[i] = new User(id);
49 int id = createAssuranceUser("fn", "ln", createUniqueName() + "@email.org", TEST_PASSWORD);
50 PreparedStatement ps = DatabaseConnection.getInstance().prepare("UPDATE users SET dob=NOW() WHERE id=?");
53 User assurer = new User(id);
54 for (int i = 0; i < users.length; i++) {
55 assertNotEquals(AssuranceResult.ASSURANCE_SUCCEDED, Notary.assure(assurer, users[i], -1, "test-notary", "2014-01-01"));
56 assertNotEquals(AssuranceResult.ASSURANCE_SUCCEDED, Notary.assure(assurer, users[i], 11, "test-notary", "2014-01-01"));
57 assertEquals(AssuranceResult.ASSURANCE_SUCCEDED, Notary.assure(assurer, users[i], 10, "test-notary", "2014-01-01"));
58 assertNotEquals(AssuranceResult.ASSURANCE_SUCCEDED, Notary.assure(assurer, users[i], 10, "test-notary", "2014-01-01"));