1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package com.xpn.xwiki

File XWikiContextTest.java

 

Code metrics

0
40
4
1
113
68
4
0.1
10
4
1

Classes

Class Line # Actions
XWikiContextTest 37 40 0% 4 0
1.0100%
 

Contributing tests

This file is covered by 3 tests. .

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;
21   
22    import org.junit.Assert;
23   
24    import org.junit.Before;
25    import org.junit.Test;
26    import org.xwiki.model.reference.DocumentReference;
27   
28    import com.xpn.xwiki.test.AbstractBridgedComponentTestCase;
29    import com.xpn.xwiki.user.api.XWikiRightService;
30    import com.xpn.xwiki.user.api.XWikiUser;
31   
32    /**
33    * Unit tests for {@link com.xpn.xwiki.XWikiContext}.
34    *
35    * @version $Id: 2733859ef99d64c9e8a44c733199450ef9d84b63 $
36    */
 
37    public class XWikiContextTest extends AbstractBridgedComponentTestCase
38    {
 
39  3 toggle @Before
40    @Override
41    public void setUp() throws Exception
42    {
43  3 super.setUp();
44   
45  3 getContext().setWiki(new XWiki());
46    }
47   
 
48  1 toggle @Test
49    public void testgetUser()
50    {
51  1 getContext().setMainXWiki("wiki");
52  1 getContext().setWikiId("wiki");
53  1 getContext().setUserReference(new DocumentReference("wiki", "space", "user"));
54   
55  1 Assert.assertEquals("space.user", getContext().getUser());
56  1 Assert.assertEquals("space.user", getContext().getLocalUser());
57  1 Assert.assertEquals("space.user", getContext().getXWikiUser().getUser());
58  1 Assert.assertTrue("space.user", getContext().getXWikiUser().isMain());
59   
60  1 getContext().setWikiId("wiki1");
61   
62  1 Assert.assertEquals("wiki:space.user", getContext().getUser());
63  1 Assert.assertEquals("space.user", getContext().getLocalUser());
64  1 Assert.assertEquals("wiki:space.user", getContext().getXWikiUser().getUser());
65  1 Assert.assertTrue("space.user", getContext().getXWikiUser().isMain());
66    }
67   
 
68  1 toggle @Test
69    public void testSetUser()
70    {
71  1 getContext().setMainXWiki("wiki");
72  1 getContext().setWikiId("wiki");
73  1 getContext().setUser("XWiki.user");
74   
75  1 Assert.assertEquals(new DocumentReference("wiki", "XWiki", "user"), getContext().getUserReference());
76  1 Assert.assertEquals("XWiki.user", getContext().getUser());
77   
78  1 getContext().setUser("user");
79   
80  1 Assert.assertEquals(new DocumentReference("wiki", "XWiki", "user"), getContext().getUserReference());
81  1 Assert.assertEquals("XWiki.user", getContext().getUser());
82    }
83   
 
84  1 toggle @Test
85    public void testAnonymousUser()
86    {
87  1 getContext().setMainXWiki("wiki");
88  1 getContext().setWikiId("wiki");
89  1 getContext().setUserReference(null);
90   
91  1 Assert.assertNull(getContext().getUserReference());
92  1 Assert.assertEquals("XWiki.XWikiGuest", getContext().getUser());
93  1 Assert.assertEquals("XWiki.XWikiGuest", getContext().getLocalUser());
94  1 Assert.assertNull(getContext().getXWikiUser());
95   
96  1 getContext().setWikiId("wiki2");
97   
98  1 Assert.assertNull(getContext().getUserReference());
99  1 Assert.assertEquals("XWiki.XWikiGuest", getContext().getUser());
100  1 Assert.assertEquals("XWiki.XWikiGuest", getContext().getLocalUser());
101  1 Assert.assertNull(getContext().getXWikiUser());
102   
103  1 getContext().setUser(XWikiRightService.GUEST_USER_FULLNAME);
104   
105  1 Assert.assertEquals(new XWikiUser(XWikiRightService.GUEST_USER_FULLNAME), getContext().getXWikiUser());
106  1 Assert.assertNull(getContext().getUserReference());
107   
108  1 getContext().setUser(XWikiRightService.GUEST_USER);
109   
110  1 Assert.assertEquals(new XWikiUser(XWikiRightService.GUEST_USER), getContext().getXWikiUser());
111  1 Assert.assertNull(getContext().getUserReference());
112    }
113    }