1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.extension.xar.internal.handler; |
21 |
|
|
22 |
|
import java.util.Arrays; |
23 |
|
import java.util.HashMap; |
24 |
|
import java.util.List; |
25 |
|
import java.util.Locale; |
26 |
|
import java.util.Map; |
27 |
|
|
28 |
|
import org.apache.commons.io.IOUtils; |
29 |
|
import org.junit.Assert; |
30 |
|
import org.junit.Before; |
31 |
|
import org.junit.Rule; |
32 |
|
import org.junit.Test; |
33 |
|
import org.xwiki.bridge.event.WikiCreatedEvent; |
34 |
|
import org.xwiki.bridge.event.WikiCreatingEvent; |
35 |
|
import org.xwiki.extension.ExtensionId; |
36 |
|
import org.xwiki.extension.InstallException; |
37 |
|
import org.xwiki.extension.UninstallException; |
38 |
|
import org.xwiki.extension.job.InstallRequest; |
39 |
|
import org.xwiki.extension.job.UninstallRequest; |
40 |
|
import org.xwiki.extension.job.internal.InstallJob; |
41 |
|
import org.xwiki.extension.job.internal.UninstallJob; |
42 |
|
import org.xwiki.extension.repository.InstalledExtensionRepository; |
43 |
|
import org.xwiki.extension.repository.internal.core.CoreExtensionScanner; |
44 |
|
import org.xwiki.extension.test.MockitoRepositoryUtilsRule; |
45 |
|
import org.xwiki.extension.xar.internal.repository.XarInstalledExtension; |
46 |
|
import org.xwiki.extension.xar.internal.repository.XarInstalledExtensionRepository; |
47 |
|
import org.xwiki.job.Job; |
48 |
|
import org.xwiki.job.JobExecutor; |
49 |
|
import org.xwiki.logging.LogLevel; |
50 |
|
import org.xwiki.logging.event.LogEvent; |
51 |
|
import org.xwiki.model.reference.DocumentReference; |
52 |
|
import org.xwiki.model.reference.EntityReference; |
53 |
|
import org.xwiki.model.reference.LocalDocumentReference; |
54 |
|
import org.xwiki.observation.ObservationManager; |
55 |
|
import org.xwiki.rendering.syntax.Syntax; |
56 |
|
import org.xwiki.security.authorization.AccessDeniedException; |
57 |
|
import org.xwiki.security.authorization.Right; |
58 |
|
import org.xwiki.test.annotation.AfterComponent; |
59 |
|
import org.xwiki.test.annotation.AllComponents; |
60 |
|
import org.xwiki.test.mockito.MockitoComponentManagerRule; |
61 |
|
|
62 |
|
import com.xpn.xwiki.CoreConfiguration; |
63 |
|
import com.xpn.xwiki.XWikiContext; |
64 |
|
import com.xpn.xwiki.doc.MandatoryDocumentInitializer; |
65 |
|
import com.xpn.xwiki.doc.XWikiAttachment; |
66 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
67 |
|
import com.xpn.xwiki.objects.BaseObject; |
68 |
|
import com.xpn.xwiki.objects.classes.BaseClass; |
69 |
|
import com.xpn.xwiki.objects.classes.NumberClass; |
70 |
|
import com.xpn.xwiki.test.MockitoOldcoreRule; |
71 |
|
import com.xpn.xwiki.util.XWikiStubContextProvider; |
72 |
|
|
73 |
|
import static org.junit.Assert.assertEquals; |
74 |
|
import static org.junit.Assert.assertFalse; |
75 |
|
import static org.mockito.ArgumentMatchers.any; |
76 |
|
import static org.mockito.ArgumentMatchers.eq; |
77 |
|
import static org.mockito.Mockito.doReturn; |
78 |
|
import static org.mockito.Mockito.doThrow; |
79 |
|
import static org.mockito.Mockito.times; |
80 |
|
import static org.mockito.Mockito.verify; |
81 |
|
import static org.mockito.Mockito.when; |
82 |
|
|
83 |
|
@AllComponents |
|
|
| 98.3% |
Uncovered Elements: 8 (468) |
Complexity: 36 |
Complexity Density: 0.08 |
|
84 |
|
public class XarExtensionHandlerTest |
85 |
|
{ |
86 |
|
private MockitoOldcoreRule oldcore = new MockitoOldcoreRule(); |
87 |
|
|
88 |
|
private MockitoComponentManagerRule componentManager = this.oldcore.getMocker(); |
89 |
|
|
90 |
|
@Rule |
91 |
|
public MockitoRepositoryUtilsRule repositoryUtil = |
92 |
|
new MockitoRepositoryUtilsRule(this.componentManager, this.oldcore); |
93 |
|
|
94 |
|
private XarInstalledExtensionRepository installedExtensionRepository; |
95 |
|
|
96 |
|
private ExtensionId localXarExtensiontId1; |
97 |
|
|
98 |
|
private ExtensionId localXarExtensiontId2; |
99 |
|
|
100 |
|
private ExtensionId collisionextension1; |
101 |
|
|
102 |
|
private ExtensionId collisionextension2; |
103 |
|
|
104 |
|
private JobExecutor jobExecutor; |
105 |
|
|
106 |
|
private InstalledExtensionRepository xarExtensionRepository; |
107 |
|
|
108 |
|
private ObservationManager observation; |
109 |
|
|
110 |
|
private Map<String, BaseClass> classes = new HashMap<String, BaseClass>(); |
111 |
|
|
112 |
|
private DocumentReference contextUser; |
113 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
114 |
20 |
@AfterComponent... |
115 |
|
public void afterComponent() throws Exception |
116 |
|
{ |
117 |
|
|
118 |
20 |
this.componentManager.registerMockComponent(CoreExtensionScanner.class); |
119 |
|
} |
120 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 1 |
Complexity Density: 0.06 |
|
121 |
20 |
@Before... |
122 |
|
public void setUp() throws Exception |
123 |
|
{ |
124 |
|
|
125 |
|
|
126 |
20 |
this.contextUser = new DocumentReference(getXWikiContext().getWikiId(), "XWiki", "ExtensionUser"); |
127 |
|
|
128 |
20 |
this.localXarExtensiontId1 = new ExtensionId("test", "1.0"); |
129 |
20 |
this.localXarExtensiontId2 = new ExtensionId("test", "2.0"); |
130 |
20 |
this.collisionextension1 = new ExtensionId("collisionextension1", "version"); |
131 |
20 |
this.collisionextension2 = new ExtensionId("collisionextension2", "version"); |
132 |
|
|
133 |
|
|
134 |
|
|
135 |
20 |
BaseClass styleSheetClass = new BaseClass(); |
136 |
20 |
this.classes.put("StyleSheetExtension", styleSheetClass); |
137 |
|
|
138 |
|
|
139 |
|
|
140 |
20 |
doReturn(true).when(this.oldcore.getSpyXWiki()).hasAttachmentRecycleBin(any(XWikiContext.class)); |
141 |
|
|
142 |
20 |
getXWikiContext().setUserReference(this.contextUser); |
143 |
|
|
144 |
20 |
((XWikiStubContextProvider) this.componentManager.getInstance(XWikiStubContextProvider.class)) |
145 |
|
.initialize(getXWikiContext()); |
146 |
|
|
147 |
20 |
CoreConfiguration coreConfiguration = this.componentManager.getInstance(CoreConfiguration.class); |
148 |
20 |
doReturn(Syntax.PLAIN_1_0).when(coreConfiguration).getDefaultDocumentSyntax(); |
149 |
|
|
150 |
|
|
151 |
|
|
152 |
20 |
this.jobExecutor = this.componentManager.getInstance(JobExecutor.class); |
153 |
20 |
this.xarExtensionRepository = |
154 |
|
this.componentManager.getInstance(InstalledExtensionRepository.class, XarExtensionHandler.TYPE); |
155 |
20 |
this.observation = this.repositoryUtil.getComponentManager().getInstance(ObservationManager.class); |
156 |
|
|
157 |
|
|
158 |
20 |
this.componentManager.<ObservationManager>getInstance(ObservationManager.class) |
159 |
|
.removeListener("RegisterMacrosOnImportListener"); |
160 |
|
|
161 |
20 |
this.installedExtensionRepository = |
162 |
|
this.componentManager.getInstance(InstalledExtensionRepository.class, "xar"); |
163 |
|
} |
164 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
165 |
4 |
private void mockHasNoAdminRight() throws AccessDeniedException... |
166 |
|
{ |
167 |
4 |
doThrow(AccessDeniedException.class).when(this.oldcore.getMockAuthorizationManager()) |
168 |
|
.checkAccess(eq(Right.ADMIN), eq(this.contextUser), any()); |
169 |
|
} |
170 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
171 |
15 |
private void verifyHasAdminRight(int times) throws AccessDeniedException... |
172 |
|
{ |
173 |
15 |
verify(this.oldcore.getMockAuthorizationManager(), times(times)).checkAccess(eq(Right.ADMIN), |
174 |
|
eq(this.contextUser), any()); |
175 |
|
} |
176 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
177 |
177 |
private XWikiContext getXWikiContext()... |
178 |
|
{ |
179 |
177 |
return this.oldcore.getXWikiContext(); |
180 |
|
} |
181 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
182 |
28 |
private XarInstalledExtension install(ExtensionId extensionId, String wiki, DocumentReference user) throws Throwable... |
183 |
|
{ |
184 |
28 |
return installOnNamespace(extensionId, wiki != null ? "wiki:" + wiki : null, user); |
185 |
|
} |
186 |
|
|
|
|
| 91.3% |
Uncovered Elements: 2 (23) |
Complexity: 5 |
Complexity Density: 0.33 |
|
187 |
29 |
private XarInstalledExtension installOnNamespace(ExtensionId extensionId, String namespace, DocumentReference user)... |
188 |
|
throws Throwable |
189 |
|
{ |
190 |
29 |
InstallRequest installRequest = new InstallRequest(); |
191 |
29 |
if (user != null) { |
192 |
28 |
installRequest.setProperty("user.reference", getXWikiContext().getUserReference()); |
193 |
28 |
installRequest.setProperty("checkrights", true); |
194 |
|
} |
195 |
29 |
installRequest.addExtension(extensionId); |
196 |
29 |
if (namespace != null) { |
197 |
17 |
installRequest.addNamespace(namespace); |
198 |
|
} |
199 |
29 |
Job installJob = this.jobExecutor.execute(InstallJob.JOBTYPE, installRequest); |
200 |
29 |
installJob.join(); |
201 |
|
|
202 |
29 |
List<LogEvent> errors = installJob.getStatus().getLog().getLogsFrom(LogLevel.WARN); |
203 |
29 |
if (!errors.isEmpty()) { |
204 |
3 |
if (errors.get(0).getThrowable() != null) { |
205 |
3 |
throw errors.get(0).getThrowable(); |
206 |
|
} else { |
207 |
0 |
throw new Exception(errors.get(0).getFormattedMessage()); |
208 |
|
} |
209 |
|
} |
210 |
|
|
211 |
26 |
return (XarInstalledExtension) this.xarExtensionRepository.resolve(extensionId); |
212 |
|
} |
213 |
|
|
|
|
| 89.5% |
Uncovered Elements: 2 (19) |
Complexity: 4 |
Complexity Density: 0.31 |
|
214 |
6 |
private void uninstall(ExtensionId extensionId, String wiki) throws Throwable... |
215 |
|
{ |
216 |
6 |
UninstallRequest uninstallRequest = new UninstallRequest(); |
217 |
6 |
uninstallRequest.setProperty("user.reference", getXWikiContext().getUserReference()); |
218 |
6 |
uninstallRequest.setProperty("checkrights", true); |
219 |
6 |
uninstallRequest.addExtension(extensionId); |
220 |
6 |
if (wiki != null) { |
221 |
4 |
uninstallRequest.addNamespace("wiki:" + wiki); |
222 |
|
} |
223 |
6 |
Job uninstallJob = this.jobExecutor.execute(UninstallJob.JOBTYPE, uninstallRequest); |
224 |
6 |
uninstallJob.join(); |
225 |
|
|
226 |
6 |
List<LogEvent> errors = uninstallJob.getStatus().getLog().getLogsFrom(LogLevel.WARN); |
227 |
6 |
if (!errors.isEmpty()) { |
228 |
2 |
if (errors.get(0).getThrowable() != null) { |
229 |
2 |
throw errors.get(0).getThrowable(); |
230 |
|
} else { |
231 |
0 |
throw new Exception(errors.get(0).getFormattedMessage()); |
232 |
|
} |
233 |
|
} |
234 |
|
} |
235 |
|
|
236 |
|
|
237 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (81) |
Complexity: 1 |
Complexity Density: 0.01 |
1PASS
|
|
238 |
1 |
@Test... |
239 |
|
public void testInstallOnWiki() throws Throwable |
240 |
|
{ |
241 |
1 |
XWikiDocument existingDocument = new XWikiDocument(new DocumentReference("wiki", "space", "page")); |
242 |
1 |
BaseObject object = new BaseObject(); |
243 |
1 |
object.setXClassReference(new DocumentReference("wiki", "space", "class")); |
244 |
1 |
existingDocument.addXObject(object); |
245 |
1 |
existingDocument.setCreatorReference(new DocumentReference("wiki", "space", "existingcreator")); |
246 |
1 |
this.oldcore.getSpyXWiki().saveDocument(existingDocument, "", true, getXWikiContext()); |
247 |
|
|
248 |
1 |
MandatoryDocumentInitializer mandatoryInitializer = |
249 |
|
this.componentManager.registerMockComponent(MandatoryDocumentInitializer.class, "space.mandatory"); |
250 |
1 |
when(mandatoryInitializer.updateDocument(any(XWikiDocument.class))).thenReturn(true); |
251 |
1 |
XWikiDocument mandatoryDocument = new XWikiDocument(new DocumentReference("wiki", "space", "mandatory")); |
252 |
1 |
mandatoryDocument.setCreatorReference(new DocumentReference("wiki", "space", "existingcreator")); |
253 |
1 |
mandatoryDocument.setSyntax(Syntax.PLAIN_1_0); |
254 |
1 |
mandatoryDocument.setContent("modified content"); |
255 |
1 |
this.oldcore.getSpyXWiki().saveDocument(mandatoryDocument, "", true, getXWikiContext()); |
256 |
|
|
257 |
|
|
258 |
|
|
259 |
1 |
XarInstalledExtension xarInstalledExtension = install(this.localXarExtensiontId1, "wiki", this.contextUser); |
260 |
|
|
261 |
1 |
verifyHasAdminRight(2); |
262 |
|
|
263 |
|
|
264 |
|
|
265 |
|
|
266 |
1 |
XWikiDocument page = |
267 |
|
this.oldcore.getSpyXWiki().getDocument(existingDocument.getDocumentReference(), getXWikiContext()); |
268 |
|
|
269 |
1 |
Assert.assertFalse("Document wiki:space.page has not been saved in the database", page.isNew()); |
270 |
|
|
271 |
1 |
Assert.assertNull(page.getXObject(object.getXClassReference())); |
272 |
|
|
273 |
1 |
Assert.assertEquals("Wrong content", "content", page.getContent()); |
274 |
1 |
Assert.assertEquals("Wrong creator", new DocumentReference("wiki", "space", "existingcreator"), |
275 |
|
page.getCreatorReference()); |
276 |
1 |
Assert.assertEquals("Wrong author", this.contextUser, page.getAuthorReference()); |
277 |
1 |
Assert.assertEquals("Wrong content author", this.contextUser, page.getContentAuthorReference()); |
278 |
1 |
Assert.assertEquals("Wrong version", "2.1", page.getVersion()); |
279 |
1 |
Assert.assertEquals("Wrong version", Locale.ROOT, page.getLocale()); |
280 |
1 |
Assert.assertFalse("Document is hidden", page.isHidden()); |
281 |
1 |
Assert.assertFalse("Document is minor edit", page.isMinorEdit()); |
282 |
|
|
283 |
1 |
BaseClass baseClass = page.getXClass(); |
284 |
1 |
Assert.assertNotNull(baseClass.getField("property")); |
285 |
1 |
Assert.assertEquals("property", baseClass.getField("property").getName()); |
286 |
1 |
Assert.assertSame(NumberClass.class, baseClass.getField("property").getClass()); |
287 |
|
|
288 |
|
|
289 |
|
|
290 |
1 |
XWikiDocument pagewithattachment = this.oldcore.getSpyXWiki() |
291 |
|
.getDocument(new DocumentReference("wiki", "space", "pagewithattachment"), getXWikiContext()); |
292 |
1 |
Assert.assertFalse(pagewithattachment.isNew()); |
293 |
1 |
Assert.assertEquals("Wrong version", "1.1", pagewithattachment.getVersion()); |
294 |
1 |
Assert.assertEquals("Wrong creator", this.contextUser, pagewithattachment.getCreatorReference()); |
295 |
1 |
Assert.assertEquals("Wrong author", this.contextUser, pagewithattachment.getAuthorReference()); |
296 |
1 |
Assert.assertEquals("Wrong content author", this.contextUser, pagewithattachment.getContentAuthorReference()); |
297 |
|
|
298 |
1 |
XWikiAttachment attachment = pagewithattachment.getAttachment("attachment.txt"); |
299 |
1 |
Assert.assertNotNull(attachment); |
300 |
1 |
Assert.assertEquals("attachment.txt", attachment.getFilename()); |
301 |
1 |
Assert.assertEquals(18, attachment.getContentSize(getXWikiContext())); |
302 |
1 |
Assert.assertEquals("attachment content", |
303 |
|
IOUtils.toString(attachment.getContentInputStream(getXWikiContext()))); |
304 |
1 |
Assert.assertEquals(this.contextUser.toString(), attachment.getAuthor()); |
305 |
|
|
306 |
|
|
307 |
|
|
308 |
1 |
XWikiDocument page1 = |
309 |
|
this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "space1", "page1"), getXWikiContext()); |
310 |
|
|
311 |
1 |
Assert.assertFalse("Document wiki:space1.page1 has not been saved in the database", page1.isNew()); |
312 |
|
|
313 |
1 |
assertEquals(Arrays.asList(xarInstalledExtension), |
314 |
|
this.installedExtensionRepository.getXarInstalledExtensions(page1.getDocumentReference())); |
315 |
1 |
assertEquals(Arrays.asList(xarInstalledExtension), |
316 |
|
this.installedExtensionRepository.getXarInstalledExtensions(page1.getDocumentReferenceWithLocale())); |
317 |
1 |
assertEquals(0, this.installedExtensionRepository |
318 |
|
.getXarInstalledExtensions(new DocumentReference("wiki", "space1", "page1", Locale.ENGLISH)).size()); |
319 |
1 |
assertEquals(0, this.installedExtensionRepository |
320 |
|
.getXarInstalledExtensions(new DocumentReference("otherwiki", "space1", "page1")).size()); |
321 |
|
|
322 |
|
|
323 |
1 |
DocumentReference translatedReference = new DocumentReference("wiki", "translated", "translated"); |
324 |
1 |
XWikiDocument defaultTranslated = |
325 |
|
this.oldcore.getSpyXWiki().getDocument(translatedReference, getXWikiContext()); |
326 |
|
|
327 |
1 |
Assert.assertNotNull("Document wiki:translated.translated has not been saved in the database", |
328 |
|
defaultTranslated); |
329 |
1 |
Assert.assertFalse("Document wiki:translated.translated has not been saved in the database", |
330 |
|
defaultTranslated.isNew()); |
331 |
|
|
332 |
1 |
Assert.assertEquals("Wrong content", "default content", defaultTranslated.getContent()); |
333 |
1 |
Assert.assertEquals("Wrong creator", this.contextUser, defaultTranslated.getCreatorReference()); |
334 |
1 |
Assert.assertEquals("Wrong author", this.contextUser, defaultTranslated.getAuthorReference()); |
335 |
1 |
Assert.assertEquals("Wrong content author", this.contextUser, defaultTranslated.getContentAuthorReference()); |
336 |
1 |
Assert.assertEquals("Wrong version", "1.1", defaultTranslated.getVersion()); |
337 |
|
|
338 |
1 |
assertEquals(Arrays.asList(xarInstalledExtension), this.installedExtensionRepository |
339 |
|
.getXarInstalledExtensions(defaultTranslated.getDocumentReferenceWithLocale())); |
340 |
|
|
341 |
|
|
342 |
1 |
XWikiDocument translated = |
343 |
|
this.oldcore.getDocuments().get(new DocumentReference(translatedReference, new Locale("tr"))); |
344 |
|
|
345 |
1 |
Assert.assertNotNull("Document wiki:translated.translated in langauge tr has not been saved in the database", |
346 |
|
translated); |
347 |
1 |
Assert.assertFalse("Document wiki:translated.translated in langauge tr has not been saved in the database", |
348 |
|
translated.isNew()); |
349 |
|
|
350 |
1 |
Assert.assertEquals("Wrong content", "tr content", translated.getContent()); |
351 |
1 |
Assert.assertEquals("Wrong creator", this.contextUser, translated.getCreatorReference()); |
352 |
1 |
Assert.assertEquals("Wrong author", this.contextUser, translated.getAuthorReference()); |
353 |
1 |
Assert.assertEquals("Wrong content author", this.contextUser, translated.getContentAuthorReference()); |
354 |
1 |
Assert.assertEquals("Wrong version", "1.1", translated.getVersion()); |
355 |
|
|
356 |
1 |
assertEquals(Arrays.asList(xarInstalledExtension), |
357 |
|
this.installedExtensionRepository.getXarInstalledExtensions(translated.getDocumentReferenceWithLocale())); |
358 |
|
|
359 |
|
|
360 |
1 |
XWikiDocument translated2 = |
361 |
|
this.oldcore.getDocuments().get(new DocumentReference(translatedReference, new Locale("fr"))); |
362 |
|
|
363 |
1 |
Assert.assertNotNull("Document wiki:translated.translated in language fr has not been saved in the database", |
364 |
|
translated2); |
365 |
1 |
Assert.assertFalse("Document wiki:translated.translated in langauge fr has not been saved in the database", |
366 |
|
translated2.isNew()); |
367 |
|
|
368 |
1 |
Assert.assertEquals("Wrong content", "fr content", translated2.getContent()); |
369 |
1 |
Assert.assertEquals("Wrong creator", this.contextUser, translated2.getCreatorReference()); |
370 |
1 |
Assert.assertEquals("Wrong author", this.contextUser, translated2.getAuthorReference()); |
371 |
1 |
Assert.assertEquals("Wrong content author", this.contextUser, translated2.getContentAuthorReference()); |
372 |
1 |
Assert.assertEquals("Wrong version", "1.1", translated2.getVersion()); |
373 |
|
|
374 |
1 |
assertEquals(Arrays.asList(xarInstalledExtension), |
375 |
|
this.installedExtensionRepository.getXarInstalledExtensions(translated2.getDocumentReferenceWithLocale())); |
376 |
|
|
377 |
|
|
378 |
|
|
379 |
1 |
XWikiDocument hiddenpage = this.oldcore.getSpyXWiki() |
380 |
|
.getDocument(new DocumentReference("wiki", "space", "hiddenpage"), getXWikiContext()); |
381 |
|
|
382 |
1 |
Assert.assertFalse("Document wiki:space.hiddenpage has not been saved in the database", hiddenpage.isNew()); |
383 |
|
|
384 |
1 |
Assert.assertTrue("Document is not hidden", hiddenpage.isHidden()); |
385 |
|
|
386 |
|
|
387 |
|
|
388 |
1 |
XWikiDocument mandatorypage = this.oldcore.getSpyXWiki() |
389 |
|
.getDocument(new DocumentReference("wiki", "space", "mandatory"), getXWikiContext()); |
390 |
|
|
391 |
1 |
Assert.assertEquals("Document wiki:space.mandatory has been overwritten", "1.1", mandatorypage.getVersion()); |
392 |
|
} |
393 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (67) |
Complexity: 1 |
Complexity Density: 0.01 |
1PASS
|
|
394 |
1 |
@Test... |
395 |
|
public void testInstallOnWikiWithoutAuthor() throws Throwable |
396 |
|
{ |
397 |
1 |
XWikiDocument existingDocument = new XWikiDocument(new DocumentReference("wiki", "space", "page")); |
398 |
1 |
BaseObject object = new BaseObject(); |
399 |
1 |
object.setXClassReference(new DocumentReference("wiki", "space", "class")); |
400 |
1 |
existingDocument.addXObject(object); |
401 |
1 |
existingDocument.setCreatorReference(new DocumentReference("wiki", "space", "existingcreator")); |
402 |
1 |
this.oldcore.getSpyXWiki().saveDocument(existingDocument, "", true, getXWikiContext()); |
403 |
|
|
404 |
|
|
405 |
|
|
406 |
1 |
install(this.localXarExtensiontId1, "wiki", null); |
407 |
|
|
408 |
|
|
409 |
|
|
410 |
1 |
DocumentReference xarAuthorReference = new DocumentReference("wiki", "XWiki", "author"); |
411 |
1 |
DocumentReference xarCreatorReference = new DocumentReference("wiki", "XWiki", "creator"); |
412 |
1 |
DocumentReference xarContentAuthorReference = new DocumentReference("wiki", "XWiki", "contentAuthor"); |
413 |
|
|
414 |
|
|
415 |
1 |
XWikiDocument page = |
416 |
|
this.oldcore.getSpyXWiki().getDocument(existingDocument.getDocumentReference(), getXWikiContext()); |
417 |
|
|
418 |
1 |
Assert.assertFalse("Document wiki:space.page has not been saved in the database", page.isNew()); |
419 |
|
|
420 |
1 |
Assert.assertNull(page.getXObject(object.getXClassReference())); |
421 |
|
|
422 |
1 |
Assert.assertEquals("Wrong content", "content", page.getContent()); |
423 |
1 |
Assert.assertEquals("Wrong creator", new DocumentReference("wiki", "space", "existingcreator"), |
424 |
|
page.getCreatorReference()); |
425 |
1 |
Assert.assertEquals("Wrong author", xarAuthorReference, page.getAuthorReference()); |
426 |
1 |
Assert.assertEquals("Wrong content author", xarContentAuthorReference, page.getContentAuthorReference()); |
427 |
1 |
Assert.assertEquals("Wrong version", "2.1", page.getVersion()); |
428 |
1 |
Assert.assertEquals("Wrong version", Locale.ROOT, page.getLocale()); |
429 |
1 |
Assert.assertFalse("Document is hidden", page.isHidden()); |
430 |
|
|
431 |
1 |
BaseClass baseClass = page.getXClass(); |
432 |
1 |
Assert.assertNotNull(baseClass.getField("property")); |
433 |
1 |
Assert.assertEquals("property", baseClass.getField("property").getName()); |
434 |
1 |
Assert.assertSame(NumberClass.class, baseClass.getField("property").getClass()); |
435 |
|
|
436 |
|
|
437 |
|
|
438 |
1 |
XWikiDocument pagewithattachment = this.oldcore.getSpyXWiki() |
439 |
|
.getDocument(new DocumentReference("wiki", "space", "pagewithattachment"), getXWikiContext()); |
440 |
1 |
Assert.assertFalse(pagewithattachment.isNew()); |
441 |
1 |
Assert.assertEquals("Wrong version", "1.1", pagewithattachment.getVersion()); |
442 |
1 |
Assert.assertEquals("Wrong creator", xarCreatorReference, pagewithattachment.getCreatorReference()); |
443 |
1 |
Assert.assertEquals("Wrong author", xarAuthorReference, pagewithattachment.getAuthorReference()); |
444 |
1 |
Assert.assertEquals("Wrong content author", xarContentAuthorReference, |
445 |
|
pagewithattachment.getContentAuthorReference()); |
446 |
|
|
447 |
1 |
XWikiAttachment attachment = pagewithattachment.getAttachment("attachment.txt"); |
448 |
1 |
Assert.assertNotNull(attachment); |
449 |
1 |
Assert.assertEquals("attachment.txt", attachment.getFilename()); |
450 |
1 |
Assert.assertEquals(18, attachment.getContentSize(getXWikiContext())); |
451 |
1 |
Assert.assertEquals("attachment content", |
452 |
|
IOUtils.toString(attachment.getContentInputStream(getXWikiContext()))); |
453 |
1 |
Assert.assertEquals("XWiki.attachmentauthor", attachment.getAuthor()); |
454 |
|
|
455 |
|
|
456 |
|
|
457 |
1 |
XWikiDocument page1 = |
458 |
|
this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "space1", "page1"), getXWikiContext()); |
459 |
|
|
460 |
1 |
Assert.assertFalse("Document wiki:space1.page1 has not been saved in the database", page1.isNew()); |
461 |
|
|
462 |
|
|
463 |
1 |
DocumentReference translatedReference = new DocumentReference("wiki", "translated", "translated"); |
464 |
1 |
XWikiDocument defaultTranslated = |
465 |
|
this.oldcore.getSpyXWiki().getDocument(translatedReference, getXWikiContext()); |
466 |
|
|
467 |
1 |
Assert.assertNotNull("Document wiki:translated.translated has not been saved in the database", |
468 |
|
defaultTranslated); |
469 |
1 |
Assert.assertFalse("Document wiki:translated.translated has not been saved in the database", |
470 |
|
defaultTranslated.isNew()); |
471 |
|
|
472 |
1 |
Assert.assertEquals("Wrong content", "default content", defaultTranslated.getContent()); |
473 |
1 |
Assert.assertEquals("Wrong creator", xarCreatorReference, defaultTranslated.getCreatorReference()); |
474 |
1 |
Assert.assertEquals("Wrong author", xarAuthorReference, defaultTranslated.getAuthorReference()); |
475 |
1 |
Assert.assertEquals("Wrong content author", xarContentAuthorReference, |
476 |
|
defaultTranslated.getContentAuthorReference()); |
477 |
1 |
Assert.assertEquals("Wrong version", "1.1", defaultTranslated.getVersion()); |
478 |
|
|
479 |
|
|
480 |
1 |
XWikiDocument translated = |
481 |
|
this.oldcore.getDocuments().get(new DocumentReference(translatedReference, new Locale("tr"))); |
482 |
|
|
483 |
1 |
Assert.assertNotNull("Document wiki:translated.translated in langauge tr has not been saved in the database", |
484 |
|
translated); |
485 |
1 |
Assert.assertFalse("Document wiki:translated.translated in langauge tr has not been saved in the database", |
486 |
|
translated.isNew()); |
487 |
|
|
488 |
1 |
Assert.assertEquals("Wrong content", "tr content", translated.getContent()); |
489 |
1 |
Assert.assertEquals("Wrong creator", xarCreatorReference, translated.getCreatorReference()); |
490 |
1 |
Assert.assertEquals("Wrong author", xarAuthorReference, translated.getAuthorReference()); |
491 |
1 |
Assert.assertEquals("Wrong content author", xarContentAuthorReference, translated.getContentAuthorReference()); |
492 |
1 |
Assert.assertEquals("Wrong version", "1.1", translated.getVersion()); |
493 |
|
|
494 |
|
|
495 |
1 |
XWikiDocument translated2 = |
496 |
|
this.oldcore.getDocuments().get(new DocumentReference(translatedReference, new Locale("fr"))); |
497 |
|
|
498 |
1 |
Assert.assertNotNull("Document wiki:translated.translated in language fr has not been saved in the database", |
499 |
|
translated2); |
500 |
1 |
Assert.assertFalse("Document wiki:translated.translated in langauge fr has not been saved in the database", |
501 |
|
translated2.isNew()); |
502 |
|
|
503 |
1 |
Assert.assertEquals("Wrong content", "fr content", translated2.getContent()); |
504 |
1 |
Assert.assertEquals("Wrong creator", xarCreatorReference, translated2.getCreatorReference()); |
505 |
1 |
Assert.assertEquals("Wrong author", xarAuthorReference, translated2.getAuthorReference()); |
506 |
1 |
Assert.assertEquals("Wrong content author", xarContentAuthorReference, translated2.getContentAuthorReference()); |
507 |
1 |
Assert.assertEquals("Wrong version", "1.1", translated2.getVersion()); |
508 |
|
|
509 |
|
|
510 |
|
|
511 |
1 |
XWikiDocument hiddenpage = this.oldcore.getSpyXWiki() |
512 |
|
.getDocument(new DocumentReference("wiki", "space", "hiddenpage"), getXWikiContext()); |
513 |
|
|
514 |
1 |
Assert.assertNotNull("Document wiki:space.hiddenpage has not been saved in the database", hiddenpage); |
515 |
1 |
Assert.assertFalse("Document wiki:space.hiddenpage has not been saved in the database", hiddenpage.isNew()); |
516 |
|
|
517 |
1 |
Assert.assertTrue("Document is not hidden", hiddenpage.isHidden()); |
518 |
|
} |
519 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (47) |
Complexity: 1 |
Complexity Density: 0.02 |
1PASS
|
|
520 |
1 |
@Test... |
521 |
|
public void testUpgradeOnWiki() throws Throwable |
522 |
|
{ |
523 |
1 |
install(this.localXarExtensiontId1, "wiki", this.contextUser); |
524 |
|
|
525 |
1 |
verifyHasAdminRight(2); |
526 |
|
|
527 |
|
|
528 |
|
|
529 |
1 |
XWikiDocument deletedpage = this.oldcore.getSpyXWiki() |
530 |
|
.getDocument(new DocumentReference("wiki", "space", "deletedpage"), getXWikiContext()); |
531 |
1 |
this.oldcore.getSpyXWiki().deleteDocument(deletedpage, getXWikiContext()); |
532 |
|
|
533 |
1 |
XWikiDocument modifieddeletedpage = this.oldcore.getSpyXWiki() |
534 |
|
.getDocument(new DocumentReference("wiki", "space", "modifieddeletedpage"), getXWikiContext()); |
535 |
1 |
this.oldcore.getSpyXWiki().deleteDocument(modifieddeletedpage, getXWikiContext()); |
536 |
|
|
537 |
1 |
XWikiDocument pagewithobject = this.oldcore.getSpyXWiki() |
538 |
|
.getDocument(new DocumentReference("wiki", "space", "pagewithobject"), getXWikiContext()); |
539 |
1 |
pagewithobject.removeXObjects(new LocalDocumentReference("XWiki", "XWikiGroups")); |
540 |
1 |
this.oldcore.getSpyXWiki().saveDocument(pagewithobject, getXWikiContext()); |
541 |
|
|
542 |
1 |
XWikiDocument deletedpagewithmodifications = this.oldcore.getSpyXWiki() |
543 |
|
.getDocument(new DocumentReference("wiki", "space1", "modified"), getXWikiContext()); |
544 |
1 |
deletedpagewithmodifications.setContent("modified content"); |
545 |
|
|
546 |
|
|
547 |
|
|
548 |
1 |
install(this.localXarExtensiontId2, "wiki", this.contextUser); |
549 |
|
|
550 |
1 |
verifyHasAdminRight(3); |
551 |
|
|
552 |
|
|
553 |
|
|
554 |
|
|
555 |
|
|
556 |
1 |
XWikiDocument samepage = this.oldcore.getSpyXWiki() |
557 |
|
.getDocument(new DocumentReference("wiki", "samespace", "samepage"), getXWikiContext()); |
558 |
|
|
559 |
1 |
Assert.assertFalse("Document samespace has been removed from the database", samepage.isNew()); |
560 |
1 |
Assert.assertEquals("Wrong versions", "1.1", samepage.getVersion()); |
561 |
|
|
562 |
|
|
563 |
|
|
564 |
1 |
XWikiDocument modifiedpage = |
565 |
|
this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "space", "page"), getXWikiContext()); |
566 |
|
|
567 |
1 |
Assert.assertFalse("Document wiki.space.page has not been saved in the database", modifiedpage.isNew()); |
568 |
|
|
569 |
1 |
Assert.assertEquals("Wrong content", "content 2", modifiedpage.getContent()); |
570 |
1 |
Assert.assertEquals("Wrong author", this.contextUser, modifiedpage.getAuthorReference()); |
571 |
1 |
Assert.assertEquals("Wrong versions", "2.1", modifiedpage.getVersion()); |
572 |
1 |
Assert.assertEquals("Wrong version", Locale.ROOT, modifiedpage.getLocale()); |
573 |
|
|
574 |
1 |
Assert.assertEquals("Wrong customclass", "customclass2", modifiedpage.getCustomClass()); |
575 |
1 |
Assert.assertEquals("Wrong defaultTemplate", "defaultTemplate2", modifiedpage.getDefaultTemplate()); |
576 |
1 |
Assert.assertEquals("Wrong hidden", true, modifiedpage.isHidden()); |
577 |
1 |
Assert.assertEquals("Wrong ValidationScript", "validationScript2", modifiedpage.getValidationScript()); |
578 |
|
|
579 |
1 |
BaseClass baseClass = modifiedpage.getXClass(); |
580 |
1 |
Assert.assertNotNull(baseClass.getField("property")); |
581 |
1 |
Assert.assertEquals("property", baseClass.getField("property").getName()); |
582 |
1 |
Assert.assertSame(NumberClass.class, baseClass.getField("property").getClass()); |
583 |
|
|
584 |
1 |
XWikiAttachment attachment = modifiedpage.getAttachment("attachment.txt"); |
585 |
1 |
Assert.assertNotNull(attachment); |
586 |
1 |
Assert.assertEquals("attachment.txt", attachment.getFilename()); |
587 |
1 |
Assert.assertEquals(18, attachment.getContentSize(getXWikiContext())); |
588 |
1 |
Assert.assertEquals("attachment content", |
589 |
|
IOUtils.toString(attachment.getContentInputStream(getXWikiContext()))); |
590 |
|
|
591 |
|
|
592 |
|
|
593 |
1 |
XWikiDocument newPage = |
594 |
|
this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "space2", "page2"), getXWikiContext()); |
595 |
|
|
596 |
1 |
Assert.assertFalse("Document wiki:space2.page2 has not been saved in the database", newPage.isNew()); |
597 |
|
|
598 |
|
|
599 |
|
|
600 |
1 |
XWikiDocument removedPage = |
601 |
|
this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "space1", "page1"), getXWikiContext()); |
602 |
|
|
603 |
1 |
Assert.assertTrue("Document wiki:space1.page1 has not been removed from the database", removedPage.isNew()); |
604 |
|
|
605 |
|
|
606 |
|
|
607 |
1 |
deletedpage = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "space", "deletedpage"), |
608 |
|
getXWikiContext()); |
609 |
|
|
610 |
1 |
Assert.assertTrue("Document wiki:space.deleted has been restored", deletedpage.isNew()); |
611 |
|
|
612 |
|
|
613 |
|
|
614 |
1 |
modifieddeletedpage = this.oldcore.getSpyXWiki() |
615 |
|
.getDocument(new DocumentReference("wiki", "space", "modifieddeletedpage"), getXWikiContext()); |
616 |
|
|
617 |
1 |
Assert.assertTrue("Document wiki:space.modifieddeletedpage has been restored", modifieddeletedpage.isNew()); |
618 |
|
|
619 |
|
|
620 |
|
|
621 |
1 |
pagewithobject = this.oldcore.getSpyXWiki() |
622 |
|
.getDocument(new DocumentReference("wiki", "space", "pagewithobject"), getXWikiContext()); |
623 |
|
|
624 |
1 |
Assert.assertNull("Document wiki:space.pagewithobject does not contain an XWiki.XWikiGroups object", |
625 |
|
pagewithobject.getXObject(new LocalDocumentReference("XWiki", "XWikiGroups"))); |
626 |
|
|
627 |
|
|
628 |
|
|
629 |
1 |
XWikiDocument space1modified = this.oldcore.getSpyXWiki() |
630 |
|
.getDocument(new DocumentReference("wiki", "space1", "modified"), getXWikiContext()); |
631 |
|
|
632 |
1 |
Assert.assertFalse("Document wiki:space.modified has been removed from the database", space1modified.isNew()); |
633 |
|
} |
634 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (47) |
Complexity: 1 |
Complexity Density: 0.02 |
1PASS
|
|
635 |
1 |
@Test... |
636 |
|
public void testUpgradeOnRoot() throws Throwable |
637 |
|
{ |
638 |
1 |
when(this.oldcore.getSpyXWiki().getVirtualWikisDatabaseNames(any(XWikiContext.class))) |
639 |
|
.thenReturn(Arrays.asList("wiki1", "wiki2")); |
640 |
|
|
641 |
1 |
install(this.localXarExtensiontId1, null, this.contextUser); |
642 |
|
|
643 |
1 |
verifyHasAdminRight(2); |
644 |
|
|
645 |
|
|
646 |
|
|
647 |
1 |
XWikiDocument deletedpage = this.oldcore.getSpyXWiki() |
648 |
|
.getDocument(new DocumentReference("wiki1", "space", "deletedpage"), getXWikiContext()); |
649 |
1 |
this.oldcore.getSpyXWiki().deleteDocument(deletedpage, getXWikiContext()); |
650 |
|
|
651 |
1 |
XWikiDocument modifieddeletedpage = this.oldcore.getSpyXWiki() |
652 |
|
.getDocument(new DocumentReference("wiki1", "space", "modifieddeletedpage"), getXWikiContext()); |
653 |
1 |
this.oldcore.getSpyXWiki().deleteDocument(modifieddeletedpage, getXWikiContext()); |
654 |
|
|
655 |
1 |
XWikiDocument pagewithobject = this.oldcore.getSpyXWiki() |
656 |
|
.getDocument(new DocumentReference("wiki1", "space", "pagewithobject"), getXWikiContext()); |
657 |
1 |
pagewithobject.removeXObjects(new LocalDocumentReference("XWiki", "XWikiGroups")); |
658 |
1 |
this.oldcore.getSpyXWiki().saveDocument(pagewithobject, getXWikiContext()); |
659 |
|
|
660 |
1 |
XWikiDocument deletedpagewithmodifications = this.oldcore.getSpyXWiki() |
661 |
|
.getDocument(new DocumentReference("wiki1", "space1", "modified"), getXWikiContext()); |
662 |
1 |
deletedpagewithmodifications.setContent("modified content"); |
663 |
|
|
664 |
|
|
665 |
|
|
666 |
1 |
install(this.localXarExtensiontId2, null, this.contextUser); |
667 |
|
|
668 |
1 |
verifyHasAdminRight(3); |
669 |
|
|
670 |
|
|
671 |
|
|
672 |
|
|
673 |
|
|
674 |
1 |
XWikiDocument samepage = this.oldcore.getSpyXWiki() |
675 |
|
.getDocument(new DocumentReference("wiki1", "samespace", "samepage"), getXWikiContext()); |
676 |
|
|
677 |
1 |
Assert.assertEquals("Wrong versions", "1.1", samepage.getVersion()); |
678 |
|
|
679 |
|
|
680 |
|
|
681 |
1 |
XWikiDocument modifiedpage = |
682 |
|
this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki1", "space", "page"), getXWikiContext()); |
683 |
|
|
684 |
1 |
Assert.assertFalse("Document wiki.space.page has not been saved in the database", modifiedpage.isNew()); |
685 |
|
|
686 |
1 |
Assert.assertEquals("Wrong content", "content 2", modifiedpage.getContent()); |
687 |
1 |
Assert.assertEquals("Wrong author", this.contextUser, modifiedpage.getAuthorReference()); |
688 |
1 |
Assert.assertEquals("Wrong versions", "2.1", modifiedpage.getVersion()); |
689 |
1 |
Assert.assertEquals("Wrong version", Locale.ROOT, modifiedpage.getLocale()); |
690 |
|
|
691 |
1 |
Assert.assertEquals("Wrong customclass", "customclass2", modifiedpage.getCustomClass()); |
692 |
1 |
Assert.assertEquals("Wrong defaultTemplate", "defaultTemplate2", modifiedpage.getDefaultTemplate()); |
693 |
1 |
Assert.assertEquals("Wrong hidden", true, modifiedpage.isHidden()); |
694 |
1 |
Assert.assertEquals("Wrong ValidationScript", "validationScript2", modifiedpage.getValidationScript()); |
695 |
|
|
696 |
1 |
BaseClass baseClass = modifiedpage.getXClass(); |
697 |
1 |
Assert.assertNotNull(baseClass.getField("property")); |
698 |
1 |
Assert.assertEquals("property", baseClass.getField("property").getName()); |
699 |
1 |
Assert.assertSame(NumberClass.class, baseClass.getField("property").getClass()); |
700 |
|
|
701 |
1 |
XWikiAttachment attachment = modifiedpage.getAttachment("attachment.txt"); |
702 |
1 |
Assert.assertNotNull(attachment); |
703 |
1 |
Assert.assertEquals("attachment.txt", attachment.getFilename()); |
704 |
1 |
Assert.assertEquals(18, attachment.getContentSize(getXWikiContext())); |
705 |
1 |
Assert.assertEquals("attachment content", |
706 |
|
IOUtils.toString(attachment.getContentInputStream(getXWikiContext()))); |
707 |
|
|
708 |
|
|
709 |
|
|
710 |
1 |
XWikiDocument newPage = this.oldcore.getSpyXWiki() |
711 |
|
.getDocument(new DocumentReference("wiki1", "space2", "page2"), getXWikiContext()); |
712 |
|
|
713 |
1 |
Assert.assertFalse("Document wiki:space2.page2 has not been saved in the database", newPage.isNew()); |
714 |
|
|
715 |
|
|
716 |
|
|
717 |
1 |
XWikiDocument removedPage = this.oldcore.getSpyXWiki() |
718 |
|
.getDocument(new DocumentReference("wiki1", "space1", "page1"), getXWikiContext()); |
719 |
|
|
720 |
1 |
Assert.assertTrue("Document wiki:space1.page1 has not been removed from the database", removedPage.isNew()); |
721 |
|
|
722 |
|
|
723 |
|
|
724 |
1 |
deletedpage = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki1", "space", "deletedpage"), |
725 |
|
getXWikiContext()); |
726 |
|
|
727 |
1 |
Assert.assertTrue("Document wiki:space.deleted has been restored", deletedpage.isNew()); |
728 |
|
|
729 |
|
|
730 |
|
|
731 |
1 |
modifieddeletedpage = this.oldcore.getSpyXWiki() |
732 |
|
.getDocument(new DocumentReference("wiki1", "space", "modifieddeletedpage"), getXWikiContext()); |
733 |
|
|
734 |
1 |
Assert.assertTrue("Document wiki:space.modifieddeletedpage has been restored", modifieddeletedpage.isNew()); |
735 |
|
|
736 |
|
|
737 |
|
|
738 |
1 |
pagewithobject = this.oldcore.getSpyXWiki() |
739 |
|
.getDocument(new DocumentReference("wiki1", "space", "pagewithobject"), getXWikiContext()); |
740 |
|
|
741 |
1 |
Assert.assertNull("Document wiki:space.pagewithobject does not contain an XWiki.XWikiGroups object", |
742 |
|
pagewithobject.getXObject(new LocalDocumentReference("XWiki", "XWikiGroups"))); |
743 |
|
|
744 |
|
|
745 |
|
|
746 |
1 |
XWikiDocument space1modified = this.oldcore.getSpyXWiki() |
747 |
|
.getDocument(new DocumentReference("wiki1", "space1", "modified"), getXWikiContext()); |
748 |
|
|
749 |
1 |
Assert.assertFalse("Document wiki:space1.modified has been removed from the database", space1modified.isNew()); |
750 |
|
} |
751 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (21) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
752 |
1 |
@Test... |
753 |
|
public void testDowngradeOnWiki() throws Throwable |
754 |
|
{ |
755 |
1 |
install(this.localXarExtensiontId2, "wiki", this.contextUser); |
756 |
|
|
757 |
1 |
verifyHasAdminRight(1); |
758 |
|
|
759 |
|
|
760 |
|
|
761 |
1 |
install(this.localXarExtensiontId1, "wiki", this.contextUser); |
762 |
|
|
763 |
1 |
verifyHasAdminRight(3); |
764 |
|
|
765 |
|
|
766 |
|
|
767 |
|
|
768 |
|
|
769 |
1 |
XWikiDocument samepage = this.oldcore.getSpyXWiki() |
770 |
|
.getDocument(new DocumentReference("wiki", "samespace", "samepage"), getXWikiContext()); |
771 |
|
|
772 |
1 |
Assert.assertEquals("Wrong versions", "1.1", samepage.getVersion()); |
773 |
|
|
774 |
|
|
775 |
|
|
776 |
1 |
XWikiDocument modifiedpage = |
777 |
|
this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "space", "page"), getXWikiContext()); |
778 |
|
|
779 |
1 |
Assert.assertFalse("Document wiki.space.page has not been saved in the database", modifiedpage.isNew()); |
780 |
|
|
781 |
1 |
Assert.assertEquals("Wrong content", "content", modifiedpage.getContent()); |
782 |
1 |
Assert.assertEquals("Wrong author", this.contextUser, modifiedpage.getAuthorReference()); |
783 |
1 |
Assert.assertEquals("Wrong versions", "2.1", modifiedpage.getVersion()); |
784 |
1 |
Assert.assertEquals("Wrong version", Locale.ROOT, modifiedpage.getLocale()); |
785 |
|
|
786 |
1 |
BaseClass baseClass = modifiedpage.getXClass(); |
787 |
1 |
Assert.assertNotNull(baseClass.getField("property")); |
788 |
1 |
Assert.assertEquals("property", baseClass.getField("property").getName()); |
789 |
1 |
Assert.assertSame(NumberClass.class, baseClass.getField("property").getClass()); |
790 |
|
|
791 |
|
|
792 |
1 |
Assert.assertNull(modifiedpage.getAttachment("attachment.txt")); |
793 |
|
|
794 |
|
|
795 |
|
|
796 |
1 |
XWikiDocument newPage = |
797 |
|
this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "space2", "page2"), getXWikiContext()); |
798 |
|
|
799 |
1 |
Assert.assertTrue("Document wiki.space2.page2 has not been removed from the database", newPage.isNew()); |
800 |
|
|
801 |
|
|
802 |
|
|
803 |
1 |
XWikiDocument removedPage = |
804 |
|
this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "space1", "page1"), getXWikiContext()); |
805 |
|
|
806 |
1 |
Assert.assertFalse("Document wiki.space1.page1 has not been saved in the database", removedPage.isNew()); |
807 |
|
} |
808 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
809 |
1 |
@Test... |
810 |
|
public void testUninstallFromWiki() throws Throwable |
811 |
|
{ |
812 |
1 |
install(this.localXarExtensiontId1, "wiki", this.contextUser); |
813 |
|
|
814 |
1 |
verifyHasAdminRight(2); |
815 |
|
|
816 |
|
|
817 |
|
|
818 |
1 |
uninstall(this.localXarExtensiontId1, "wiki"); |
819 |
|
|
820 |
1 |
verifyHasAdminRight(3); |
821 |
|
|
822 |
|
|
823 |
|
|
824 |
|
|
825 |
1 |
XWikiDocument page = |
826 |
|
this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "space", "page"), getXWikiContext()); |
827 |
|
|
828 |
1 |
Assert.assertFalse("Document wiki.space.page has been removed from the database", page.isNew()); |
829 |
|
|
830 |
|
|
831 |
1 |
XWikiDocument page1 = |
832 |
|
this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "space1", "page1"), getXWikiContext()); |
833 |
|
|
834 |
1 |
Assert.assertTrue("Document wiki.space1.page1 has not been removed from the database", page1.isNew()); |
835 |
|
} |
836 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
837 |
1 |
@Test... |
838 |
|
public void testUninstallMandatory() throws Throwable |
839 |
|
{ |
840 |
|
|
841 |
1 |
MandatoryDocumentInitializer mandatoryInitializer = |
842 |
|
this.componentManager.registerMockComponent(MandatoryDocumentInitializer.class, "space.page"); |
843 |
|
|
844 |
1 |
when(mandatoryInitializer.updateDocument(any(XWikiDocument.class))).thenReturn(true); |
845 |
|
|
846 |
1 |
install(this.localXarExtensiontId1, "wiki", this.contextUser); |
847 |
|
|
848 |
1 |
verifyHasAdminRight(2); |
849 |
|
|
850 |
|
|
851 |
|
|
852 |
1 |
uninstall(this.localXarExtensiontId1, "wiki"); |
853 |
|
|
854 |
1 |
verifyHasAdminRight(3); |
855 |
|
|
856 |
|
|
857 |
|
|
858 |
1 |
XWikiDocument page = |
859 |
|
this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki", "space", "page"), getXWikiContext()); |
860 |
|
|
861 |
1 |
Assert.assertFalse("Document wiki.space.page has been removed from the database", page.isNew()); |
862 |
|
} |
863 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
864 |
1 |
@Test... |
865 |
|
public void testUninstallExtensionWithCommonDocumentOnWiki() throws Throwable |
866 |
|
{ |
867 |
1 |
install(this.collisionextension1, "wiki", this.contextUser); |
868 |
1 |
install(this.collisionextension2, "wiki", this.contextUser); |
869 |
|
|
870 |
|
|
871 |
|
|
872 |
1 |
uninstall(this.collisionextension1, "wiki"); |
873 |
|
|
874 |
1 |
XWikiDocument page = this.oldcore.getSpyXWiki() |
875 |
|
.getDocument(new DocumentReference("wiki", "samespace", "samepage"), getXWikiContext()); |
876 |
|
|
877 |
1 |
assertFalse(page.isNew()); |
878 |
|
} |
879 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
880 |
1 |
@Test... |
881 |
|
public void testUninstallExtensionWithCommonDocumentOnRoot() throws Throwable |
882 |
|
{ |
883 |
1 |
install(this.collisionextension1, null, this.contextUser); |
884 |
1 |
install(this.collisionextension2, null, this.contextUser); |
885 |
|
} |
886 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
887 |
1 |
@Test... |
888 |
|
public void testUninstallExtensionWithCommonDocumentOnRootAndWiki() throws Throwable |
889 |
|
{ |
890 |
1 |
install(this.collisionextension1, "wiki", this.contextUser); |
891 |
1 |
install(this.collisionextension2, null, this.contextUser); |
892 |
|
} |
893 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
894 |
1 |
@Test... |
895 |
|
public void testUninstallExtensionWithCommonDocumentOnWikiAndRoot() throws Throwable |
896 |
|
{ |
897 |
1 |
install(this.collisionextension1, null, this.contextUser); |
898 |
1 |
install(this.collisionextension2, "wiki", this.contextUser); |
899 |
|
} |
900 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
901 |
1 |
@Test... |
902 |
|
public void testInstallOnRoot() throws Throwable |
903 |
|
{ |
904 |
1 |
doReturn(Arrays.asList("wiki1", "wiki2")).when(this.oldcore.getSpyXWiki()) |
905 |
|
.getVirtualWikisDatabaseNames(any(XWikiContext.class)); |
906 |
|
|
907 |
|
|
908 |
|
|
909 |
1 |
install(this.localXarExtensiontId1, null, this.contextUser); |
910 |
|
|
911 |
1 |
verifyHasAdminRight(2); |
912 |
|
|
913 |
|
|
914 |
|
|
915 |
1 |
XWikiDocument pageWiki1 = this.oldcore.getSpyXWiki() |
916 |
|
.getDocument(new DocumentReference("wiki1", "space1", "page1"), getXWikiContext()); |
917 |
|
|
918 |
1 |
Assert.assertFalse(pageWiki1.isNew()); |
919 |
|
|
920 |
1 |
XWikiDocument pageWiki2 = this.oldcore.getSpyXWiki() |
921 |
|
.getDocument(new DocumentReference("wiki2", "space1", "page1"), getXWikiContext()); |
922 |
|
|
923 |
1 |
Assert.assertFalse(pageWiki2.isNew()); |
924 |
|
|
925 |
1 |
XWikiDocument overwrittenpage = this.oldcore.getSpyXWiki() |
926 |
|
.getDocument(new DocumentReference("wiki1", "space", "overwrittenpage"), getXWikiContext()); |
927 |
|
|
928 |
1 |
Assert.assertFalse(overwrittenpage.isNew()); |
929 |
1 |
Assert.assertEquals("1.1", overwrittenpage.getVersion()); |
930 |
|
|
931 |
|
|
932 |
|
|
933 |
1 |
uninstall(this.localXarExtensiontId1, null); |
934 |
|
|
935 |
1 |
verifyHasAdminRight(3); |
936 |
|
|
937 |
|
|
938 |
|
|
939 |
1 |
pageWiki1 = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki1", "space1", "page1"), |
940 |
|
getXWikiContext()); |
941 |
|
|
942 |
1 |
Assert.assertTrue("Document wiki1:space1.page1 hasn't been removed from the database", pageWiki1.isNew()); |
943 |
|
|
944 |
1 |
pageWiki2 = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki2", "space1", "page1"), |
945 |
|
getXWikiContext()); |
946 |
|
|
947 |
1 |
Assert.assertTrue(pageWiki2.isNew()); |
948 |
|
} |
949 |
|
|
950 |
|
|
951 |
|
|
952 |
|
|
953 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
954 |
1 |
@Test(expected = InstallException.class)... |
955 |
|
public void testInstallOnRootWithoutAdminRights() throws Throwable |
956 |
|
{ |
957 |
1 |
mockHasNoAdminRight(); |
958 |
|
|
959 |
1 |
install(this.localXarExtensiontId1, null, this.contextUser); |
960 |
|
|
961 |
0 |
verifyHasAdminRight(1); |
962 |
|
} |
963 |
|
|
964 |
|
|
965 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
966 |
1 |
@Test(expected = InstallException.class)... |
967 |
|
public void testInstallOnWikiWithoutAdminRights() throws Throwable |
968 |
|
{ |
969 |
1 |
mockHasNoAdminRight(); |
970 |
|
|
971 |
1 |
install(this.localXarExtensiontId1, "wiki", this.contextUser); |
972 |
|
|
973 |
0 |
verifyHasAdminRight(1); |
974 |
|
} |
975 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
976 |
1 |
@Test(expected = InstallException.class)... |
977 |
|
public void testInstallOnUnsupportedNamespace() throws Throwable |
978 |
|
{ |
979 |
1 |
installOnNamespace(this.localXarExtensiontId1, "unsupportednamespace", this.contextUser); |
980 |
|
} |
981 |
|
|
982 |
|
|
983 |
|
|
|
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
984 |
1 |
@Test(expected = UninstallException.class)... |
985 |
|
public void testUninstallOnRootWithoutAdminRights() throws Throwable |
986 |
|
{ |
987 |
1 |
doReturn(Arrays.asList("wiki1", "wiki2")).when(this.oldcore.getSpyXWiki()) |
988 |
|
.getVirtualWikisDatabaseNames(any(XWikiContext.class)); |
989 |
|
|
990 |
1 |
install(this.localXarExtensiontId1, null, this.contextUser); |
991 |
|
|
992 |
1 |
verifyHasAdminRight(2); |
993 |
|
|
994 |
1 |
mockHasNoAdminRight(); |
995 |
|
|
996 |
1 |
uninstall(this.localXarExtensiontId1, null); |
997 |
|
|
998 |
0 |
verifyHasAdminRight(3); |
999 |
|
} |
1000 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
1001 |
1 |
@Test(expected = UninstallException.class)... |
1002 |
|
public void testUninstallOnWikiWithoutAdminRights() throws Throwable |
1003 |
|
{ |
1004 |
1 |
install(this.localXarExtensiontId1, "wiki", this.contextUser); |
1005 |
|
|
1006 |
1 |
verifyHasAdminRight(2); |
1007 |
|
|
1008 |
1 |
mockHasNoAdminRight(); |
1009 |
|
|
1010 |
1 |
uninstall(this.localXarExtensiontId1, "wiki"); |
1011 |
|
|
1012 |
0 |
verifyHasAdminRight(3); |
1013 |
|
} |
1014 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
1015 |
1 |
@Test... |
1016 |
|
public void testInstallOnNamespaceThenOnRoot() throws Throwable |
1017 |
|
{ |
1018 |
1 |
doReturn(Arrays.asList("wiki1", "wiki2")).when(this.oldcore.getSpyXWiki()) |
1019 |
|
.getVirtualWikisDatabaseNames(any(XWikiContext.class)); |
1020 |
|
|
1021 |
|
|
1022 |
|
|
1023 |
1 |
install(this.localXarExtensiontId1, "wiki1", this.contextUser); |
1024 |
|
|
1025 |
|
|
1026 |
|
|
1027 |
1 |
XWikiDocument pageWiki1 = |
1028 |
|
this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki1", "space", "page"), getXWikiContext()); |
1029 |
|
|
1030 |
1 |
Assert.assertFalse(pageWiki1.isNew()); |
1031 |
1 |
Assert.assertEquals("1.1", pageWiki1.getVersion()); |
1032 |
|
|
1033 |
1 |
pageWiki1.setContent("modified content"); |
1034 |
1 |
this.oldcore.getSpyXWiki().saveDocument(pageWiki1, getXWikiContext()); |
1035 |
|
|
1036 |
1 |
pageWiki1 = |
1037 |
|
this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki1", "space", "page"), getXWikiContext()); |
1038 |
|
|
1039 |
1 |
Assert.assertFalse(pageWiki1.isNew()); |
1040 |
1 |
Assert.assertEquals("2.1", pageWiki1.getVersion()); |
1041 |
|
|
1042 |
|
|
1043 |
|
|
1044 |
1 |
install(this.localXarExtensiontId1, null, this.contextUser); |
1045 |
|
|
1046 |
|
|
1047 |
|
|
1048 |
1 |
pageWiki1 = |
1049 |
|
this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki1", "space", "page"), getXWikiContext()); |
1050 |
|
|
1051 |
1 |
Assert.assertFalse(pageWiki1.isNew()); |
1052 |
1 |
Assert.assertEquals("2.1", pageWiki1.getVersion()); |
1053 |
|
|
1054 |
1 |
Assert.assertEquals("modified content", pageWiki1.getContent()); |
1055 |
|
} |
1056 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (25) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
1057 |
1 |
@Test... |
1058 |
|
public void testInstallOnNamespaceThenUpgradeOnRoot() throws Throwable |
1059 |
|
{ |
1060 |
1 |
doReturn(Arrays.asList("wiki1", "wiki2")).when(this.oldcore.getSpyXWiki()) |
1061 |
|
.getVirtualWikisDatabaseNames(any(XWikiContext.class)); |
1062 |
|
|
1063 |
|
|
1064 |
|
|
1065 |
1 |
install(this.localXarExtensiontId1, "wiki1", this.contextUser); |
1066 |
|
|
1067 |
|
|
1068 |
|
|
1069 |
1 |
XWikiDocument pageWiki1 = |
1070 |
|
this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki1", "space", "page"), getXWikiContext()); |
1071 |
|
|
1072 |
1 |
Assert.assertFalse(pageWiki1.isNew()); |
1073 |
1 |
Assert.assertEquals("1.1", pageWiki1.getVersion()); |
1074 |
|
|
1075 |
1 |
pageWiki1 = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki1", "samespace", "samepage"), |
1076 |
|
getXWikiContext()); |
1077 |
|
|
1078 |
1 |
Assert.assertFalse(pageWiki1.isNew()); |
1079 |
1 |
Assert.assertEquals("1.1", pageWiki1.getVersion()); |
1080 |
|
|
1081 |
1 |
XWikiDocument pageWiki2 = |
1082 |
|
this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki2", "space", "page"), getXWikiContext()); |
1083 |
|
|
1084 |
1 |
Assert.assertTrue(pageWiki2.isNew()); |
1085 |
|
|
1086 |
1 |
pageWiki2 = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki2", "samespace", "samepage"), |
1087 |
|
getXWikiContext()); |
1088 |
|
|
1089 |
1 |
Assert.assertTrue(pageWiki2.isNew()); |
1090 |
|
|
1091 |
|
|
1092 |
|
|
1093 |
1 |
install(this.localXarExtensiontId2, null, this.contextUser); |
1094 |
|
|
1095 |
|
|
1096 |
|
|
1097 |
1 |
pageWiki1 = |
1098 |
|
this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki1", "space", "page"), getXWikiContext()); |
1099 |
|
|
1100 |
1 |
Assert.assertFalse(pageWiki1.isNew()); |
1101 |
1 |
Assert.assertEquals("2.1", pageWiki1.getVersion()); |
1102 |
|
|
1103 |
1 |
pageWiki1 = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki1", "samespace", "samepage"), |
1104 |
|
getXWikiContext()); |
1105 |
|
|
1106 |
1 |
Assert.assertFalse(pageWiki1.isNew()); |
1107 |
1 |
Assert.assertEquals("1.1", pageWiki1.getVersion()); |
1108 |
|
|
1109 |
1 |
pageWiki2 = |
1110 |
|
this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki2", "space", "page"), getXWikiContext()); |
1111 |
|
|
1112 |
1 |
Assert.assertFalse(pageWiki2.isNew()); |
1113 |
1 |
Assert.assertEquals("1.1", pageWiki1.getVersion()); |
1114 |
|
|
1115 |
1 |
pageWiki2 = this.oldcore.getSpyXWiki().getDocument(new DocumentReference("wiki2", "samespace", "samepage"), |
1116 |
|
getXWikiContext()); |
1117 |
|
|
1118 |
1 |
Assert.assertFalse(pageWiki2.isNew()); |
1119 |
1 |
Assert.assertEquals("1.1", pageWiki2.getVersion()); |
1120 |
|
} |
1121 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
1122 |
1 |
@Test... |
1123 |
|
public void testCreateNewWiki() throws Throwable |
1124 |
|
{ |
1125 |
1 |
doReturn(Arrays.asList("wiki1", "wiki2")).when(this.oldcore.getSpyXWiki()) |
1126 |
|
.getVirtualWikisDatabaseNames(any(XWikiContext.class)); |
1127 |
|
|
1128 |
1 |
install(this.localXarExtensiontId1, null, this.contextUser); |
1129 |
|
|
1130 |
1 |
Assert.assertFalse(this.oldcore.getSpyXWiki() |
1131 |
|
.getDocument(new DocumentReference("wiki1", "space1", "page1"), getXWikiContext()).isNew()); |
1132 |
1 |
Assert.assertFalse(this.oldcore.getSpyXWiki() |
1133 |
|
.getDocument(new DocumentReference("wiki2", "space1", "page1"), getXWikiContext()).isNew()); |
1134 |
1 |
Assert.assertTrue(this.oldcore.getSpyXWiki() |
1135 |
|
.getDocument(new DocumentReference("newwiki", "space1", "page1"), getXWikiContext()).isNew()); |
1136 |
|
|
1137 |
1 |
this.observation.notify(new WikiCreatingEvent("newwiki"), null, this.oldcore.getXWikiContext()); |
1138 |
1 |
this.observation.notify(new WikiCreatedEvent("newwiki"), null, this.oldcore.getXWikiContext()); |
1139 |
|
|
1140 |
1 |
Assert.assertFalse(this.oldcore.getSpyXWiki() |
1141 |
|
.getDocument(new DocumentReference("wiki1", "space1", "page1"), getXWikiContext()).isNew()); |
1142 |
1 |
Assert.assertFalse(this.oldcore.getSpyXWiki() |
1143 |
|
.getDocument(new DocumentReference("wiki2", "space1", "page1"), getXWikiContext()).isNew()); |
1144 |
1 |
Assert.assertFalse(this.oldcore.getSpyXWiki() |
1145 |
|
.getDocument(new DocumentReference("newwiki", "space1", "page1"), getXWikiContext()).isNew()); |
1146 |
|
} |
1147 |
|
} |