1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.wiki.user.script; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.Collection; |
24 |
|
|
25 |
|
import javax.inject.Provider; |
26 |
|
|
27 |
|
import org.junit.Before; |
28 |
|
import org.junit.Rule; |
29 |
|
import org.junit.Test; |
30 |
|
import org.xwiki.component.util.DefaultParameterizedType; |
31 |
|
import org.xwiki.context.Execution; |
32 |
|
import org.xwiki.context.ExecutionContext; |
33 |
|
import org.xwiki.model.reference.DocumentReference; |
34 |
|
import org.xwiki.model.reference.DocumentReferenceResolver; |
35 |
|
import org.xwiki.model.reference.WikiReference; |
36 |
|
import org.xwiki.security.authorization.AccessDeniedException; |
37 |
|
import org.xwiki.security.authorization.AuthorizationManager; |
38 |
|
import org.xwiki.security.authorization.Right; |
39 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
40 |
|
import org.xwiki.wiki.descriptor.WikiDescriptorManager; |
41 |
|
import org.xwiki.wiki.user.MemberCandidacy; |
42 |
|
import org.xwiki.wiki.user.MembershipType; |
43 |
|
import org.xwiki.wiki.user.UserScope; |
44 |
|
import org.xwiki.wiki.user.WikiUserManager; |
45 |
|
import org.xwiki.wiki.user.WikiUserManagerException; |
46 |
|
|
47 |
|
import com.xpn.xwiki.XWikiContext; |
48 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
49 |
|
|
50 |
|
import static org.junit.Assert.assertEquals; |
51 |
|
import static org.junit.Assert.assertFalse; |
52 |
|
import static org.junit.Assert.assertNotNull; |
53 |
|
import static org.junit.Assert.assertNull; |
54 |
|
import static org.junit.Assert.assertTrue; |
55 |
|
import static org.mockito.ArgumentMatchers.any; |
56 |
|
import static org.mockito.ArgumentMatchers.eq; |
57 |
|
import static org.mockito.Mockito.doThrow; |
58 |
|
import static org.mockito.Mockito.mock; |
59 |
|
import static org.mockito.Mockito.verify; |
60 |
|
import static org.mockito.Mockito.verifyZeroInteractions; |
61 |
|
import static org.mockito.Mockito.when; |
62 |
|
|
63 |
|
|
64 |
|
@link |
65 |
|
|
66 |
|
@version |
67 |
|
@since |
68 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (472) |
Complexity: 71 |
Complexity Density: 0.18 |
|
69 |
|
public class WikiUserManagerScriptServiceTest |
70 |
|
{ |
71 |
|
@Rule |
72 |
|
public MockitoComponentMockingRule<WikiUserManagerScriptService> mocker = |
73 |
|
new MockitoComponentMockingRule(WikiUserManagerScriptService.class); |
74 |
|
|
75 |
|
private WikiUserManager wikiUserManager; |
76 |
|
|
77 |
|
private WikiDescriptorManager wikiDescriptorManager; |
78 |
|
|
79 |
|
private AuthorizationManager authorizationManager; |
80 |
|
|
81 |
|
private Provider<XWikiContext> xcontextProvider; |
82 |
|
|
83 |
|
private DocumentReferenceResolver<String> documentReferenceResolver; |
84 |
|
|
85 |
|
private Execution execution; |
86 |
|
|
87 |
|
private ExecutionContext executionContext; |
88 |
|
|
89 |
|
private XWikiContext xcontext; |
90 |
|
|
91 |
|
private XWikiDocument currentDoc; |
92 |
|
|
93 |
|
private DocumentReference userDocRef; |
94 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 1 |
Complexity Density: 0.05 |
|
95 |
68 |
@Before... |
96 |
|
public void setUp() throws Exception |
97 |
|
{ |
98 |
|
|
99 |
68 |
wikiUserManager = mocker.getInstance(WikiUserManager.class); |
100 |
68 |
wikiDescriptorManager = mocker.getInstance(WikiDescriptorManager.class); |
101 |
68 |
authorizationManager = mocker.getInstance(AuthorizationManager.class); |
102 |
68 |
xcontextProvider = mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER); |
103 |
68 |
documentReferenceResolver = mocker.getInstance(new DefaultParameterizedType(null, |
104 |
|
DocumentReferenceResolver.class, String.class)); |
105 |
68 |
execution = mocker.getInstance(Execution.class); |
106 |
|
|
107 |
|
|
108 |
68 |
xcontext = mock(XWikiContext.class); |
109 |
68 |
when(xcontextProvider.get()).thenReturn(xcontext); |
110 |
68 |
when(wikiDescriptorManager.getMainWikiId()).thenReturn("mainWiki"); |
111 |
68 |
when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("subwiki"); |
112 |
|
|
113 |
68 |
executionContext = new ExecutionContext(); |
114 |
68 |
when(execution.getContext()).thenReturn(executionContext); |
115 |
|
|
116 |
68 |
currentDoc = mock(XWikiDocument.class); |
117 |
68 |
when(xcontext.getDoc()).thenReturn(currentDoc); |
118 |
|
|
119 |
68 |
userDocRef = new DocumentReference("mainWiki", "XWiki", "User"); |
120 |
68 |
when(xcontext.getUserReference()).thenReturn(userDocRef); |
121 |
|
|
122 |
68 |
DocumentReference userReference = new DocumentReference("mainWiki", "XWiki", "User"); |
123 |
68 |
when(documentReferenceResolver.resolve("mainWiki:XWiki.User")).thenReturn(userReference); |
124 |
68 |
DocumentReference otherUser = new DocumentReference("mainWiki", "XWiki", "OtherUser"); |
125 |
68 |
when(documentReferenceResolver.resolve("mainWiki:XWiki.OtherUser")).thenReturn(otherUser); |
126 |
|
} |
127 |
|
|
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
@return |
132 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
133 |
8 |
private Exception currentScriptHasNotAdminRight() throws AccessDeniedException... |
134 |
|
{ |
135 |
8 |
DocumentReference authorDocRef = new DocumentReference("mainWiki", "XWiki", "NonAdmin"); |
136 |
8 |
when(currentDoc.getAuthorReference()).thenReturn(authorDocRef); |
137 |
|
|
138 |
8 |
DocumentReference currentDocRef = new DocumentReference("subwiki", "Space", "PageToTest"); |
139 |
8 |
when(currentDoc.getDocumentReference()).thenReturn(currentDocRef); |
140 |
|
|
141 |
8 |
Exception exception = new AccessDeniedException(Right.ADMIN, authorDocRef, currentDocRef); |
142 |
8 |
doThrow(exception).when(authorizationManager).checkAccess(Right.ADMIN, authorDocRef, currentDocRef); |
143 |
|
|
144 |
8 |
return exception; |
145 |
|
} |
146 |
|
|
147 |
|
|
148 |
|
|
149 |
|
|
150 |
|
@return |
151 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
152 |
18 |
private Exception currentUserHasNotAdminRight() throws AccessDeniedException... |
153 |
|
{ |
154 |
18 |
WikiReference wiki = new WikiReference("subwiki"); |
155 |
18 |
Exception exception = new AccessDeniedException(Right.ADMIN, userDocRef, wiki); |
156 |
|
|
157 |
18 |
doThrow(exception).when(authorizationManager).checkAccess(eq(Right.ADMIN), eq(userDocRef), eq(wiki)); |
158 |
|
|
159 |
18 |
return exception; |
160 |
|
} |
161 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
162 |
1 |
@Test... |
163 |
|
public void getUserScope() throws Exception |
164 |
|
{ |
165 |
1 |
when(wikiUserManager.getUserScope("subwiki")).thenReturn(UserScope.GLOBAL_ONLY); |
166 |
1 |
UserScope result = mocker.getComponentUnderTest().getUserScope(); |
167 |
1 |
assertEquals(UserScope.GLOBAL_ONLY, result); |
168 |
|
} |
169 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
170 |
1 |
@Test... |
171 |
|
public void getUserScopeWithError() throws Exception |
172 |
|
{ |
173 |
|
|
174 |
1 |
Exception expectedException = new WikiUserManagerException("Error in getUserScope"); |
175 |
1 |
when(wikiUserManager.getUserScope("test")).thenThrow(expectedException); |
176 |
|
|
177 |
|
|
178 |
1 |
UserScope result = mocker.getComponentUnderTest().getUserScope("test"); |
179 |
|
|
180 |
|
|
181 |
1 |
assertNull(result); |
182 |
1 |
assertEquals(expectedException, mocker.getComponentUnderTest().getLastError()); |
183 |
|
} |
184 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
185 |
1 |
@Test... |
186 |
|
public void setUserScope() throws Exception |
187 |
|
{ |
188 |
|
|
189 |
1 |
boolean result = mocker.getComponentUnderTest().setUserScope("subwiki", "LOCAL_ONLY"); |
190 |
|
|
191 |
|
|
192 |
1 |
assertEquals(true, result); |
193 |
1 |
verify(wikiUserManager).setUserScope(eq("subwiki"), eq(UserScope.LOCAL_ONLY)); |
194 |
|
} |
195 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
196 |
1 |
@Test... |
197 |
|
public void setUserScopeWhenScriptHasNoRight() throws Exception |
198 |
|
{ |
199 |
|
|
200 |
1 |
Exception expectedException = currentScriptHasNotAdminRight(); |
201 |
|
|
202 |
|
|
203 |
1 |
boolean result = mocker.getComponentUnderTest().setUserScope("subwiki", "LOCAL_ONLY"); |
204 |
|
|
205 |
|
|
206 |
1 |
assertFalse(result); |
207 |
1 |
assertEquals(expectedException, mocker.getComponentUnderTest().getLastError()); |
208 |
1 |
verifyZeroInteractions(wikiUserManager); |
209 |
|
} |
210 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
211 |
1 |
@Test... |
212 |
|
public void setUserScopeWhenUserHasNoRight() throws Exception |
213 |
|
{ |
214 |
|
|
215 |
1 |
Exception expectedException = currentUserHasNotAdminRight(); |
216 |
|
|
217 |
|
|
218 |
1 |
boolean result = mocker.getComponentUnderTest().setUserScope("subwiki", "LOCAL_ONLY"); |
219 |
|
|
220 |
|
|
221 |
1 |
assertFalse(result); |
222 |
1 |
assertEquals(expectedException, mocker.getComponentUnderTest().getLastError()); |
223 |
1 |
verifyZeroInteractions(wikiUserManager); |
224 |
|
} |
225 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
226 |
1 |
@Test... |
227 |
|
public void setUserScopeWhenWrongValue() throws Exception |
228 |
|
{ |
229 |
|
|
230 |
1 |
boolean result = mocker.getComponentUnderTest().setUserScope("subwiki", "wrong value"); |
231 |
|
|
232 |
|
|
233 |
1 |
assertFalse(result); |
234 |
1 |
assertTrue(mocker.getComponentUnderTest().getLastError() instanceof IllegalArgumentException); |
235 |
1 |
verifyZeroInteractions(wikiUserManager); |
236 |
|
} |
237 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
238 |
1 |
@Test... |
239 |
|
public void setUserScopeError() throws Exception |
240 |
|
{ |
241 |
|
|
242 |
1 |
WikiUserManagerException expectedException = new WikiUserManagerException("error in setUserScope"); |
243 |
1 |
doThrow(expectedException).when(wikiUserManager).setUserScope(any(), any(UserScope.class)); |
244 |
|
|
245 |
|
|
246 |
1 |
boolean result = mocker.getComponentUnderTest().setUserScope("subwiki", "LOCAL_ONLY"); |
247 |
|
|
248 |
|
|
249 |
1 |
assertFalse(result); |
250 |
1 |
assertEquals(expectedException, mocker.getComponentUnderTest().getLastError()); |
251 |
|
} |
252 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
253 |
1 |
@Test... |
254 |
|
public void getMembershipType() throws Exception |
255 |
|
{ |
256 |
|
|
257 |
1 |
when(wikiUserManager.getMembershipType("subwiki")).thenReturn(MembershipType.INVITE); |
258 |
|
|
259 |
|
|
260 |
1 |
MembershipType result = mocker.getComponentUnderTest().getMembershipType(); |
261 |
|
|
262 |
|
|
263 |
1 |
assertEquals(MembershipType.INVITE, result); |
264 |
|
} |
265 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
266 |
1 |
@Test... |
267 |
|
public void getMembershipTypeWithError() throws Exception |
268 |
|
{ |
269 |
|
|
270 |
1 |
Exception expectedException = new WikiUserManagerException("Error in getMembershipType"); |
271 |
1 |
when(wikiUserManager.getMembershipType("test")).thenThrow(expectedException); |
272 |
|
|
273 |
|
|
274 |
1 |
MembershipType result = mocker.getComponentUnderTest().getMembershipType("test"); |
275 |
|
|
276 |
|
|
277 |
1 |
assertNull(result); |
278 |
1 |
assertEquals(expectedException, mocker.getComponentUnderTest().getLastError()); |
279 |
|
} |
280 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
281 |
1 |
@Test... |
282 |
|
public void setMembershipType() throws Exception |
283 |
|
{ |
284 |
|
|
285 |
1 |
boolean result = mocker.getComponentUnderTest().setUserScope("subwiki", "LOCAL_ONLY"); |
286 |
|
|
287 |
|
|
288 |
1 |
assertTrue(result); |
289 |
|
} |
290 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
291 |
1 |
@Test... |
292 |
|
public void setMembershipTypeWhenScriptHasNoRight() throws Exception |
293 |
|
{ |
294 |
|
|
295 |
1 |
Exception expectedException = currentScriptHasNotAdminRight(); |
296 |
|
|
297 |
|
|
298 |
1 |
boolean result = mocker.getComponentUnderTest().setMembershipType("subwiki", "INVITE"); |
299 |
|
|
300 |
|
|
301 |
1 |
assertFalse(result); |
302 |
1 |
assertEquals(expectedException, mocker.getComponentUnderTest().getLastError()); |
303 |
1 |
verifyZeroInteractions(wikiUserManager); |
304 |
|
} |
305 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
306 |
1 |
@Test... |
307 |
|
public void setMembershipTypeWhenUserHasNoRight() throws Exception |
308 |
|
{ |
309 |
|
|
310 |
1 |
Exception expectedExtension = currentUserHasNotAdminRight(); |
311 |
|
|
312 |
|
|
313 |
1 |
boolean result = mocker.getComponentUnderTest().setMembershipType("subwiki", "INVITE"); |
314 |
|
|
315 |
|
|
316 |
1 |
assertFalse(result); |
317 |
1 |
assertEquals(expectedExtension, mocker.getComponentUnderTest().getLastError()); |
318 |
1 |
verifyZeroInteractions(wikiUserManager); |
319 |
|
} |
320 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
321 |
1 |
@Test... |
322 |
|
public void setMembershipTypeWrongValue() throws Exception |
323 |
|
{ |
324 |
|
|
325 |
1 |
boolean result = mocker.getComponentUnderTest().setMembershipType("subwiki", "wrong value"); |
326 |
|
|
327 |
|
|
328 |
1 |
assertEquals(false, result); |
329 |
1 |
assertTrue(mocker.getComponentUnderTest().getLastError() instanceof IllegalArgumentException); |
330 |
1 |
verifyZeroInteractions(wikiUserManager); |
331 |
|
} |
332 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
333 |
1 |
@Test... |
334 |
|
public void setMembershipTypeError() throws Exception |
335 |
|
{ |
336 |
|
|
337 |
1 |
WikiUserManagerException expectedException = new WikiUserManagerException("error in setMembershipType"); |
338 |
1 |
doThrow(expectedException).when(wikiUserManager).setMembershipType(any(), any(MembershipType.class)); |
339 |
|
|
340 |
|
|
341 |
1 |
boolean result = mocker.getComponentUnderTest().setMembershipType("subwiki", "INVITE"); |
342 |
|
|
343 |
|
|
344 |
1 |
assertEquals(false, result); |
345 |
1 |
assertEquals(expectedException, mocker.getComponentUnderTest().getLastError()); |
346 |
|
} |
347 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
348 |
1 |
@Test... |
349 |
|
public void getMembers() throws Exception |
350 |
|
{ |
351 |
|
|
352 |
1 |
Collection<String> members = new ArrayList<String>(); |
353 |
1 |
when(wikiUserManager.getMembers("subwiki")).thenReturn(members); |
354 |
|
|
355 |
|
|
356 |
1 |
Collection<String> result = mocker.getComponentUnderTest().getMembers("subwiki"); |
357 |
|
|
358 |
|
|
359 |
1 |
assertEquals(members, result); |
360 |
|
} |
361 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
362 |
1 |
@Test... |
363 |
|
public void getMembersError() throws Exception |
364 |
|
{ |
365 |
|
|
366 |
1 |
Exception expectedException = new WikiUserManagerException("error in getMembers"); |
367 |
1 |
when(wikiUserManager.getMembers("subwiki")).thenThrow(expectedException); |
368 |
|
|
369 |
|
|
370 |
1 |
Collection<String> result = mocker.getComponentUnderTest().getMembers("subwiki"); |
371 |
|
|
372 |
|
|
373 |
1 |
assertNull(result); |
374 |
1 |
assertEquals(expectedException, mocker.getComponentUnderTest().getLastError()); |
375 |
|
} |
376 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
377 |
1 |
@Test... |
378 |
|
public void isMember() throws Exception |
379 |
|
{ |
380 |
|
|
381 |
1 |
when(wikiUserManager.isMember("mainWiki:XWiki.User", "subwiki")).thenReturn(true); |
382 |
1 |
when(wikiUserManager.isMember("mainWiki:XWiki.User", "subwiki2")).thenReturn(false); |
383 |
|
|
384 |
|
|
385 |
1 |
boolean result1 = mocker.getComponentUnderTest().isMember("mainWiki:XWiki.User", "subwiki"); |
386 |
1 |
boolean result2 = mocker.getComponentUnderTest().isMember("mainWiki:XWiki.User", "subwiki2"); |
387 |
|
|
388 |
|
|
389 |
1 |
assertTrue(result1); |
390 |
1 |
assertFalse(result2); |
391 |
|
} |
392 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
393 |
1 |
@Test... |
394 |
|
public void isMemberError() throws Exception |
395 |
|
{ |
396 |
|
|
397 |
1 |
Exception expectedException = new WikiUserManagerException("error in isMember"); |
398 |
1 |
when(wikiUserManager.isMember("mainWiki:XWiki.User", "subwiki")).thenThrow(expectedException); |
399 |
|
|
400 |
|
|
401 |
1 |
Boolean result = mocker.getComponentUnderTest().isMember("mainWiki:XWiki.User", "subwiki"); |
402 |
|
|
403 |
|
|
404 |
1 |
assertNull(result); |
405 |
1 |
assertEquals(expectedException, mocker.getComponentUnderTest().getLastError()); |
406 |
|
} |
407 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
408 |
1 |
@Test... |
409 |
|
public void addMember() throws Exception |
410 |
|
{ |
411 |
|
|
412 |
1 |
boolean result = mocker.getComponentUnderTest().addMember("xwiki:XWiki.UserA", "subwiki"); |
413 |
|
|
414 |
|
|
415 |
1 |
assertTrue(result); |
416 |
1 |
verify(wikiUserManager).addMember("xwiki:XWiki.UserA", "subwiki"); |
417 |
|
} |
418 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
419 |
1 |
@Test... |
420 |
|
public void addMemberWhenScriptHasNoRight() throws Exception |
421 |
|
{ |
422 |
|
|
423 |
1 |
Exception expectedException = currentScriptHasNotAdminRight(); |
424 |
|
|
425 |
|
|
426 |
1 |
boolean result = mocker.getComponentUnderTest().addMember("xwiki:XWiki.UserA", "subwiki"); |
427 |
|
|
428 |
|
|
429 |
1 |
assertEquals(false, result); |
430 |
1 |
assertEquals(expectedException, mocker.getComponentUnderTest().getLastError()); |
431 |
1 |
verifyZeroInteractions(wikiUserManager); |
432 |
|
} |
433 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
434 |
1 |
@Test... |
435 |
|
public void addMemberWhenUserHasNoRight() throws Exception |
436 |
|
{ |
437 |
|
|
438 |
1 |
Exception expectedException = currentUserHasNotAdminRight(); |
439 |
|
|
440 |
|
|
441 |
1 |
boolean result = mocker.getComponentUnderTest().addMember("xwiki:XWiki.UserA", "subwiki"); |
442 |
|
|
443 |
|
|
444 |
1 |
assertFalse(result); |
445 |
1 |
assertEquals(expectedException, mocker.getComponentUnderTest().getLastError()); |
446 |
1 |
verifyZeroInteractions(wikiUserManager); |
447 |
|
} |
448 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
449 |
1 |
@Test... |
450 |
|
public void addMembers() throws Exception |
451 |
|
{ |
452 |
|
|
453 |
1 |
Collection<String> userIds = new ArrayList<String>(); |
454 |
1 |
boolean result = mocker.getComponentUnderTest().addMembers(userIds, "subwiki"); |
455 |
|
|
456 |
|
|
457 |
1 |
assertTrue(result); |
458 |
1 |
verify(wikiUserManager).addMembers(userIds, "subwiki"); |
459 |
|
} |
460 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
461 |
1 |
@Test... |
462 |
|
public void addMembersWhenScriptHasNoRight() throws Exception |
463 |
|
{ |
464 |
|
|
465 |
1 |
Exception expectedExtension = currentScriptHasNotAdminRight(); |
466 |
|
|
467 |
|
|
468 |
1 |
Collection<String> userIds = new ArrayList<String>(); |
469 |
1 |
boolean result = mocker.getComponentUnderTest().addMembers(userIds, "subwiki"); |
470 |
|
|
471 |
|
|
472 |
1 |
assertFalse(result); |
473 |
1 |
assertEquals(expectedExtension, mocker.getComponentUnderTest().getLastError()); |
474 |
1 |
verifyZeroInteractions(wikiUserManager); |
475 |
|
} |
476 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
477 |
1 |
@Test... |
478 |
|
public void addMembersWhenUserHasNoRight() throws Exception |
479 |
|
{ |
480 |
|
|
481 |
1 |
Exception expectedException = currentUserHasNotAdminRight(); |
482 |
|
|
483 |
|
|
484 |
1 |
Collection<String> userIds = new ArrayList<String>(); |
485 |
1 |
boolean result = mocker.getComponentUnderTest().addMembers(userIds, "subwiki"); |
486 |
|
|
487 |
|
|
488 |
1 |
assertFalse(result); |
489 |
1 |
assertEquals(expectedException, mocker.getComponentUnderTest().getLastError()); |
490 |
1 |
verifyZeroInteractions(wikiUserManager); |
491 |
|
} |
492 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
493 |
1 |
@Test... |
494 |
|
public void removeMember() throws Exception |
495 |
|
{ |
496 |
|
|
497 |
1 |
boolean result = mocker.getComponentUnderTest().removeMember("xwiki:XWiki.UserA", "subwiki"); |
498 |
|
|
499 |
|
|
500 |
1 |
assertTrue(result); |
501 |
1 |
verify(wikiUserManager).removeMember("xwiki:XWiki.UserA", "subwiki"); |
502 |
|
} |
503 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
504 |
1 |
@Test... |
505 |
|
public void removeMemberWhenScriptHasNoRight() throws Exception |
506 |
|
{ |
507 |
|
|
508 |
1 |
Exception expectedException = currentScriptHasNotAdminRight(); |
509 |
|
|
510 |
|
|
511 |
1 |
boolean result = mocker.getComponentUnderTest().removeMember("xwiki:XWiki.UserA", "subwiki"); |
512 |
|
|
513 |
|
|
514 |
1 |
assertFalse(result); |
515 |
1 |
assertEquals(expectedException, mocker.getComponentUnderTest().getLastError()); |
516 |
1 |
verifyZeroInteractions(wikiUserManager); |
517 |
|
} |
518 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
519 |
1 |
@Test... |
520 |
|
public void removeMemberWhenUserHasNoRight() throws Exception |
521 |
|
{ |
522 |
|
|
523 |
1 |
Exception expectedException = currentUserHasNotAdminRight(); |
524 |
|
|
525 |
|
|
526 |
1 |
boolean result = mocker.getComponentUnderTest().removeMember("xwiki:XWiki.UserA", "subwiki"); |
527 |
|
|
528 |
|
|
529 |
1 |
assertEquals(false, result); |
530 |
1 |
assertEquals(expectedException, mocker.getComponentUnderTest().getLastError()); |
531 |
1 |
verifyZeroInteractions(wikiUserManager); |
532 |
|
} |
533 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
534 |
1 |
@Test... |
535 |
|
public void getCandidacyAsAdmin() throws Exception |
536 |
|
{ |
537 |
|
|
538 |
1 |
MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.OtherUser", |
539 |
|
MemberCandidacy.CandidateType.REQUEST); |
540 |
1 |
candidacy.setId(12); |
541 |
1 |
candidacy.setAdminPrivateComment("private message"); |
542 |
1 |
when(wikiUserManager.getCandidacy("subwiki", candidacy.getId())).thenReturn(candidacy); |
543 |
1 |
when(authorizationManager.hasAccess(eq(Right.ADMIN), eq(userDocRef), |
544 |
|
eq(new WikiReference("subwiki")))).thenReturn(true); |
545 |
|
|
546 |
|
|
547 |
1 |
MemberCandidacy result = mocker.getComponentUnderTest().getCandidacy("subwiki", 12); |
548 |
|
|
549 |
|
|
550 |
1 |
assertEquals(candidacy, result); |
551 |
1 |
assertEquals("private message", result.getAdminPrivateComment()); |
552 |
|
} |
553 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
554 |
1 |
@Test... |
555 |
|
public void getCandidacyAsUserConcerned() throws Exception |
556 |
|
{ |
557 |
|
|
558 |
|
|
559 |
|
|
560 |
1 |
MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.User", |
561 |
|
MemberCandidacy.CandidateType.REQUEST); |
562 |
1 |
candidacy.setId(12); |
563 |
1 |
candidacy.setAdminPrivateComment("some private message that I should not be able to see"); |
564 |
|
|
565 |
1 |
when(wikiUserManager.getCandidacy("subwiki", candidacy.getId())).thenReturn(candidacy); |
566 |
|
|
567 |
|
|
568 |
1 |
MemberCandidacy result = mocker.getComponentUnderTest().getCandidacy("subwiki", 12); |
569 |
|
|
570 |
|
|
571 |
1 |
assertEquals(candidacy, result); |
572 |
|
|
573 |
1 |
assertNull(candidacy.getAdminPrivateComment()); |
574 |
|
} |
575 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
576 |
1 |
@Test... |
577 |
|
public void getCandidacyWhenNoRight() throws Exception |
578 |
|
{ |
579 |
|
|
580 |
|
|
581 |
|
|
582 |
1 |
MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.OtherUser", |
583 |
|
MemberCandidacy.CandidateType.REQUEST); |
584 |
1 |
candidacy.setId(12); |
585 |
1 |
when(wikiUserManager.getCandidacy("subwiki", candidacy.getId())).thenReturn(candidacy); |
586 |
|
|
587 |
|
|
588 |
1 |
when(authorizationManager.hasAccess(eq(Right.ADMIN), eq(userDocRef), |
589 |
|
eq(new WikiReference("subwiki")))).thenReturn(false); |
590 |
|
|
591 |
|
|
592 |
1 |
MemberCandidacy result = mocker.getComponentUnderTest().getCandidacy("subwiki", 12); |
593 |
|
|
594 |
|
|
595 |
1 |
assertNull(result); |
596 |
1 |
Exception exception = mocker.getComponentUnderTest().getLastError(); |
597 |
1 |
assertTrue(exception instanceof WikiUserManagerScriptServiceException); |
598 |
1 |
assertEquals("You are not allowed to see this candidacy.", exception.getMessage()); |
599 |
|
} |
600 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
601 |
1 |
@Test... |
602 |
|
public void getCandidacyWhenError() throws Exception |
603 |
|
{ |
604 |
|
|
605 |
1 |
Exception exception = new WikiUserManagerException("error in getCandidacy"); |
606 |
1 |
when(wikiUserManager.getCandidacy("subwiki", 42)).thenThrow(exception); |
607 |
|
|
608 |
|
|
609 |
1 |
MemberCandidacy result = mocker.getComponentUnderTest().getCandidacy("subwiki", 42); |
610 |
|
|
611 |
|
|
612 |
1 |
assertNull(result); |
613 |
1 |
assertEquals(exception, mocker.getComponentUnderTest().getLastError()); |
614 |
|
} |
615 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
616 |
1 |
@Test... |
617 |
|
public void getAllInvitations() throws Exception |
618 |
|
{ |
619 |
1 |
ArrayList<MemberCandidacy> candidacies = new ArrayList<MemberCandidacy>(); |
620 |
|
|
621 |
1 |
candidacies.add(new MemberCandidacy("subwiki", "mainWiki:XWiki.User", |
622 |
|
MemberCandidacy.CandidateType.INVITATION)); |
623 |
|
|
624 |
1 |
candidacies.add(new MemberCandidacy("subwiki", "mainWiki:XWiki.OtherUser", |
625 |
|
MemberCandidacy.CandidateType.INVITATION)); |
626 |
1 |
candidacies.get(0).setAdminPrivateComment("private message"); |
627 |
|
|
628 |
|
|
629 |
1 |
when(authorizationManager.hasAccess(eq(Right.ADMIN), eq(userDocRef), |
630 |
|
eq(new WikiReference("subwiki")))).thenReturn(false); |
631 |
|
|
632 |
1 |
when(wikiUserManager.getAllInvitations("subwiki")).thenReturn(candidacies); |
633 |
|
|
634 |
|
|
635 |
1 |
Collection<MemberCandidacy> result = mocker.getComponentUnderTest().getAllInvitations("subwiki"); |
636 |
|
|
637 |
|
|
638 |
1 |
assertEquals(1, result.size()); |
639 |
1 |
assertTrue(result.contains(candidacies.get(0))); |
640 |
1 |
assertFalse(result.contains(candidacies.get(1))); |
641 |
|
|
642 |
1 |
assertNull(((MemberCandidacy)result.toArray()[0]).getAdminPrivateComment()); |
643 |
|
} |
644 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
645 |
1 |
@Test... |
646 |
|
public void getAllInvitationsError() throws Exception |
647 |
|
{ |
648 |
|
|
649 |
1 |
Exception expectedException = new WikiUserManagerException("error in getAllInvitations()"); |
650 |
1 |
when(wikiUserManager.getAllInvitations("subwiki")).thenThrow(expectedException); |
651 |
|
|
652 |
|
|
653 |
1 |
Collection<MemberCandidacy> result = mocker.getComponentUnderTest().getAllInvitations("subwiki"); |
654 |
|
|
655 |
|
|
656 |
1 |
assertNull(result); |
657 |
1 |
assertEquals(expectedException, mocker.getComponentUnderTest().getLastError()); |
658 |
|
} |
659 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
660 |
1 |
@Test... |
661 |
|
public void getAllRequests() throws Exception |
662 |
|
{ |
663 |
1 |
ArrayList<MemberCandidacy> candidacies = new ArrayList<MemberCandidacy>(); |
664 |
|
|
665 |
1 |
candidacies.add(new MemberCandidacy("subwiki", "mainWiki:XWiki.User", |
666 |
|
MemberCandidacy.CandidateType.REQUEST)); |
667 |
|
|
668 |
1 |
candidacies.add(new MemberCandidacy("subwiki", "mainWiki:XWiki.OtherUser", |
669 |
|
MemberCandidacy.CandidateType.REQUEST)); |
670 |
1 |
candidacies.get(0).setAdminPrivateComment("private message"); |
671 |
|
|
672 |
|
|
673 |
1 |
when(authorizationManager.hasAccess(eq(Right.ADMIN), eq(userDocRef), |
674 |
|
eq(new WikiReference("subwiki")))).thenReturn(false); |
675 |
|
|
676 |
1 |
when(wikiUserManager.getAllRequests("subwiki")).thenReturn(candidacies); |
677 |
|
|
678 |
|
|
679 |
1 |
Collection<MemberCandidacy> result = mocker.getComponentUnderTest().getAllRequests("subwiki"); |
680 |
|
|
681 |
|
|
682 |
1 |
assertEquals(1, result.size()); |
683 |
1 |
assertTrue(result.contains(candidacies.get(0))); |
684 |
1 |
assertFalse(result.contains(candidacies.get(1))); |
685 |
|
|
686 |
1 |
assertNull(((MemberCandidacy)result.toArray()[0]).getAdminPrivateComment()); |
687 |
|
} |
688 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
689 |
1 |
@Test... |
690 |
|
public void getAllRequestError() throws Exception |
691 |
|
{ |
692 |
|
|
693 |
1 |
Exception expectedException = new WikiUserManagerException("error in getAllRequests()"); |
694 |
1 |
when(wikiUserManager.getAllRequests("subwiki")).thenThrow(expectedException); |
695 |
|
|
696 |
|
|
697 |
1 |
Collection<MemberCandidacy> result = mocker.getComponentUnderTest().getAllRequests("subwiki"); |
698 |
|
|
699 |
|
|
700 |
1 |
assertNull(result); |
701 |
1 |
assertEquals(expectedException, mocker.getComponentUnderTest().getLastError()); |
702 |
|
} |
703 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
704 |
1 |
@Test... |
705 |
|
public void join() throws Exception |
706 |
|
{ |
707 |
|
|
708 |
1 |
String userId = "mainWiki:XWiki.User"; |
709 |
1 |
String wikiId = "wikiId"; |
710 |
1 |
boolean result = this.mocker.getComponentUnderTest().join(userId, wikiId); |
711 |
|
|
712 |
|
|
713 |
1 |
assertTrue(result); |
714 |
1 |
verify(wikiUserManager).join(userId, wikiId); |
715 |
|
} |
716 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
717 |
1 |
@Test... |
718 |
|
public void joinWhenUserIsNotCurrentUser() throws Exception |
719 |
|
{ |
720 |
|
|
721 |
1 |
String userId = "mainWiki:XWiki.OtherUser"; |
722 |
1 |
String wikiId = "wikiId"; |
723 |
1 |
boolean result = this.mocker.getComponentUnderTest().join(userId, wikiId); |
724 |
|
|
725 |
|
|
726 |
1 |
assertFalse(result); |
727 |
1 |
assertEquals("User [mainWiki:XWiki.User] cannot call $services.wiki.user.join() with an other userId.", |
728 |
|
this.mocker.getComponentUnderTest().getLastError().getMessage()); |
729 |
1 |
verifyZeroInteractions(wikiUserManager); |
730 |
|
} |
731 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
732 |
1 |
@Test... |
733 |
|
public void joinWhenError() throws Exception |
734 |
|
{ |
735 |
1 |
String userId = "mainWiki:XWiki.User"; |
736 |
1 |
String wikiId = "wikiId"; |
737 |
|
|
738 |
|
|
739 |
1 |
WikiUserManagerException expectedException = new WikiUserManagerException("error in wikiUserManager#join()"); |
740 |
1 |
doThrow(expectedException).when(wikiUserManager).join(userId, wikiId); |
741 |
|
|
742 |
|
|
743 |
1 |
boolean result = this.mocker.getComponentUnderTest().join(userId, wikiId); |
744 |
|
|
745 |
|
|
746 |
1 |
assertFalse(result); |
747 |
1 |
assertEquals(expectedException, this.mocker.getComponentUnderTest().getLastError()); |
748 |
|
} |
749 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
750 |
1 |
@Test... |
751 |
|
public void leave() throws Exception |
752 |
|
{ |
753 |
1 |
String userId = "mainWiki:XWiki.User"; |
754 |
1 |
String wikiId = "wikiId"; |
755 |
|
|
756 |
|
|
757 |
1 |
boolean result = this.mocker.getComponentUnderTest().leave(userId, wikiId); |
758 |
|
|
759 |
|
|
760 |
1 |
assertTrue(result); |
761 |
1 |
verify(wikiUserManager).leave(userId, wikiId); |
762 |
|
} |
763 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
764 |
1 |
@Test... |
765 |
|
public void leaveWhenUserIsNotCurrentUser() throws Exception |
766 |
|
{ |
767 |
1 |
String userId = "mainWiki:XWiki.OtherUser"; |
768 |
1 |
String wikiId = "wikiId"; |
769 |
|
|
770 |
|
|
771 |
1 |
boolean result = this.mocker.getComponentUnderTest().leave(userId, wikiId); |
772 |
|
|
773 |
|
|
774 |
1 |
assertFalse(result); |
775 |
1 |
assertEquals("User [mainWiki:XWiki.User] cannot call $services.wiki.user.leave() with an other userId.", |
776 |
|
this.mocker.getComponentUnderTest().getLastError().getMessage()); |
777 |
1 |
verifyZeroInteractions(wikiUserManager); |
778 |
|
} |
779 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
780 |
1 |
@Test... |
781 |
|
public void leaveWhenError() throws Exception |
782 |
|
{ |
783 |
1 |
String userId = "mainWiki:XWiki.User"; |
784 |
1 |
String wikiId = "wikiId"; |
785 |
|
|
786 |
|
|
787 |
1 |
WikiUserManagerException expectedException = new WikiUserManagerException("error in wikiUserManager#leave()"); |
788 |
1 |
doThrow(expectedException).when(wikiUserManager).leave(userId, wikiId); |
789 |
|
|
790 |
|
|
791 |
1 |
boolean result = this.mocker.getComponentUnderTest().leave(userId, wikiId); |
792 |
|
|
793 |
|
|
794 |
1 |
assertFalse(result); |
795 |
1 |
assertEquals(expectedException, this.mocker.getComponentUnderTest().getLastError()); |
796 |
|
} |
797 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
798 |
1 |
@Test... |
799 |
|
public void hasPendingInvitation() throws Exception |
800 |
|
{ |
801 |
1 |
String wikiId = "subwiki"; |
802 |
|
|
803 |
|
|
804 |
1 |
when(wikiUserManager.hasPendingInvitation(userDocRef, wikiId)).thenReturn(true); |
805 |
1 |
assertTrue(mocker.getComponentUnderTest().hasPendingInvitation(userDocRef, wikiId)); |
806 |
|
|
807 |
|
|
808 |
1 |
when(wikiUserManager.hasPendingInvitation(userDocRef, wikiId)).thenReturn(false); |
809 |
1 |
assertFalse(mocker.getComponentUnderTest().hasPendingInvitation(userDocRef, wikiId)); |
810 |
|
} |
811 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
812 |
1 |
@Test... |
813 |
|
public void hasPendingInvitationWhenError() throws Exception |
814 |
|
{ |
815 |
1 |
String wikiId = "subwiki"; |
816 |
|
|
817 |
|
|
818 |
1 |
DocumentReference userToTest = new DocumentReference("mainWiki", "XWiki", "User"); |
819 |
1 |
Exception expectedException = new WikiUserManagerException("exception"); |
820 |
1 |
doThrow(expectedException).when(wikiUserManager).hasPendingInvitation(userToTest, wikiId); |
821 |
|
|
822 |
|
|
823 |
1 |
Boolean result = mocker.getComponentUnderTest().hasPendingInvitation(userToTest, wikiId); |
824 |
|
|
825 |
|
|
826 |
1 |
assertNull(result); |
827 |
1 |
assertEquals(expectedException, mocker.getComponentUnderTest().getLastError()); |
828 |
|
} |
829 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
830 |
1 |
@Test... |
831 |
|
public void hasPendingInvitationWhenPageHasNoRight() throws Exception |
832 |
|
{ |
833 |
1 |
String wikiId = "subwiki"; |
834 |
1 |
DocumentReference userToTest = new DocumentReference("mainWiki", "XWiki", "User"); |
835 |
|
|
836 |
|
|
837 |
1 |
Exception expectedException = currentScriptHasNotAdminRight(); |
838 |
|
|
839 |
|
|
840 |
1 |
Boolean result = mocker.getComponentUnderTest().hasPendingInvitation(userToTest, wikiId); |
841 |
|
|
842 |
|
|
843 |
1 |
assertNull(result); |
844 |
1 |
assertEquals(expectedException, mocker.getComponentUnderTest().getLastError()); |
845 |
1 |
verifyZeroInteractions(wikiUserManager); |
846 |
|
} |
847 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
848 |
1 |
@Test... |
849 |
|
public void hasPendingRequest() throws Exception |
850 |
|
{ |
851 |
1 |
String wikiId = "subwiki"; |
852 |
|
|
853 |
|
|
854 |
1 |
when(wikiUserManager.hasPendingRequest(userDocRef, wikiId)).thenReturn(true); |
855 |
1 |
assertTrue(mocker.getComponentUnderTest().hasPendingRequest(userDocRef, wikiId)); |
856 |
|
|
857 |
|
|
858 |
1 |
when(wikiUserManager.hasPendingRequest(userDocRef, wikiId)).thenReturn(false); |
859 |
1 |
assertFalse(mocker.getComponentUnderTest().hasPendingRequest(userDocRef, wikiId)); |
860 |
|
} |
861 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
862 |
1 |
@Test... |
863 |
|
public void hasPendingRequestWhenError() throws Exception |
864 |
|
{ |
865 |
1 |
String wikiId = "subwiki"; |
866 |
1 |
DocumentReference userToTest = new DocumentReference("mainWiki", "XWiki", "User"); |
867 |
|
|
868 |
|
|
869 |
1 |
Exception expectedException = new WikiUserManagerException("exception"); |
870 |
1 |
doThrow(expectedException).when(wikiUserManager).hasPendingRequest(userToTest, wikiId); |
871 |
|
|
872 |
|
|
873 |
1 |
Boolean result = mocker.getComponentUnderTest().hasPendingRequest(userToTest, wikiId); |
874 |
|
|
875 |
|
|
876 |
1 |
assertNull(result); |
877 |
1 |
assertEquals(expectedException, mocker.getComponentUnderTest().getLastError()); |
878 |
|
|
879 |
|
} |
880 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
881 |
1 |
@Test... |
882 |
|
public void hasPendingRequestWhenScriptHasNoRight() throws Exception |
883 |
|
{ |
884 |
1 |
String wikiId = "subwiki"; |
885 |
1 |
DocumentReference userToTest = new DocumentReference("mainWiki", "XWiki", "User"); |
886 |
|
|
887 |
|
|
888 |
1 |
Exception expectedException = currentScriptHasNotAdminRight(); |
889 |
|
|
890 |
|
|
891 |
1 |
Boolean result = mocker.getComponentUnderTest().hasPendingRequest(userToTest, wikiId); |
892 |
|
|
893 |
|
|
894 |
1 |
assertNull(result); |
895 |
1 |
assertEquals(expectedException, mocker.getComponentUnderTest().getLastError()); |
896 |
1 |
verifyZeroInteractions(wikiUserManager); |
897 |
|
} |
898 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
899 |
1 |
@Test... |
900 |
|
public void acceptRequest() throws Exception |
901 |
|
{ |
902 |
1 |
MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.User", |
903 |
|
MemberCandidacy.CandidateType.INVITATION); |
904 |
|
|
905 |
|
|
906 |
1 |
Boolean result = mocker.getComponentUnderTest().acceptRequest(candidacy, "message", "comment"); |
907 |
|
|
908 |
|
|
909 |
1 |
assertTrue(result); |
910 |
1 |
assertNull(mocker.getComponentUnderTest().getLastError()); |
911 |
1 |
verify(wikiUserManager).acceptRequest(candidacy, "message", "comment"); |
912 |
|
} |
913 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
914 |
1 |
@Test... |
915 |
|
public void acceptRequestWhenUserHasNoAdminRight() throws Exception |
916 |
|
{ |
917 |
1 |
MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.OtherUser", |
918 |
|
MemberCandidacy.CandidateType.INVITATION); |
919 |
|
|
920 |
|
|
921 |
1 |
Exception expecyedException = currentUserHasNotAdminRight(); |
922 |
|
|
923 |
|
|
924 |
1 |
Boolean result = mocker.getComponentUnderTest().acceptRequest(candidacy, "message", "comment"); |
925 |
|
|
926 |
|
|
927 |
1 |
assertFalse(result); |
928 |
1 |
assertEquals(expecyedException, mocker.getComponentUnderTest().getLastError()); |
929 |
1 |
verifyZeroInteractions(wikiUserManager); |
930 |
|
} |
931 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
932 |
1 |
@Test... |
933 |
|
public void acceptRequestWhenNoAdminRightButConcerned() throws Exception |
934 |
|
{ |
935 |
1 |
MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.User", |
936 |
|
MemberCandidacy.CandidateType.INVITATION); |
937 |
|
|
938 |
|
|
939 |
1 |
currentUserHasNotAdminRight(); |
940 |
|
|
941 |
|
|
942 |
1 |
Boolean result = mocker.getComponentUnderTest().acceptRequest(candidacy, "message", "comment"); |
943 |
|
|
944 |
|
|
945 |
1 |
assertTrue(result); |
946 |
1 |
assertNull(mocker.getComponentUnderTest().getLastError()); |
947 |
1 |
verify(wikiUserManager).acceptRequest(candidacy, "message", "comment"); |
948 |
|
} |
949 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
950 |
1 |
@Test... |
951 |
|
public void askToJoin() throws Exception |
952 |
|
{ |
953 |
|
|
954 |
1 |
MemberCandidacy candidacy = new MemberCandidacy(); |
955 |
1 |
when(wikiUserManager.askToJoin("mainWiki:XWiki.User", "subwiki", "please!")).thenReturn(candidacy); |
956 |
|
|
957 |
|
|
958 |
1 |
MemberCandidacy result = mocker.getComponentUnderTest().askToJoin("mainWiki:XWiki.User", "subwiki", "please!"); |
959 |
|
|
960 |
|
|
961 |
1 |
assertEquals(candidacy, result); |
962 |
1 |
assertNull(mocker.getComponentUnderTest().getLastError()); |
963 |
|
} |
964 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
965 |
1 |
@Test... |
966 |
|
public void askToJoinWhenScriptHasNoRight() throws Exception |
967 |
|
{ |
968 |
|
|
969 |
1 |
Exception expectedException = currentScriptHasNotAdminRight(); |
970 |
|
|
971 |
|
|
972 |
1 |
MemberCandidacy result = mocker.getComponentUnderTest().askToJoin("mainWiki:XWiki.User", "subwiki", "please!"); |
973 |
|
|
974 |
|
|
975 |
1 |
assertNull(result); |
976 |
1 |
assertEquals(expectedException, mocker.getComponentUnderTest().getLastError()); |
977 |
1 |
verifyZeroInteractions(wikiUserManager); |
978 |
|
} |
979 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
980 |
1 |
@Test... |
981 |
|
public void askToJoinWhenUsertHasNoRight() throws Exception |
982 |
|
{ |
983 |
|
|
984 |
1 |
Exception expectedException = currentUserHasNotAdminRight(); |
985 |
|
|
986 |
|
|
987 |
1 |
MemberCandidacy result = mocker.getComponentUnderTest().askToJoin("mainWiki:XWiki.OtherUser", |
988 |
|
"subwiki", "please!"); |
989 |
|
|
990 |
|
|
991 |
1 |
assertNull(result); |
992 |
1 |
assertEquals(expectedException, mocker.getComponentUnderTest().getLastError()); |
993 |
1 |
verifyZeroInteractions(wikiUserManager); |
994 |
|
} |
995 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
996 |
1 |
@Test... |
997 |
|
public void askToJoinWhenUserHasNoRightButConcerned() throws Exception |
998 |
|
{ |
999 |
|
|
1000 |
1 |
currentUserHasNotAdminRight(); |
1001 |
1 |
MemberCandidacy candidacy = new MemberCandidacy(); |
1002 |
1 |
when(wikiUserManager.askToJoin("mainWiki:XWiki.User", "subwiki", "please!")).thenReturn(candidacy); |
1003 |
|
|
1004 |
|
|
1005 |
1 |
MemberCandidacy result = mocker.getComponentUnderTest().askToJoin("mainWiki:XWiki.User", |
1006 |
|
"subwiki", "please!"); |
1007 |
|
|
1008 |
|
|
1009 |
1 |
assertEquals(candidacy, result); |
1010 |
1 |
assertNull(mocker.getComponentUnderTest().getLastError()); |
1011 |
|
} |
1012 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
1013 |
1 |
@Test... |
1014 |
|
public void refuseRequest() throws Exception |
1015 |
|
{ |
1016 |
1 |
MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.User", |
1017 |
|
MemberCandidacy.CandidateType.INVITATION); |
1018 |
|
|
1019 |
|
|
1020 |
1 |
Boolean result = mocker.getComponentUnderTest().refuseRequest(candidacy, "message", "comment"); |
1021 |
|
|
1022 |
|
|
1023 |
1 |
assertTrue(result); |
1024 |
1 |
assertNull(mocker.getComponentUnderTest().getLastError()); |
1025 |
1 |
verify(wikiUserManager).refuseRequest(candidacy, "message", "comment"); |
1026 |
|
} |
1027 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
1028 |
1 |
@Test... |
1029 |
|
public void refuseRequestWhenUserHasNoAdminRight() throws Exception |
1030 |
|
{ |
1031 |
1 |
MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.OtherUser", |
1032 |
|
MemberCandidacy.CandidateType.INVITATION); |
1033 |
|
|
1034 |
|
|
1035 |
1 |
Exception expectedException = currentUserHasNotAdminRight(); |
1036 |
|
|
1037 |
|
|
1038 |
1 |
Boolean result = mocker.getComponentUnderTest().refuseRequest(candidacy, "message", "comment"); |
1039 |
|
|
1040 |
|
|
1041 |
1 |
assertFalse(result); |
1042 |
1 |
assertEquals(expectedException, mocker.getComponentUnderTest().getLastError()); |
1043 |
1 |
verifyZeroInteractions(wikiUserManager); |
1044 |
|
} |
1045 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
1046 |
1 |
@Test... |
1047 |
|
public void refuseRequestWhenUserHasNoAdminRightButConcerned() throws Exception |
1048 |
|
{ |
1049 |
1 |
MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.User", |
1050 |
|
MemberCandidacy.CandidateType.INVITATION); |
1051 |
|
|
1052 |
|
|
1053 |
1 |
currentUserHasNotAdminRight(); |
1054 |
|
|
1055 |
|
|
1056 |
1 |
Boolean result = mocker.getComponentUnderTest().refuseRequest(candidacy, "message", "comment"); |
1057 |
|
|
1058 |
|
|
1059 |
1 |
assertTrue(result); |
1060 |
1 |
assertNull(mocker.getComponentUnderTest().getLastError()); |
1061 |
1 |
verify(wikiUserManager).refuseRequest(candidacy, "message", "comment"); |
1062 |
|
} |
1063 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
1064 |
1 |
@Test... |
1065 |
|
public void cancelCandidacy() throws Exception |
1066 |
|
{ |
1067 |
1 |
MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.User", |
1068 |
|
MemberCandidacy.CandidateType.INVITATION); |
1069 |
|
|
1070 |
|
|
1071 |
1 |
Boolean result = mocker.getComponentUnderTest().cancelCandidacy(candidacy); |
1072 |
|
|
1073 |
|
|
1074 |
1 |
assertTrue(result); |
1075 |
1 |
assertNull(mocker.getComponentUnderTest().getLastError()); |
1076 |
1 |
verify(wikiUserManager).cancelCandidacy(candidacy); |
1077 |
|
|
1078 |
|
} |
1079 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
1080 |
1 |
@Test... |
1081 |
|
public void cancelCandidacyWhenUserHasNoAdminRight() throws Exception |
1082 |
|
{ |
1083 |
1 |
MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.OtherUser", |
1084 |
|
MemberCandidacy.CandidateType.INVITATION); |
1085 |
|
|
1086 |
|
|
1087 |
1 |
Exception expectedException = currentUserHasNotAdminRight(); |
1088 |
|
|
1089 |
|
|
1090 |
1 |
Boolean result = mocker.getComponentUnderTest().cancelCandidacy(candidacy); |
1091 |
|
|
1092 |
|
|
1093 |
1 |
assertFalse(result); |
1094 |
1 |
assertEquals(expectedException, mocker.getComponentUnderTest().getLastError()); |
1095 |
1 |
verifyZeroInteractions(wikiUserManager); |
1096 |
|
} |
1097 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
1098 |
1 |
@Test... |
1099 |
|
public void cancelCandidacyWhenUserHasNoAdminRightButConcerned() throws Exception |
1100 |
|
{ |
1101 |
1 |
MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.User", |
1102 |
|
MemberCandidacy.CandidateType.INVITATION); |
1103 |
|
|
1104 |
|
|
1105 |
1 |
currentUserHasNotAdminRight(); |
1106 |
|
|
1107 |
|
|
1108 |
1 |
Boolean result = mocker.getComponentUnderTest().cancelCandidacy(candidacy); |
1109 |
|
|
1110 |
|
|
1111 |
1 |
assertTrue(result); |
1112 |
1 |
assertNull(mocker.getComponentUnderTest().getLastError()); |
1113 |
1 |
verify(wikiUserManager).cancelCandidacy(candidacy); |
1114 |
|
} |
1115 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
1116 |
1 |
@Test... |
1117 |
|
public void invite() throws Exception |
1118 |
|
{ |
1119 |
|
|
1120 |
1 |
when(wikiUserManager.invite(any(), any(), any())).thenReturn(new MemberCandidacy()); |
1121 |
|
|
1122 |
|
|
1123 |
1 |
MemberCandidacy result = mocker.getComponentUnderTest().invite("someUser", "subwiki", "someMessage"); |
1124 |
|
|
1125 |
|
|
1126 |
1 |
assertNotNull(result); |
1127 |
|
} |
1128 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
1129 |
1 |
@Test... |
1130 |
|
public void inviteWhenUserHasNoAdminRight() throws Exception |
1131 |
|
{ |
1132 |
|
|
1133 |
1 |
Exception expectedException = currentUserHasNotAdminRight(); |
1134 |
|
|
1135 |
|
|
1136 |
1 |
MemberCandidacy result = mocker.getComponentUnderTest().invite("someUser", "subwiki", "someMessage"); |
1137 |
|
|
1138 |
|
|
1139 |
1 |
assertNull(result); |
1140 |
1 |
assertEquals(expectedException, mocker.getComponentUnderTest().getLastError()); |
1141 |
1 |
verifyZeroInteractions(wikiUserManager); |
1142 |
|
} |
1143 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
1144 |
1 |
@Test... |
1145 |
|
public void acceptInvitation() throws Exception |
1146 |
|
{ |
1147 |
1 |
MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.User", |
1148 |
|
MemberCandidacy.CandidateType.INVITATION); |
1149 |
|
|
1150 |
|
|
1151 |
1 |
Boolean result = mocker.getComponentUnderTest().acceptInvitation(candidacy, "thanks"); |
1152 |
|
|
1153 |
|
|
1154 |
1 |
assertTrue(result); |
1155 |
1 |
assertNull(mocker.getComponentUnderTest().getLastError()); |
1156 |
1 |
verify(wikiUserManager).acceptInvitation(candidacy, "thanks"); |
1157 |
|
} |
1158 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
1159 |
1 |
@Test... |
1160 |
|
public void acceptInvitationWhenUserHasNoAdminRight() throws Exception |
1161 |
|
{ |
1162 |
1 |
MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.OtherUser", |
1163 |
|
MemberCandidacy.CandidateType.INVITATION); |
1164 |
|
|
1165 |
|
|
1166 |
1 |
Exception exception = currentUserHasNotAdminRight(); |
1167 |
|
|
1168 |
|
|
1169 |
1 |
Boolean result = mocker.getComponentUnderTest().acceptInvitation(candidacy, "thanks"); |
1170 |
|
|
1171 |
|
|
1172 |
1 |
assertFalse(result); |
1173 |
1 |
assertEquals(exception, mocker.getComponentUnderTest().getLastError()); |
1174 |
1 |
verifyZeroInteractions(wikiUserManager); |
1175 |
|
} |
1176 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
1177 |
1 |
@Test... |
1178 |
|
public void acceptInvitationWhenUserHasNoAdminRightButConcerned() throws Exception |
1179 |
|
{ |
1180 |
1 |
MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.User", |
1181 |
|
MemberCandidacy.CandidateType.INVITATION); |
1182 |
|
|
1183 |
|
|
1184 |
1 |
currentUserHasNotAdminRight(); |
1185 |
|
|
1186 |
|
|
1187 |
1 |
Boolean result = mocker.getComponentUnderTest().acceptInvitation(candidacy, "thanks"); |
1188 |
|
|
1189 |
|
|
1190 |
1 |
assertTrue(result); |
1191 |
1 |
assertNull(mocker.getComponentUnderTest().getLastError()); |
1192 |
1 |
verify(wikiUserManager).acceptInvitation(candidacy, "thanks"); |
1193 |
|
} |
1194 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
1195 |
1 |
@Test... |
1196 |
|
public void refuseInvitation() throws Exception |
1197 |
|
{ |
1198 |
1 |
MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.User", |
1199 |
|
MemberCandidacy.CandidateType.INVITATION); |
1200 |
|
|
1201 |
|
|
1202 |
1 |
Boolean result = mocker.getComponentUnderTest().refuseInvitation(candidacy, "no thanks"); |
1203 |
|
|
1204 |
|
|
1205 |
1 |
assertTrue(result); |
1206 |
1 |
assertNull(mocker.getComponentUnderTest().getLastError()); |
1207 |
1 |
verify(wikiUserManager).refuseInvitation(candidacy, "no thanks"); |
1208 |
|
|
1209 |
|
} |
1210 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
1211 |
1 |
@Test... |
1212 |
|
public void refuseInvitationWhenUserHasNoAdminRight() throws Exception |
1213 |
|
{ |
1214 |
1 |
MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.OtherUser", |
1215 |
|
MemberCandidacy.CandidateType.INVITATION); |
1216 |
|
|
1217 |
|
|
1218 |
1 |
Exception expectedException = currentUserHasNotAdminRight(); |
1219 |
|
|
1220 |
|
|
1221 |
1 |
Boolean result = mocker.getComponentUnderTest().refuseInvitation(candidacy, "no thanks"); |
1222 |
|
|
1223 |
|
|
1224 |
1 |
assertFalse(result); |
1225 |
1 |
assertEquals(expectedException, mocker.getComponentUnderTest().getLastError()); |
1226 |
1 |
verifyZeroInteractions(wikiUserManager); |
1227 |
|
} |
1228 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
1229 |
1 |
@Test... |
1230 |
|
public void refuseInvitationWhenUserHasNoAdminRightButConcerned() throws Exception |
1231 |
|
{ |
1232 |
1 |
MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.User", |
1233 |
|
MemberCandidacy.CandidateType.INVITATION); |
1234 |
|
|
1235 |
|
|
1236 |
1 |
currentUserHasNotAdminRight(); |
1237 |
|
|
1238 |
|
|
1239 |
1 |
Boolean result = mocker.getComponentUnderTest().refuseInvitation(candidacy, "no thanks"); |
1240 |
|
|
1241 |
|
|
1242 |
1 |
assertTrue(result); |
1243 |
1 |
assertNull(mocker.getComponentUnderTest().getLastError()); |
1244 |
1 |
verify(wikiUserManager).refuseInvitation(candidacy, "no thanks"); |
1245 |
|
} |
1246 |
|
} |