1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.wiki.script; |
21 |
|
|
22 |
|
import static org.junit.Assert.assertEquals; |
23 |
|
import static org.junit.Assert.assertFalse; |
24 |
|
import static org.junit.Assert.assertNull; |
25 |
|
import static org.junit.Assert.assertTrue; |
26 |
|
import static org.mockito.ArgumentMatchers.eq; |
27 |
|
import static org.mockito.Mockito.doThrow; |
28 |
|
import static org.mockito.Mockito.mock; |
29 |
|
import static org.mockito.Mockito.never; |
30 |
|
import static org.mockito.Mockito.times; |
31 |
|
import static org.mockito.Mockito.verify; |
32 |
|
import static org.mockito.Mockito.when; |
33 |
|
|
34 |
|
import java.util.ArrayList; |
35 |
|
import java.util.Arrays; |
36 |
|
import java.util.Collection; |
37 |
|
|
38 |
|
import javax.inject.Provider; |
39 |
|
|
40 |
|
import org.apache.commons.lang3.StringUtils; |
41 |
|
import org.junit.Before; |
42 |
|
import org.junit.Rule; |
43 |
|
import org.junit.Test; |
44 |
|
import org.xwiki.component.util.DefaultParameterizedType; |
45 |
|
import org.xwiki.context.Execution; |
46 |
|
import org.xwiki.context.ExecutionContext; |
47 |
|
import org.xwiki.model.reference.DocumentReference; |
48 |
|
import org.xwiki.model.reference.EntityReferenceSerializer; |
49 |
|
import org.xwiki.model.reference.WikiReference; |
50 |
|
import org.xwiki.script.service.ScriptServiceManager; |
51 |
|
import org.xwiki.security.authorization.AccessDeniedException; |
52 |
|
import org.xwiki.security.authorization.AuthorizationManager; |
53 |
|
import org.xwiki.security.authorization.Right; |
54 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
55 |
|
import org.xwiki.url.internal.standard.StandardURLConfiguration; |
56 |
|
import org.xwiki.wiki.configuration.WikiConfiguration; |
57 |
|
import org.xwiki.wiki.descriptor.WikiDescriptor; |
58 |
|
import org.xwiki.wiki.descriptor.WikiDescriptorManager; |
59 |
|
import org.xwiki.wiki.internal.descriptor.document.WikiDescriptorDocumentHelper; |
60 |
|
import org.xwiki.wiki.manager.WikiManager; |
61 |
|
import org.xwiki.wiki.manager.WikiManagerException; |
62 |
|
|
63 |
|
import com.xpn.xwiki.XWikiContext; |
64 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
65 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (257) |
Complexity: 38 |
Complexity Density: 0.17 |
|
66 |
|
public class WikiManagerScriptServiceTest |
67 |
|
{ |
68 |
|
@Rule |
69 |
|
public MockitoComponentMockingRule<WikiManagerScriptService> mocker = |
70 |
|
new MockitoComponentMockingRule<WikiManagerScriptService>(WikiManagerScriptService.class); |
71 |
|
|
72 |
|
private WikiManager wikiManager; |
73 |
|
|
74 |
|
private WikiDescriptorManager wikiDescriptorManager; |
75 |
|
|
76 |
|
private Provider<XWikiContext> xcontextProvider; |
77 |
|
|
78 |
|
private Execution execution; |
79 |
|
|
80 |
|
private AuthorizationManager authorizationManager; |
81 |
|
|
82 |
|
private EntityReferenceSerializer<String> entityReferenceSerializer; |
83 |
|
|
84 |
|
private ScriptServiceManager scriptServiceManager; |
85 |
|
|
86 |
|
private StandardURLConfiguration standardURLConfiguration; |
87 |
|
|
88 |
|
private WikiConfiguration wikiConfiguration; |
89 |
|
|
90 |
|
private XWikiContext xcontext; |
91 |
|
|
92 |
|
private ExecutionContext executionContext; |
93 |
|
|
94 |
|
private DocumentReference currentUserRef; |
95 |
|
|
96 |
|
private XWikiDocument currentDoc; |
97 |
|
|
98 |
|
private WikiDescriptorDocumentHelper wikiDescriptorDocumentHelper; |
99 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 1 |
Complexity Density: 0.05 |
|
100 |
33 |
@Before... |
101 |
|
public void setUp() throws Exception |
102 |
|
{ |
103 |
33 |
wikiManager = mocker.getInstance(WikiManager.class); |
104 |
33 |
wikiDescriptorManager = mocker.getInstance(WikiDescriptorManager.class); |
105 |
33 |
authorizationManager = mocker.getInstance(AuthorizationManager.class); |
106 |
33 |
scriptServiceManager = mocker.getInstance(ScriptServiceManager.class); |
107 |
33 |
entityReferenceSerializer = |
108 |
|
mocker.getInstance(new DefaultParameterizedType(null, EntityReferenceSerializer.class, String.class)); |
109 |
33 |
standardURLConfiguration = mocker.getInstance(StandardURLConfiguration.class); |
110 |
33 |
wikiConfiguration = mocker.getInstance(WikiConfiguration.class); |
111 |
33 |
xcontextProvider = mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER); |
112 |
33 |
xcontext = mock(XWikiContext.class); |
113 |
33 |
when(xcontextProvider.get()).thenReturn(xcontext); |
114 |
33 |
execution = mocker.getInstance(Execution.class); |
115 |
33 |
executionContext = new ExecutionContext(); |
116 |
33 |
when(execution.getContext()).thenReturn(executionContext); |
117 |
|
|
118 |
33 |
currentUserRef = new DocumentReference("mainWiki", "XWiki", "User"); |
119 |
33 |
when(xcontext.getUserReference()).thenReturn(currentUserRef); |
120 |
|
|
121 |
33 |
currentDoc = mock(XWikiDocument.class); |
122 |
33 |
when(xcontext.getDoc()).thenReturn(currentDoc); |
123 |
|
|
124 |
33 |
when(wikiDescriptorManager.getMainWikiId()).thenReturn("mainWiki"); |
125 |
|
|
126 |
33 |
when(entityReferenceSerializer.serialize(currentUserRef)).thenReturn("mainWiki:XWiki.User"); |
127 |
|
|
128 |
33 |
wikiDescriptorDocumentHelper = mocker.getInstance(WikiDescriptorDocumentHelper.class); |
129 |
|
} |
130 |
|
|
131 |
|
|
132 |
|
@return |
133 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
134 |
1 |
private Exception currentScriptHasNotProgrammingRight() throws AccessDeniedException... |
135 |
|
{ |
136 |
1 |
DocumentReference authorDocRef = new DocumentReference("mainWiki", "XWiki", "Admin"); |
137 |
1 |
when(currentDoc.getAuthorReference()).thenReturn(authorDocRef); |
138 |
1 |
DocumentReference currentDocRef = new DocumentReference("subwiki", "Test", "test"); |
139 |
1 |
when(currentDoc.getDocumentReference()).thenReturn(currentDocRef); |
140 |
|
|
141 |
1 |
Exception exception = new AccessDeniedException(Right.PROGRAM, authorDocRef, currentDocRef); |
142 |
1 |
doThrow(exception).when(authorizationManager).checkAccess(Right.PROGRAM, authorDocRef, currentDocRef); |
143 |
|
|
144 |
1 |
return exception; |
145 |
|
} |
146 |
|
|
147 |
|
|
148 |
|
@return |
149 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
150 |
1 |
private Exception currentUserHasNotProgrammingRight() throws AccessDeniedException... |
151 |
|
{ |
152 |
1 |
WikiReference wiki = new WikiReference("mainWiki"); |
153 |
1 |
Exception exception = new AccessDeniedException(Right.PROGRAM, currentUserRef, wiki); |
154 |
1 |
doThrow(exception).when(authorizationManager).checkAccess(eq(Right.PROGRAM), eq(currentUserRef), eq(wiki)); |
155 |
|
|
156 |
1 |
return exception; |
157 |
|
} |
158 |
|
|
159 |
|
|
160 |
|
@return |
161 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
162 |
1 |
private Exception currentUserHasNotCreateWikiRight() throws AccessDeniedException... |
163 |
|
{ |
164 |
1 |
WikiReference wiki = new WikiReference("mainWiki"); |
165 |
1 |
Exception exception = new AccessDeniedException(Right.CREATE_WIKI, currentUserRef, wiki); |
166 |
1 |
doThrow(exception).when(authorizationManager).checkAccess(eq(Right.CREATE_WIKI), eq(currentUserRef), eq(wiki)); |
167 |
|
|
168 |
1 |
return exception; |
169 |
|
} |
170 |
|
|
171 |
|
|
172 |
|
@param |
173 |
|
@return |
174 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
175 |
2 |
private DocumentReference getAndSetupDescriptorDocument(String wikiId)... |
176 |
|
{ |
177 |
2 |
DocumentReference descriptorDocument = |
178 |
|
new DocumentReference("mainWiki", "XWiki", "XWikiServer" + StringUtils.capitalize(wikiId)); |
179 |
2 |
when(wikiDescriptorDocumentHelper.getDocumentReferenceFromId(wikiId)).thenReturn(descriptorDocument); |
180 |
|
|
181 |
2 |
return descriptorDocument; |
182 |
|
} |
183 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
184 |
1 |
@Test... |
185 |
|
public void get() throws Exception |
186 |
|
{ |
187 |
|
|
188 |
1 |
mocker.getComponentUnderTest().get("template"); |
189 |
|
|
190 |
1 |
verify(scriptServiceManager).get("wiki.template"); |
191 |
|
} |
192 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
193 |
1 |
@Test... |
194 |
|
public void createWiki() throws Exception |
195 |
|
{ |
196 |
1 |
WikiDescriptor descriptor = new WikiDescriptor("newiki", "alias"); |
197 |
1 |
when(wikiManager.create("newwiki", "alias", true)).thenReturn(descriptor); |
198 |
|
|
199 |
1 |
WikiDescriptor result = mocker.getComponentUnderTest().createWiki("newwiki", "alias", "userA", true); |
200 |
1 |
assertEquals(descriptor, result); |
201 |
1 |
assertEquals("userA", result.getOwnerId()); |
202 |
1 |
verify(wikiDescriptorManager).saveDescriptor(result); |
203 |
|
} |
204 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
205 |
1 |
@Test... |
206 |
|
public void createWikiWithoutPR() throws Exception |
207 |
|
{ |
208 |
1 |
Exception exception = currentScriptHasNotProgrammingRight(); |
209 |
|
|
210 |
1 |
WikiDescriptor result = mocker.getComponentUnderTest().createWiki("newwiki", "alias", "userA", true); |
211 |
1 |
assertNull(result); |
212 |
1 |
assertEquals(exception, mocker.getComponentUnderTest().getLastError()); |
213 |
|
} |
214 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
215 |
1 |
@Test... |
216 |
|
public void createWikiWithoutCreateWikiRight() throws Exception |
217 |
|
{ |
218 |
1 |
Exception exception = currentUserHasNotCreateWikiRight(); |
219 |
|
|
220 |
1 |
WikiDescriptor result = mocker.getComponentUnderTest().createWiki("newwiki", "alias", "userA", true); |
221 |
1 |
assertNull(result); |
222 |
1 |
assertEquals(exception, mocker.getComponentUnderTest().getLastError()); |
223 |
|
} |
224 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
225 |
1 |
@Test... |
226 |
|
public void createWikiNoFailOnExistWithoutPR() throws Exception |
227 |
|
{ |
228 |
1 |
Exception exception = currentUserHasNotProgrammingRight(); |
229 |
|
|
230 |
1 |
WikiDescriptor result = mocker.getComponentUnderTest().createWiki("newwiki", "alias", "userA", false); |
231 |
1 |
assertNull(result); |
232 |
1 |
assertEquals(exception, mocker.getComponentUnderTest().getLastError()); |
233 |
|
} |
234 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
235 |
1 |
@Test... |
236 |
|
public void createWikiError() throws Exception |
237 |
|
{ |
238 |
1 |
Exception exception = new WikiManagerException("error on create"); |
239 |
1 |
when(wikiManager.create("newwiki", "alias", true)).thenThrow(exception); |
240 |
1 |
WikiDescriptor result = mocker.getComponentUnderTest().createWiki("newwiki", "alias", "userA", true); |
241 |
1 |
assertNull(result); |
242 |
1 |
assertEquals(exception, mocker.getComponentUnderTest().getLastError()); |
243 |
|
} |
244 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
245 |
1 |
@Test... |
246 |
|
public void getByAlias() throws Exception |
247 |
|
{ |
248 |
1 |
WikiDescriptor descriptor = new WikiDescriptor("wikiId", "wikiAlias"); |
249 |
1 |
when(wikiDescriptorManager.getByAlias("wikiAlias")).thenReturn(descriptor); |
250 |
|
|
251 |
1 |
WikiDescriptor result = mocker.getComponentUnderTest().getByAlias("wikiAlias"); |
252 |
1 |
assertEquals(descriptor, result); |
253 |
|
} |
254 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
255 |
1 |
@Test... |
256 |
|
public void getByAliasError() throws Exception |
257 |
|
{ |
258 |
1 |
Exception exception = new WikiManagerException("error in getByAlias"); |
259 |
1 |
when(wikiDescriptorManager.getByAlias("wikiAlias")).thenThrow(exception); |
260 |
|
|
261 |
1 |
WikiDescriptor result = mocker.getComponentUnderTest().getByAlias("wikiAlias"); |
262 |
1 |
assertNull(result); |
263 |
1 |
assertEquals(exception, mocker.getComponentUnderTest().getLastError()); |
264 |
|
} |
265 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
266 |
1 |
@Test... |
267 |
|
public void getById() throws Exception |
268 |
|
{ |
269 |
1 |
WikiDescriptor descriptor = new WikiDescriptor("wikiId", "wikiAlias"); |
270 |
1 |
when(wikiDescriptorManager.getById("wikiId")).thenReturn(descriptor); |
271 |
|
|
272 |
1 |
WikiDescriptor result = mocker.getComponentUnderTest().getById("wikiId"); |
273 |
1 |
assertEquals(descriptor, result); |
274 |
|
} |
275 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
276 |
1 |
@Test... |
277 |
|
public void getByIdError() throws Exception |
278 |
|
{ |
279 |
1 |
Exception exception = new WikiManagerException("error in getById"); |
280 |
1 |
when(wikiDescriptorManager.getById("wikiId")).thenThrow(exception); |
281 |
|
|
282 |
1 |
WikiDescriptor result = mocker.getComponentUnderTest().getById("wikiId"); |
283 |
1 |
assertNull(result); |
284 |
1 |
assertEquals(exception, mocker.getComponentUnderTest().getLastError()); |
285 |
|
} |
286 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
287 |
1 |
@Test... |
288 |
|
public void getAll() throws Exception |
289 |
|
{ |
290 |
1 |
WikiDescriptor descriptor1 = new WikiDescriptor("wikiId1", "wikiAlias1"); |
291 |
1 |
WikiDescriptor descriptor2 = new WikiDescriptor("wikiId2", "wikiAlias2"); |
292 |
1 |
Collection<WikiDescriptor> descriptors = new ArrayList<WikiDescriptor>(); |
293 |
1 |
descriptors.add(descriptor1); |
294 |
1 |
descriptors.add(descriptor2); |
295 |
1 |
when(wikiDescriptorManager.getAll()).thenReturn(descriptors); |
296 |
|
|
297 |
1 |
Collection<WikiDescriptor> result = mocker.getComponentUnderTest().getAll(); |
298 |
1 |
assertEquals(descriptors, result); |
299 |
|
} |
300 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
301 |
1 |
@Test... |
302 |
|
public void getAllIds() throws Exception |
303 |
|
{ |
304 |
1 |
Collection<String> wikiIds = Arrays.asList("wikiId1", "wikiId2"); |
305 |
1 |
when(wikiDescriptorManager.getAllIds()).thenReturn(wikiIds); |
306 |
|
|
307 |
1 |
Collection<String> result = mocker.getComponentUnderTest().getAllIds(); |
308 |
1 |
assertEquals(wikiIds, result); |
309 |
|
} |
310 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
311 |
1 |
@Test... |
312 |
|
public void getAllError() throws Exception |
313 |
|
{ |
314 |
1 |
Exception exception = new WikiManagerException("error in getAll"); |
315 |
1 |
when(wikiDescriptorManager.getAll()).thenThrow(exception); |
316 |
|
|
317 |
1 |
Collection<WikiDescriptor> result = mocker.getComponentUnderTest().getAll(); |
318 |
1 |
assertTrue(result.isEmpty()); |
319 |
1 |
assertEquals(exception, mocker.getComponentUnderTest().getLastError()); |
320 |
|
} |
321 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
322 |
1 |
@Test... |
323 |
|
public void getAllIdsError() throws Exception |
324 |
|
{ |
325 |
1 |
Exception exception = new WikiManagerException("error in getAllIds"); |
326 |
1 |
when(wikiDescriptorManager.getAllIds()).thenThrow(exception); |
327 |
|
|
328 |
1 |
Collection<String> result = mocker.getComponentUnderTest().getAllIds(); |
329 |
1 |
assertTrue(result.isEmpty()); |
330 |
1 |
assertEquals(exception, mocker.getComponentUnderTest().getLastError()); |
331 |
|
} |
332 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
333 |
1 |
@Test... |
334 |
|
public void exists() throws Exception |
335 |
|
{ |
336 |
1 |
when(wikiDescriptorManager.exists("wikiId")).thenReturn(true); |
337 |
1 |
when(wikiDescriptorManager.exists("no")).thenReturn(false); |
338 |
|
|
339 |
1 |
assertTrue(mocker.getComponentUnderTest().exists("wikiId")); |
340 |
1 |
assertFalse(mocker.getComponentUnderTest().exists("no")); |
341 |
|
} |
342 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
343 |
1 |
@Test... |
344 |
|
public void existsError() throws Exception |
345 |
|
{ |
346 |
1 |
Exception exception = new WikiManagerException("error in exists"); |
347 |
1 |
when(wikiDescriptorManager.exists("wikiId")).thenThrow(exception); |
348 |
|
|
349 |
1 |
Boolean result = mocker.getComponentUnderTest().exists("wikiId"); |
350 |
1 |
assertNull(result); |
351 |
1 |
assertEquals(exception, mocker.getComponentUnderTest().getLastError()); |
352 |
|
} |
353 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
354 |
1 |
@Test... |
355 |
|
public void idAvailable() throws Exception |
356 |
|
{ |
357 |
1 |
when(wikiManager.idAvailable("wikiId")).thenReturn(true); |
358 |
1 |
when(wikiManager.idAvailable("no")).thenReturn(false); |
359 |
|
|
360 |
1 |
assertTrue(mocker.getComponentUnderTest().idAvailable("wikiId")); |
361 |
1 |
assertFalse(mocker.getComponentUnderTest().idAvailable("no")); |
362 |
|
} |
363 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
364 |
1 |
@Test... |
365 |
|
public void idAvailableError() throws Exception |
366 |
|
{ |
367 |
1 |
Exception exception = new WikiManagerException("error in idAvailable"); |
368 |
1 |
when(wikiManager.idAvailable("wikiId")).thenThrow(exception); |
369 |
|
|
370 |
1 |
Boolean result = mocker.getComponentUnderTest().idAvailable("wikiId"); |
371 |
1 |
assertNull(result); |
372 |
1 |
assertEquals(exception, mocker.getComponentUnderTest().getLastError()); |
373 |
1 |
assertEquals(exception, mocker.getComponentUnderTest().getLastException()); |
374 |
|
} |
375 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
376 |
1 |
@Test... |
377 |
|
public void getMainWikiDescriptor() throws Exception |
378 |
|
{ |
379 |
1 |
WikiDescriptor descriptor = new WikiDescriptor("mainWiki", "wikiAlias"); |
380 |
1 |
when(wikiDescriptorManager.getMainWikiDescriptor()).thenReturn(descriptor); |
381 |
|
|
382 |
1 |
WikiDescriptor result = mocker.getComponentUnderTest().getMainWikiDescriptor(); |
383 |
1 |
assertEquals(descriptor, result); |
384 |
|
} |
385 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
386 |
1 |
@Test... |
387 |
|
public void getMainWikiDescriptorError() throws Exception |
388 |
|
{ |
389 |
1 |
Exception exception = new WikiManagerException("error in getMainWikiDescriptor"); |
390 |
1 |
when(wikiDescriptorManager.getMainWikiDescriptor()).thenThrow(exception); |
391 |
|
|
392 |
1 |
WikiDescriptor result = mocker.getComponentUnderTest().getMainWikiDescriptor(); |
393 |
1 |
assertNull(result); |
394 |
1 |
assertEquals(exception, mocker.getComponentUnderTest().getLastError()); |
395 |
|
} |
396 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
397 |
1 |
@Test... |
398 |
|
public void getMainWikiId() throws Exception |
399 |
|
{ |
400 |
1 |
String result = mocker.getComponentUnderTest().getMainWikiId(); |
401 |
1 |
assertEquals("mainWiki", result); |
402 |
|
} |
403 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
404 |
1 |
@Test... |
405 |
|
public void getCurrentWikiId() throws Exception |
406 |
|
{ |
407 |
1 |
when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("currentWiki"); |
408 |
1 |
String result = mocker.getComponentUnderTest().getCurrentWikiId(); |
409 |
1 |
assertEquals("currentWiki", result); |
410 |
|
} |
411 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
412 |
1 |
@Test... |
413 |
|
public void saveDescriptorWhenICanEditDescriptorDocument() throws Exception |
414 |
|
{ |
415 |
1 |
WikiDescriptor oldDescriptor = new WikiDescriptor("wikiId", "wikiAlias"); |
416 |
1 |
oldDescriptor.setOwnerId("SomeUser"); |
417 |
1 |
when(wikiDescriptorManager.getById(oldDescriptor.getId())).thenReturn(oldDescriptor); |
418 |
|
|
419 |
1 |
DocumentReference wikiDescriptorDocRef = getAndSetupDescriptorDocument(oldDescriptor.getId()); |
420 |
1 |
when(this.authorizationManager.hasAccess(Right.EDIT, currentUserRef, wikiDescriptorDocRef)).thenReturn(true); |
421 |
|
|
422 |
|
|
423 |
1 |
WikiDescriptor descriptor = new WikiDescriptor(oldDescriptor.getId(), "wikiAlias"); |
424 |
1 |
descriptor.setOwnerId(oldDescriptor.getOwnerId()); |
425 |
1 |
boolean result = mocker.getComponentUnderTest().saveDescriptor(descriptor); |
426 |
1 |
assertTrue(result); |
427 |
|
|
428 |
|
|
429 |
1 |
verify(wikiDescriptorManager).saveDescriptor(descriptor); |
430 |
|
} |
431 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
432 |
1 |
@Test... |
433 |
|
public void saveDescriptorWhenIAmOwner() throws Exception |
434 |
|
{ |
435 |
1 |
WikiDescriptor oldDescriptor = mock(WikiDescriptor.class); |
436 |
1 |
when(oldDescriptor.getId()).thenReturn("wikiId"); |
437 |
1 |
when(oldDescriptor.getOwnerId()).thenReturn("mainWiki:XWiki.User"); |
438 |
1 |
when(wikiDescriptorManager.getById(oldDescriptor.getId())).thenReturn(oldDescriptor); |
439 |
|
|
440 |
|
|
441 |
1 |
WikiDescriptor descriptor = new WikiDescriptor(oldDescriptor.getId(), "wikiAlias"); |
442 |
1 |
descriptor.setOwnerId(oldDescriptor.getOwnerId()); |
443 |
1 |
boolean result = mocker.getComponentUnderTest().saveDescriptor(descriptor); |
444 |
1 |
assertTrue(result); |
445 |
|
|
446 |
|
|
447 |
1 |
verify(oldDescriptor, times(2)).getOwnerId(); |
448 |
|
|
449 |
|
|
450 |
1 |
verify(wikiDescriptorManager).saveDescriptor(descriptor); |
451 |
|
} |
452 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
453 |
1 |
@Test... |
454 |
|
public void saveDescriptorWhenIAmLocalAdmin() throws Exception |
455 |
|
{ |
456 |
1 |
WikiDescriptor oldDescriptor = new WikiDescriptor("wikiId", "wikiAlias"); |
457 |
1 |
oldDescriptor.setOwnerId("SomeUser"); |
458 |
1 |
when(wikiDescriptorManager.getById(oldDescriptor.getId())).thenReturn(oldDescriptor); |
459 |
|
|
460 |
|
|
461 |
1 |
when(authorizationManager.hasAccess(eq(Right.ADMIN), eq(currentUserRef), eq(new WikiReference("wikiId")))) |
462 |
|
.thenReturn(true); |
463 |
|
|
464 |
|
|
465 |
1 |
WikiDescriptor descriptor = new WikiDescriptor(oldDescriptor.getId(), "wikiAlias"); |
466 |
1 |
descriptor.setOwnerId(oldDescriptor.getOwnerId()); |
467 |
1 |
boolean result = mocker.getComponentUnderTest().saveDescriptor(descriptor); |
468 |
1 |
assertTrue(result); |
469 |
|
|
470 |
|
|
471 |
1 |
verify(authorizationManager).hasAccess(eq(Right.ADMIN), eq(currentUserRef), eq(new WikiReference("wikiId"))); |
472 |
|
|
473 |
1 |
verify(wikiDescriptorManager).saveDescriptor(descriptor); |
474 |
|
} |
475 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
476 |
1 |
@Test... |
477 |
|
public void saveDescriptorWhenIAmNotOwnerNorLocalAdminNorGlobalAdmin() throws Exception |
478 |
|
{ |
479 |
1 |
WikiDescriptor oldDescriptor = new WikiDescriptor("wikiId", "wikiAlias"); |
480 |
1 |
oldDescriptor.setOwnerId("SomeUser"); |
481 |
1 |
when(wikiDescriptorManager.getById(oldDescriptor.getId())).thenReturn(oldDescriptor); |
482 |
|
|
483 |
1 |
when(authorizationManager.hasAccess(eq(Right.ADMIN), eq(currentUserRef), eq(new WikiReference("wikiId")))) |
484 |
|
.thenReturn(false); |
485 |
|
|
486 |
|
|
487 |
1 |
WikiDescriptor descriptor = new WikiDescriptor(oldDescriptor.getId(), "wikiAlias"); |
488 |
1 |
oldDescriptor.setOwnerId(oldDescriptor.getOwnerId()); |
489 |
1 |
boolean result = mocker.getComponentUnderTest().saveDescriptor(descriptor); |
490 |
1 |
assertFalse(result); |
491 |
|
|
492 |
|
|
493 |
1 |
verify(wikiDescriptorManager, never()).saveDescriptor(descriptor); |
494 |
|
|
495 |
1 |
Exception exception = new AccessDeniedException(currentUserRef, new WikiReference("wikiId")); |
496 |
1 |
assertEquals(exception.getMessage(), mocker.getComponentUnderTest().getLastError().getMessage()); |
497 |
1 |
assertEquals(exception.getClass(), mocker.getComponentUnderTest().getLastError().getClass()); |
498 |
|
} |
499 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
500 |
1 |
@Test... |
501 |
|
public void saveDescriptorWhenIAmLocalAdminAndChangeOwner() throws Exception |
502 |
|
{ |
503 |
1 |
WikiDescriptor oldDescriptor = new WikiDescriptor("wikiId", "wikiAlias"); |
504 |
1 |
oldDescriptor.setOwnerId("SomeUser"); |
505 |
1 |
when(wikiDescriptorManager.getById(oldDescriptor.getId())).thenReturn(oldDescriptor); |
506 |
|
|
507 |
|
|
508 |
1 |
WikiDescriptor descriptor = new WikiDescriptor(oldDescriptor.getId(), "wikiAlias"); |
509 |
1 |
descriptor.setOwnerId("SomeOtherUserOrMyself"); |
510 |
1 |
boolean result = mocker.getComponentUnderTest().saveDescriptor(descriptor); |
511 |
1 |
assertFalse(result); |
512 |
|
|
513 |
|
|
514 |
1 |
verify(authorizationManager).hasAccess(eq(Right.ADMIN), eq(currentUserRef), eq(new WikiReference("wikiId"))); |
515 |
|
|
516 |
|
|
517 |
1 |
verify(wikiDescriptorManager, never()).saveDescriptor(descriptor); |
518 |
|
|
519 |
1 |
Exception expectedException = new AccessDeniedException(currentUserRef, new WikiReference("wikiId")); |
520 |
1 |
assertEquals(expectedException.getMessage(), mocker.getComponentUnderTest().getLastError().getMessage()); |
521 |
1 |
assertEquals(expectedException.getClass(), mocker.getComponentUnderTest().getLastError().getClass()); |
522 |
|
} |
523 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
524 |
1 |
@Test... |
525 |
|
public void saveDescriptorWhenICanEditDescriptorDocumentAndChangeOwner() throws Exception |
526 |
|
{ |
527 |
1 |
WikiDescriptor oldDescriptor = new WikiDescriptor("wikiId", "wikiAlias"); |
528 |
1 |
oldDescriptor.setOwnerId("SomeUser"); |
529 |
1 |
when(wikiDescriptorManager.getById(oldDescriptor.getId())).thenReturn(oldDescriptor); |
530 |
|
|
531 |
1 |
DocumentReference wikiDescriptorDocRef = getAndSetupDescriptorDocument(oldDescriptor.getId()); |
532 |
1 |
when(this.authorizationManager.hasAccess(Right.EDIT, currentUserRef, wikiDescriptorDocRef)).thenReturn(true); |
533 |
|
|
534 |
|
|
535 |
1 |
WikiDescriptor descriptor = new WikiDescriptor(oldDescriptor.getId(), "wikiAlias"); |
536 |
1 |
descriptor.setOwnerId("SomeOtherUserOrMyself"); |
537 |
1 |
boolean result = mocker.getComponentUnderTest().saveDescriptor(descriptor); |
538 |
1 |
assertTrue(result); |
539 |
|
|
540 |
|
|
541 |
1 |
verify(wikiDescriptorManager).saveDescriptor(descriptor); |
542 |
|
} |
543 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
544 |
1 |
@Test... |
545 |
|
public void saveDescriptorWhenDescriptorDidNotExist() throws Exception |
546 |
|
{ |
547 |
1 |
WikiDescriptor descriptor = new WikiDescriptor("wikiId", "wikiAlias"); |
548 |
1 |
boolean result = mocker.getComponentUnderTest().saveDescriptor(descriptor); |
549 |
1 |
assertFalse(result); |
550 |
|
|
551 |
|
|
552 |
1 |
verify(authorizationManager).hasAccess(eq(Right.ADMIN), eq(currentUserRef), eq(new WikiReference("mainWiki"))); |
553 |
|
|
554 |
|
|
555 |
1 |
verify(wikiDescriptorManager, never()).saveDescriptor(descriptor); |
556 |
|
} |
557 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
558 |
1 |
@Test... |
559 |
|
public void saveDescriptorWhenDescriptorDidNotExistAndIAmGlobalAdmin() throws Exception |
560 |
|
{ |
561 |
1 |
when(this.authorizationManager.hasAccess(Right.ADMIN, currentUserRef, new WikiReference("mainWiki"))) |
562 |
|
.thenReturn(true); |
563 |
|
|
564 |
1 |
WikiDescriptor descriptor = new WikiDescriptor("wikiId", "wikiAlias"); |
565 |
1 |
boolean result = mocker.getComponentUnderTest().saveDescriptor(descriptor); |
566 |
1 |
assertTrue(result); |
567 |
|
|
568 |
|
|
569 |
1 |
verify(authorizationManager).hasAccess(eq(Right.ADMIN), eq(currentUserRef), eq(new WikiReference("mainWiki"))); |
570 |
|
|
571 |
|
|
572 |
1 |
verify(wikiDescriptorManager).saveDescriptor(descriptor); |
573 |
|
} |
574 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
575 |
1 |
@Test... |
576 |
|
public void isPathMode() throws Exception |
577 |
|
{ |
578 |
1 |
when(standardURLConfiguration.isPathBasedMultiWiki()).thenReturn(true); |
579 |
1 |
assertTrue(mocker.getComponentUnderTest().isPathMode()); |
580 |
|
|
581 |
1 |
when(standardURLConfiguration.isPathBasedMultiWiki()).thenReturn(false); |
582 |
1 |
assertFalse(mocker.getComponentUnderTest().isPathMode()); |
583 |
|
} |
584 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
585 |
1 |
@Test... |
586 |
|
public void getAliasSuffix() throws Exception |
587 |
|
{ |
588 |
1 |
when(wikiConfiguration.getAliasSuffix()).thenReturn("mysuffix.org"); |
589 |
1 |
assertEquals(mocker.getComponentUnderTest().getAliasSuffix(), "mysuffix.org"); |
590 |
|
} |
591 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
592 |
1 |
@Test... |
593 |
|
public void getCurrentDescriptor() throws Exception |
594 |
|
{ |
595 |
1 |
mocker.getComponentUnderTest().getCurrentWikiDescriptor(); |
596 |
|
|
597 |
1 |
verify(wikiDescriptorManager).getCurrentWikiDescriptor(); |
598 |
|
} |
599 |
|
} |