1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.component.wiki

File DefaultWikiComponentBuilderTest.java

 

Code metrics

0
30
5
1
106
75
6
0.2
6
5
1.2

Classes

Class Line # Actions
DefaultWikiComponentBuilderTest 39 30 0% 6 1
0.971428697.1%
 

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