|
From: Pelle B. <pe...@us...> - 2004-03-26 23:47:37
|
Update of /cvsroot/neuclear/neuclear-ledger/src/java/org/neuclear/ledger/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25331/src/java/org/neuclear/ledger/tests Modified Files: AbstractLedgerBrowserTest.java Log Message: The simple browse(book) now works on hibernate, I have implemented the other two, which currently don not constrain the query correctly. Index: AbstractLedgerBrowserTest.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-ledger/src/java/org/neuclear/ledger/tests/AbstractLedgerBrowserTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** AbstractLedgerBrowserTest.java 26 Mar 2004 18:37:56 -0000 1.1 --- AbstractLedgerBrowserTest.java 26 Mar 2004 23:36:34 -0000 1.2 *************** *** 8,14 **** --- 8,19 ---- import org.neuclear.ledger.browser.LedgerBrowser; + import java.util.Date; + /* $Id$ $Log$ + Revision 1.2 2004/03/26 23:36:34 pelle + The simple browse(book) now works on hibernate, I have implemented the other two, which currently don not constrain the query correctly. + Revision 1.1 2004/03/26 18:37:56 pelle More work on browsers. Added an AbstractLedgerBrowserTest for unit testing LedgerBrowsers. *************** *** 29,44 **** public abstract Ledger getLedger() throws LowlevelLedgerException; ! public void testIsBrowser() throws LowlevelLedgerException { ! final Ledger ledger = getLedger(); assertTrue("Ledger is instance of LedgerBrowser", ledger instanceof LedgerBrowser); ledger.close(); } public void testAmountOfEntries() throws LowlevelLedgerException, InvalidTransactionException { ! final Ledger ledger = getLedger(); ! assertTrue("Ledger is instance of LedgerBrowser", ledger instanceof LedgerBrowser); ! final LedgerBrowser browser = (LedgerBrowser) ledger; final String bob = getBobBook(); final String alice = getAliceBook(); --- 34,62 ---- public abstract Ledger getLedger() throws LowlevelLedgerException; ! protected void setUp() throws Exception { ! ledger = getLedger(); assertTrue("Ledger is instance of LedgerBrowser", ledger instanceof LedgerBrowser); + browser = (LedgerBrowser) ledger; + } + + protected void tearDown() throws Exception { ledger.close(); } public void testAmountOfEntries() throws LowlevelLedgerException, InvalidTransactionException { ! final String bob = getBobBook(); ! final String alice = getAliceBook(); ! assertBookBrowserSize(bob, 0, browser.browse(bob)); ! assertBookBrowserSize(alice, 0, browser.browse(alice)); ! int i; ! for (i = 0; i < 10; i++) { ! ledger.transfer(bob, alice, 10, "test" + i); ! } ! assertBookBrowserSize(bob, i, browser.browse(bob)); ! assertBookBrowserSize(alice, i, browser.browse(alice)); ! } + public void testEntryContent() throws LowlevelLedgerException, InvalidTransactionException { final String bob = getBobBook(); final String alice = getAliceBook(); *************** *** 50,58 **** ledger.transfer(bob, alice, 10, "test" + i); } assertBookBrowserSize(bob, i, browser.browse(bob)); assertBookBrowserSize(alice, i, browser.browse(alice)); - ledger.close(); } --- 68,144 ---- ledger.transfer(bob, alice, 10, "test" + i); } + assertVerifyBrowserContent(bob, alice, -10, i, browser.browse(bob)); + assertVerifyBrowserContent(alice, bob, 10, i, browser.browse(alice)); + + + } + + public void testAmountOfEntriesFromTime() throws LowlevelLedgerException, InvalidTransactionException { + final String bob = getBobBook(); + final String alice = getAliceBook(); + + Date t1 = new Date(); + assertBookBrowserSize(bob, 0, browser.browse(bob)); + assertBookBrowserSize(alice, 0, browser.browse(alice)); + int i; + for (i = 0; i < 10; i++) { + ledger.transfer(bob, alice, 10, "test" + i); + } assertBookBrowserSize(bob, i, browser.browse(bob)); assertBookBrowserSize(alice, i, browser.browse(alice)); + Date t2 = new Date(); + assertTrue(t2.after(t1)); + + for (i = 0; i < 10; i++) { + ledger.transfer(bob, alice, 10, "test" + i); + } + assertBookBrowserSize(bob, 20, browser.browse(bob)); + assertBookBrowserSize(alice, 20, browser.browse(alice)); + + assertBookBrowserSize(bob, 20, browser.browseFrom(bob, t1)); + assertBookBrowserSize(alice, 20, browser.browseFrom(alice, t1)); + + + assertBookBrowserSize(bob, i, browser.browseFrom(bob, t2)); + assertBookBrowserSize(alice, i, browser.browseFrom(alice, t2)); + + } + + public void testEntryContentFromTime() throws LowlevelLedgerException, InvalidTransactionException { + final String bob = getBobBook(); + final String alice = getAliceBook(); + + assertBookBrowserSize(bob, 0, browser.browse(bob)); + assertBookBrowserSize(alice, 0, browser.browse(alice)); + int i; + for (i = 0; i < 10; i++) { + ledger.transfer(bob, alice, 10, "test" + i); + } + assertVerifyBrowserContent(bob, alice, -10, i, browser.browse(bob)); + assertVerifyBrowserContent(alice, bob, 10, i, browser.browse(alice)); + + + } + + + public void assertVerifyBrowserContent(final String book, final String counterparty, final double amount, final int count, final BookBrowser bb) throws LowlevelLedgerException { + assertNotNull("null book browser for " + book, bb); + int total = 0; + while (bb.next()) { + assertEquals("book", book, bb.getBook()); + assertEquals("counterparty", counterparty, bb.getCounterparty()); + assertEquals("amount", amount, bb.getAmount(), 0); + assertEquals("comment", "test" + total, bb.getComment()); + assertNotNull("id", bb.getId()); + assertNotNull("reqid", bb.getRequestId()); + assertNotNull("valuetime", bb.getValuetime()); + assertNull("expiry", bb.getExpirytime()); + assertNull("cancelled", bb.getCancelled()); + assertNull("completed", bb.getCompletedId()); + total++; + } + assertEquals("The size doesnt match for: " + book, count, total); } *************** *** 78,80 **** --- 164,169 ---- } + protected Ledger ledger; + protected LedgerBrowser browser; + } |