Author: batosai
Date: 2008-09-20 22:26:12 +0000 (Sat, 20 Sep 2008)
New Revision: 22725

Added:
   trunk/plugins/WoT/test/
   trunk/plugins/WoT/test/IdentityTest.java
   trunk/plugins/WoT/test/ScoreTest.java
   trunk/plugins/WoT/test/TrustTest.java
   trunk/plugins/WoT/test/WoTTest.java
Removed:
   trunk/plugins/WoT/IdentityTest.java
   trunk/plugins/WoT/ScoreTest.java
   trunk/plugins/WoT/TrustTest.java
   trunk/plugins/WoT/WoTTest.java
Log:
Moved unit tests to their own package.

Deleted: trunk/plugins/WoT/IdentityTest.java
===================================================================
--- trunk/plugins/WoT/IdentityTest.java 2008-09-20 22:21:39 UTC (rev 22724)
+++ trunk/plugins/WoT/IdentityTest.java 2008-09-20 22:26:12 UTC (rev 22725)
@@ -1,106 +0,0 @@
-/**
- * This code is part of WoT, a plugin for Freenet. It is distributed 
- * under the GNU General Public License, version 2 (or at your option
- * any later version). See http://www.gnu.org/ for details of the GPL.
- */
-package plugins.WoT;
-
-import java.io.File;
-import java.net.MalformedURLException;
-
-import plugins.WoT.exceptions.DuplicateIdentityException;
-import plugins.WoT.exceptions.InvalidParameterException;
-import plugins.WoT.exceptions.UnknownIdentityException;
-
-import com.db4o.Db4o;
-import com.db4o.ObjectContainer;
-import com.db4o.ObjectSet;
-
-import junit.framework.TestCase;
-
-/**
- * @author Julien Cornuwel (batosai at freenetproject.org)
- */
-public class IdentityTest extends TestCase {
-       
-       private String uri = "USK at 
yGvITGZzrY1vUZK-4AaYLgcjZ7ysRqNTMfdcO8gS-LY,-ab5bJVD3Lp-LXEQqBAhJpMKrKJ19RnNaZMIkusU79s,AQACAAE/WoT/0";
-       private Identity identity;
-       private ObjectContainer db;
-       
-       public IdentityTest(String name) {
-               super(name);
-       }
-       
-       protected void setUp() throws Exception {
-               super.setUp();
-               
-               db = Db4o.openFile("identityTest.db4o");
-               
-               identity = new Identity(uri, "test", "true");
-               identity.addContext("bleh", db);
-               
-               db.store(identity);
-               db.commit();
-       }
-
-       protected void tearDown() throws Exception {
-               db.close();
-               new File("identityTest.db4o").delete();
-       }
-       
-       public void testIdentityStored() {
-               ObjectSet<Identity> result = db.queryByExample(Identity.class);
-               assertEquals(result.size(), 1);
-       }
-       
-       public void testGetByURI() throws MalformedURLException, 
UnknownIdentityException, DuplicateIdentityException {
-               assertNotNull(Identity.getByURI(db, uri));
-       }
-       
-       public void testGetNbIdentities() {
-               assertEquals(Identity.getNbIdentities(db), 1);
-       }
-
-       public void testContexts() throws InvalidParameterException  {
-               assertFalse(identity.hasContext("foo"));
-               identity.addContext("test", db);
-               assertTrue(identity.hasContext("test"));
-               identity.removeContext("test", db);
-               assertFalse(identity.hasContext("test"));
-       }
-
-       public void testProperties() {
-               try {
-                       identity.setProp("foo", "bar", db);
-               } catch (InvalidParameterException e) {}
-               
-               try {
-                       assertTrue(identity.getProp("foo").equals("bar"));
-               } catch (InvalidParameterException e) { fail(); }
-               
-               try {
-                       identity.removeProp("foo", db);
-               } catch (InvalidParameterException e) { fail(); }
-               
-               try {
-                       identity.getProp("foo");
-                       fail();
-               } catch (InvalidParameterException e) {}
-       }
-       
-       public void testPersistence() throws MalformedURLException, 
DuplicateIdentityException {
-               db.close();
-               
-               System.gc();
-               System.runFinalization();
-               
-               db = Db4o.openFile("identityTest.db4o");
-               
-               assertEquals(Identity.getNbIdentities(db), 1);
-               try {
-                       Identity.getByURI(db, uri);
-               } catch (UnknownIdentityException e) {
-                       fail();
-               }
-       }
-}

Deleted: trunk/plugins/WoT/ScoreTest.java
===================================================================
--- trunk/plugins/WoT/ScoreTest.java    2008-09-20 22:21:39 UTC (rev 22724)
+++ trunk/plugins/WoT/ScoreTest.java    2008-09-20 22:26:12 UTC (rev 22725)
@@ -1,86 +0,0 @@
-/**
- * This code is part of WoT, a plugin for Freenet. It is distributed 
- * under the GNU General Public License, version 2 (or at your option
- * any later version). See http://www.gnu.org/ for details of the GPL.
- */
-package plugins.WoT;
-
-import java.io.File;
-import java.net.MalformedURLException;
-
-import plugins.WoT.exceptions.DuplicateIdentityException;
-import plugins.WoT.exceptions.DuplicateScoreException;
-import plugins.WoT.exceptions.NotInTrustTreeException;
-import plugins.WoT.exceptions.UnknownIdentityException;
-
-import junit.framework.TestCase;
-
-import com.db4o.Db4o;
-import com.db4o.ObjectContainer;
-
-/**
- * @author Julien Cornuwel (batosai at freenetproject.org)
- */
-public class ScoreTest extends TestCase {
-       
-       private String uriA = "USK at 
MF2Vc6FRgeFMZJ0s2l9hOop87EYWAydUZakJzL0OfV8,fQeN-RMQZsUrDha2LCJWOMFk1-EiXZxfTnBT8NEgY00,AQACAAE/WoT/0";
-       private String uriB = "USK at 
R3Lp2s4jdX-3Q96c0A9530qg7JsvA9vi2K0hwY9wG-4,ipkgYftRpo0StBlYkJUawZhg~SO29NZIINseUtBhEfE,AQACAAE/WoT/0";
-       OwnIdentity a;
-       Identity b;
-       
-       private ObjectContainer db;
-       
-       public ScoreTest(String name) {
-               super(name);
-       }
-       
-       protected void setUp() throws Exception {
-               
-               super.setUp();
-               db = Db4o.openFile("scoreTest.db4o");
-               
-               a = new OwnIdentity(uriA, uriA, "A", "true");
-               b = new Identity(uriB, "B", "true");
-               db.store(a);
-               db.store(b);
-               Score score = new Score(a,b,100,1,40);
-               db.store(score);
-               db.commit();
-       }
-       
-       protected void tearDown() throws Exception {
-               db.close();
-               new File("scoreTest.db4o").delete();
-       }
-       
-       public void testScoreCreation() throws NotInTrustTreeException, 
DuplicateScoreException  {
-               
-               Score score = b.getScore(a, db);
-               
-               assertTrue(score.getScore() == 100);
-               assertTrue(score.getRank() == 1);
-               assertTrue(score.getCapacity() == 40);
-               assertTrue(score.getTreeOwner() == a);
-               assertTrue(score.getTarget() == b);
-       }
-       
-       public void testScorePersistence() throws NotInTrustTreeException, 
DuplicateScoreException, MalformedURLException, UnknownIdentityException, 
DuplicateIdentityException {
-               
-               db.close();
-               
-               System.gc();
-               System.runFinalization();
-               
-               db = Db4o.openFile("scoreTest.db4o");
-               
-               a = OwnIdentity.getByURI(db, uriA);
-               b = Identity.getByURI(db, uriB);
-               Score score = b.getScore(a, db);
-               
-               assertTrue(score.getScore() == 100);
-               assertTrue(score.getRank() == 1);
-               assertTrue(score.getCapacity() == 40);
-               assertTrue(score.getTreeOwner() == a);
-               assertTrue(score.getTarget() == b);
-       }
-}
\ No newline at end of file

Deleted: trunk/plugins/WoT/TrustTest.java
===================================================================
--- trunk/plugins/WoT/TrustTest.java    2008-09-20 22:21:39 UTC (rev 22724)
+++ trunk/plugins/WoT/TrustTest.java    2008-09-20 22:26:12 UTC (rev 22725)
@@ -1,85 +0,0 @@
-/**
- * This code is part of WoT, a plugin for Freenet. It is distributed 
- * under the GNU General Public License, version 2 (or at your option
- * any later version). See http://www.gnu.org/ for details of the GPL.
- */
-package plugins.WoT;
-
-import java.io.File;
-import java.net.MalformedURLException;
-
-import plugins.WoT.exceptions.DuplicateIdentityException;
-import plugins.WoT.exceptions.DuplicateTrustException;
-import plugins.WoT.exceptions.InvalidParameterException;
-import plugins.WoT.exceptions.NotTrustedException;
-import plugins.WoT.exceptions.UnknownIdentityException;
-
-import junit.framework.TestCase;
-
-import com.db4o.Db4o;
-import com.db4o.ObjectContainer;
-
-/**
- * @author Julien Cornuwel (batosai at freenetproject.org)
- */
-public class TrustTest extends TestCase {
-       
-       private String uriA = "USK at 
MF2Vc6FRgeFMZJ0s2l9hOop87EYWAydUZakJzL0OfV8,fQeN-RMQZsUrDha2LCJWOMFk1-EiXZxfTnBT8NEgY00,AQACAAE/WoT/0";
-       private String uriB = "USK at 
R3Lp2s4jdX-3Q96c0A9530qg7JsvA9vi2K0hwY9wG-4,ipkgYftRpo0StBlYkJUawZhg~SO29NZIINseUtBhEfE,AQACAAE/WoT/0";
-       
-       private Identity a;
-       private Identity b;
-       
-       private ObjectContainer db;
-       
-       public TrustTest(String name) {
-               super(name);
-       }
-       
-       protected void setUp() throws Exception {
-               
-               super.setUp();
-               db = Db4o.openFile("trustTest.db4o");
-
-               a = new Identity(uriA, "A", "true");
-               b = new Identity(uriB, "B", "true");
-               Trust trust = new Trust(a,b,100,"test");
-               db.store(trust);
-               db.store(a);
-               db.store(b);
-               db.commit();
-       }
-       
-       protected void tearDown() throws Exception {
-               db.close();
-               new File("trustTest.db4o").delete();
-       }
-       
-       public void testTrust() throws InvalidParameterException, 
NotTrustedException, DuplicateTrustException {
-
-               Trust trust = a.getGivenTrust(b, db);
-               assertTrue(trust.getTruster() == a);
-               assertTrue(trust.getTrustee() == b);
-               assertTrue(trust.getValue() == 100);
-               assertTrue(trust.getComment().equals("test"));
-       }
-       
-       public void testTrustPersistence() throws MalformedURLException, 
UnknownIdentityException, DuplicateIdentityException, NotTrustedException, 
DuplicateTrustException  {
-               
-               db.close();
-               
-               System.gc();
-               System.runFinalization();
-               
-               db = Db4o.openFile("trustTest.db4o");
-               
-               a = Identity.getByURI(db, uriA);
-               b = Identity.getByURI(db, uriB);
-               Trust trust = a.getGivenTrust(b, db);
-               
-               assertTrue(trust.getTruster() == a);
-               assertTrue(trust.getTrustee() == b);
-               assertTrue(trust.getValue() == 100);
-               assertTrue(trust.getComment().equals("test"));
-       }
-}

Deleted: trunk/plugins/WoT/WoTTest.java
===================================================================
--- trunk/plugins/WoT/WoTTest.java      2008-09-20 22:21:39 UTC (rev 22724)
+++ trunk/plugins/WoT/WoTTest.java      2008-09-20 22:26:12 UTC (rev 22725)
@@ -1,275 +0,0 @@
-/**
- * This code is part of WoT, a plugin for Freenet. It is distributed 
- * under the GNU General Public License, version 2 (or at your option
- * any later version). See http://www.gnu.org/ for details of the GPL.
- */
-package plugins.WoT;
-
-import java.io.File;
-import java.net.MalformedURLException;
-
-import plugins.WoT.exceptions.DuplicateScoreException;
-import plugins.WoT.exceptions.DuplicateTrustException;
-import plugins.WoT.exceptions.InvalidParameterException;
-import plugins.WoT.exceptions.NotInTrustTreeException;
-import plugins.WoT.exceptions.NotTrustedException;
-
-import com.db4o.Db4o;
-import com.db4o.ObjectContainer;
-import com.db4o.ObjectSet;
-
-import junit.framework.TestCase;
-
-/**
- * @author Julien Cornuwel (batosai at freenetproject.org)
- */
-public class WoTTest extends TestCase {
-       
-       private ObjectContainer db;
-       
-       private String uriA = "USK at 
MF2Vc6FRgeFMZJ0s2l9hOop87EYWAydUZakJzL0OfV8,fQeN-RMQZsUrDha2LCJWOMFk1-EiXZxfTnBT8NEgY00,AQACAAE/WoT/0";
-       private String uriB = "USK at 
R3Lp2s4jdX-3Q96c0A9530qg7JsvA9vi2K0hwY9wG-4,ipkgYftRpo0StBlYkJUawZhg~SO29NZIINseUtBhEfE,AQACAAE/WoT/0";
-       private String uriC = "USK at 
qd-hk0vHYg7YvK2BQsJMcUD5QSF0tDkgnnF6lnWUH0g,xTFOV9ddCQQk6vQ6G~jfL6IzRUgmfMcZJ6nuySu~NUc,AQACAAE/WoT/0";
-               
-       public WoTTest(String name) {
-               super(name);
-       }
-       
-       protected void setUp() throws Exception {
-               
-               super.setUp();
-               db = Db4o.openFile("wotTest.db4o");
-       }
-       
-       protected void tearDown() throws Exception {
-               db.close();
-               new File("wotTest.db4o").delete();
-       }
-       
-       public void testInitTrustTree() throws DuplicateScoreException, 
NotInTrustTreeException, MalformedURLException, InvalidParameterException {
-               
-               OwnIdentity a = new OwnIdentity(uriA, uriA, "A", "true");
-               db.store(a);
-               a.initTrustTree(db);
-               
-               assertTrue(Identity.getNbIdentities(db) == 0);
-               assertTrue(OwnIdentity.getNbOwnIdentities(db) == 1);
-               assertTrue(Trust.getNb(db) == 0);
-               assertTrue(Score.getNb(db) == 1);
-
-               assertTrue(a.getScore(a, db).getScore() == 100);
-               assertTrue(a.getScore(a, db).getRank() == 0);
-               assertTrue(a.getScore(a, db).getCapacity() == 100);
-               assertTrue(a.getScore(a, db).getTreeOwner() == a);
-               assertTrue(a.getScore(a, db).getTarget() == a);
-               
-               // Empty the database
-               ObjectSet<Object> all = db.queryByExample(new Object());
-               while(all.hasNext()) db.delete(all.next());
-       }
-       
-       public void testSetTrust() throws DuplicateTrustException, 
InvalidParameterException, DuplicateScoreException, NotTrustedException, 
NotInTrustTreeException, MalformedURLException {
-
-               OwnIdentity a = new OwnIdentity(uriA, uriA, "A", "true");
-               Identity b = new Identity(uriB, "B", "true");
-               db.store(a);
-               db.store(b);
-               
-               // With A's trust tree not initialized, B shouldn't get a Score.
-               a.setTrust(db, b, 10, "Foo");
-
-               assertTrue(Identity.getNbIdentities(db) == 1);
-               assertTrue(OwnIdentity.getNbOwnIdentities(db) == 1);
-               assertTrue(Trust.getNb(db) == 1);
-               assertTrue(Score.getNb(db) == 0);
-               
-               // Initialize A's trust tree and set the trust relationship
-               a.initTrustTree(db);
-               a.setTrust(db, b, 100, "Foo");
-               
-               // Check we have the correct number of objects
-               assertTrue(Identity.getNbIdentities(db) == 1);
-               assertTrue(OwnIdentity.getNbOwnIdentities(db) == 1);
-               assertTrue(Trust.getNb(db) == 1);
-               assertTrue(Score.getNb(db) == 2);
-               
-               // Check the Trust object
-               assertTrue(b.getReceivedTrust(a, db).getTruster() == a);
-               assertTrue(b.getReceivedTrust(a, db).getTrustee() == b);
-               assertTrue(b.getReceivedTrust(a, db).getValue() == 100);
-               assertTrue(b.getReceivedTrust(a, 
db).getComment().equals("Foo"));
-
-               // Check a's Score object
-               assertTrue(a.getScore(a, db).getScore() == 100);
-               assertTrue(a.getScore(a, db).getRank() == 0);
-               assertTrue(a.getScore(a, db).getCapacity() == 100);
-               
-               // Check B's Score object
-               assertTrue(b.getScore(a, db).getScore() == 100);
-               assertTrue(b.getScore(a, db).getRank() == 1);
-               assertTrue(b.getScore(a, db).getCapacity() == 40);
-               
-               // Change the trust value and comment
-               a.setTrust(db, b, 50, "Bar");
-               
-               // Check we have the correct number of objects
-               assertTrue(Identity.getNbIdentities(db) == 1);
-               assertTrue(OwnIdentity.getNbOwnIdentities(db) == 1);
-               assertTrue(Trust.getNb(db) == 1);
-               assertTrue(Score.getNb(db) == 2);
-               
-               // Check the Trust object
-               assertTrue(b.getReceivedTrust(a, db).getTruster() == a);
-               assertTrue(b.getReceivedTrust(a, db).getTrustee() == b);
-               assertTrue(b.getReceivedTrust(a, db).getValue() == 50);
-               assertTrue(b.getReceivedTrust(a, 
db).getComment().equals("Bar"));
-
-               // Check a's Score object
-               assertTrue(a.getScore(a, db).getScore() == 100);
-               assertTrue(a.getScore(a, db).getRank() == 0);
-               assertTrue(a.getScore(a, db).getCapacity() == 100);
-               
-               // Check B's Score object
-               assertTrue(b.getScore(a, db).getScore() == 50);
-               assertTrue(b.getScore(a, db).getRank() == 1);
-               assertTrue(b.getScore(a, db).getCapacity() == 40);
-               
-               // Empty the database
-               ObjectSet<Object> all = db.queryByExample(new Object());
-               while(all.hasNext()) db.delete(all.next());
-       }
-       
-       public void testRemoveTrust() throws MalformedURLException, 
InvalidParameterException, DuplicateScoreException, DuplicateTrustException, 
NotTrustedException, NotInTrustTreeException {
-               OwnIdentity a = new OwnIdentity(uriA, uriA, "A", "true");
-               Identity b = new Identity(uriB, "B", "true");
-               Identity c = new Identity(uriC, "C", "true");
-               db.store(a);
-               db.store(b);
-               db.store(c);
-               a.initTrustTree(db);
-               a.setTrust(db, b, 100, "Foo");
-               b.setTrust(db, c, 50, "Bar");
-               
-               // Check we have the correct number of objects
-               assertTrue(OwnIdentity.getNbOwnIdentities(db) == 1);
-               assertTrue(Identity.getNbIdentities(db) == 2);
-               assertTrue(Trust.getNb(db) == 2);
-               assertTrue(Score.getNb(db) == 3);
-               
-               // Check a's Score object
-               assertTrue(a.getScore(a, db).getScore() == 100);
-               assertTrue(a.getScore(a, db).getRank() == 0);
-               assertTrue(a.getScore(a, db).getCapacity() == 100);
-               
-               // Check B's Score object
-               assertTrue(b.getScore(a, db).getScore() == 100);
-               assertTrue(b.getScore(a, db).getRank() == 1);
-               assertTrue(b.getScore(a, db).getCapacity() == 40);
-               
-               // Check C's Score object
-               assertTrue(c.getScore(a, db).getScore() == 20);
-               assertTrue(c.getScore(a, db).getRank() == 2);
-               assertTrue(c.getScore(a, db).getCapacity() == 16);
-               
-               a.setTrust(db, b, -1, "Bastard");
-               
-               // Check we have the correct number of objects
-               assertTrue(OwnIdentity.getNbOwnIdentities(db) == 1);
-               assertTrue(Identity.getNbIdentities(db) == 2);
-               assertTrue(Trust.getNb(db) == 2);
-               assertTrue(Score.getNb(db) == 2);
-               
-               // Check a's Score object
-               assertTrue(a.getScore(a, db).getScore() == 100);
-               assertTrue(a.getScore(a, db).getRank() == 0);
-               assertTrue(a.getScore(a, db).getCapacity() == 100);
-               
-               // Check B's Score object
-               assertTrue(b.getScore(a, db).getScore() == -1);
-               assertTrue(b.getScore(a, db).getRank() == 1);
-               assertTrue(b.getScore(a, db).getCapacity() == 0);
-               
-               // C should not have a score anymore
-               try {
-                       c.getScore(a, db);
-                       fail();
-               }
-               catch (NotInTrustTreeException e) {}
-               
-               // Empty the database
-               ObjectSet<Object> all = db.queryByExample(new Object());
-               while(all.hasNext()) db.delete(all.next());
-       }
-       
-       public void testTrustLoop() throws MalformedURLException, 
InvalidParameterException, DuplicateScoreException, DuplicateTrustException, 
NotInTrustTreeException {
-               OwnIdentity a = new OwnIdentity(uriA, uriA, "A", "true");
-               Identity b = new Identity(uriB, "B", "true");
-               Identity c = new Identity(uriC, "C", "true");
-               db.store(a);
-               db.store(b);
-               db.store(c);
-               a.initTrustTree(db);
-               a.setTrust(db, b, 100, "Foo");
-               b.setTrust(db, c, 50, "Bar");
-               c.setTrust(db, a, 100, "Bleh");
-               c.setTrust(db, b, 50, "Oops");
-               
-               // Check we have the correct number of objects
-               assertTrue(OwnIdentity.getNbOwnIdentities(db) == 1);
-               assertTrue(Identity.getNbIdentities(db) == 2);
-               assertTrue(Trust.getNb(db) == 4);
-               assertTrue(Score.getNb(db) == 3);
-               
-               // Check a's Score object
-               assertTrue(a.getScore(a, db).getScore() == 100);
-               assertTrue(a.getScore(a, db).getRank() == 0);
-               assertTrue(a.getScore(a, db).getCapacity() == 100);
-               
-               // Check B's Score object
-               assertTrue(b.getScore(a, db).getScore() == 108);
-               assertTrue(b.getScore(a, db).getRank() == 1);
-               assertTrue(b.getScore(a, db).getCapacity() == 40);
-               
-               // Check C's Score object
-               assertTrue(c.getScore(a, db).getScore() == 20);
-               assertTrue(c.getScore(a, db).getRank() == 2);
-               assertTrue(c.getScore(a, db).getCapacity() == 16);
-       }
-       
-       public void testOwnIndentitiesTrust() throws MalformedURLException, 
InvalidParameterException, DuplicateScoreException, DuplicateTrustException, 
NotTrustedException, NotInTrustTreeException {
-               OwnIdentity a = new OwnIdentity(uriA, uriA, "A", "true");
-               OwnIdentity b = new OwnIdentity(uriB, uriB, "B", "true");
-               db.store(a);
-               db.store(b);
-               a.initTrustTree(db);
-               b.initTrustTree(db);
-               a.setTrust(db, b, 100, "Foo");
-               b.setTrust(db, a, 100, "Bar");
-               
-               // Check we have the correct number of objects
-               assertTrue(OwnIdentity.getNbOwnIdentities(db) == 2);
-               assertTrue(Identity.getNbIdentities(db) == 0);
-               assertTrue(Trust.getNb(db) == 2);
-               assertTrue(Score.getNb(db) == 4);
-               
-               // Check a's own Score object
-               assertTrue(a.getScore(a, db).getScore() == 100);
-               assertTrue(a.getScore(a, db).getRank() == 0);
-               assertTrue(a.getScore(a, db).getCapacity() == 100);
-               
-               // Check a's Score object
-               assertTrue(a.getScore(b, db).getScore() == 100);
-               assertTrue(a.getScore(b, db).getRank() == 1);
-               assertTrue(a.getScore(b, db).getCapacity() == 40);
-                               
-               // Check B's own Score object
-               assertTrue(b.getScore(b, db).getScore() == 100);
-               assertTrue(b.getScore(b, db).getRank() == 0);
-               assertTrue(b.getScore(b, db).getCapacity() == 100);
-
-               // Check B's Score object
-               assertTrue(b.getScore(a, db).getScore() == 100);
-               assertTrue(b.getScore(a, db).getRank() == 1);
-               assertTrue(b.getScore(a, db).getCapacity() == 40);
-       }
-}

Copied: trunk/plugins/WoT/test/IdentityTest.java (from rev 22724, 
trunk/plugins/WoT/IdentityTest.java)
===================================================================
--- trunk/plugins/WoT/test/IdentityTest.java                            (rev 0)
+++ trunk/plugins/WoT/test/IdentityTest.java    2008-09-20 22:26:12 UTC (rev 
22725)
@@ -0,0 +1,107 @@
+/**
+ * This code is part of WoT, a plugin for Freenet. It is distributed 
+ * under the GNU General Public License, version 2 (or at your option
+ * any later version). See http://www.gnu.org/ for details of the GPL.
+ */
+package plugins.WoT.test;
+
+import java.io.File;
+import java.net.MalformedURLException;
+
+import plugins.WoT.Identity;
+import plugins.WoT.exceptions.DuplicateIdentityException;
+import plugins.WoT.exceptions.InvalidParameterException;
+import plugins.WoT.exceptions.UnknownIdentityException;
+
+import com.db4o.Db4o;
+import com.db4o.ObjectContainer;
+import com.db4o.ObjectSet;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Julien Cornuwel (batosai at freenetproject.org)
+ */
+public class IdentityTest extends TestCase {
+       
+       private String uri = "USK at 
yGvITGZzrY1vUZK-4AaYLgcjZ7ysRqNTMfdcO8gS-LY,-ab5bJVD3Lp-LXEQqBAhJpMKrKJ19RnNaZMIkusU79s,AQACAAE/WoT/0";
+       private Identity identity;
+       private ObjectContainer db;
+       
+       public IdentityTest(String name) {
+               super(name);
+       }
+       
+       protected void setUp() throws Exception {
+               super.setUp();
+               
+               db = Db4o.openFile("identityTest.db4o");
+               
+               identity = new Identity(uri, "test", "true");
+               identity.addContext("bleh", db);
+               
+               db.store(identity);
+               db.commit();
+       }
+
+       protected void tearDown() throws Exception {
+               db.close();
+               new File("identityTest.db4o").delete();
+       }
+       
+       public void testIdentityStored() {
+               ObjectSet<Identity> result = db.queryByExample(Identity.class);
+               assertEquals(result.size(), 1);
+       }
+       
+       public void testGetByURI() throws MalformedURLException, 
UnknownIdentityException, DuplicateIdentityException {
+               assertNotNull(Identity.getByURI(db, uri));
+       }
+       
+       public void testGetNbIdentities() {
+               assertEquals(Identity.getNbIdentities(db), 1);
+       }
+
+       public void testContexts() throws InvalidParameterException  {
+               assertFalse(identity.hasContext("foo"));
+               identity.addContext("test", db);
+               assertTrue(identity.hasContext("test"));
+               identity.removeContext("test", db);
+               assertFalse(identity.hasContext("test"));
+       }
+
+       public void testProperties() {
+               try {
+                       identity.setProp("foo", "bar", db);
+               } catch (InvalidParameterException e) {}
+               
+               try {
+                       assertTrue(identity.getProp("foo").equals("bar"));
+               } catch (InvalidParameterException e) { fail(); }
+               
+               try {
+                       identity.removeProp("foo", db);
+               } catch (InvalidParameterException e) { fail(); }
+               
+               try {
+                       identity.getProp("foo");
+                       fail();
+               } catch (InvalidParameterException e) {}
+       }
+       
+       public void testPersistence() throws MalformedURLException, 
DuplicateIdentityException {
+               db.close();
+               
+               System.gc();
+               System.runFinalization();
+               
+               db = Db4o.openFile("identityTest.db4o");
+               
+               assertEquals(Identity.getNbIdentities(db), 1);
+               try {
+                       Identity.getByURI(db, uri);
+               } catch (UnknownIdentityException e) {
+                       fail();
+               }
+       }
+}

Copied: trunk/plugins/WoT/test/ScoreTest.java (from rev 22724, 
trunk/plugins/WoT/ScoreTest.java)
===================================================================
--- trunk/plugins/WoT/test/ScoreTest.java                               (rev 0)
+++ trunk/plugins/WoT/test/ScoreTest.java       2008-09-20 22:26:12 UTC (rev 
22725)
@@ -0,0 +1,89 @@
+/**
+ * This code is part of WoT, a plugin for Freenet. It is distributed 
+ * under the GNU General Public License, version 2 (or at your option
+ * any later version). See http://www.gnu.org/ for details of the GPL.
+ */
+package plugins.WoT.test;
+
+import java.io.File;
+import java.net.MalformedURLException;
+
+import plugins.WoT.Identity;
+import plugins.WoT.OwnIdentity;
+import plugins.WoT.Score;
+import plugins.WoT.exceptions.DuplicateIdentityException;
+import plugins.WoT.exceptions.DuplicateScoreException;
+import plugins.WoT.exceptions.NotInTrustTreeException;
+import plugins.WoT.exceptions.UnknownIdentityException;
+
+import junit.framework.TestCase;
+
+import com.db4o.Db4o;
+import com.db4o.ObjectContainer;
+
+/**
+ * @author Julien Cornuwel (batosai at freenetproject.org)
+ */
+public class ScoreTest extends TestCase {
+       
+       private String uriA = "USK at 
MF2Vc6FRgeFMZJ0s2l9hOop87EYWAydUZakJzL0OfV8,fQeN-RMQZsUrDha2LCJWOMFk1-EiXZxfTnBT8NEgY00,AQACAAE/WoT/0";
+       private String uriB = "USK at 
R3Lp2s4jdX-3Q96c0A9530qg7JsvA9vi2K0hwY9wG-4,ipkgYftRpo0StBlYkJUawZhg~SO29NZIINseUtBhEfE,AQACAAE/WoT/0";
+       OwnIdentity a;
+       Identity b;
+       
+       private ObjectContainer db;
+       
+       public ScoreTest(String name) {
+               super(name);
+       }
+       
+       protected void setUp() throws Exception {
+               
+               super.setUp();
+               db = Db4o.openFile("scoreTest.db4o");
+               
+               a = new OwnIdentity(uriA, uriA, "A", "true");
+               b = new Identity(uriB, "B", "true");
+               db.store(a);
+               db.store(b);
+               Score score = new Score(a,b,100,1,40);
+               db.store(score);
+               db.commit();
+       }
+       
+       protected void tearDown() throws Exception {
+               db.close();
+               new File("scoreTest.db4o").delete();
+       }
+       
+       public void testScoreCreation() throws NotInTrustTreeException, 
DuplicateScoreException  {
+               
+               Score score = b.getScore(a, db);
+               
+               assertTrue(score.getScore() == 100);
+               assertTrue(score.getRank() == 1);
+               assertTrue(score.getCapacity() == 40);
+               assertTrue(score.getTreeOwner() == a);
+               assertTrue(score.getTarget() == b);
+       }
+       
+       public void testScorePersistence() throws NotInTrustTreeException, 
DuplicateScoreException, MalformedURLException, UnknownIdentityException, 
DuplicateIdentityException {
+               
+               db.close();
+               
+               System.gc();
+               System.runFinalization();
+               
+               db = Db4o.openFile("scoreTest.db4o");
+               
+               a = OwnIdentity.getByURI(db, uriA);
+               b = Identity.getByURI(db, uriB);
+               Score score = b.getScore(a, db);
+               
+               assertTrue(score.getScore() == 100);
+               assertTrue(score.getRank() == 1);
+               assertTrue(score.getCapacity() == 40);
+               assertTrue(score.getTreeOwner() == a);
+               assertTrue(score.getTarget() == b);
+       }
+}
\ No newline at end of file

Copied: trunk/plugins/WoT/test/TrustTest.java (from rev 22724, 
trunk/plugins/WoT/TrustTest.java)
===================================================================
--- trunk/plugins/WoT/test/TrustTest.java                               (rev 0)
+++ trunk/plugins/WoT/test/TrustTest.java       2008-09-20 22:26:12 UTC (rev 
22725)
@@ -0,0 +1,87 @@
+/**
+ * This code is part of WoT, a plugin for Freenet. It is distributed 
+ * under the GNU General Public License, version 2 (or at your option
+ * any later version). See http://www.gnu.org/ for details of the GPL.
+ */
+package plugins.WoT.test;
+
+import java.io.File;
+import java.net.MalformedURLException;
+
+import plugins.WoT.Identity;
+import plugins.WoT.Trust;
+import plugins.WoT.exceptions.DuplicateIdentityException;
+import plugins.WoT.exceptions.DuplicateTrustException;
+import plugins.WoT.exceptions.InvalidParameterException;
+import plugins.WoT.exceptions.NotTrustedException;
+import plugins.WoT.exceptions.UnknownIdentityException;
+
+import junit.framework.TestCase;
+
+import com.db4o.Db4o;
+import com.db4o.ObjectContainer;
+
+/**
+ * @author Julien Cornuwel (batosai at freenetproject.org)
+ */
+public class TrustTest extends TestCase {
+       
+       private String uriA = "USK at 
MF2Vc6FRgeFMZJ0s2l9hOop87EYWAydUZakJzL0OfV8,fQeN-RMQZsUrDha2LCJWOMFk1-EiXZxfTnBT8NEgY00,AQACAAE/WoT/0";
+       private String uriB = "USK at 
R3Lp2s4jdX-3Q96c0A9530qg7JsvA9vi2K0hwY9wG-4,ipkgYftRpo0StBlYkJUawZhg~SO29NZIINseUtBhEfE,AQACAAE/WoT/0";
+       
+       private Identity a;
+       private Identity b;
+       
+       private ObjectContainer db;
+       
+       public TrustTest(String name) {
+               super(name);
+       }
+       
+       protected void setUp() throws Exception {
+               
+               super.setUp();
+               db = Db4o.openFile("trustTest.db4o");
+
+               a = new Identity(uriA, "A", "true");
+               b = new Identity(uriB, "B", "true");
+               Trust trust = new Trust(a,b,100,"test");
+               db.store(trust);
+               db.store(a);
+               db.store(b);
+               db.commit();
+       }
+       
+       protected void tearDown() throws Exception {
+               db.close();
+               new File("trustTest.db4o").delete();
+       }
+       
+       public void testTrust() throws InvalidParameterException, 
NotTrustedException, DuplicateTrustException {
+
+               Trust trust = a.getGivenTrust(b, db);
+               assertTrue(trust.getTruster() == a);
+               assertTrue(trust.getTrustee() == b);
+               assertTrue(trust.getValue() == 100);
+               assertTrue(trust.getComment().equals("test"));
+       }
+       
+       public void testTrustPersistence() throws MalformedURLException, 
UnknownIdentityException, DuplicateIdentityException, NotTrustedException, 
DuplicateTrustException  {
+               
+               db.close();
+               
+               System.gc();
+               System.runFinalization();
+               
+               db = Db4o.openFile("trustTest.db4o");
+               
+               a = Identity.getByURI(db, uriA);
+               b = Identity.getByURI(db, uriB);
+               Trust trust = a.getGivenTrust(b, db);
+               
+               assertTrue(trust.getTruster() == a);
+               assertTrue(trust.getTrustee() == b);
+               assertTrue(trust.getValue() == 100);
+               assertTrue(trust.getComment().equals("test"));
+       }
+}

Copied: trunk/plugins/WoT/test/WoTTest.java (from rev 22724, 
trunk/plugins/WoT/WoTTest.java)
===================================================================
--- trunk/plugins/WoT/test/WoTTest.java                         (rev 0)
+++ trunk/plugins/WoT/test/WoTTest.java 2008-09-20 22:26:12 UTC (rev 22725)
@@ -0,0 +1,279 @@
+/**
+ * This code is part of WoT, a plugin for Freenet. It is distributed 
+ * under the GNU General Public License, version 2 (or at your option
+ * any later version). See http://www.gnu.org/ for details of the GPL.
+ */
+package plugins.WoT.test;
+
+import java.io.File;
+import java.net.MalformedURLException;
+
+import plugins.WoT.Identity;
+import plugins.WoT.OwnIdentity;
+import plugins.WoT.Score;
+import plugins.WoT.Trust;
+import plugins.WoT.exceptions.DuplicateScoreException;
+import plugins.WoT.exceptions.DuplicateTrustException;
+import plugins.WoT.exceptions.InvalidParameterException;
+import plugins.WoT.exceptions.NotInTrustTreeException;
+import plugins.WoT.exceptions.NotTrustedException;
+
+import com.db4o.Db4o;
+import com.db4o.ObjectContainer;
+import com.db4o.ObjectSet;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Julien Cornuwel (batosai at freenetproject.org)
+ */
+public class WoTTest extends TestCase {
+       
+       private ObjectContainer db;
+       
+       private String uriA = "USK at 
MF2Vc6FRgeFMZJ0s2l9hOop87EYWAydUZakJzL0OfV8,fQeN-RMQZsUrDha2LCJWOMFk1-EiXZxfTnBT8NEgY00,AQACAAE/WoT/0";
+       private String uriB = "USK at 
R3Lp2s4jdX-3Q96c0A9530qg7JsvA9vi2K0hwY9wG-4,ipkgYftRpo0StBlYkJUawZhg~SO29NZIINseUtBhEfE,AQACAAE/WoT/0";
+       private String uriC = "USK at 
qd-hk0vHYg7YvK2BQsJMcUD5QSF0tDkgnnF6lnWUH0g,xTFOV9ddCQQk6vQ6G~jfL6IzRUgmfMcZJ6nuySu~NUc,AQACAAE/WoT/0";
+               
+       public WoTTest(String name) {
+               super(name);
+       }
+       
+       protected void setUp() throws Exception {
+               
+               super.setUp();
+               db = Db4o.openFile("wotTest.db4o");
+       }
+       
+       protected void tearDown() throws Exception {
+               db.close();
+               new File("wotTest.db4o").delete();
+       }
+       
+       public void testInitTrustTree() throws DuplicateScoreException, 
NotInTrustTreeException, MalformedURLException, InvalidParameterException {
+               
+               OwnIdentity a = new OwnIdentity(uriA, uriA, "A", "true");
+               db.store(a);
+               a.initTrustTree(db);
+               
+               assertTrue(Identity.getNbIdentities(db) == 0);
+               assertTrue(OwnIdentity.getNbOwnIdentities(db) == 1);
+               assertTrue(Trust.getNb(db) == 0);
+               assertTrue(Score.getNb(db) == 1);
+
+               assertTrue(a.getScore(a, db).getScore() == 100);
+               assertTrue(a.getScore(a, db).getRank() == 0);
+               assertTrue(a.getScore(a, db).getCapacity() == 100);
+               assertTrue(a.getScore(a, db).getTreeOwner() == a);
+               assertTrue(a.getScore(a, db).getTarget() == a);
+               
+               // Empty the database
+               ObjectSet<Object> all = db.queryByExample(new Object());
+               while(all.hasNext()) db.delete(all.next());
+       }
+       
+       public void testSetTrust() throws DuplicateTrustException, 
InvalidParameterException, DuplicateScoreException, NotTrustedException, 
NotInTrustTreeException, MalformedURLException {
+
+               OwnIdentity a = new OwnIdentity(uriA, uriA, "A", "true");
+               Identity b = new Identity(uriB, "B", "true");
+               db.store(a);
+               db.store(b);
+               
+               // With A's trust tree not initialized, B shouldn't get a Score.
+               a.setTrust(db, b, 10, "Foo");
+
+               assertTrue(Identity.getNbIdentities(db) == 1);
+               assertTrue(OwnIdentity.getNbOwnIdentities(db) == 1);
+               assertTrue(Trust.getNb(db) == 1);
+               assertTrue(Score.getNb(db) == 0);
+               
+               // Initialize A's trust tree and set the trust relationship
+               a.initTrustTree(db);
+               a.setTrust(db, b, 100, "Foo");
+               
+               // Check we have the correct number of objects
+               assertTrue(Identity.getNbIdentities(db) == 1);
+               assertTrue(OwnIdentity.getNbOwnIdentities(db) == 1);
+               assertTrue(Trust.getNb(db) == 1);
+               assertTrue(Score.getNb(db) == 2);
+               
+               // Check the Trust object
+               assertTrue(b.getReceivedTrust(a, db).getTruster() == a);
+               assertTrue(b.getReceivedTrust(a, db).getTrustee() == b);
+               assertTrue(b.getReceivedTrust(a, db).getValue() == 100);
+               assertTrue(b.getReceivedTrust(a, 
db).getComment().equals("Foo"));
+
+               // Check a's Score object
+               assertTrue(a.getScore(a, db).getScore() == 100);
+               assertTrue(a.getScore(a, db).getRank() == 0);
+               assertTrue(a.getScore(a, db).getCapacity() == 100);
+               
+               // Check B's Score object
+               assertTrue(b.getScore(a, db).getScore() == 100);
+               assertTrue(b.getScore(a, db).getRank() == 1);
+               assertTrue(b.getScore(a, db).getCapacity() == 40);
+               
+               // Change the trust value and comment
+               a.setTrust(db, b, 50, "Bar");
+               
+               // Check we have the correct number of objects
+               assertTrue(Identity.getNbIdentities(db) == 1);
+               assertTrue(OwnIdentity.getNbOwnIdentities(db) == 1);
+               assertTrue(Trust.getNb(db) == 1);
+               assertTrue(Score.getNb(db) == 2);
+               
+               // Check the Trust object
+               assertTrue(b.getReceivedTrust(a, db).getTruster() == a);
+               assertTrue(b.getReceivedTrust(a, db).getTrustee() == b);
+               assertTrue(b.getReceivedTrust(a, db).getValue() == 50);
+               assertTrue(b.getReceivedTrust(a, 
db).getComment().equals("Bar"));
+
+               // Check a's Score object
+               assertTrue(a.getScore(a, db).getScore() == 100);
+               assertTrue(a.getScore(a, db).getRank() == 0);
+               assertTrue(a.getScore(a, db).getCapacity() == 100);
+               
+               // Check B's Score object
+               assertTrue(b.getScore(a, db).getScore() == 50);
+               assertTrue(b.getScore(a, db).getRank() == 1);
+               assertTrue(b.getScore(a, db).getCapacity() == 40);
+               
+               // Empty the database
+               ObjectSet<Object> all = db.queryByExample(new Object());
+               while(all.hasNext()) db.delete(all.next());
+       }
+       
+       public void testRemoveTrust() throws MalformedURLException, 
InvalidParameterException, DuplicateScoreException, DuplicateTrustException, 
NotTrustedException, NotInTrustTreeException {
+               OwnIdentity a = new OwnIdentity(uriA, uriA, "A", "true");
+               Identity b = new Identity(uriB, "B", "true");
+               Identity c = new Identity(uriC, "C", "true");
+               db.store(a);
+               db.store(b);
+               db.store(c);
+               a.initTrustTree(db);
+               a.setTrust(db, b, 100, "Foo");
+               b.setTrust(db, c, 50, "Bar");
+               
+               // Check we have the correct number of objects
+               assertTrue(OwnIdentity.getNbOwnIdentities(db) == 1);
+               assertTrue(Identity.getNbIdentities(db) == 2);
+               assertTrue(Trust.getNb(db) == 2);
+               assertTrue(Score.getNb(db) == 3);
+               
+               // Check a's Score object
+               assertTrue(a.getScore(a, db).getScore() == 100);
+               assertTrue(a.getScore(a, db).getRank() == 0);
+               assertTrue(a.getScore(a, db).getCapacity() == 100);
+               
+               // Check B's Score object
+               assertTrue(b.getScore(a, db).getScore() == 100);
+               assertTrue(b.getScore(a, db).getRank() == 1);
+               assertTrue(b.getScore(a, db).getCapacity() == 40);
+               
+               // Check C's Score object
+               assertTrue(c.getScore(a, db).getScore() == 20);
+               assertTrue(c.getScore(a, db).getRank() == 2);
+               assertTrue(c.getScore(a, db).getCapacity() == 16);
+               
+               a.setTrust(db, b, -1, "Bastard");
+               
+               // Check we have the correct number of objects
+               assertTrue(OwnIdentity.getNbOwnIdentities(db) == 1);
+               assertTrue(Identity.getNbIdentities(db) == 2);
+               assertTrue(Trust.getNb(db) == 2);
+               assertTrue(Score.getNb(db) == 2);
+               
+               // Check a's Score object
+               assertTrue(a.getScore(a, db).getScore() == 100);
+               assertTrue(a.getScore(a, db).getRank() == 0);
+               assertTrue(a.getScore(a, db).getCapacity() == 100);
+               
+               // Check B's Score object
+               assertTrue(b.getScore(a, db).getScore() == -1);
+               assertTrue(b.getScore(a, db).getRank() == 1);
+               assertTrue(b.getScore(a, db).getCapacity() == 0);
+               
+               // C should not have a score anymore
+               try {
+                       c.getScore(a, db);
+                       fail();
+               }
+               catch (NotInTrustTreeException e) {}
+               
+               // Empty the database
+               ObjectSet<Object> all = db.queryByExample(new Object());
+               while(all.hasNext()) db.delete(all.next());
+       }
+       
+       public void testTrustLoop() throws MalformedURLException, 
InvalidParameterException, DuplicateScoreException, DuplicateTrustException, 
NotInTrustTreeException {
+               OwnIdentity a = new OwnIdentity(uriA, uriA, "A", "true");
+               Identity b = new Identity(uriB, "B", "true");
+               Identity c = new Identity(uriC, "C", "true");
+               db.store(a);
+               db.store(b);
+               db.store(c);
+               a.initTrustTree(db);
+               a.setTrust(db, b, 100, "Foo");
+               b.setTrust(db, c, 50, "Bar");
+               c.setTrust(db, a, 100, "Bleh");
+               c.setTrust(db, b, 50, "Oops");
+               
+               // Check we have the correct number of objects
+               assertTrue(OwnIdentity.getNbOwnIdentities(db) == 1);
+               assertTrue(Identity.getNbIdentities(db) == 2);
+               assertTrue(Trust.getNb(db) == 4);
+               assertTrue(Score.getNb(db) == 3);
+               
+               // Check a's Score object
+               assertTrue(a.getScore(a, db).getScore() == 100);
+               assertTrue(a.getScore(a, db).getRank() == 0);
+               assertTrue(a.getScore(a, db).getCapacity() == 100);
+               
+               // Check B's Score object
+               assertTrue(b.getScore(a, db).getScore() == 108);
+               assertTrue(b.getScore(a, db).getRank() == 1);
+               assertTrue(b.getScore(a, db).getCapacity() == 40);
+               
+               // Check C's Score object
+               assertTrue(c.getScore(a, db).getScore() == 20);
+               assertTrue(c.getScore(a, db).getRank() == 2);
+               assertTrue(c.getScore(a, db).getCapacity() == 16);
+       }
+       
+       public void testOwnIndentitiesTrust() throws MalformedURLException, 
InvalidParameterException, DuplicateScoreException, DuplicateTrustException, 
NotTrustedException, NotInTrustTreeException {
+               OwnIdentity a = new OwnIdentity(uriA, uriA, "A", "true");
+               OwnIdentity b = new OwnIdentity(uriB, uriB, "B", "true");
+               db.store(a);
+               db.store(b);
+               a.initTrustTree(db);
+               b.initTrustTree(db);
+               a.setTrust(db, b, 100, "Foo");
+               b.setTrust(db, a, 100, "Bar");
+               
+               // Check we have the correct number of objects
+               assertTrue(OwnIdentity.getNbOwnIdentities(db) == 2);
+               assertTrue(Identity.getNbIdentities(db) == 0);
+               assertTrue(Trust.getNb(db) == 2);
+               assertTrue(Score.getNb(db) == 4);
+               
+               // Check a's own Score object
+               assertTrue(a.getScore(a, db).getScore() == 100);
+               assertTrue(a.getScore(a, db).getRank() == 0);
+               assertTrue(a.getScore(a, db).getCapacity() == 100);
+               
+               // Check a's Score object
+               assertTrue(a.getScore(b, db).getScore() == 100);
+               assertTrue(a.getScore(b, db).getRank() == 1);
+               assertTrue(a.getScore(b, db).getCapacity() == 40);
+                               
+               // Check B's own Score object
+               assertTrue(b.getScore(b, db).getScore() == 100);
+               assertTrue(b.getScore(b, db).getRank() == 0);
+               assertTrue(b.getScore(b, db).getCapacity() == 100);
+
+               // Check B's Score object
+               assertTrue(b.getScore(a, db).getScore() == 100);
+               assertTrue(b.getScore(a, db).getRank() == 1);
+               assertTrue(b.getScore(a, db).getCapacity() == 40);
+       }
+}


Reply via email to