Author: batosai
Date: 2008-09-07 14:32:55 +0000 (Sun, 07 Sep 2008)
New Revision: 22532
Modified:
trunk/plugins/WoT/src/plugins/WoT/ScoreTest.java
Log:
Cleaned up unit test for Score.
Modified: trunk/plugins/WoT/src/plugins/WoT/ScoreTest.java
===================================================================
--- trunk/plugins/WoT/src/plugins/WoT/ScoreTest.java 2008-09-07 14:31:16 UTC
(rev 22531)
+++ trunk/plugins/WoT/src/plugins/WoT/ScoreTest.java 2008-09-07 14:32:55 UTC
(rev 22532)
@@ -6,6 +6,7 @@
package plugins.WoT;
import java.io.File;
+import java.net.MalformedURLException;
import junit.framework.TestCase;
@@ -19,12 +20,10 @@
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 OwnIdentity a;
- private Identity b;
-
private ObjectContainer db;
- private boolean firstRun = false;
public ScoreTest(String name) {
super(name);
@@ -35,37 +34,23 @@
super.setUp();
db = Db4o.openFile("scoreTest.db4o");
- try {
- a = OwnIdentity.getByURI(db, uriA);
- b = Identity.getByURI(db, uriB);
- } catch (UnknownIdentityException e) {
- a = new OwnIdentity(uriA, uriA, "A", "true", "test");
- b = new Identity(uriB, "B", "true", "test");
- db.store(a);
- db.store(b);
- firstRun = true;
- System.out.println("First run of the score test. Run it
again to check data persistency");
- }
+ a = new OwnIdentity(uriA, uriA, "A", "true", "test");
+ b = new Identity(uriB, "B", "true", "test");
+ 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();
- if(!firstRun) new File("scoreTest.db4o").delete();
+ new File("scoreTest.db4o").delete();
}
- /*
- * You have to run 'ant' twice in order to really perform this test.
The goal is to check if db4o
- * is able to find a Trust object by its Identities pointers, even
across Database restarts.
- */
- public void testScore() throws DuplicateTrustException,
InvalidParameterException, DuplicateScoreException, NotInTrustTreeException {
- Score score;
+ public void testScoreCreation() throws NotInTrustTreeException,
DuplicateScoreException {
- if(firstRun) {
- score = new Score(a,b,100,1,40);
- db.store(score);
- } else {
- score = b.getScore(a, db);
- }
+ Score score = b.getScore(a, db);
assertTrue(score.getScore() == 100);
assertTrue(score.getRank() == 1);
@@ -73,4 +58,21 @@
assertTrue(score.getTreeOwner() == a);
assertTrue(score.getTarget() == b);
}
+
+ public void testScorePersistence() throws NotInTrustTreeException,
DuplicateScoreException, MalformedURLException, UnknownIdentityException,
DuplicateIdentityException {
+
+ db.close();
+ // TODO Force a garbage collection/finalization
+ 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