]> WPIA git - gigi.git/blobdiff - tests/org/cacert/gigi/util/TestNotary.java
add: Allow multiple names, name-schemes, multi-name-assurance, etc.
[gigi.git] / tests / org / cacert / gigi / util / TestNotary.java
index 22f75b2362789c0f84c92d5608343c483ab50806..21045c9a229b1ef1d87bc453dfb35c5f7d4856a7 100644 (file)
@@ -2,29 +2,24 @@ package org.cacert.gigi.util;
 
 import static org.junit.Assert.*;
 
-import java.io.IOException;
 import java.sql.SQLException;
 import java.util.Date;
 
 import org.cacert.gigi.GigiApiException;
 import org.cacert.gigi.database.GigiPreparedStatement;
 import org.cacert.gigi.dbObjects.Assurance.AssuranceType;
+import org.cacert.gigi.dbObjects.ObjectCache;
 import org.cacert.gigi.dbObjects.User;
 import org.cacert.gigi.output.DateSelector;
-import org.cacert.gigi.testUtils.ManagedTest;
+import org.cacert.gigi.testUtils.BusinessTest;
 import org.junit.Test;
 
-public class TestNotary extends ManagedTest {
+public class TestNotary extends BusinessTest {
 
     // These tests create a lot of users and therefore require resetting of the
     // registering-rate-limit.
     @Test
     public void testNormalAssurance() throws SQLException, GigiApiException {
-        try {
-            clearCaches();
-        } catch (IOException e) {
-            throw new Error(e);
-        }
         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);
@@ -36,7 +31,7 @@ public class TestNotary extends ManagedTest {
         };
 
         try {
-            Notary.assure(assurer, users[0], users[0].getName(), users[0].getDoB(), -1, "test-notary", "2014-01-01", AssuranceType.FACE_TO_FACE);
+            Notary.assure(assurer, users[0], users[0].getPreferredName(), users[0].getDoB(), -1, "test-notary", "2014-01-01", AssuranceType.FACE_TO_FACE);
             fail("This shouldn't have passed");
         } catch (GigiApiException e) {
             // expected
@@ -45,7 +40,7 @@ public class TestNotary extends ManagedTest {
             assertEquals(result[i], assurer.getMaxAssurePoints());
 
             assuranceFail(assurer, users[i], result[i] + 1, "test-notary", "2014-01-01");
-            Notary.assure(assurer, users[i], users[i].getName(), users[i].getDoB(), result[i], "test-notary", "2014-01-01", AssuranceType.FACE_TO_FACE);
+            Notary.assure(assurer, users[i], users[i].getPreferredName(), users[i].getDoB(), result[i], "test-notary", "2014-01-01", AssuranceType.FACE_TO_FACE);
             assuranceFail(assurer, users[i], result[i], "test-notary", "2014-01-01");
         }
 
@@ -57,7 +52,7 @@ public class TestNotary extends ManagedTest {
 
     private void assuranceFail(User assurer, User user, int i, String location, String date) throws SQLException {
         try {
-            Notary.assure(assurer, user, user.getName(), user.getDoB(), i, location, date, AssuranceType.FACE_TO_FACE);
+            Notary.assure(assurer, user, user.getPreferredName(), user.getDoB(), i, location, date, AssuranceType.FACE_TO_FACE);
             fail("This shouldn't have passed");
         } catch (GigiApiException e) {
             // expected
@@ -66,11 +61,6 @@ public class TestNotary extends ManagedTest {
 
     @Test
     public void testPoJam() throws SQLException, GigiApiException {
-        try {
-            clearCaches();
-        } catch (IOException e) {
-            throw new Error(e);
-        }
         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);
@@ -81,12 +71,13 @@ public class TestNotary extends ManagedTest {
             ps.setInt(1, id);
             ps.execute();
         }
+        ObjectCache.clearAllCaches(); // reload values from db
         User assurer = User.getById(id);
         for (int i = 0; i < users.length; i++) {
             assuranceFail(assurer, users[i], -1, "test-notary", "2014-01-01");
             assuranceFail(assurer, users[i], 11, "test-notary", "2014-01-01");
             if (User.POJAM_ENABLED) {
-                Notary.assure(assurer, users[i], users[i].getName(), users[i].getDoB(), 10, "test-notary", "2014-01-01", AssuranceType.FACE_TO_FACE);
+                Notary.assure(assurer, users[i], users[i].getPreferredName(), users[i].getDoB(), 10, "test-notary", "2014-01-01", AssuranceType.FACE_TO_FACE);
             }
             assuranceFail(assurer, users[i], 10, "test-notary", "2014-01-01");
         }
@@ -122,7 +113,7 @@ public class TestNotary extends ManagedTest {
         assuranceFail(assuree, assuranceUser, 10, "notary-junit-test", "2014-01-01");
 
         // valid
-        Notary.assure(assuranceUser, assuree, assuree.getName(), assuree.getDoB(), 10, "notary-junit-test", "2014-01-01", AssuranceType.FACE_TO_FACE);
+        Notary.assure(assuranceUser, assuree, assuree.getPreferredName(), assuree.getDoB(), 10, "notary-junit-test", "2014-01-01", AssuranceType.FACE_TO_FACE);
 
         // assure double
         assuranceFail(assuranceUser, assuree, 10, "notary-junit-test", "2014-01-01");