]> WPIA git - gigi.git/blobdiff - tests/org/cacert/gigi/util/TestNotary.java
Move the "dbObject"s to their own package.
[gigi.git] / tests / org / cacert / gigi / util / TestNotary.java
index 7b1f5a133db93d47528fa41fca6816ae3267cbab..5191b07d2109d808e815a7d37e6b706a3409ddcc 100644 (file)
@@ -1,8 +1,10 @@
 package org.cacert.gigi.util;
 
+import java.sql.PreparedStatement;
 import java.sql.SQLException;
 
-import org.cacert.gigi.User;
+import org.cacert.gigi.database.DatabaseConnection;
+import org.cacert.gigi.dbObjects.User;
 import org.cacert.gigi.testUtils.ManagedTest;
 import org.cacert.gigi.util.Notary.AssuranceResult;
 import org.junit.Test;
@@ -10,37 +12,50 @@ import org.junit.Test;
 import static org.junit.Assert.*;
 
 public class TestNotary extends ManagedTest {
-       @Test
-       public void testSigning() throws SQLException {
-               User[] users = new User[30];
-               for (int i = 0; i < users.length; i++) {
-                       int id = createVerifiedUser("fn" + i, "ln" + i, createUniqueName()
-                                       + "@email.org", "xvXV12°§");
-                       users[i] = new User(id);
-               }
-               User assurer = new User(createAssuranceUser("fn", "ln",
-                               createUniqueName() + "@email.org", "xvXV12°§"));
-               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, 30, 30, 30, 35, 35, 35,
-                               35, 35, 35};
-
-               System.out.println(result.length);
-               assertNotEquals(AssuranceResult.ASSURANCE_SUCCEDED, Notary.assure(
-                               assurer, users[0], -1, "test-notary", "2014-01-01"));
-               for (int i = 0; i < result.length; i++) {
-                       assertEquals(result[i], assurer.getMaxAssurePoints());
-                       assertNotEquals(AssuranceResult.ASSURANCE_SUCCEDED, Notary.assure(
-                                       assurer, users[i], result[i] + 1, "test-notary",
-                                       "2014-01-01"));
-                       assertEquals(AssuranceResult.ASSURANCE_SUCCEDED, Notary.assure(
-                                       assurer, users[i], result[i], "test-notary", "2014-01-01"));
-                       assertNotEquals(AssuranceResult.ASSURANCE_SUCCEDED, Notary.assure(
-                                       assurer, users[i], result[i], "test-notary", "2014-01-01"));
-               }
-
-               assertEquals(35, assurer.getMaxAssurePoints());
-
-               assertEquals(2 + 60, assurer.getExperiencePoints());
-
-       }
+
+    @Test
+    public void testNormalAssurance() throws SQLException {
+        User[] users = new User[30];
+        for (int i = 0; i < users.length; i++) {
+            int id = createVerifiedUser("fn" + i, "ln" + i, createUniqueName() + "@email.org", TEST_PASSWORD);
+            users[i] = new User(id);
+        }
+        User assurer = new User(createAssuranceUser("fn", "ln", createUniqueName() + "@email.org", TEST_PASSWORD));
+        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, 30, 30, 30, 35, 35, 35, 35, 35, 35
+        };
+
+        assertNotEquals(AssuranceResult.ASSURANCE_SUCCEDED, Notary.assure(assurer, users[0], -1, "test-notary", "2014-01-01"));
+        for (int i = 0; i < result.length; i++) {
+            assertEquals(result[i], assurer.getMaxAssurePoints());
+            assertNotEquals(AssuranceResult.ASSURANCE_SUCCEDED, Notary.assure(assurer, users[i], result[i] + 1, "test-notary", "2014-01-01"));
+            assertEquals(AssuranceResult.ASSURANCE_SUCCEDED, Notary.assure(assurer, users[i], result[i], "test-notary", "2014-01-01"));
+            assertNotEquals(AssuranceResult.ASSURANCE_SUCCEDED, Notary.assure(assurer, users[i], result[i], "test-notary", "2014-01-01"));
+        }
+
+        assertEquals(35, assurer.getMaxAssurePoints());
+
+        assertEquals(2 + 60, assurer.getExperiencePoints());
+
+    }
+
+    @Test
+    public void testPoJam() throws SQLException {
+        User[] users = new User[30];
+        for (int i = 0; i < users.length; i++) {
+            int id = createVerifiedUser("fn" + i, "ln" + i, createUniqueName() + "@email.org", TEST_PASSWORD);
+            users[i] = new User(id);
+        }
+        int id = createAssuranceUser("fn", "ln", createUniqueName() + "@email.org", TEST_PASSWORD);
+        PreparedStatement ps = DatabaseConnection.getInstance().prepare("UPDATE users SET dob=NOW() WHERE id=?");
+        ps.setInt(1, id);
+        ps.execute();
+        User assurer = new User(id);
+        for (int i = 0; i < users.length; i++) {
+            assertNotEquals(AssuranceResult.ASSURANCE_SUCCEDED, Notary.assure(assurer, users[i], -1, "test-notary", "2014-01-01"));
+            assertNotEquals(AssuranceResult.ASSURANCE_SUCCEDED, Notary.assure(assurer, users[i], 11, "test-notary", "2014-01-01"));
+            assertEquals(AssuranceResult.ASSURANCE_SUCCEDED, Notary.assure(assurer, users[i], 10, "test-notary", "2014-01-01"));
+            assertNotEquals(AssuranceResult.ASSURANCE_SUCCEDED, Notary.assure(assurer, users[i], 10, "test-notary", "2014-01-01"));
+        }
+    }
 }