]> WPIA git - gigi.git/blob - tests/org/cacert/gigi/util/TestNotary.java
[EMPTY] Formatting with configured formatter.
[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() + "@email.org", "xvXV12°§");
20                         users[i] = new User(id);
21                 }
22                 User assurer = new User(createAssuranceUser("fn", "ln", createUniqueName() + "@email.org", "xvXV12°§"));
23                 int[] result = new int[] { 10, 10, 10, 10, 15, 15, 15, 15, 15, 20, 20, 20, 20, 20, 25, 25, 25, 25, 25, 30, 30,
24                                 30, 30, 30, 35, 35, 35, 35, 35, 35 };
25
26                 System.out.println(result.length);
27                 assertNotEquals(AssuranceResult.ASSURANCE_SUCCEDED,
28                         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,
32                                 Notary.assure(assurer, users[i], result[i] + 1, "test-notary", "2014-01-01"));
33                         assertEquals(AssuranceResult.ASSURANCE_SUCCEDED,
34                                 Notary.assure(assurer, users[i], result[i], "test-notary", "2014-01-01"));
35                         assertNotEquals(AssuranceResult.ASSURANCE_SUCCEDED,
36                                 Notary.assure(assurer, users[i], result[i], "test-notary", "2014-01-01"));
37                 }
38
39                 assertEquals(35, assurer.getMaxAssurePoints());
40
41                 assertEquals(2 + 60, assurer.getExperiencePoints());
42
43         }
44
45         @Test
46         public void testPoJam() throws SQLException {
47                 User[] users = new User[30];
48                 for (int i = 0; i < users.length; i++) {
49                         int id = createVerifiedUser("fn" + i, "ln" + i, createUniqueName() + "@email.org", "xvXV12°§");
50                         users[i] = new User(id);
51                 }
52                 int id = createAssuranceUser("fn", "ln", createUniqueName() + "@email.org", "xvXV12°§");
53                 PreparedStatement ps = DatabaseConnection.getInstance().prepare("UPDATE users SET dob=NOW() WHERE id=?");
54                 ps.setInt(1, id);
55                 ps.execute();
56                 User assurer = new User(id);
57                 for (int i = 0; i < users.length; i++) {
58                         assertNotEquals(AssuranceResult.ASSURANCE_SUCCEDED,
59                                 Notary.assure(assurer, users[i], -1, "test-notary", "2014-01-01"));
60                         assertNotEquals(AssuranceResult.ASSURANCE_SUCCEDED,
61                                 Notary.assure(assurer, users[i], 11, "test-notary", "2014-01-01"));
62                         assertEquals(AssuranceResult.ASSURANCE_SUCCEDED,
63                                 Notary.assure(assurer, users[i], 10, "test-notary", "2014-01-01"));
64                         assertNotEquals(AssuranceResult.ASSURANCE_SUCCEDED,
65                                 Notary.assure(assurer, users[i], 10, "test-notary", "2014-01-01"));
66                 }
67         }
68 }