]> WPIA git - gigi.git/blob - tests/org/cacert/gigi/util/TestNotary.java
Implement PoJam test.
[gigi.git] / tests / org / cacert / gigi / util / TestNotary.java
1 package org.cacert.gigi.util;
2
3 import java.sql.PreparedStatement;
4 import java.sql.SQLException;
5
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;
11
12 import static org.junit.Assert.*;
13
14 public class TestNotary extends ManagedTest {
15         @Test
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);
22                 }
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,
27                                 35, 35, 35};
28
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",
36                                         "2014-01-01"));
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"));
41                 }
42
43                 assertEquals(35, assurer.getMaxAssurePoints());
44
45                 assertEquals(2 + 60, assurer.getExperiencePoints());
46
47         }
48
49         @Test
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);
56                 }
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=?");
61                 ps.setInt(1, id);
62                 ps.execute();
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"));
73                 }
74         }
75 }