Author: batosai
Date: 2008-08-20 20:14:10 +0000 (Wed, 20 Aug 2008)
New Revision: 22066

Modified:
   trunk/apps/WoT/src/plugins/WoT/WebInterface.java
   trunk/apps/WoT/src/plugins/WoT/WotTestDrive.java
Log:
Added test of OwnIdentities creation (bug #2518)

Modified: trunk/apps/WoT/src/plugins/WoT/WebInterface.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/WebInterface.java    2008-08-20 19:10:33 UTC 
(rev 22065)
+++ trunk/apps/WoT/src/plugins/WoT/WebInterface.java    2008-08-20 20:14:10 UTC 
(rev 22066)
@@ -280,7 +280,7 @@
                HTMLNode box = pm.getInfobox("WoT test results");
                HTMLNode boxContent = pm.getContentNode(box);

-               boxContent.addChild("pre", new WotTestDrive(wot,db).fullTest());
+               boxContent.addChild("pre", new 
WotTestDrive(wot,db,client).fullTest());

                contentNode.addChild(box);
                return pageNode.generate();

Modified: trunk/apps/WoT/src/plugins/WoT/WotTestDrive.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/WotTestDrive.java    2008-08-20 19:10:33 UTC 
(rev 22065)
+++ trunk/apps/WoT/src/plugins/WoT/WotTestDrive.java    2008-08-20 20:14:10 UTC 
(rev 22066)
@@ -5,8 +5,14 @@
  */
 package plugins.WoT;

+import java.util.Date;
+
 import com.db4o.ObjectContainer;
+import com.db4o.ObjectSet;

+import freenet.client.HighLevelSimpleClient;
+import freenet.keys.FreenetURI;
+
 /**
  * A local Identity (it belongs to the user)
  * 
@@ -17,15 +23,58 @@

        WoT wot;
        ObjectContainer db;
+       HighLevelSimpleClient client;

-       public WotTestDrive(WoT wot, ObjectContainer db) {
+       public WotTestDrive(WoT wot, ObjectContainer db, HighLevelSimpleClient 
client) {
                this.wot = wot;
                this.db = db;
+               this.client = client;
        }

        public String fullTest() {
-               String result = "";

-               return result;
+               StringBuffer out = new StringBuffer();
+               
+               // Empty database
+               ObjectSet<Object> all = db.queryByExample(Object.class);
+               while(all.hasNext()) db.delete(all.next());
+       
+               out.append("* Create identity with keys:");
+               createIdentityWithKeys(out,
+                               "SSK at 
AJpdMz4qaNiMX3MGmHCPvsP9wE~Rzk1M9cfA5abjnzKT,6dg0VehJynirCW1zYU2g1Yss4Ss~2BWst-oeje0HQEU,AQECAAE/WoT",
 
+                               "SSK at 
h5Lcp80DUPSidjbzmz632D6JpZo2chDCsP4d6TzK~1E,6dg0VehJynirCW1zYU2g1Yss4Ss~2BWst-oeje0HQEU,AQACAAE/WoT");
+               
+               out.append("* Create identity without keys:");
+               createIdentityWithoutKeys(out);
+               
+               // Empty database
+               all = db.queryByExample(Object.class);
+               while(all.hasNext()) db.delete(all.next());
+               
+               return out.toString();
        }
+       
+       private void createIdentityWithKeys(StringBuffer out, String insertURI, 
String requestURI) {
+               
+               try {
+                       OwnIdentity test1 = new OwnIdentity(insertURI, 
requestURI, new Date(0), new Date(), "Test1", "true");
+                       
+                       test1.addContext("Testing", db);
+                       db.store(test1);
+
+                       Score score = new Score(test1, test1, 100, 0, 100); // 
We need to initialize the trust tree 
+                       db.store(score);
+                                               
+                       out.append("OK\n");
+               } catch (InvalidParameterException e) {
+                       out.append("NOK\n");
+                       out.append(e.getMessage());
+               }
+       }
+       
+       private void createIdentityWithoutKeys(StringBuffer out) {
+               FreenetURI[] keypair = client.generateKeyPair("WoT");
+               createIdentityWithKeys(out, keypair[0].toString(), 
keypair[1].toString());
+       }
+       
 }


Reply via email to