1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.user.impl.xwiki; |
21 |
|
|
22 |
|
import java.util.Arrays; |
23 |
|
import java.util.HashSet; |
24 |
|
|
25 |
|
import org.junit.Before; |
26 |
|
import org.junit.Rule; |
27 |
|
import org.junit.Test; |
28 |
|
import org.xwiki.model.reference.DocumentReference; |
29 |
|
|
30 |
|
import com.xpn.xwiki.XWikiContext; |
31 |
|
import com.xpn.xwiki.XWikiException; |
32 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
33 |
|
import com.xpn.xwiki.objects.BaseObject; |
34 |
|
import com.xpn.xwiki.test.MockitoOldcoreRule; |
35 |
|
import com.xpn.xwiki.test.reference.ReferenceComponentList; |
36 |
|
|
37 |
|
import static org.junit.Assert.assertEquals; |
38 |
|
import static org.mockito.ArgumentMatchers.any; |
39 |
|
import static org.mockito.Mockito.doReturn; |
40 |
|
|
41 |
|
@ReferenceComponentList |
|
|
| 100% |
Uncovered Elements: 0 (19) |
Complexity: 2 |
Complexity Density: 0.12 |
|
42 |
|
public class XWikiGroupServiceImplTest |
43 |
|
{ |
44 |
|
@Rule |
45 |
|
public MockitoOldcoreRule oldcore = new MockitoOldcoreRule(); |
46 |
|
|
47 |
|
XWikiGroupServiceImpl groupService; |
48 |
|
|
49 |
|
private XWikiDocument user; |
50 |
|
|
51 |
|
private XWikiDocument userWithSpaces; |
52 |
|
|
53 |
|
private XWikiDocument group; |
54 |
|
|
55 |
|
private BaseObject groupObject; |
56 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
|
57 |
1 |
@Before... |
58 |
|
public void before() throws Exception |
59 |
|
{ |
60 |
1 |
this.groupService = new XWikiGroupServiceImpl(); |
61 |
|
|
62 |
1 |
doReturn(0).when(this.oldcore.getSpyXWiki()).getMaxRecursiveSpaceChecks(any(XWikiContext.class)); |
63 |
|
|
64 |
1 |
this.user = new XWikiDocument(new DocumentReference("wiki", "XWiki", "user")); |
65 |
1 |
this.user.newXObject(new DocumentReference("wiki", "XWiki", "XWikiUser"), this.oldcore.getXWikiContext()); |
66 |
1 |
this.oldcore.getSpyXWiki().saveDocument(this.user, this.oldcore.getXWikiContext()); |
67 |
|
|
68 |
1 |
this.userWithSpaces = new XWikiDocument(new DocumentReference("wiki", "XWiki", "user with spaces")); |
69 |
1 |
this.userWithSpaces.newXObject(new DocumentReference("wiki", "XWiki", "XWikiUser"), |
70 |
|
this.oldcore.getXWikiContext()); |
71 |
1 |
this.oldcore.getSpyXWiki().saveDocument(this.userWithSpaces, this.oldcore.getXWikiContext()); |
72 |
|
|
73 |
1 |
this.group = new XWikiDocument(new DocumentReference("wiki", "XWiki", "group")); |
74 |
1 |
this.groupObject = |
75 |
|
this.group |
76 |
|
.newXObject(new DocumentReference("wiki", "XWiki", "XWikiGroups"), this.oldcore.getXWikiContext()); |
77 |
1 |
this.groupObject.setStringValue("member", this.user.getFullName()); |
78 |
1 |
this.oldcore.getSpyXWiki().saveDocument(this.group, this.oldcore.getXWikiContext()); |
79 |
|
|
80 |
1 |
this.oldcore.getXWikiContext().setWikiId("wiki"); |
81 |
|
} |
82 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
83 |
1 |
@Test... |
84 |
|
public void testListMemberForGroup() throws XWikiException |
85 |
|
{ |
86 |
1 |
assertEquals( |
87 |
|
new HashSet<String>(Arrays.asList(this.user.getFullName())), |
88 |
|
new HashSet<String>(this.groupService.listMemberForGroup(this.group.getFullName(), |
89 |
|
this.oldcore.getXWikiContext()))); |
90 |
|
|
91 |
1 |
this.groupObject.setStringValue("member", this.userWithSpaces.getFullName()); |
92 |
1 |
this.oldcore.getSpyXWiki().saveDocument(this.group, this.oldcore.getXWikiContext()); |
93 |
|
|
94 |
1 |
assertEquals(new HashSet<String>(Arrays.asList(this.userWithSpaces.getFullName())), new HashSet<String>( |
95 |
|
this.groupService.listMemberForGroup(this.group.getFullName(), this.oldcore.getXWikiContext()))); |
96 |
|
} |
97 |
|
} |