Author: vmassol
Date: 2008-01-27 14:32:24 +0100 (Sun, 27 Jan 2008)
New Revision: 7093
Modified:
xwiki-platform/core/trunk/xwiki-core/src/test/java/com/xpn/xwiki/doc/XWikiDocumentArchiveTest.java
Log:
Added a unit test to prove that the diff and full content revision algorithm
works fine
Modified:
xwiki-platform/core/trunk/xwiki-core/src/test/java/com/xpn/xwiki/doc/XWikiDocumentArchiveTest.java
===================================================================
---
xwiki-platform/core/trunk/xwiki-core/src/test/java/com/xpn/xwiki/doc/XWikiDocumentArchiveTest.java
2008-01-26 14:44:08 UTC (rev 7092)
+++
xwiki-platform/core/trunk/xwiki-core/src/test/java/com/xpn/xwiki/doc/XWikiDocumentArchiveTest.java
2008-01-27 13:32:24 UTC (rev 7093)
@@ -210,11 +210,7 @@
doc.setDocumentArchive(archive);
String author = "XWiki.some author";
- doc.setContent("content 1.1");
- doc.setAuthor(author);
- doc.setComment("initial, 1.1");
- doc.setDate(new Date());
- archive.updateArchive(doc, doc.getAuthor(), doc.getDate(),
doc.getComment(), null, context);
+ addRevisionToHistory(archive, doc, "content 1.1", author, "initial
1.1");
XWikiDocument doc11 = (XWikiDocument) doc.clone();
doc.setContent("content 2.1\nqwe @ ");
@@ -253,11 +249,7 @@
doc.setDocumentArchive(archive);
String author = "XWiki.some author";
- doc.setContent("content 1.1");
- doc.setAuthor(author);
- doc.setComment("initial, 1.1");
- doc.setDate(new Date());
- archive.updateArchive(doc, doc.getAuthor(), doc.getDate(),
doc.getComment(), null, context);
+ addRevisionToHistory(archive, doc, "content 1.1", author, "initial
1.1");
Date creationDate = doc.getCreationDate();
@@ -272,4 +264,60 @@
assertEquals(creationDate, latest.getCreationDate());
}
+
+ public void testVerifyDiffAndFullRevisionAlgorithm() throws Exception
+ {
+ XWikiDocument doc = new XWikiDocument("Test", "Test");
+ XWikiDocumentArchive archive = new XWikiDocumentArchive(doc.getId());
+ doc.setDocumentArchive(archive);
+ String author = "XWiki.some author";
+
+ // The first revision is always a full revision (not a diff)
+ addRevisionToHistory(archive, doc, "content 1.1", author, "1.1");
+ assertFalse(archive.getNode(new Version(1, 1)).isDiff());
+
+ // When a new revision is added the new revision is always the full
revision but the previous one is
+ // modified to be a diff.
+ addRevisionToHistory(archive, doc, "content 2.1", author, "2.1");
+ assertTrue(archive.getNode(new Version(1, 1)).isDiff());
+ assertFalse(archive.getNode(new Version(2, 1)).isDiff());
+
+ addRevisionToHistory(archive, doc, "content 3.1", author, "3.1");
+ assertTrue(archive.getNode(new Version(1, 1)).isDiff());
+ assertTrue(archive.getNode(new Version(2, 1)).isDiff());
+ assertFalse(archive.getNode(new Version(3, 1)).isDiff());
+
+ addRevisionToHistory(archive, doc, "content 4.1", author, "4.1");
+ assertTrue(archive.getNode(new Version(1, 1)).isDiff());
+ assertTrue(archive.getNode(new Version(2, 1)).isDiff());
+ assertTrue(archive.getNode(new Version(3, 1)).isDiff());
+ assertFalse(archive.getNode(new Version(4, 1)).isDiff());
+
+ // Every 5th revision we save the full content and not a diff
+ addRevisionToHistory(archive, doc, "content 5.1", author, "5.1");
+ assertTrue(archive.getNode(new Version(1, 1)).isDiff());
+ assertTrue(archive.getNode(new Version(2, 1)).isDiff());
+ assertTrue(archive.getNode(new Version(3, 1)).isDiff());
+ assertTrue(archive.getNode(new Version(4, 1)).isDiff());
+ assertFalse(archive.getNode(new Version(5, 1)).isDiff());
+
+ // Verify that the 5th revision is kept as a full content revision
when the 6th is added
+ addRevisionToHistory(archive, doc, "content 6.1", author, "6.1");
+ assertTrue(archive.getNode(new Version(1, 1)).isDiff());
+ assertTrue(archive.getNode(new Version(2, 1)).isDiff());
+ assertTrue(archive.getNode(new Version(3, 1)).isDiff());
+ assertTrue(archive.getNode(new Version(4, 1)).isDiff());
+ assertFalse(archive.getNode(new Version(5, 1)).isDiff());
+ assertFalse(archive.getNode(new Version(6, 1)).isDiff());
+ }
+
+ private void addRevisionToHistory(XWikiDocumentArchive archive,
XWikiDocument document, String content,
+ String author, String comment) throws XWikiException
+ {
+ document.setContent(content);
+ document.setAuthor(author);
+ document.setComment(comment);
+ document.setDate(new Date());
+ archive.updateArchive(document, document.getAuthor(),
document.getDate(), document.getComment(), null, context);
+ }
}
_______________________________________________
notifications mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/notifications