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

File AbstractWikiTestCase.java

 

Coverage histogram

../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

0
13
4
1
86
43
4
0.31
3.25
4
1

Classes

Class Line # Actions
AbstractWikiTestCase 41 13 0% 4 0
1.0100%
 

Contributing tests

This file is covered by 18 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   
21    package org.xwiki.security.authorization;
22   
23    import org.junit.Before;
24    import org.xwiki.context.Execution;
25    import org.xwiki.context.ExecutionContext;
26    import org.xwiki.observation.EventListener;
27    import org.xwiki.security.authorization.testwikibuilding.LegacyTestWiki;
28    import org.xwiki.test.annotation.AllComponents;
29    import org.xwiki.test.jmock.AbstractComponentTestCase;
30   
31    import com.xpn.xwiki.XWikiContext;
32    import com.xpn.xwiki.web.Utils;
33   
34    /**
35    * Abstract class that should be inherited when writing tests case based on XML based mocked wikis
36    *
37    * @version $Id: aa62ca4f27cba7fe3f39a11b415c36161bdb2e7d $
38    * @since 4.2
39    */
40    @AllComponents
 
41    public abstract class AbstractWikiTestCase extends AbstractComponentTestCase
42    {
43    /**
44    * An execution context.
45    */
46    private ExecutionContext executionContext;
47   
 
48  18 toggle @Before
49    @Override
50    public void setUp() throws Exception
51    {
52  18 super.setUp();
53   
54  18 this.executionContext = new ExecutionContext();
55  18 Execution execution = getComponentManager().getInstance(Execution.class);
56  18 execution.setContext(this.executionContext);
57  18 Utils.setComponentManager(getComponentManager());
58    }
59   
 
60  18 toggle @Override
61    protected void registerComponents() throws Exception
62    {
63  18 super.registerComponents();
64   
65    // Get rid of annoying listeners we don't need
66  18 getComponentManager().unregisterComponent(EventListener.class, "XObjectEventGeneratorListener");
67  18 getComponentManager().unregisterComponent(EventListener.class, "AttachmentEventGeneratorListener");
68  18 getComponentManager().unregisterComponent(EventListener.class, "XClassPropertyEventGeneratorListener");
69    }
70   
 
71  93 toggle protected void setContext(XWikiContext ctx)
72    {
73  93 this.executionContext.setProperty(XWikiContext.EXECUTIONCONTEXT_KEY, ctx);
74    }
75   
76    /**
77    * @param filename The filename of the wiki description file.
78    * @return A mocked wiki instance that can be used by both the old, and the caching right service implementation.
79    */
 
80  10 toggle protected LegacyTestWiki newTestWiki(String filename, boolean legacymock) throws Exception
81    {
82  10 LegacyTestWiki testWiki = new LegacyTestWiki(getMockery(), getComponentManager(), filename, legacymock);
83  10 setContext(testWiki.getXWikiContext());
84  10 return testWiki;
85    }
86    }