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 {
16 public void testNormalAssurance() throws SQLException {
17 User[] users = new User[30];
18 for (int i = 0; i < users.length; i++) {
19 int id = createVerifiedUser("fn" + i, "ln" + i, createUniqueName()
20 + "@email.org", "xvXV12°§");
21 users[i] = new User(id);
23 User assurer = new User(createAssuranceUser("fn", "ln",
24 createUniqueName() + "@email.org", "xvXV12°§"));
25 int[] result = new int[]{10, 10, 10, 10, 15, 15, 15, 15, 15, 20, 20,
26 20, 20, 20, 25, 25, 25, 25, 25, 30, 30, 30, 30, 30, 35, 35, 35,
29 System.out.println(result.length);
30 assertNotEquals(AssuranceResult.ASSURANCE_SUCCEDED, Notary.assure(
31 assurer, users[0], -1, "test-notary", "2014-01-01"));
32 for (int i = 0; i < result.length; i++) {
33 assertEquals(result[i], assurer.getMaxAssurePoints());
34 assertNotEquals(AssuranceResult.ASSURANCE_SUCCEDED, Notary.assure(
35 assurer, users[i], result[i] + 1, "test-notary",
37 assertEquals(AssuranceResult.ASSURANCE_SUCCEDED, Notary.assure(
38 assurer, users[i], result[i], "test-notary", "2014-01-01"));
39 assertNotEquals(AssuranceResult.ASSURANCE_SUCCEDED, Notary.assure(
40 assurer, users[i], result[i], "test-notary", "2014-01-01"));
43 assertEquals(35, assurer.getMaxAssurePoints());
45 assertEquals(2 + 60, assurer.getExperiencePoints());
50 public void testPoJam() throws SQLException {
51 User[] users = new User[30];
52 for (int i = 0; i < users.length; i++) {
53 int id = createVerifiedUser("fn" + i, "ln" + i, createUniqueName()
54 + "@email.org", "xvXV12°§");
55 users[i] = new User(id);
57 int id = createAssuranceUser("fn", "ln", createUniqueName()
58 + "@email.org", "xvXV12°§");
59 PreparedStatement ps = DatabaseConnection.getInstance().prepare(
60 "UPDATE users SET dob=NOW() WHERE id=?");
63 User assurer = new User(id);
64 for (int i = 0; i < users.length; i++) {
65 assertNotEquals(AssuranceResult.ASSURANCE_SUCCEDED, Notary.assure(
66 assurer, users[i], -1, "test-notary", "2014-01-01"));
67 assertNotEquals(AssuranceResult.ASSURANCE_SUCCEDED, Notary.assure(
68 assurer, users[i], 11, "test-notary", "2014-01-01"));
69 assertEquals(AssuranceResult.ASSURANCE_SUCCEDED, Notary.assure(
70 assurer, users[i], 10, "test-notary", "2014-01-01"));
71 assertNotEquals(AssuranceResult.ASSURANCE_SUCCEDED, Notary.assure(
72 assurer, users[i], 10, "test-notary", "2014-01-01"));