|
From: <pe...@us...> - 2003-11-21 04:43:24
|
Update of /cvsroot/neuclear/neuclear-ledger/src/test/org/neuclear/ledger
In directory sc8-pr-cvs1:/tmp/cvs-serv10452/src/test/org/neuclear/ledger
Modified Files:
LedgerTest.java SQLLedgerTest.java
Log Message:
EncryptedFileStore now works. It uses the PBECipher with DES3 afair.
Otherwise You will Finaliate.
Anything that can be final has been made final throughout everyting. We've used IDEA's Inspector tool to find all instance of variables that could be final.
This should hopefully make everything more stable (and secure).
Index: LedgerTest.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-ledger/src/test/org/neuclear/ledger/LedgerTest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** LedgerTest.java 11 Nov 2003 21:17:32 -0000 1.4
--- LedgerTest.java 21 Nov 2003 04:43:21 -0000 1.5
***************
*** 8,11 ****
--- 8,14 ----
import java.util.Random;
+ import org.neuclear.ledger.implementations.SQLLedger;
+ import org.neuclear.commons.sql.DefaultConnectionSource;
+
/**
* (C) 2003 Antilles Software Ventures SA
***************
*** 15,18 ****
--- 18,27 ----
* $Id$
* $Log$
+ * Revision 1.5 2003/11/21 04:43:21 pelle
+ * EncryptedFileStore now works. It uses the PBECipher with DES3 afair.
+ * Otherwise You will Finaliate.
+ * Anything that can be final has been made final throughout everyting. We've used IDEA's Inspector tool to find all instance of variables that could be final.
+ * This should hopefully make everything more stable (and secure).
+ *
* Revision 1.4 2003/11/11 21:17:32 pelle
* Further vital reshuffling.
***************
*** 92,102 ****
*/
public abstract class LedgerTest extends TestCase {
! protected String account1 = "Bob";
! protected String account2 = "Alice";
! public LedgerTest(String s) throws LedgerCreationException, LowlevelLedgerException {
super(s);
! ledger = LedgerFactory.getInstance().getLedger("neu://superbux/reserve");
}
--- 101,111 ----
*/
public abstract class LedgerTest extends TestCase {
! protected final String account1 = "Bob";
! protected final String account2 = "Alice";
! public LedgerTest(final String s) throws LowlevelLedgerException, UnknownLedgerException {
super(s);
! ledger = new SQLLedger(new DefaultConnectionSource(), "neu://superbux/reserve");
}
***************
*** 104,111 ****
public abstract Ledger createLedger();
! public void testPostTransaction() throws LedgerException {
! Book bob = getNewBobBook();
! Book alice = getNewAliceBook();
! Date t1 = new Date();
bob.transfer(alice, 100, "Loan", t1);
}
--- 113,120 ----
public abstract Ledger createLedger();
! public final void testPostTransaction() throws LedgerException {
! final Book bob = getNewBobBook();
! final Book alice = getNewAliceBook();
! final Date t1 = new Date();
bob.transfer(alice, 100, "Loan", t1);
}
***************
*** 119,142 ****
}
! private Book createNewBook(String name) throws BookExistsException, LowlevelLedgerException {
! BigInteger id = new BigInteger(168, new Random());
! String bookID = name + id.toString(36);
System.out.println("bookid: " + bookID);
return ledger.createNewBook(bookID, name);
}
! public void testAccountCreate() throws LedgerException {
! Book bob = getNewBobBook();
assertNotNull(bob);
assertTrue(ledger.bookExists(bob.getBookID()));
}
! public void testBalance() throws LedgerException {
! Book alice = getNewAliceBook();
! Book bob = getNewBobBook();
! double aliceBalance = alice.getBalance();
! double bobBalance = bob.getBalance();
final double amount = 105;
! Date t1 = new Date();
alice.transfer(bob, amount, "Repayment", t1);
assertEquals(aliceBalance - amount, alice.getBalance(), 0);
--- 128,151 ----
}
! private Book createNewBook(final String name) throws BookExistsException, LowlevelLedgerException {
! final BigInteger id = new BigInteger(168, new Random());
! final String bookID = name + id.toString(36);
System.out.println("bookid: " + bookID);
return ledger.createNewBook(bookID, name);
}
! public final void testAccountCreate() throws LedgerException {
! final Book bob = getNewBobBook();
assertNotNull(bob);
assertTrue(ledger.bookExists(bob.getBookID()));
}
! public final void testBalance() throws LedgerException {
! final Book alice = getNewAliceBook();
! final Book bob = getNewBobBook();
! final double aliceBalance = alice.getBalance();
! final double bobBalance = bob.getBalance();
final double amount = 105;
! final Date t1 = new Date();
alice.transfer(bob, amount, "Repayment", t1);
assertEquals(aliceBalance - amount, alice.getBalance(), 0);
***************
*** 144,170 ****
}
! public void testTimeBalance() throws LedgerException {
! Calendar cal = Calendar.getInstance();
! Date t1 = cal.getTime();
cal.add(Calendar.DAY_OF_YEAR, 1);
! Date t2 = cal.getTime();
cal.add(Calendar.DAY_OF_YEAR, 1);
! Date t3 = cal.getTime();
cal.add(Calendar.DAY_OF_YEAR, 1);
! Date t4 = cal.getTime();
cal.add(Calendar.DAY_OF_YEAR, 1);
! Date t5 = cal.getTime();
! Book alice = getNewAliceBook();
! Book bob = getNewBobBook();
final double amount = 105;
! double payment = amount / 2;
alice.transfer(bob, payment, "Repayment", t2);
alice.transfer(bob, payment, "2nd Repayment", t4);
! double aliceBalance = alice.getBalance(t1);
! double bobBalance = bob.getBalance(t1);
assertEquals(aliceBalance - payment, alice.getBalance(t2), 0);
--- 153,179 ----
}
! public final void testTimeBalance() throws LedgerException {
! final Calendar cal = Calendar.getInstance();
! final Date t1 = cal.getTime();
cal.add(Calendar.DAY_OF_YEAR, 1);
! final Date t2 = cal.getTime();
cal.add(Calendar.DAY_OF_YEAR, 1);
! final Date t3 = cal.getTime();
cal.add(Calendar.DAY_OF_YEAR, 1);
! final Date t4 = cal.getTime();
cal.add(Calendar.DAY_OF_YEAR, 1);
! final Date t5 = cal.getTime();
! final Book alice = getNewAliceBook();
! final Book bob = getNewBobBook();
final double amount = 105;
! final double payment = amount / 2;
alice.transfer(bob, payment, "Repayment", t2);
alice.transfer(bob, payment, "2nd Repayment", t4);
! final double aliceBalance = alice.getBalance(t1);
! final double bobBalance = bob.getBalance(t1);
assertEquals(aliceBalance - payment, alice.getBalance(t2), 0);
***************
*** 181,198 ****
}
! public void testHold() throws LedgerException {
! Calendar cal = Calendar.getInstance();
! Date t1 = cal.getTime();
cal.add(Calendar.DAY_OF_YEAR, 1);
! Date t2 = cal.getTime();
cal.add(Calendar.DAY_OF_YEAR, 1);
! Date t3 = cal.getTime();
cal.add(Calendar.DAY_OF_YEAR, 1);
! Date t4 = cal.getTime();
cal.add(Calendar.DAY_OF_YEAR, 1);
! Date t5 = cal.getTime();
! Book alice = getNewAliceBook();
! Book bob = getNewBobBook();
--- 190,207 ----
}
! public final void testHold() throws LedgerException {
! final Calendar cal = Calendar.getInstance();
! final Date t1 = cal.getTime();
cal.add(Calendar.DAY_OF_YEAR, 1);
! final Date t2 = cal.getTime();
cal.add(Calendar.DAY_OF_YEAR, 1);
! final Date t3 = cal.getTime();
cal.add(Calendar.DAY_OF_YEAR, 1);
! final Date t4 = cal.getTime();
cal.add(Calendar.DAY_OF_YEAR, 1);
! final Date t5 = cal.getTime();
! final Book alice = getNewAliceBook();
! final Book bob = getNewBobBook();
***************
*** 202,207 ****
alice.hold(bob, amount, "Hold", t2, t4);
! double aliceBalance = alice.getBalance(t1);
! double bobBalance = bob.getBalance(t1);
// First lets check it hasnt affected the real balance
assertEquals(aliceBalance, alice.getBalance(t2), 0);
--- 211,216 ----
alice.hold(bob, amount, "Hold", t2, t4);
! final double aliceBalance = alice.getBalance(t1);
! final double bobBalance = bob.getBalance(t1);
// First lets check it hasnt affected the real balance
assertEquals(aliceBalance, alice.getBalance(t2), 0);
***************
*** 237,251 ****
}
! public void testReversal() throws LedgerException {
! Book bob = getNewBobBook();
! Book alice = getNewAliceBook();
! double amount = 123;
! double balance = bob.getBalance();
! PostedTransaction tran = bob.transfer(alice, amount, "Hello", new Date());
assertNotNull(tran);
assertEquals(bob.getBalance(), balance - amount, 0);
! PostedTransaction reverse = tran.reverse("Reverse it");
assertNotNull(reverse);
assertEquals(bob.getBalance(), balance, 0);
--- 246,260 ----
}
! public final void testReversal() throws LedgerException {
! final Book bob = getNewBobBook();
! final Book alice = getNewAliceBook();
! final double amount = 123;
! final double balance = bob.getBalance();
! final PostedTransaction tran = bob.transfer(alice, amount, "Hello", new Date());
assertNotNull(tran);
assertEquals(bob.getBalance(), balance - amount, 0);
! final PostedTransaction reverse = tran.reverse("Reverse it");
assertNotNull(reverse);
assertEquals(bob.getBalance(), balance, 0);
***************
*** 253,278 ****
}
! public void testCompleteHeld() throws LedgerException {
! Calendar cal = Calendar.getInstance();
! Date t1 = cal.getTime();
cal.add(Calendar.DAY_OF_YEAR, 1);
! Date t2 = cal.getTime();
cal.add(Calendar.DAY_OF_YEAR, 1);
! Date t3 = cal.getTime();
cal.add(Calendar.DAY_OF_YEAR, 1);
! Date t4 = cal.getTime();
cal.add(Calendar.DAY_OF_YEAR, 1);
! Date t5 = cal.getTime();
! Book ignacio = createNewBook("neu://verax/testusers/Ignacio");
! Book palacio = createNewBook("neu://verax/testusers/Palacio");
! double amount = 123;
! double held = 200;
! double balance = ignacio.getBalance(t1);
! PostedHeldTransaction hold = ignacio.hold(palacio, held, "Hello", t2, t4);
assertNotNull(hold);
assertEquals(ignacio.getBalance(t1), balance, 0);
--- 262,287 ----
}
! public final void testCompleteHeld() throws LedgerException {
! final Calendar cal = Calendar.getInstance();
! final Date t1 = cal.getTime();
cal.add(Calendar.DAY_OF_YEAR, 1);
! final Date t2 = cal.getTime();
cal.add(Calendar.DAY_OF_YEAR, 1);
! final Date t3 = cal.getTime();
cal.add(Calendar.DAY_OF_YEAR, 1);
! final Date t4 = cal.getTime();
cal.add(Calendar.DAY_OF_YEAR, 1);
! final Date t5 = cal.getTime();
! final Book ignacio = createNewBook("neu://verax/testusers/Ignacio");
! final Book palacio = createNewBook("neu://verax/testusers/Palacio");
! final double amount = 123;
! final double held = 200;
! final double balance = ignacio.getBalance(t1);
! final PostedHeldTransaction hold = ignacio.hold(palacio, held, "Hello", t2, t4);
assertNotNull(hold);
assertEquals(ignacio.getBalance(t1), balance, 0);
***************
*** 312,361 ****
}
! public void testFindTransaction() throws LowlevelLedgerException, BookExistsException, UnBalancedTransactionException, InvalidTransactionException, UnknownTransactionException, UnknownBookException {
! Book bob = getNewBobBook();
! Book alice = getNewAliceBook();
! double amount = 123;
! PostedTransaction tran = bob.transfer(alice, amount, "Can we find this again", new Date());
assertNotNull(tran);
! PostedTransaction found = ledger.findTransaction(tran.getXid());
assertNotNull(found);
assertEquals(found.getXid(), tran.getXid());
}
! public void testFindHeldTransaction() throws LowlevelLedgerException, BookExistsException, UnBalancedTransactionException, InvalidTransactionException, UnknownTransactionException, UnknownBookException {
! Book bob = getNewBobBook();
! Book alice = getNewAliceBook();
! double amount = 123;
! PostedHeldTransaction tran = bob.hold(alice, amount, "Can we find this again", new Date(), new Date());
assertNotNull(tran);
! PostedHeldTransaction found = ledger.findHeldTransaction(tran.getXid());
assertNotNull(found);
assertEquals(found.getXid(), tran.getXid());
}
! public void testCancelHeld() throws LedgerException {
! Calendar cal = Calendar.getInstance();
! Date t1 = cal.getTime();
cal.add(Calendar.DAY_OF_YEAR, 1);
! Date t2 = cal.getTime();
cal.add(Calendar.DAY_OF_YEAR, 1);
! Date t3 = cal.getTime();
cal.add(Calendar.DAY_OF_YEAR, 1);
! Date t4 = cal.getTime();
cal.add(Calendar.DAY_OF_YEAR, 1);
! Date t5 = cal.getTime();
! Book ignacio = createNewBook("neu://verax/testusers/Ignacio");
! Book palacio = createNewBook("neu://verax/testusers/Palacio");
! double amount = 123;
! double held = 200;
! double balance = ignacio.getBalance(t1);
! PostedHeldTransaction hold = ignacio.hold(palacio, held, "Hello", t2, t4);
assertNotNull(hold);
hold.cancel();
--- 321,370 ----
}
! public final void testFindTransaction() throws LowlevelLedgerException, BookExistsException, UnBalancedTransactionException, InvalidTransactionException, UnknownTransactionException, UnknownBookException {
! final Book bob = getNewBobBook();
! final Book alice = getNewAliceBook();
! final double amount = 123;
! final PostedTransaction tran = bob.transfer(alice, amount, "Can we find this again", new Date());
assertNotNull(tran);
! final PostedTransaction found = ledger.findTransaction(tran.getXid());
assertNotNull(found);
assertEquals(found.getXid(), tran.getXid());
}
! public final void testFindHeldTransaction() throws LowlevelLedgerException, BookExistsException, UnBalancedTransactionException, InvalidTransactionException, UnknownTransactionException, UnknownBookException {
! final Book bob = getNewBobBook();
! final Book alice = getNewAliceBook();
! final double amount = 123;
! final PostedHeldTransaction tran = bob.hold(alice, amount, "Can we find this again", new Date(), new Date());
assertNotNull(tran);
! final PostedHeldTransaction found = ledger.findHeldTransaction(tran.getXid());
assertNotNull(found);
assertEquals(found.getXid(), tran.getXid());
}
! public final void testCancelHeld() throws LedgerException {
! final Calendar cal = Calendar.getInstance();
! final Date t1 = cal.getTime();
cal.add(Calendar.DAY_OF_YEAR, 1);
! final Date t2 = cal.getTime();
cal.add(Calendar.DAY_OF_YEAR, 1);
! final Date t3 = cal.getTime();
cal.add(Calendar.DAY_OF_YEAR, 1);
! final Date t4 = cal.getTime();
cal.add(Calendar.DAY_OF_YEAR, 1);
! final Date t5 = cal.getTime();
! final Book ignacio = createNewBook("neu://verax/testusers/Ignacio");
! final Book palacio = createNewBook("neu://verax/testusers/Palacio");
! final double amount = 123;
! final double held = 200;
! final double balance = ignacio.getBalance(t1);
! final PostedHeldTransaction hold = ignacio.hold(palacio, held, "Hello", t2, t4);
assertNotNull(hold);
hold.cancel();
***************
*** 370,373 ****
}
! Ledger ledger;
}
--- 379,382 ----
}
! final Ledger ledger;
}
Index: SQLLedgerTest.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-ledger/src/test/org/neuclear/ledger/SQLLedgerTest.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** SQLLedgerTest.java 20 Sep 2003 23:16:21 -0000 1.1.1.1
--- SQLLedgerTest.java 21 Nov 2003 04:43:21 -0000 1.2
***************
*** 16,25 ****
* To change this template use Options | File Templates.
*/
! public class SQLLedgerTest extends LedgerTest{
! public SQLLedgerTest(String s) throws LedgerCreationException, LowlevelLedgerException {
super(s);
}
! public Ledger createLedger() {
return null; //To change body of implemented methods use Options | File Templates.
}
--- 16,25 ----
* To change this template use Options | File Templates.
*/
! public final class SQLLedgerTest extends LedgerTest{
! public SQLLedgerTest(final String s) throws LowlevelLedgerException, UnknownLedgerException {
super(s);
}
! public final Ledger createLedger() {
return null; //To change body of implemented methods use Options | File Templates.
}
|