| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package com.xpn.xwiki.api; |
| 21 |
|
|
| 22 |
|
import java.util.Calendar; |
| 23 |
|
import java.util.Collections; |
| 24 |
|
import java.util.HashMap; |
| 25 |
|
import java.util.Map; |
| 26 |
|
import java.util.Random; |
| 27 |
|
|
| 28 |
|
import org.jmock.Mock; |
| 29 |
|
import org.jmock.core.Invocation; |
| 30 |
|
import org.jmock.core.stub.CustomStub; |
| 31 |
|
import org.xwiki.model.reference.DocumentReference; |
| 32 |
|
import org.xwiki.rendering.syntax.Syntax; |
| 33 |
|
|
| 34 |
|
import com.xpn.xwiki.XWikiConfig; |
| 35 |
|
import com.xpn.xwiki.XWikiContext; |
| 36 |
|
import com.xpn.xwiki.XWikiException; |
| 37 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
| 38 |
|
import com.xpn.xwiki.doc.XWikiDocumentArchive; |
| 39 |
|
import com.xpn.xwiki.store.XWikiHibernateStore; |
| 40 |
|
import com.xpn.xwiki.store.XWikiHibernateVersioningStore; |
| 41 |
|
import com.xpn.xwiki.store.XWikiStoreInterface; |
| 42 |
|
import com.xpn.xwiki.store.XWikiVersioningStoreInterface; |
| 43 |
|
import com.xpn.xwiki.test.AbstractBridgedXWikiComponentTestCase; |
| 44 |
|
import com.xpn.xwiki.user.api.XWikiRightService; |
| 45 |
|
import com.xpn.xwiki.user.impl.xwiki.XWikiRightServiceImpl; |
| 46 |
|
|
| 47 |
|
|
| 48 |
|
@link |
| 49 |
|
|
| 50 |
|
@version |
| 51 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (62) |
Complexity: 8 |
Complexity Density: 0.15 |
|
| 52 |
|
public class XWikiTest extends AbstractBridgedXWikiComponentTestCase |
| 53 |
|
{ |
| 54 |
|
public static final Random rand = new Random(Calendar.getInstance().getTimeInMillis()); |
| 55 |
|
|
| 56 |
|
private com.xpn.xwiki.XWiki xwiki; |
| 57 |
|
|
| 58 |
|
private Document apiDocument; |
| 59 |
|
|
| 60 |
|
private XWiki apiXWiki; |
| 61 |
|
|
| 62 |
|
private Mock mockXWikiStore; |
| 63 |
|
|
| 64 |
|
private Mock mockXWikiVersioningStore; |
| 65 |
|
|
| 66 |
|
private Mock mockXWikiRightService; |
| 67 |
|
|
| 68 |
|
private Map<String, XWikiDocument> docs = new HashMap<String, XWikiDocument>(); |
| 69 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (24) |
Complexity: 1 |
Complexity Density: 0.04 |
|
| 70 |
4 |
@Override... |
| 71 |
|
protected void setUp() throws Exception |
| 72 |
|
{ |
| 73 |
4 |
super.setUp(); |
| 74 |
4 |
this.xwiki = new com.xpn.xwiki.XWiki(); |
| 75 |
4 |
getContext().setWiki(this.xwiki); |
| 76 |
4 |
this.xwiki.setConfig(new XWikiConfig()); |
| 77 |
|
|
| 78 |
4 |
this.apiXWiki = new XWiki(this.xwiki, getContext()); |
| 79 |
|
|
| 80 |
4 |
this.mockXWikiStore = |
| 81 |
|
mock(XWikiHibernateStore.class, new java.lang.Class[] {com.xpn.xwiki.XWiki.class, XWikiContext.class}, |
| 82 |
|
new java.lang.Object[] {this.xwiki, getContext()}); |
| 83 |
4 |
this.mockXWikiStore.stubs().method("loadXWikiDoc").will( |
| 84 |
|
new CustomStub("Implements XWikiStoreInterface.loadXWikiDoc") |
| 85 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 86 |
16 |
@Override... |
| 87 |
|
public java.lang.Object invoke(Invocation invocation) throws Throwable |
| 88 |
|
{ |
| 89 |
16 |
XWikiDocument shallowDoc = (XWikiDocument) invocation.parameterValues.get(0); |
| 90 |
16 |
if (XWikiTest.this.docs.containsKey(shallowDoc.getName())) { |
| 91 |
6 |
return XWikiTest.this.docs.get(shallowDoc.getName()); |
| 92 |
|
} else { |
| 93 |
10 |
return shallowDoc; |
| 94 |
|
} |
| 95 |
|
} |
| 96 |
|
}); |
| 97 |
4 |
this.mockXWikiStore.stubs().method("saveXWikiDoc").will( |
| 98 |
|
new CustomStub("Implements XWikiStoreInterface.saveXWikiDoc") |
| 99 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
| 100 |
7 |
@Override... |
| 101 |
|
public java.lang.Object invoke(Invocation invocation) throws Throwable |
| 102 |
|
{ |
| 103 |
7 |
XWikiDocument document = (XWikiDocument) invocation.parameterValues.get(0); |
| 104 |
7 |
document.setNew(false); |
| 105 |
7 |
document.setStore((XWikiStoreInterface) XWikiTest.this.mockXWikiStore.proxy()); |
| 106 |
7 |
document.setId(rand.nextLong()); |
| 107 |
7 |
XWikiTest.this.docs.put(document.getName(), document); |
| 108 |
7 |
return null; |
| 109 |
|
} |
| 110 |
|
}); |
| 111 |
4 |
this.mockXWikiStore.stubs().method("getTranslationList").will(returnValue(Collections.EMPTY_LIST)); |
| 112 |
|
|
| 113 |
4 |
this.mockXWikiVersioningStore = |
| 114 |
|
mock(XWikiHibernateVersioningStore.class, new java.lang.Class[] {com.xpn.xwiki.XWiki.class, |
| 115 |
|
XWikiContext.class}, new java.lang.Object[] {this.xwiki, getContext()}); |
| 116 |
4 |
this.mockXWikiVersioningStore.stubs().method("getXWikiDocumentArchive").will( |
| 117 |
|
returnValue(new XWikiDocumentArchive())); |
| 118 |
4 |
this.mockXWikiVersioningStore.stubs().method("saveXWikiDocArchive").will(returnValue(null)); |
| 119 |
|
|
| 120 |
4 |
this.mockXWikiRightService = |
| 121 |
|
mock(XWikiRightServiceImpl.class, new java.lang.Class[] {}, new java.lang.Object[] {}); |
| 122 |
4 |
this.mockXWikiRightService.stubs().method("hasAccessLevel").will(returnValue(true)); |
| 123 |
4 |
this.mockXWikiRightService.stubs().method("hasProgrammingRights").will(returnValue(true)); |
| 124 |
|
|
| 125 |
4 |
this.xwiki.setStore((XWikiStoreInterface) this.mockXWikiStore.proxy()); |
| 126 |
4 |
this.xwiki.setVersioningStore((XWikiVersioningStoreInterface) this.mockXWikiVersioningStore.proxy()); |
| 127 |
4 |
this.xwiki.setRightService((XWikiRightService) this.mockXWikiRightService.proxy()); |
| 128 |
|
|
| 129 |
4 |
getContext().setUser("Redtail"); |
| 130 |
4 |
this.apiDocument = |
| 131 |
|
new Document(new XWikiDocument(new DocumentReference("Wiki", "MilkyWay", "Fidis")), getContext()); |
| 132 |
4 |
this.apiDocument.getDocument().setCreator("c" + getContext().getUser()); |
| 133 |
4 |
this.apiDocument.getDocument().setAuthor("a" + getContext().getUser()); |
| 134 |
4 |
this.apiDocument.save(); |
| 135 |
4 |
getContext().setUser("Earth"); |
| 136 |
|
} |
| 137 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
| 138 |
1 |
public void testAuthorIsntChangedAfterDocumentCopy() throws XWikiException... |
| 139 |
|
{ |
| 140 |
1 |
String copyName = "Lyre"; |
| 141 |
1 |
this.apiXWiki.copyDocument(this.apiDocument.getName(), copyName); |
| 142 |
1 |
Document copy = this.apiXWiki.getDocument(copyName); |
| 143 |
|
|
| 144 |
1 |
assertEquals("XWiki.Earth", copy.getAuthor()); |
| 145 |
|
} |
| 146 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
| 147 |
1 |
public void testCreatorIsntChangedAfterDocumentCopy() throws XWikiException... |
| 148 |
|
{ |
| 149 |
1 |
String copyName = "Sirius"; |
| 150 |
1 |
this.apiXWiki.copyDocument(this.apiDocument.getName(), copyName); |
| 151 |
1 |
Document copy = this.apiXWiki.getDocument(copyName); |
| 152 |
|
|
| 153 |
1 |
assertEquals("XWiki.Earth", copy.getCreator()); |
| 154 |
|
} |
| 155 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
| 156 |
1 |
public void testCreationDateAfterDocumentCopy() throws XWikiException... |
| 157 |
|
{ |
| 158 |
1 |
String copyName = this.apiDocument.getName() + "Copy"; |
| 159 |
1 |
long startTime = (Calendar.getInstance().getTimeInMillis() / 1000) * 1000; |
| 160 |
1 |
this.apiXWiki.copyDocument(this.apiDocument.getName(), copyName); |
| 161 |
1 |
long endTime = (Calendar.getInstance().getTimeInMillis() / 1000) * 1000; |
| 162 |
1 |
long copyCreationTime = this.apiXWiki.getDocument(copyName).getCreationDate().getTime(); |
| 163 |
|
|
| 164 |
1 |
assertTrue(startTime <= copyCreationTime && copyCreationTime <= endTime); |
| 165 |
|
} |
| 166 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
| 167 |
1 |
public void testGetAvailableRendererSyntax()... |
| 168 |
|
{ |
| 169 |
1 |
assertEquals(Syntax.PLAIN_1_0, this.apiXWiki.getAvailableRendererSyntax("plain", "1.0")); |
| 170 |
1 |
assertEquals(Syntax.PLAIN_1_0, this.apiXWiki.getAvailableRendererSyntax("Plain", "1.0")); |
| 171 |
1 |
assertEquals(Syntax.PLAIN_1_0, this.apiXWiki.getAvailableRendererSyntax("plain", null)); |
| 172 |
1 |
assertNull(this.apiXWiki.getAvailableRendererSyntax("plai", "1.0")); |
| 173 |
1 |
assertNull(this.apiXWiki.getAvailableRendererSyntax("plai", null)); |
| 174 |
|
} |
| 175 |
|
} |