summaryrefslogtreecommitdiffstats
path: root/test/src
diff options
context:
space:
mode:
authorJames Ahlborn <jtahlborn@yahoo.com>2007-11-26 20:18:09 +0000
committerJames Ahlborn <jtahlborn@yahoo.com>2007-11-26 20:18:09 +0000
commit2c900e17e9bd5299ecbc7c4bc19eff06583e1069 (patch)
tree999a0afb8aa369dc26e3595ac86115bc05aa4571 /test/src
parentd14cd359868ad5472e9bbf1f92185af44a9c98ac (diff)
downloadjackcess-2c900e17e9bd5299ecbc7c4bc19eff06583e1069.tar.gz
jackcess-2c900e17e9bd5299ecbc7c4bc19eff06583e1069.zip
make usagemap cursor work similarly to Cursor; handle live additions and deletions better
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@183 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'test/src')
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/CursorTest.java72
1 files changed, 72 insertions, 0 deletions
diff --git a/test/src/java/com/healthmarketscience/jackcess/CursorTest.java b/test/src/java/com/healthmarketscience/jackcess/CursorTest.java
index ed3e5c5..dc6cc01 100644
--- a/test/src/java/com/healthmarketscience/jackcess/CursorTest.java
+++ b/test/src/java/com/healthmarketscience/jackcess/CursorTest.java
@@ -155,5 +155,77 @@ public class CursorTest extends TestCase {
db.close();
}
+ public void testLiveAddition() throws Exception {
+ Database db = createTestTable();
+
+ Table table = db.getTable("test");
+
+ Cursor cursor1 = Cursor.createCursor(table);
+ Cursor cursor2 = Cursor.createCursor(table);
+ cursor1.skipNextRows(11);
+ cursor2.skipNextRows(11);
+
+ assertTrue(cursor1.isAfterLast());
+ assertTrue(cursor2.isAfterLast());
+
+ int newRowNum = 11;
+ table.addRow(newRowNum, "data" + newRowNum);
+ Map<String,Object> expectedRow =
+ createExpectedRow("id", newRowNum, "value", "data" + newRowNum);
+
+ assertFalse(cursor1.isAfterLast());
+ assertFalse(cursor2.isAfterLast());
+
+ assertEquals(expectedRow, cursor1.getCurrentRow());
+ assertEquals(expectedRow, cursor2.getCurrentRow());
+ assertFalse(cursor1.moveToNextRow());
+ assertFalse(cursor2.moveToNextRow());
+ assertTrue(cursor1.isAfterLast());
+ assertTrue(cursor2.isAfterLast());
+
+ db.close();
+ }
+
+ public void testLiveDeletion() throws Exception {
+ Database db = createTestTable();
+
+ Table table = db.getTable("test");
+
+ Cursor cursor1 = Cursor.createCursor(table);
+ Cursor cursor2 = Cursor.createCursor(table);
+ Cursor cursor3 = Cursor.createCursor(table);
+ Cursor cursor4 = Cursor.createCursor(table);
+ cursor1.skipNextRows(2);
+ cursor2.skipNextRows(3);
+ cursor3.skipNextRows(3);
+ cursor4.skipNextRows(4);
+
+ Map<String,Object> expectedPrevRow =
+ createExpectedRow("id", 1, "value", "data" + 1);
+ Map<String,Object> expectedDeletedRow =
+ createExpectedRow("id", 2, "value", "data" + 2);
+ Map<String,Object> expectedNextRow =
+ createExpectedRow("id", 3, "value", "data" + 3);
+
+ assertEquals(expectedDeletedRow, cursor2.getCurrentRow());
+ assertEquals(expectedDeletedRow, cursor3.getCurrentRow());
+
+ assertFalse(cursor2.isCurrentRowDeleted());
+ assertFalse(cursor3.isCurrentRowDeleted());
+
+ cursor2.deleteCurrentRow();
+
+ assertTrue(cursor2.isCurrentRowDeleted());
+ assertTrue(cursor3.isCurrentRowDeleted());
+
+ assertEquals(expectedNextRow, cursor1.getNextRow());
+ assertEquals(expectedNextRow, cursor2.getNextRow());
+ assertEquals(expectedNextRow, cursor3.getNextRow());
+
+ assertEquals(expectedPrevRow, cursor3.getPreviousRow());
+
+ db.close();
+ }
+
}