1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.rendering.macro.script

File ScriptMockSetup.java

 

Coverage histogram

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

Code metrics

0
15
4
1
88
43
4
0.27
3.75
4
1

Classes

Class Line # Actions
ScriptMockSetup 40 15 0% 4 0
1.0100%
 

Contributing tests

No tests hitting this source file were found.

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.rendering.macro.script;
21   
22    import org.jmock.Expectations;
23    import org.jmock.Mockery;
24    import org.jmock.integration.junit4.JUnit4Mockery;
25    import org.xwiki.bridge.DocumentAccessBridge;
26    import org.xwiki.model.reference.AttachmentReferenceResolver;
27    import org.xwiki.model.reference.DocumentReferenceResolver;
28    import org.xwiki.model.reference.SpaceReferenceResolver;
29    import org.xwiki.rendering.wiki.WikiModel;
30    import org.xwiki.security.authorization.ContextualAuthorizationManager;
31    import org.xwiki.security.authorization.Right;
32    import org.xwiki.test.jmock.MockingComponentManager;
33   
34    /**
35    * Dynamic mock setup for script macros.
36    *
37    * @version $Id: 5619925dca7782341a6a3951b9345845315ea83b $
38    * @since 2.0RC1
39    */
 
40    public class ScriptMockSetup
41    {
42    public DocumentAccessBridge bridge;
43   
44    public ContextualAuthorizationManager authorizationManager;
45   
46    public AttachmentReferenceResolver<String> attachmentReferenceResolver;
47   
48    public DocumentReferenceResolver<String> documentReferenceResolver;
49   
50    public SpaceReferenceResolver<String> spaceReferenceResolver;
51   
52    public WikiModel wikiModel;
53   
 
54  18 toggle public ScriptMockSetup(MockingComponentManager componentManager) throws Exception
55    {
56  18 this(new JUnit4Mockery(), componentManager);
57    }
58   
 
59  66 toggle public ScriptMockSetup(Mockery mockery, MockingComponentManager cm) throws Exception
60    {
61    // Document Access Bridge Mock setup
62  66 this.bridge = cm.registerMockComponent(mockery, DocumentAccessBridge.class);
 
63  66 toggle mockery.checking(new Expectations() {{
64  66 allowing(bridge).hasProgrammingRights(); will(returnValue(true));
65    }});
66   
67    // Contextual Authorization Manager Mock setup
68  66 this.authorizationManager = cm.registerMockComponent(mockery, ContextualAuthorizationManager.class);
 
69  66 toggle mockery.checking(new Expectations() {{
70  66 allowing(authorizationManager).hasAccess(Right.SCRIPT); will(returnValue(true));
71  66 allowing(authorizationManager).hasAccess(Right.PROGRAM); will(returnValue(true));
72    }});
73   
74    // Register a WikiModel mock so that we're in wiki mode (otherwise links will be considered as URLs for ex).
75  66 this.wikiModel = cm.registerMockComponent(mockery, WikiModel.class);
76   
77    // Use a mock for the AttachmentReference Resolver
78  66 this.attachmentReferenceResolver =
79    cm.registerMockComponent(mockery, AttachmentReferenceResolver.TYPE_STRING, "current");
80   
81    // Use a mock for the DocumentReference Resolver
82  66 this.documentReferenceResolver =
83    cm.registerMockComponent(mockery, DocumentReferenceResolver.TYPE_STRING, "current");
84   
85    // Use a mock for the SpaceReference Resolver
86  66 this.spaceReferenceResolver = cm.registerMockComponent(mockery, SpaceReferenceResolver.TYPE_STRING, "current");
87    }
88    }