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

File DefaultWikiComponentBuilderTest.java

 

Code metrics

0
31
5
1
112
79
6
0.19
6.2
5
1.2

Classes

Class Line # Actions
DefaultWikiComponentBuilderTest 41 31 0% 6 1
0.972222297.2%
 

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.component.wiki;
21   
22    import java.util.List;
23   
24    import org.apache.commons.collections.ListUtils;
25    import org.apache.commons.collections.MapUtils;
26    import org.jmock.Expectations;
27    import org.junit.Assert;
28    import org.junit.Before;
29    import org.junit.Test;
30    import org.xwiki.component.wiki.internal.DefaultWikiComponentBuilder;
31    import org.xwiki.component.wiki.internal.WikiComponentConstants;
32    import org.xwiki.component.wiki.internal.bridge.WikiComponentBridge;
33    import org.xwiki.model.reference.DocumentReference;
34    import org.xwiki.rendering.syntax.Syntax;
35    import org.xwiki.security.authorization.ContextualAuthorizationManager;
36    import org.xwiki.security.authorization.Right;
37    import org.xwiki.test.jmock.AbstractMockingComponentTestCase;
38    import org.xwiki.test.jmock.annotation.MockingRequirement;
39   
40    @MockingRequirement(DefaultWikiComponentBuilder.class)
 
41    public class DefaultWikiComponentBuilderTest extends AbstractMockingComponentTestCase implements WikiComponentConstants
42    {
43    private static final DocumentReference DOC_REFERENCE = new DocumentReference("xwiki", "XWiki", "MyComponent");
44   
45    private static final DocumentReference AUTHOR_REFERENCE = new DocumentReference("xwiki", "XWiki", "Admin");
46   
47    private WikiComponentBuilder builder;
48   
49    private WikiComponentBridge bridge;
50   
51    private ContextualAuthorizationManager authorization;
52   
 
53  2 toggle @Before
54    public void configure() throws Exception
55    {
56  2 this.builder = getComponentManager().getInstance(WikiComponentBuilder.class);
57  2 this.bridge = getComponentManager().getInstance(WikiComponentBridge.class);
58  2 this.authorization = getComponentManager().getInstance(ContextualAuthorizationManager.class);
59    }
60   
 
61  1 toggle @Test
62    public void buildComponentsWithoutProgrammingRights() throws Exception
63    {
64  1 getMockery().checking(new Expectations()
65    {
 
66  1 toggle {
67  1 oneOf(authorization).hasAccess(Right.PROGRAM, DOC_REFERENCE);
68  1 will(returnValue(false));
69    }
70    });
71   
72  1 try {
73  1 this.builder.buildComponents(DOC_REFERENCE);
74  0 Assert.fail("Should have thrown an exception");
75    } catch (WikiComponentException expected) {
76  1 Assert.assertEquals("Registering wiki components requires programming rights", expected.getMessage());
77    }
78    }
79   
 
80  1 toggle @Test
81    public void buildComponents() throws Exception
82    {
83  1 getMockery().checking(new Expectations()
84    {
 
85  1 toggle {
86  1 oneOf(bridge).getAuthorReference(DOC_REFERENCE);
87  1 will(returnValue(AUTHOR_REFERENCE));
88  1 oneOf(bridge).getRoleType(DOC_REFERENCE);
89  1 will(returnValue(TestRole.class));
90  1 oneOf(bridge).getRoleHint(DOC_REFERENCE);
91  1 will(returnValue("test"));
92  1 oneOf(bridge).getScope(DOC_REFERENCE);
93  1 will(returnValue(WikiComponentScope.WIKI));
94  1 oneOf(bridge).getHandledMethods(DOC_REFERENCE);
95  1 will(returnValue(MapUtils.EMPTY_MAP));
96  1 oneOf(bridge).getDependencies(DOC_REFERENCE);
97  1 will(returnValue(MapUtils.EMPTY_MAP));
98  1 oneOf(bridge).getDeclaredInterfaces(DOC_REFERENCE);
99  1 will(returnValue(ListUtils.EMPTY_LIST));
100  1 oneOf(bridge).getSyntax(DOC_REFERENCE);
101  1 will(returnValue(Syntax.XWIKI_2_1));
102   
103  1 oneOf(authorization).hasAccess(Right.PROGRAM, DOC_REFERENCE);
104  1 will(returnValue(true));
105    }
106    });
107   
108  1 List<WikiComponent> components = this.builder.buildComponents(DOC_REFERENCE);
109   
110  1 Assert.assertEquals(1, components.size());
111    }
112    }