1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
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) |
|
|
| 97.2% |
Uncovered Elements: 1 (36) |
Complexity: 6 |
Complexity Density: 0.19 |
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
53 |
2 |
@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 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
1PASS
|
|
61 |
1 |
@Test... |
62 |
|
public void buildComponentsWithoutProgrammingRights() throws Exception |
63 |
|
{ |
64 |
1 |
getMockery().checking(new Expectations() |
65 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
66 |
1 |
{... |
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
80 |
1 |
@Test... |
81 |
|
public void buildComponents() throws Exception |
82 |
|
{ |
83 |
1 |
getMockery().checking(new Expectations() |
84 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 1 |
Complexity Density: 0.06 |
|
85 |
1 |
{... |
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 |
|
} |