]> WPIA git - gigi.git/blob - tests/org/cacert/gigi/util/TestNotary.java
Move the "dbObject"s to their own package.
[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.database.DatabaseConnection;
7 import org.cacert.gigi.dbObjects.User;
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
16     @Test
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);
22         }
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
26         };
27
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"));
34         }
35
36         assertEquals(35, assurer.getMaxAssurePoints());
37
38         assertEquals(2 + 60, assurer.getExperiencePoints());
39
40     }
41
42     @Test
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);
48         }
49         int id = createAssuranceUser("fn", "ln", createUniqueName() + "@email.org", TEST_PASSWORD);
50         PreparedStatement ps = DatabaseConnection.getInstance().prepare("UPDATE users SET dob=NOW() WHERE id=?");
51         ps.setInt(1, id);
52         ps.execute();
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"));
59         }
60     }
61 }