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