| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package com.xpn.xwiki.doc; |
| 21 |
|
|
| 22 |
|
import java.util.Date; |
| 23 |
|
|
| 24 |
|
import org.jmock.Mock; |
| 25 |
|
import org.suigeneris.jrcs.rcs.Version; |
| 26 |
|
import org.xwiki.model.reference.DocumentReference; |
| 27 |
|
|
| 28 |
|
import com.xpn.xwiki.XWiki; |
| 29 |
|
import com.xpn.xwiki.XWikiConfig; |
| 30 |
|
import com.xpn.xwiki.XWikiContext; |
| 31 |
|
import com.xpn.xwiki.XWikiException; |
| 32 |
|
import com.xpn.xwiki.test.AbstractBridgedXWikiComponentTestCase; |
| 33 |
|
import com.xpn.xwiki.user.api.XWikiRightService; |
| 34 |
|
|
| 35 |
|
|
| 36 |
|
@link |
| 37 |
|
|
| 38 |
|
@version |
| 39 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (131) |
Complexity: 7 |
Complexity Density: 0.06 |
|
| 40 |
|
public class XWikiDocumentArchiveTest extends AbstractBridgedXWikiComponentTestCase |
| 41 |
|
{ |
| 42 |
|
private XWikiContext context; |
| 43 |
|
|
| 44 |
|
private Mock mockXWiki; |
| 45 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
| 46 |
5 |
@Override... |
| 47 |
|
protected void setUp() throws Exception |
| 48 |
|
{ |
| 49 |
5 |
super.setUp(); |
| 50 |
|
|
| 51 |
5 |
this.mockXWiki = mock(XWiki.class); |
| 52 |
5 |
this.mockXWiki.stubs().method("getEncoding").will(returnValue("iso-8859-1")); |
| 53 |
5 |
this.mockXWiki.stubs().method("getConfig").will(returnValue(new XWikiConfig())); |
| 54 |
|
|
| 55 |
5 |
this.context = new XWikiContext(); |
| 56 |
5 |
this.context.setWiki((XWiki) this.mockXWiki.proxy()); |
| 57 |
|
} |
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
| 61 |
|
|
| 62 |
|
|
| 63 |
|
|
| 64 |
|
|
| 65 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
| 66 |
1 |
public void testUpdateArchiveWhenSpaceInUsername() throws Exception... |
| 67 |
|
{ |
| 68 |
1 |
String originalArchive = "head\t1.1;\n" + |
| 69 |
|
"access;\n" + |
| 70 |
|
"symbols;\n" + |
| 71 |
|
"locks; strict;\n" + |
| 72 |
|
"comment\t@# @;\n" + |
| 73 |
|
"\n" + |
| 74 |
|
"\n" + |
| 75 |
|
"1.1\n" + |
| 76 |
|
"date\t2007.02.14.14.01.57;\tauthor vmassol;\tstate Exp;\n" + |
| 77 |
|
"branches;\n" + |
| 78 |
|
"next\t;\n" + |
| 79 |
|
"\n" + |
| 80 |
|
"\n" + |
| 81 |
|
"desc\n" + |
| 82 |
|
"@@\n" + |
| 83 |
|
"\n" + |
| 84 |
|
"\n" + |
| 85 |
|
"1.1\n" + |
| 86 |
|
"log\n" + |
| 87 |
|
"@KnowledgeBase.WebHome\n" + |
| 88 |
|
"@\n" + |
| 89 |
|
"text\n" + |
| 90 |
|
"@<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" + |
| 91 |
|
"\n" + |
| 92 |
|
"<xwikidoc>\n" + |
| 93 |
|
"<web>KnowledgeBase</web>\n" + |
| 94 |
|
"<name>WebHome</name>\n" + |
| 95 |
|
"<language></language>\n" + |
| 96 |
|
"<defaultLanguage>en</defaultLanguage>\n" + |
| 97 |
|
"<translation>0</translation>\n" + |
| 98 |
|
"<parent>Main.Notes</parent>\n" + |
| 99 |
|
"<creator>XWiki.Admin</creator>\n" + |
| 100 |
|
"<author>XWiki.Admin</author>\n" + |
| 101 |
|
"<customClass></customClass>\n" + |
| 102 |
|
"<contentAuthor>XWiki.Admin</contentAuthor>\n" + |
| 103 |
|
"<creationDate>1165874272000</creationDate>\n" + |
| 104 |
|
"<date>1166177448000</date>\n" + |
| 105 |
|
"<contentUpdateDate>1171458116000</contentUpdateDate>\n" + |
| 106 |
|
"<version>1.1</version>\n" + |
| 107 |
|
"<title></title>\n" + |
| 108 |
|
"<template></template>\n" + |
| 109 |
|
"<defaultTemplate></defaultTemplate>\n" + |
| 110 |
|
"<validationScript></validationScript>\n" + |
| 111 |
|
"<object>\n" + |
| 112 |
|
"<class>\n" + |
| 113 |
|
"<name>XWiki.TagClass</name>\n" + |
| 114 |
|
"<customClass></customClass>\n" + |
| 115 |
|
"<customMapping></customMapping>\n" + |
| 116 |
|
"<defaultViewSheet></defaultViewSheet>\n" + |
| 117 |
|
"<defaultEditSheet></defaultEditSheet>\n" + |
| 118 |
|
"<defaultWeb></defaultWeb>\n" + |
| 119 |
|
"<nameField></nameField>\n" + |
| 120 |
|
"<validationScript></validationScript>\n" + |
| 121 |
|
"<tags>\n" + |
| 122 |
|
"<name>tags</name>\n" + |
| 123 |
|
"<prettyName>Tags</prettyName>\n" + |
| 124 |
|
"<unmodifiable>0</unmodifiable>\n" + |
| 125 |
|
"<relationalStorage>1</relationalStorage>\n" + |
| 126 |
|
"<displayType>checkbox</displayType>\n" + |
| 127 |
|
"<multiSelect>1</multiSelect>\n" + |
| 128 |
|
"<size>30</size>\n" + |
| 129 |
|
"<separator> </separator>\n" + |
| 130 |
|
"<separators> ,|</separators>\n" + |
| 131 |
|
"<values></values>\n" + |
| 132 |
|
"<number>1</number>\n" + |
| 133 |
|
"<classType>com.xpn.xwiki.objects.classes.StaticListClass</classType>\n" + |
| 134 |
|
"</tags>\n" + |
| 135 |
|
"</class>\n" + |
| 136 |
|
"<name>KnowledgeBase.WebHome</name>\n" + |
| 137 |
|
"<number>0</number>\n" + |
| 138 |
|
"<className>XWiki.TagClass</className>\n" + |
| 139 |
|
"<property>\n" + |
| 140 |
|
"<tags/>\n" + |
| 141 |
|
"</property>\n" + |
| 142 |
|
"</object>\n" + |
| 143 |
|
"<content>1 Wiki Knowledge Base\n" + |
| 144 |
|
"\n" + |
| 145 |
|
"This is the Wiki Knowledge Base, where you can start writing about your favorite subjects.\n" + |
| 146 |
|
"\n" + |
| 147 |
|
"To create new pages, click edit button and write links using brackets around words.\n" + |
| 148 |
|
"\n" + |
| 149 |
|
"* [Example Link 1]\n" + |
| 150 |
|
"* [Example Link 2]</content>\n" + |
| 151 |
|
"</xwikidoc>\n" + |
| 152 |
|
"@"; |
| 153 |
|
|
| 154 |
1 |
XWikiDocumentArchive archive = new XWikiDocumentArchive(123456789L); |
| 155 |
1 |
archive.setArchive(originalArchive); |
| 156 |
|
|
| 157 |
|
|
| 158 |
1 |
System.setProperty("user.name", "Vincent Massol"); |
| 159 |
|
|
| 160 |
1 |
XWikiDocument doc = new XWikiDocument(new DocumentReference("Wiki", "KnowledgeBase", "WebHome")); |
| 161 |
1 |
doc.setContent(doc.getContent() + "\nsomething added"); |
| 162 |
1 |
archive.updateArchive(doc, XWikiRightService.GUEST_USER_FULLNAME, new Date(), "some comment", null, context); |
| 163 |
|
|
| 164 |
|
|
| 165 |
|
|
| 166 |
|
|
| 167 |
1 |
new XWikiDocumentArchive(123456789L).setArchive(archive.getArchive(context)); |
| 168 |
|
} |
| 169 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (40) |
Complexity: 1 |
Complexity Density: 0.03 |
1PASS
|
|
| 170 |
1 |
public void testUpdateLoad() throws XWikiException... |
| 171 |
|
{ |
| 172 |
1 |
XWikiDocument doc = new XWikiDocument(new DocumentReference("Test", "Test", "Test")); |
| 173 |
1 |
doc.setContent("content 1.1"); |
| 174 |
|
|
| 175 |
1 |
XWikiDocumentArchive archive = new XWikiDocumentArchive(doc.getId()); |
| 176 |
1 |
assertEquals(0, archive.getNodes().size()); |
| 177 |
|
|
| 178 |
1 |
String author = "XWiki.some author"; |
| 179 |
1 |
archive.updateArchive(doc, author, new Date(), "initial, 1.1", null, context); |
| 180 |
1 |
assertEquals(new Version(1,1), archive.getLatestVersion()); |
| 181 |
1 |
String archive11 = archive.getArchive(context); |
| 182 |
1 |
assertEquals(1, archive.getNodes().size()); |
| 183 |
1 |
assertEquals(1, archive.getUpdatedNodeInfos().size()); |
| 184 |
1 |
assertEquals(1, archive.getUpdatedNodeContents().size()); |
| 185 |
|
|
| 186 |
1 |
XWikiDocumentArchive archive2 = new XWikiDocumentArchive(doc.getId()); |
| 187 |
1 |
archive2.setArchive(archive11); |
| 188 |
1 |
assertEquals(new Version(1,1), archive2.getLatestVersion()); |
| 189 |
1 |
assertEquals(archive11, archive2.getArchive(context)); |
| 190 |
1 |
assertEquals(1, archive2.getNodes().size()); |
| 191 |
1 |
assertEquals(1, archive2.getUpdatedNodeInfos().size()); |
| 192 |
1 |
assertEquals(1, archive2.getUpdatedNodeContents().size()); |
| 193 |
|
|
| 194 |
1 |
doc.setContent("content\n1.2"); |
| 195 |
1 |
archive.updateArchive(doc, author, new Date(), "1.2", new Version(1,2), context); |
| 196 |
1 |
assertEquals(new Version(1,2), archive.getLatestVersion()); |
| 197 |
1 |
String archive12 = archive.getArchive(context); |
| 198 |
1 |
assertEquals(2, archive.getNodes().size()); |
| 199 |
1 |
assertEquals(2, archive.getUpdatedNodeInfos().size()); |
| 200 |
1 |
assertEquals(2, archive.getUpdatedNodeContents().size()); |
| 201 |
|
|
| 202 |
1 |
XWikiDocumentArchive archive3 = new XWikiDocumentArchive(doc.getId()); |
| 203 |
1 |
archive3.setArchive(archive12); |
| 204 |
1 |
assertEquals(new Version(1,2), archive3.getLatestVersion()); |
| 205 |
1 |
assertEquals(2, archive3.getNodes().size()); |
| 206 |
1 |
assertEquals(2, archive3.getUpdatedNodeInfos().size()); |
| 207 |
1 |
assertEquals(2, archive3.getUpdatedNodeContents().size()); |
| 208 |
|
|
| 209 |
1 |
doc.setContent("major change\ncontent\n2.1"); |
| 210 |
1 |
archive.updateArchive(doc, author, new Date(), "2.1", new Version(1,1), context); |
| 211 |
1 |
assertEquals(new Version(2,1), archive.getLatestVersion()); |
| 212 |
1 |
assertEquals(3, archive.getNodes().size()); |
| 213 |
1 |
assertEquals(3, archive.getUpdatedNodeInfos().size()); |
| 214 |
1 |
assertEquals(3, archive.getUpdatedNodeContents().size()); |
| 215 |
|
|
| 216 |
1 |
doc.setContent("major change\ncontent\n 3.3"); |
| 217 |
1 |
archive.updateArchive(doc, author, new Date(), "2.1", new Version(3,3), context); |
| 218 |
1 |
assertEquals(new Version(3,3), archive.getLatestVersion()); |
| 219 |
|
} |
| 220 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (23) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
| 221 |
1 |
public void testRemoveVersions() throws XWikiException... |
| 222 |
|
{ |
| 223 |
1 |
XWikiDocument doc = new XWikiDocument(new DocumentReference("Test", "Test", "Test")); |
| 224 |
1 |
XWikiDocumentArchive archive = new XWikiDocumentArchive(doc.getId()); |
| 225 |
1 |
doc.setDocumentArchive(archive); |
| 226 |
1 |
String author = "XWiki.some author"; |
| 227 |
|
|
| 228 |
1 |
addRevisionToHistory(archive, doc, "content 1.1", author, "initial 1.1"); |
| 229 |
1 |
XWikiDocument doc11 = doc.clone(); |
| 230 |
|
|
| 231 |
1 |
doc.setContent("content 2.1\nqwe @ "); |
| 232 |
1 |
archive.updateArchive(doc, author, new Date(), "2.1", new Version(2,1), context); |
| 233 |
|
|
| 234 |
1 |
doc.setContent("content 2.2\nqweq@ "); |
| 235 |
1 |
archive.updateArchive(doc, author, new Date(), "2.2", new Version(2,2), context); |
| 236 |
|
|
| 237 |
1 |
doc.setContent("content 2.3\nqweqe @@"); |
| 238 |
1 |
archive.updateArchive(doc, author, new Date(), "2.3", new Version(2,3), context); |
| 239 |
1 |
assertEquals(new Version(2,3), archive.getLatestVersion()); |
| 240 |
|
|
| 241 |
1 |
archive.removeVersions(new Version(2,1), new Version(2,2), context); |
| 242 |
|
|
| 243 |
1 |
assertEquals(2, archive.getNodes().size()); |
| 244 |
1 |
assertEquals(2, archive.getDeletedNodeInfo().size()); |
| 245 |
1 |
assertNull(archive.getNode(new Version(2,1))); |
| 246 |
1 |
assertNull(archive.getNode(new Version(2,2))); |
| 247 |
|
|
| 248 |
1 |
XWikiDocument actual = archive.loadDocument(new Version(1,1), context); |
| 249 |
1 |
assertEquals(doc11.getContent(), actual.getContent()); |
| 250 |
1 |
assertEquals(doc11.getDate(), actual.getDate()); |
| 251 |
1 |
assertEquals(doc11.getAuthor(), actual.getAuthor()); |
| 252 |
1 |
assertEquals(doc11.getComment(), actual.getComment()); |
| 253 |
|
} |
| 254 |
|
|
| 255 |
|
|
| 256 |
|
|
| 257 |
|
|
| 258 |
|
@see |
| 259 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
| 260 |
1 |
public void testVerifyCreationDateWhenLoadingDocumentFromArchive() throws Exception... |
| 261 |
|
{ |
| 262 |
1 |
XWikiDocument doc = new XWikiDocument(new DocumentReference("Test", "Test", "Test")); |
| 263 |
1 |
XWikiDocumentArchive archive = new XWikiDocumentArchive(doc.getId()); |
| 264 |
1 |
doc.setDocumentArchive(archive); |
| 265 |
1 |
String author = "XWiki.some author"; |
| 266 |
|
|
| 267 |
1 |
addRevisionToHistory(archive, doc, "content 1.1", author, "initial 1.1"); |
| 268 |
|
|
| 269 |
1 |
Date creationDate = doc.getCreationDate(); |
| 270 |
|
|
| 271 |
|
|
| 272 |
|
|
| 273 |
1 |
Thread.sleep(1000L); |
| 274 |
|
|
| 275 |
1 |
doc.setContent("content 2.1\nqwe @ "); |
| 276 |
1 |
archive.updateArchive(doc, author, new Date(), "2.1", new Version(2,1), context); |
| 277 |
|
|
| 278 |
1 |
XWikiDocument latest = archive.loadDocument(new Version(2,1), context); |
| 279 |
|
|
| 280 |
1 |
assertEquals(creationDate, latest.getCreationDate()); |
| 281 |
|
} |
| 282 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (31) |
Complexity: 1 |
Complexity Density: 0.03 |
1PASS
|
|
| 283 |
1 |
public void testVerifyDiffAndFullRevisionAlgorithm() throws Exception... |
| 284 |
|
{ |
| 285 |
1 |
XWikiDocument doc = new XWikiDocument(new DocumentReference("Test", "Test", "Test")); |
| 286 |
1 |
XWikiDocumentArchive archive = new XWikiDocumentArchive(doc.getId()); |
| 287 |
1 |
doc.setDocumentArchive(archive); |
| 288 |
1 |
String author = "XWiki.some author"; |
| 289 |
|
|
| 290 |
|
|
| 291 |
1 |
addRevisionToHistory(archive, doc, "content 1.1", author, "1.1"); |
| 292 |
1 |
assertFalse(archive.getNode(new Version(1, 1)).isDiff()); |
| 293 |
|
|
| 294 |
|
|
| 295 |
|
|
| 296 |
1 |
addRevisionToHistory(archive, doc, "content 2.1", author, "2.1"); |
| 297 |
1 |
assertTrue(archive.getNode(new Version(1, 1)).isDiff()); |
| 298 |
1 |
assertFalse(archive.getNode(new Version(2, 1)).isDiff()); |
| 299 |
|
|
| 300 |
1 |
addRevisionToHistory(archive, doc, "content 3.1", author, "3.1"); |
| 301 |
1 |
assertTrue(archive.getNode(new Version(1, 1)).isDiff()); |
| 302 |
1 |
assertTrue(archive.getNode(new Version(2, 1)).isDiff()); |
| 303 |
1 |
assertFalse(archive.getNode(new Version(3, 1)).isDiff()); |
| 304 |
|
|
| 305 |
1 |
addRevisionToHistory(archive, doc, "content 4.1", author, "4.1"); |
| 306 |
1 |
assertTrue(archive.getNode(new Version(1, 1)).isDiff()); |
| 307 |
1 |
assertTrue(archive.getNode(new Version(2, 1)).isDiff()); |
| 308 |
1 |
assertTrue(archive.getNode(new Version(3, 1)).isDiff()); |
| 309 |
1 |
assertFalse(archive.getNode(new Version(4, 1)).isDiff()); |
| 310 |
|
|
| 311 |
|
|
| 312 |
1 |
addRevisionToHistory(archive, doc, "content 5.1", author, "5.1"); |
| 313 |
1 |
assertTrue(archive.getNode(new Version(1, 1)).isDiff()); |
| 314 |
1 |
assertTrue(archive.getNode(new Version(2, 1)).isDiff()); |
| 315 |
1 |
assertTrue(archive.getNode(new Version(3, 1)).isDiff()); |
| 316 |
1 |
assertTrue(archive.getNode(new Version(4, 1)).isDiff()); |
| 317 |
1 |
assertFalse(archive.getNode(new Version(5, 1)).isDiff()); |
| 318 |
|
|
| 319 |
|
|
| 320 |
1 |
addRevisionToHistory(archive, doc, "content 6.1", author, "6.1"); |
| 321 |
1 |
assertTrue(archive.getNode(new Version(1, 1)).isDiff()); |
| 322 |
1 |
assertTrue(archive.getNode(new Version(2, 1)).isDiff()); |
| 323 |
1 |
assertTrue(archive.getNode(new Version(3, 1)).isDiff()); |
| 324 |
1 |
assertTrue(archive.getNode(new Version(4, 1)).isDiff()); |
| 325 |
1 |
assertFalse(archive.getNode(new Version(5, 1)).isDiff()); |
| 326 |
1 |
assertFalse(archive.getNode(new Version(6, 1)).isDiff()); |
| 327 |
|
} |
| 328 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
| 329 |
8 |
private void addRevisionToHistory(XWikiDocumentArchive archive, XWikiDocument document, String content,... |
| 330 |
|
String author, String comment) throws XWikiException |
| 331 |
|
{ |
| 332 |
8 |
document.setContent(content); |
| 333 |
8 |
document.setAuthor(author); |
| 334 |
8 |
document.setComment(comment); |
| 335 |
8 |
document.setDate(new Date()); |
| 336 |
8 |
archive.updateArchive(document, document.getAuthor(), document.getDate(), document.getComment(), null, context); |
| 337 |
|
} |
| 338 |
|
} |