1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package com.xpn.xwiki.plugin.packaging; |
22 |
|
|
23 |
|
import java.io.File; |
24 |
|
import java.util.ArrayList; |
25 |
|
import java.util.Arrays; |
26 |
|
import java.util.HashMap; |
27 |
|
import java.util.Iterator; |
28 |
|
import java.util.List; |
29 |
|
import java.util.Locale; |
30 |
|
import java.util.Map; |
31 |
|
|
32 |
|
import org.apache.commons.io.FileUtils; |
33 |
|
import org.jmock.Mock; |
34 |
|
import org.jmock.core.Invocation; |
35 |
|
import org.jmock.core.stub.CustomStub; |
36 |
|
import org.jmock.core.stub.VoidStub; |
37 |
|
import org.xwiki.extension.ExtensionId; |
38 |
|
import org.xwiki.extension.event.ExtensionInstalledEvent; |
39 |
|
import org.xwiki.extension.repository.InstalledExtensionRepository; |
40 |
|
import org.xwiki.extension.repository.LocalExtensionRepository; |
41 |
|
import org.xwiki.extension.repository.internal.local.DefaultLocalExtension; |
42 |
|
import org.xwiki.localization.LocalizationContext; |
43 |
|
import org.xwiki.model.reference.DocumentReference; |
44 |
|
import org.xwiki.observation.EventListener; |
45 |
|
import org.xwiki.observation.ObservationManager; |
46 |
|
|
47 |
|
import com.xpn.xwiki.XWiki; |
48 |
|
import com.xpn.xwiki.XWikiConfig; |
49 |
|
import com.xpn.xwiki.XWikiContext; |
50 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
51 |
|
import com.xpn.xwiki.store.XWikiHibernateRecycleBinStore; |
52 |
|
import com.xpn.xwiki.store.XWikiHibernateStore; |
53 |
|
import com.xpn.xwiki.store.XWikiHibernateVersioningStore; |
54 |
|
import com.xpn.xwiki.store.XWikiStoreInterface; |
55 |
|
import com.xpn.xwiki.store.XWikiVersioningStoreInterface; |
56 |
|
import com.xpn.xwiki.user.api.XWikiRightService; |
57 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (229) |
Complexity: 19 |
Complexity Density: 0.09 |
|
58 |
|
public class ImportTest extends AbstractPackageTest |
59 |
|
{ |
60 |
|
private Package pack; |
61 |
|
|
62 |
|
private XWiki xwiki; |
63 |
|
|
64 |
|
private Mock mockXWikiStore; |
65 |
|
|
66 |
|
private Mock mockRecycleBinStore; |
67 |
|
|
68 |
|
private Mock mockXWikiVersioningStore; |
69 |
|
|
70 |
|
private Mock mockRightService; |
71 |
|
|
72 |
|
private Map<String, XWikiDocument> docs = new HashMap<String, XWikiDocument>(); |
73 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (26) |
Complexity: 1 |
Complexity Density: 0.04 |
|
74 |
7 |
@Override... |
75 |
|
protected void setUp() throws Exception |
76 |
|
{ |
77 |
7 |
super.setUp(); |
78 |
|
|
79 |
7 |
this.pack = new Package(); |
80 |
7 |
this.xwiki = new XWiki(); |
81 |
7 |
getContext().setWiki(this.xwiki); |
82 |
7 |
this.xwiki.setConfig(new XWikiConfig()); |
83 |
|
|
84 |
7 |
Mock mockLocalizationContext = registerMockComponent(LocalizationContext.class); |
85 |
7 |
mockLocalizationContext.stubs().method("getCurrentLocale").will(returnValue(Locale.ROOT)); |
86 |
|
|
87 |
|
|
88 |
7 |
this.mockXWikiStore = |
89 |
|
mock(XWikiHibernateStore.class, new Class[] {XWiki.class, XWikiContext.class}, new Object[] {this.xwiki, |
90 |
|
getContext()}); |
91 |
7 |
this.mockXWikiStore.stubs().method("loadXWikiDoc") |
92 |
|
.will(new CustomStub("Implements XWikiStoreInterface.loadXWikiDoc") |
93 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
94 |
74 |
@Override... |
95 |
|
public Object invoke(Invocation invocation) throws Throwable |
96 |
|
{ |
97 |
74 |
XWikiDocument shallowDoc = (XWikiDocument) invocation.parameterValues.get(0); |
98 |
74 |
String documentKey = shallowDoc.getFullName(); |
99 |
74 |
if (!shallowDoc.getLanguage().equals("")) { |
100 |
19 |
documentKey += "." + shallowDoc.getLanguage(); |
101 |
|
} |
102 |
74 |
if (docs.containsKey(documentKey)) { |
103 |
29 |
return docs.get(documentKey); |
104 |
|
} else { |
105 |
45 |
return shallowDoc; |
106 |
|
} |
107 |
|
} |
108 |
|
}); |
109 |
7 |
this.mockXWikiStore.stubs().method("saveXWikiDoc") |
110 |
|
.will(new CustomStub("Implements XWikiStoreInterface.saveXWikiDoc") |
111 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
112 |
16 |
@Override... |
113 |
|
public Object invoke(Invocation invocation) throws Throwable |
114 |
|
{ |
115 |
16 |
XWikiDocument document = (XWikiDocument) invocation.parameterValues.get(0); |
116 |
16 |
document.setNew(false); |
117 |
16 |
document.setStore((XWikiStoreInterface) mockXWikiStore.proxy()); |
118 |
|
|
119 |
16 |
String documentKey = document.getFullName(); |
120 |
16 |
if (!document.getLanguage().equals("")) { |
121 |
7 |
documentKey += "." + document.getLanguage(); |
122 |
|
} |
123 |
16 |
docs.put(documentKey, document); |
124 |
16 |
return null; |
125 |
|
} |
126 |
|
}); |
127 |
7 |
this.mockXWikiStore.stubs().method("deleteXWikiDoc") |
128 |
|
.will(new CustomStub("Implements XWikiStoreInterface.deleteXWikiDoc") |
129 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
130 |
3 |
@Override... |
131 |
|
public Object invoke(Invocation invocation) throws Throwable |
132 |
|
{ |
133 |
3 |
XWikiDocument document = (XWikiDocument) invocation.parameterValues.get(0); |
134 |
|
|
135 |
3 |
String documentKey = document.getFullName(); |
136 |
3 |
if (!document.getLanguage().equals("")) { |
137 |
1 |
documentKey += "." + document.getLanguage(); |
138 |
|
} |
139 |
3 |
docs.remove(documentKey); |
140 |
3 |
return null; |
141 |
|
} |
142 |
|
}); |
143 |
7 |
this.mockXWikiStore.stubs().method("getTranslationList") |
144 |
|
.will(new CustomStub("Implements XWikiStoreInterface.getTranslationList") |
145 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 4 |
Complexity Density: 0.57 |
|
146 |
3 |
@Override... |
147 |
|
public Object invoke(Invocation invocation) throws Throwable |
148 |
|
{ |
149 |
3 |
XWikiDocument document = (XWikiDocument) invocation.parameterValues.get(0); |
150 |
|
|
151 |
3 |
List translationList = new ArrayList(); |
152 |
8 |
for (Iterator pairsIt = docs.entrySet().iterator(); pairsIt.hasNext();) { |
153 |
5 |
Map.Entry currentEntry = (Map.Entry) pairsIt.next(); |
154 |
5 |
if (((String) currentEntry.getKey()).startsWith(document.getFullName()) |
155 |
|
&& !((XWikiDocument) currentEntry.getValue()).getLanguage().equals("")) { |
156 |
|
|
157 |
2 |
translationList.add(((XWikiDocument) currentEntry.getValue()).getLanguage()); |
158 |
|
} |
159 |
|
} |
160 |
3 |
return translationList; |
161 |
|
} |
162 |
|
}); |
163 |
7 |
this.mockXWikiStore.stubs().method("injectCustomMapping").will(returnValue(false)); |
164 |
|
|
165 |
7 |
this.mockRecycleBinStore = |
166 |
|
mock(XWikiHibernateRecycleBinStore.class, new Class[] {XWikiContext.class}, new Object[] {getContext()}); |
167 |
7 |
this.mockRecycleBinStore.stubs().method("saveToRecycleBin").will(VoidStub.INSTANCE); |
168 |
|
|
169 |
7 |
this.mockXWikiVersioningStore = |
170 |
|
mock(XWikiHibernateVersioningStore.class, new Class[] {XWiki.class, XWikiContext.class}, new Object[] { |
171 |
|
this.xwiki, getContext()}); |
172 |
7 |
this.mockXWikiVersioningStore.stubs().method("getXWikiDocumentArchive").will(returnValue(null)); |
173 |
7 |
this.mockXWikiVersioningStore.stubs().method("resetRCSArchive").will(returnValue(null)); |
174 |
|
|
175 |
7 |
this.xwiki.setStore((XWikiStoreInterface) mockXWikiStore.proxy()); |
176 |
7 |
this.xwiki.setRecycleBinStore((XWikiHibernateRecycleBinStore) this.mockRecycleBinStore.proxy()); |
177 |
7 |
this.xwiki.setVersioningStore((XWikiVersioningStoreInterface) mockXWikiVersioningStore.proxy()); |
178 |
|
|
179 |
|
|
180 |
7 |
this.mockRightService = mock(XWikiRightService.class); |
181 |
7 |
this.mockRightService.stubs().method("checkAccess").will(returnValue(true)); |
182 |
7 |
this.mockRightService.stubs().method("hasWikiAdminRights").will(returnValue(true)); |
183 |
7 |
this.mockRightService.stubs().method("hasProgrammingRights").will(returnValue(true)); |
184 |
7 |
this.xwiki.setRightService((XWikiRightService) this.mockRightService.proxy()); |
185 |
|
} |
186 |
|
|
187 |
|
|
188 |
|
|
189 |
|
|
190 |
|
@throws |
191 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
192 |
1 |
public void testImportDocument() throws Exception... |
193 |
|
{ |
194 |
1 |
XWikiDocument doc1 = new XWikiDocument(new DocumentReference("Test", "Test", "DocImport")); |
195 |
1 |
doc1.setDefaultLanguage("en"); |
196 |
|
|
197 |
1 |
byte[] zipFile = this.createZipFile(new XWikiDocument[] {doc1}, new String[] {"ISO-8859-1"}, null); |
198 |
|
|
199 |
|
|
200 |
1 |
this.pack = new Package(); |
201 |
|
|
202 |
1 |
this.pack.Import(zipFile, getContext()); |
203 |
1 |
this.pack.install(getContext()); |
204 |
|
|
205 |
|
|
206 |
1 |
XWikiDocument foundDocument = |
207 |
|
this.xwiki.getDocument(new DocumentReference("Test", "Test", "DocImport"), getContext()); |
208 |
1 |
assertFalse(foundDocument.isNew()); |
209 |
|
|
210 |
1 |
XWikiDocument nonExistingDocument = |
211 |
|
this.xwiki.getDocument(new DocumentReference("Test", "Test", "DocImportNonexisting"), getContext()); |
212 |
1 |
assertTrue(nonExistingDocument.isNew()); |
213 |
|
|
214 |
1 |
XWikiDocument foundTranslationDocument = foundDocument.getTranslatedDocument("fr", getContext()); |
215 |
1 |
assertSame(foundDocument, foundTranslationDocument); |
216 |
|
|
217 |
1 |
XWikiDocument doc1Translation = new XWikiDocument(new DocumentReference("Test", "Test", "DocImport")); |
218 |
1 |
doc1Translation.setLanguage("fr"); |
219 |
1 |
doc1Translation.setDefaultLanguage("en"); |
220 |
1 |
this.xwiki.saveDocument(doc1Translation, getContext()); |
221 |
1 |
foundTranslationDocument = foundDocument.getTranslatedDocument("fr", getContext()); |
222 |
1 |
assertNotSame(foundDocument, foundTranslationDocument); |
223 |
|
} |
224 |
|
|
225 |
|
|
226 |
|
|
227 |
|
|
228 |
|
@throws |
229 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (34) |
Complexity: 1 |
Complexity Density: 0.03 |
1PASS
|
|
230 |
1 |
public void testImportExtension() throws Exception... |
231 |
|
{ |
232 |
1 |
ExtensionId extensionId = new ExtensionId("test", "1.0"); |
233 |
|
|
234 |
1 |
XWikiDocument doc1 = new XWikiDocument(new DocumentReference("Test", "Test", "DocImport")); |
235 |
1 |
doc1.setDefaultLanguage("en"); |
236 |
|
|
237 |
1 |
byte[] zipFile = this.createZipFile(new XWikiDocument[] {doc1}, new String[] {"ISO-8859-1"}, extensionId); |
238 |
|
|
239 |
|
|
240 |
1 |
DefaultLocalExtension localExtension = new DefaultLocalExtension(null, extensionId, "xar"); |
241 |
1 |
File file = File.createTempFile("temp", ".xar"); |
242 |
1 |
FileUtils.writeByteArrayToFile(file, zipFile); |
243 |
1 |
localExtension.setFile(file); |
244 |
1 |
LocalExtensionRepository localeRepository = getComponentManager().getInstance(LocalExtensionRepository.class); |
245 |
1 |
localeRepository.storeExtension(localExtension); |
246 |
|
|
247 |
|
|
248 |
1 |
Mock extensionListener = mock(EventListener.class); |
249 |
1 |
extensionListener.stubs().method("getEvents").will(returnValue(Arrays.asList(new ExtensionInstalledEvent()))); |
250 |
1 |
extensionListener.stubs().method("getName").will(returnValue("extension installed listener")); |
251 |
1 |
extensionListener.expects(once()).method("onEvent"); |
252 |
1 |
ObservationManager observationManager = getComponentManager().getInstance(ObservationManager.class); |
253 |
1 |
observationManager.addListener((EventListener) extensionListener.proxy()); |
254 |
|
|
255 |
|
|
256 |
1 |
this.pack = new Package(); |
257 |
|
|
258 |
1 |
this.pack.Import(zipFile, getContext()); |
259 |
1 |
this.pack.install(getContext()); |
260 |
|
|
261 |
|
|
262 |
1 |
XWikiDocument foundDocument = |
263 |
|
this.xwiki.getDocument(new DocumentReference("Test", "Test", "DocImport"), getContext()); |
264 |
1 |
assertFalse(foundDocument.isNew()); |
265 |
|
|
266 |
1 |
XWikiDocument nonExistingDocument = |
267 |
|
this.xwiki.getDocument(new DocumentReference("Test", "Test", "DocImportNonexisting"), getContext()); |
268 |
1 |
assertTrue(nonExistingDocument.isNew()); |
269 |
|
|
270 |
1 |
XWikiDocument foundTranslationDocument = foundDocument.getTranslatedDocument("fr", getContext()); |
271 |
1 |
assertSame(foundDocument, foundTranslationDocument); |
272 |
|
|
273 |
1 |
XWikiDocument doc1Translation = new XWikiDocument(new DocumentReference("Test", "Test", "DocImport")); |
274 |
1 |
doc1Translation.setLanguage("fr"); |
275 |
1 |
doc1Translation.setDefaultLanguage("en"); |
276 |
1 |
this.xwiki.saveDocument(doc1Translation, getContext()); |
277 |
1 |
foundTranslationDocument = foundDocument.getTranslatedDocument("fr", getContext()); |
278 |
1 |
assertNotSame(foundDocument, foundTranslationDocument); |
279 |
|
|
280 |
|
|
281 |
1 |
InstalledExtensionRepository installedExtensionRepository = |
282 |
|
getComponentManager().getInstance(InstalledExtensionRepository.class); |
283 |
1 |
assertNotNull(installedExtensionRepository.getInstalledExtension(extensionId)); |
284 |
1 |
assertNotNull(installedExtensionRepository.getInstalledExtension(extensionId.getId(), "wiki:" |
285 |
|
+ getContext().getWikiId())); |
286 |
|
} |
287 |
|
|
288 |
|
|
289 |
|
|
290 |
|
|
291 |
|
@throws |
292 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
293 |
1 |
public void testImportDocumentNonAsciiTitle() throws Exception... |
294 |
|
{ |
295 |
1 |
XWikiDocument doc1 = new XWikiDocument(new DocumentReference("Test", "Test", "\u60A8\u597D\u4E16\u754C")); |
296 |
1 |
doc1.setDefaultLanguage("zh"); |
297 |
|
|
298 |
1 |
byte[] zipFile = this.createZipFile(new XWikiDocument[] {doc1}, new String[] {"UTF-8"}, "UTF-8", null); |
299 |
|
|
300 |
|
|
301 |
1 |
this.pack = new Package(); |
302 |
|
|
303 |
1 |
this.pack.Import(zipFile, getContext()); |
304 |
1 |
this.pack.install(getContext()); |
305 |
|
|
306 |
|
|
307 |
1 |
XWikiDocument foundDocument = |
308 |
|
this.xwiki.getDocument(new DocumentReference("Test", "Test", "\u60A8\u597D\u4E16\u754C"), getContext()); |
309 |
1 |
assertFalse(foundDocument.isNew()); |
310 |
|
|
311 |
1 |
XWikiDocument nonExistingDocument = |
312 |
|
this.xwiki.getDocument(new DocumentReference("Test", "Test", "DocImportNonexisting"), getContext()); |
313 |
1 |
assertTrue(nonExistingDocument.isNew()); |
314 |
|
|
315 |
1 |
XWikiDocument foundTranslationDocument = foundDocument.getTranslatedDocument("fr", getContext()); |
316 |
1 |
assertSame(foundDocument, foundTranslationDocument); |
317 |
|
|
318 |
1 |
XWikiDocument doc1Translation = |
319 |
|
new XWikiDocument(new DocumentReference("Test", "Test", "\u60A8\u597D\u4E16\u754C")); |
320 |
1 |
doc1Translation.setLanguage("fr"); |
321 |
1 |
doc1Translation.setDefaultLanguage("zh"); |
322 |
1 |
this.xwiki.saveDocument(doc1Translation, getContext()); |
323 |
1 |
foundTranslationDocument = foundDocument.getTranslatedDocument("fr", getContext()); |
324 |
1 |
assertNotSame(foundDocument, foundTranslationDocument); |
325 |
|
} |
326 |
|
|
327 |
|
|
328 |
|
|
329 |
|
|
330 |
|
@throws |
331 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (21) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
332 |
1 |
public void testImportDocumentNonAsciiTitleNonUtf8PlatformEncoding() throws Exception... |
333 |
|
{ |
334 |
1 |
String oldEncoding = System.getProperty("file.encoding"); |
335 |
1 |
System.setProperty("file.encoding", "ISO-8859-1"); |
336 |
|
|
337 |
1 |
XWikiDocument doc1 = new XWikiDocument(new DocumentReference("Test", "Test", "\u60A8\u597D\u4E16\u754C")); |
338 |
1 |
doc1.setDefaultLanguage("zh"); |
339 |
|
|
340 |
1 |
byte[] zipFile = |
341 |
|
this.createZipFileUsingCommonsCompress(new XWikiDocument[] {doc1}, new String[] {"UTF-8"}, "UTF-8", null); |
342 |
|
|
343 |
|
|
344 |
1 |
this.pack = new Package(); |
345 |
|
|
346 |
|
|
347 |
1 |
this.pack.Import(zipFile, getContext()); |
348 |
1 |
this.pack.install(getContext()); |
349 |
|
|
350 |
1 |
System.setProperty("file.encoding", oldEncoding); |
351 |
|
|
352 |
|
|
353 |
1 |
XWikiDocument foundDocument = |
354 |
|
this.xwiki.getDocument(new DocumentReference("Test", "Test", "\u60A8\u597D\u4E16\u754C"), getContext()); |
355 |
1 |
assertFalse(foundDocument.isNew()); |
356 |
|
|
357 |
1 |
XWikiDocument nonExistingDocument = |
358 |
|
this.xwiki.getDocument(new DocumentReference("Test", "Test", "DocImportNonexisting"), getContext()); |
359 |
1 |
assertTrue(nonExistingDocument.isNew()); |
360 |
|
|
361 |
1 |
XWikiDocument foundTranslationDocument = foundDocument.getTranslatedDocument("fr", getContext()); |
362 |
1 |
assertSame(foundDocument, foundTranslationDocument); |
363 |
|
|
364 |
1 |
XWikiDocument doc1Translation = |
365 |
|
new XWikiDocument(new DocumentReference("Test", "Test", "\u60A8\u597D\u4E16\u754C")); |
366 |
1 |
doc1Translation.setLanguage("fr"); |
367 |
1 |
doc1Translation.setDefaultLanguage("zh"); |
368 |
1 |
this.xwiki.saveDocument(doc1Translation, getContext()); |
369 |
1 |
foundTranslationDocument = foundDocument.getTranslatedDocument("fr", getContext()); |
370 |
1 |
assertNotSame(foundDocument, foundTranslationDocument); |
371 |
|
} |
372 |
|
|
373 |
|
|
374 |
|
|
375 |
|
|
376 |
|
@throws |
377 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
378 |
1 |
public void testImportDocumentXarCreatedByCommonsCompress() throws Exception... |
379 |
|
{ |
380 |
1 |
XWikiDocument doc1 = new XWikiDocument(new DocumentReference("Test", "Test", "DocImport")); |
381 |
1 |
doc1.setDefaultLanguage("en"); |
382 |
|
|
383 |
1 |
byte[] zipFile = |
384 |
|
this.createZipFileUsingCommonsCompress(new XWikiDocument[] {doc1}, new String[] {"ISO-8859-1"}, null); |
385 |
|
|
386 |
|
|
387 |
1 |
this.pack = new Package(); |
388 |
|
|
389 |
1 |
this.pack.Import(zipFile, getContext()); |
390 |
1 |
this.pack.install(getContext()); |
391 |
|
|
392 |
|
|
393 |
1 |
XWikiDocument foundDocument = |
394 |
|
this.xwiki.getDocument(new DocumentReference("Test", "Test", "DocImport"), getContext()); |
395 |
1 |
assertFalse(foundDocument.isNew()); |
396 |
|
|
397 |
1 |
XWikiDocument nonExistingDocument = |
398 |
|
this.xwiki.getDocument(new DocumentReference("Test", "Test", "DocImportNonexisting"), getContext()); |
399 |
1 |
assertTrue(nonExistingDocument.isNew()); |
400 |
|
|
401 |
1 |
XWikiDocument foundTranslationDocument = foundDocument.getTranslatedDocument("fr", getContext()); |
402 |
1 |
assertSame(foundDocument, foundTranslationDocument); |
403 |
|
|
404 |
1 |
XWikiDocument doc1Translation = new XWikiDocument(new DocumentReference("Test", "Test", "DocImport")); |
405 |
1 |
doc1Translation.setLanguage("fr"); |
406 |
1 |
doc1Translation.setDefaultLanguage("en"); |
407 |
1 |
this.xwiki.saveDocument(doc1Translation, getContext()); |
408 |
1 |
foundTranslationDocument = foundDocument.getTranslatedDocument("fr", getContext()); |
409 |
1 |
assertNotSame(foundDocument, foundTranslationDocument); |
410 |
|
} |
411 |
|
|
412 |
|
|
413 |
|
|
414 |
|
|
415 |
|
@throws |
416 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (19) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
417 |
1 |
public void testImportOverwriteDocument() throws Exception... |
418 |
|
{ |
419 |
1 |
XWikiDocument doc1 = new XWikiDocument(new DocumentReference("Test", "Test", "DocImportOverwrite")); |
420 |
1 |
doc1.setDefaultLanguage("en"); |
421 |
|
|
422 |
1 |
byte[] zipFile = this.createZipFile(new XWikiDocument[] {doc1}, new String[] {"ISO-8859-1"}, null); |
423 |
|
|
424 |
|
|
425 |
1 |
this.pack = new Package(); |
426 |
|
|
427 |
1 |
this.pack.Import(zipFile, getContext()); |
428 |
1 |
this.pack.install(getContext()); |
429 |
|
|
430 |
|
|
431 |
1 |
XWikiDocument foundDocument = |
432 |
|
this.xwiki.getDocument(new DocumentReference("Test", "Test", "DocImportOverwrite"), getContext()); |
433 |
1 |
assertFalse(foundDocument.isNew()); |
434 |
|
|
435 |
|
|
436 |
1 |
String newContent = "This is new content"; |
437 |
1 |
XWikiDocument overwritingDoc = new XWikiDocument(new DocumentReference("Test", "Test", "DocImportOverwrite")); |
438 |
1 |
overwritingDoc.setContent(newContent); |
439 |
|
|
440 |
1 |
zipFile = this.createZipFile(new XWikiDocument[] {overwritingDoc}, new String[] {"ISO-8859-1"}, null); |
441 |
|
|
442 |
|
|
443 |
1 |
this.pack = new Package(); |
444 |
|
|
445 |
1 |
this.pack.Import(zipFile, getContext()); |
446 |
1 |
this.pack.install(getContext()); |
447 |
|
|
448 |
|
|
449 |
1 |
XWikiDocument foundOverwritingDoc = |
450 |
|
this.xwiki.getDocument(new DocumentReference("Test", "Test", "DocImportOverwrite"), getContext()); |
451 |
1 |
assertFalse(foundOverwritingDoc.isNew()); |
452 |
1 |
assertEquals(foundOverwritingDoc.getContent(), newContent); |
453 |
1 |
assertEquals(foundDocument, foundOverwritingDoc.getOriginalDocument()); |
454 |
|
} |
455 |
|
|
456 |
|
|
457 |
|
|
458 |
|
|
459 |
|
@throws |
460 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (23) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
461 |
1 |
public void testImportTranslationsOverwrite() throws Exception... |
462 |
|
{ |
463 |
1 |
XWikiDocument original = new XWikiDocument(new DocumentReference("Test", "Test", "DocTranslation")); |
464 |
1 |
original.setDefaultLanguage("en"); |
465 |
1 |
original.setTranslation(0); |
466 |
1 |
XWikiDocument translation = new XWikiDocument(new DocumentReference("Test", "Test", "DocTranslation")); |
467 |
1 |
translation.setLanguage("fr"); |
468 |
1 |
translation.setDefaultLanguage("en"); |
469 |
1 |
translation.setTranslation(1); |
470 |
1 |
translation.setOriginalDocument(original); |
471 |
|
|
472 |
|
|
473 |
1 |
byte[] zipFile = |
474 |
|
this.createZipFile(new XWikiDocument[] {original, translation}, new String[] {"ISO-8859-1", "ISO-8859-1"}, |
475 |
|
null); |
476 |
|
|
477 |
|
|
478 |
1 |
this.pack = new Package(); |
479 |
1 |
this.pack.Import(zipFile, getContext()); |
480 |
1 |
this.pack.install(getContext()); |
481 |
1 |
XWikiDocument foundDocument = |
482 |
|
this.xwiki.getDocument(new DocumentReference("Test", "Test", "DocTranslation"), getContext()); |
483 |
1 |
assertFalse(foundDocument.isNew()); |
484 |
|
|
485 |
1 |
XWikiDocument translationDoc = foundDocument.getTranslatedDocument("fr", getContext()); |
486 |
1 |
assertFalse(translationDoc.isNew()); |
487 |
|
|
488 |
|
|
489 |
1 |
this.pack = new Package(); |
490 |
|
|
491 |
1 |
this.pack.Import(zipFile, getContext()); |
492 |
1 |
this.pack.install(getContext()); |
493 |
1 |
foundDocument = this.xwiki.getDocument(new DocumentReference("Test", "Test", "DocTranslation"), getContext()); |
494 |
|
|
495 |
1 |
assertFalse(foundDocument.isNew()); |
496 |
|
|
497 |
1 |
translationDoc = foundDocument.getTranslatedDocument("fr", getContext()); |
498 |
1 |
assertFalse(translationDoc.isNew()); |
499 |
|
} |
500 |
|
|
501 |
|
} |