1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.user.impl.xwiki

File XWikiGroupServiceImplTest.java

 

Code metrics

0
17
2
1
97
59
2
0.12
8.5
2
1

Classes

Class Line # Actions
XWikiGroupServiceImplTest 42 17 0% 2 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
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
 
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   
 
57  1 toggle @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   
 
83  1 toggle @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    }