Implement PoJam test.
authorFelix Dörre <felix@dogcraft.de>
Sat, 5 Jul 2014 18:20:07 +0000 (20:20 +0200)
committerFelix Dörre <felix@dogcraft.de>
Sat, 5 Jul 2014 18:20:07 +0000 (20:20 +0200)
tests/org/cacert/gigi/util/TestNotary.java

index 7b1f5a133db93d47528fa41fca6816ae3267cbab..274b323967acd2c6b2a2d1ce225ea5e5d599ba4b 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.testUtils.ManagedTest;
 import org.cacert.gigi.util.Notary.AssuranceResult;
 import org.junit.Test;
@@ -11,7 +13,7 @@ import static org.junit.Assert.*;
 
 public class TestNotary extends ManagedTest {
        @Test
-       public void testSigning() throws SQLException {
+       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()
@@ -43,4 +45,31 @@ public class TestNotary extends ManagedTest {
                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", "xvXV12°§");
+                       users[i] = new User(id);
+               }
+               int id = createAssuranceUser("fn", "ln", createUniqueName()
+                               + "@email.org", "xvXV12°§");
+               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"));
+               }
+       }
 }