1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.security.authorization.internal

File DefaultContextualAuthorizationManagerTest.java

 

Code metrics

0
9
3
1
91
50
3
0.33
3
3
1

Classes

Class Line # Actions
DefaultContextualAuthorizationManagerTest 47 9 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 2 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 org.xwiki.security.authorization.internal;
21   
22    import org.junit.Before;
23    import org.junit.Rule;
24    import org.junit.Test;
25    import org.xwiki.model.reference.DocumentReference;
26    import org.xwiki.model.reference.LocalDocumentReference;
27    import org.xwiki.model.reference.WikiReference;
28    import org.xwiki.security.authorization.AuthorizationManager;
29    import org.xwiki.security.authorization.ContextualAuthorizationManager;
30    import org.xwiki.security.authorization.Right;
31    import org.xwiki.test.mockito.MockitoComponentMockingRule;
32   
33    import com.xpn.xwiki.test.MockitoOldcoreRule;
34    import com.xpn.xwiki.test.reference.ReferenceComponentList;
35   
36    import static org.mockito.ArgumentMatchers.eq;
37    import static org.mockito.ArgumentMatchers.isNull;
38    import static org.mockito.ArgumentMatchers.same;
39    import static org.mockito.Mockito.verify;
40   
41    /**
42    * Validate {@link DefaultContextualAuthorizationManager}.
43    *
44    * @version $Id: c3e6da73d1fe55f9f501e170461dd4ea5e011751 $
45    */
46    @ReferenceComponentList
 
47    public class DefaultContextualAuthorizationManagerTest
48    {
49    public MockitoComponentMockingRule<ContextualAuthorizationManager> mocker =
50    new MockitoComponentMockingRule<ContextualAuthorizationManager>(DefaultContextualAuthorizationManager.class);
51   
52    @Rule
53    public MockitoOldcoreRule oldcore = new MockitoOldcoreRule(mocker);
54   
55    private AuthorizationManager authorizationManager;
56   
57    private WikiReference currentWikiReference;
58   
 
59  2 toggle @Before
60    public void before() throws Exception
61    {
62  2 this.authorizationManager = this.mocker.getInstance(AuthorizationManager.class);
63   
64  2 this.currentWikiReference = new WikiReference("wiki");
65  2 this.oldcore.getXWikiContext().setWikiId(this.currentWikiReference.getName());
66    }
67   
68    // Tests
69   
 
70  1 toggle @Test
71    public void checkAccess() throws Exception
72    {
73  1 LocalDocumentReference localReference = new LocalDocumentReference("space", "page");
74   
75  1 this.mocker.getComponentUnderTest().checkAccess(Right.VIEW, localReference);
76   
77  1 verify(this.authorizationManager).checkAccess(same(Right.VIEW), isNull(DocumentReference.class),
78    eq(new DocumentReference(localReference, this.currentWikiReference)));
79    }
80   
 
81  1 toggle @Test
82    public void hasAccess() throws Exception
83    {
84  1 LocalDocumentReference localReference = new LocalDocumentReference("space", "page");
85   
86  1 this.mocker.getComponentUnderTest().hasAccess(Right.VIEW, localReference);
87   
88  1 verify(this.authorizationManager).hasAccess(same(Right.VIEW), isNull(DocumentReference.class),
89    eq(new DocumentReference(localReference, this.currentWikiReference)));
90    }
91    }