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

File AbstractLegacyWikiTestCase.java

 

Coverage histogram

../../../../img/srcFileCovDistChart6.png
69% of files have more coverage

Code metrics

0
35
13
1
231
102
13
0.37
2.69
13
1

Classes

Class Line # Actions
AbstractLegacyWikiTestCase 40 35 0% 13 20
0.583333358.3%
 

Contributing tests

This file is covered by 10 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;
21   
22    import org.junit.Before;
23    import org.xwiki.security.authorization.internal.XWikiCachingRightService;
24    import org.xwiki.test.annotation.AllComponents;
25   
26    import com.xpn.xwiki.XWikiContext;
27    import com.xpn.xwiki.user.api.XWikiRightService;
28    import com.xpn.xwiki.user.impl.xwiki.XWikiRightServiceImpl;
29   
30    import org.junit.Assert;
31   
32    /**
33    * Abstract class that should be inherited when writing tests for comparing the result of different right service
34    * implementations.
35    *
36    * @version $Id: 37a65525a0093b89e7ec59eeee19755372531052 $
37    * @since 4.2
38    */
39    @AllComponents
 
40    public abstract class AbstractLegacyWikiTestCase extends AbstractWikiTestCase
41    {
42    /**
43    * Instance of the original implementation for reference.
44    */
45    private XWikiRightServiceImpl legacyImpl;
46   
47    /**
48    * The instance that is beeing tested.
49    */
50    private XWikiCachingRightService cachingImpl;
51   
 
52  10 toggle @Before
53    @Override
54    public void setUp() throws Exception
55    {
56  10 super.setUp();
57   
58  10 this.legacyImpl = new XWikiRightServiceImpl();
59  10 this.cachingImpl = new XWikiCachingRightService();
60    }
61   
62    /**
63    * @param message A message explaining the assertion.
64    * @param accessLevel The access level to check.
65    * @param userName The name of the user.
66    * @param documentName The document name.
67    * @param ctx The context.
68    */
 
69  21 toggle protected void assertAccessLevelTrue(String message, String accessLevel, String userName, String documentName,
70    XWikiContext ctx) throws Exception
71    {
72  21 setContext(ctx);
73   
74  21 Assert.assertTrue("Old implementation: " + message,
75    this.legacyImpl.hasAccessLevel(accessLevel, userName, documentName, ctx));
76   
77  21 Assert.assertTrue("Caching implementation: " + message,
78    this.cachingImpl.hasAccessLevel(accessLevel, userName, documentName, ctx));
79    }
80   
81    /**
82    * @param message A message explaining the assertion.
83    * @param accessLevel The access level to check.
84    * @param userName The name of the user.
85    * @param documentName The document name.
86    * @param ctx The context.
87    */
 
88  7 toggle protected void assertAccessLevelFalse(String message, String accessLevel, String userName, String documentName,
89    XWikiContext ctx) throws Exception
90    {
91  7 setContext(ctx);
92   
93  7 Assert.assertFalse("Old implementation: " + message,
94    this.legacyImpl.hasAccessLevel(accessLevel, userName, documentName, ctx));
95   
96  7 Assert.assertFalse("Caching implementation: " + message,
97    this.cachingImpl.hasAccessLevel(accessLevel, userName, documentName, ctx));
98    }
99   
100    /**
101    * @param message A message explaining the assertion.
102    * @param ctx The context.
103    */
 
104  0 toggle protected void assertAdminRightsTrue(String message, XWikiContext ctx) throws Exception
105    {
106  0 setContext(ctx);
107   
108  0 Assert.assertTrue("Old implementation: " + message, this.legacyImpl.hasAdminRights(ctx));
109   
110  0 Assert.assertTrue("Caching implementation: " + message, this.cachingImpl.hasAdminRights(ctx));
111    }
112   
113    /**
114    * @param message A message explaining the assertion.
115    * @param ctx The context.
116    */
 
117  0 toggle protected void assertAdminRightsFalse(String message, XWikiContext ctx) throws Exception
118    {
119  0 setContext(ctx);
120   
121  0 Assert.assertFalse("Old implementation: " + message, this.legacyImpl.hasAdminRights(ctx));
122   
123  0 Assert.assertFalse("Caching implementation: " + message, this.cachingImpl.hasAdminRights(ctx));
124    }
125   
126    /**
127    * @param message A message explaining the assertion.
128    * @param ctx The context.
129    */
 
130  1 toggle protected void assertAdminRightsFalseExpectedDifference(String message, XWikiContext ctx) throws Exception
131    {
132  1 setContext(ctx);
133   
134  1 Assert.assertTrue("Old implementation: " + message, this.legacyImpl.hasAdminRights(ctx));
135   
136  1 Assert.assertFalse("Caching implementation: " + message, this.cachingImpl.hasAdminRights(ctx));
137    }
138   
139    /**
140    * @param message A message explaining the assertion.
141    * @param ctx The context.
142    */
 
143  0 toggle protected void assertWikiAdminRightsTrue(String message, XWikiContext ctx) throws Exception
144    {
145  0 setContext(ctx);
146   
147  0 Assert.assertTrue("Old implementation: " + message, this.legacyImpl.hasWikiAdminRights(ctx));
148   
149  0 Assert.assertTrue("Caching implementation: " + message, this.cachingImpl.hasWikiAdminRights(ctx));
150    }
151   
152    /**
153    * @param message A message explaining the assertion.
154    * @param ctx The context.
155    */
 
156  0 toggle protected void assertWikiAdminRightsFalse(String message, XWikiContext ctx) throws Exception
157    {
158  0 setContext(ctx);
159   
160  0 Assert.assertFalse("Old implementation: " + message, this.legacyImpl.hasWikiAdminRights(ctx));
161   
162  0 Assert.assertFalse("Caching implementation: " + message, this.cachingImpl.hasWikiAdminRights(ctx));
163    }
164   
165    /**
166    * @param message A message explaining the assertion.
167    * @param ctx The context.
168    */
 
169  1 toggle protected void assertWikiAdminRightsFalseExpectedDifference(String message, XWikiContext ctx) throws Exception
170    {
171  1 setContext(ctx);
172   
173  1 Assert.assertTrue("Old implementation: " + message, this.legacyImpl.hasWikiAdminRights(ctx));
174   
175  1 Assert.assertFalse("Caching implementation: " + message, this.cachingImpl.hasWikiAdminRights(ctx));
176    }
177   
178    /**
179    * @param message A message explaining the assertion.
180    * @param accessLevel The access level to check.
181    * @param userName The name of the user.
182    * @param documentName The document name.
183    * @param ctx The context.
184    */
 
185  0 toggle protected void assertAccessLevelTrueExpectedDifference(String message, String accessLevel, String userName,
186    String documentName, XWikiContext ctx) throws Exception
187    {
188  0 setContext(ctx);
189   
190  0 Assert.assertFalse("Old implementation is is expected to differ: " + message,
191    this.legacyImpl.hasAccessLevel(accessLevel, userName, documentName, ctx));
192   
193  0 Assert.assertTrue("Caching implementation: " + message,
194    this.cachingImpl.hasAccessLevel(accessLevel, userName, documentName, ctx));
195    }
196   
197    /**
198    * @param message A message explaining the assertion.
199    * @param accessLevel The access level to check.
200    * @param userName The name of the user.
201    * @param documentName The document name.
202    * @param ctx The context.
203    */
 
204  2 toggle protected void assertAccessLevelFalseExpectedDifference(String message, String accessLevel, String userName,
205    String documentName, XWikiContext ctx) throws Exception
206    {
207  2 setContext(ctx);
208   
209  2 Assert.assertTrue("Old implementation is expected to differ: " + message,
210    this.legacyImpl.hasAccessLevel(accessLevel, userName, documentName, ctx));
211   
212  2 Assert.assertFalse("Caching implementation: " + message,
213    this.cachingImpl.hasAccessLevel(accessLevel, userName, documentName, ctx));
214    }
215   
216    /**
217    * @return An instance of the old implementation.
218    */
 
219  6 toggle protected XWikiRightService getLegacyImpl()
220    {
221  6 return this.legacyImpl;
222    }
223   
224    /**
225    * @return An instance of the caching implementation.
226    */
 
227  6 toggle protected XWikiRightService getCachingImpl()
228    {
229  6 return this.cachingImpl;
230    }
231    }