1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.rendering.macro.dashboard; |
21 |
|
|
22 |
|
import java.io.Reader; |
23 |
|
import java.io.Writer; |
24 |
|
import java.util.Arrays; |
25 |
|
import java.util.Collections; |
26 |
|
import java.util.Map; |
27 |
|
import java.util.Properties; |
28 |
|
|
29 |
|
import org.apache.velocity.VelocityContext; |
30 |
|
import org.hamcrest.core.AnyOf; |
31 |
|
import org.jmock.Expectations; |
32 |
|
import org.jmock.Mockery; |
33 |
|
import org.jmock.api.Invocation; |
34 |
|
import org.jmock.integration.junit4.JUnit4Mockery; |
35 |
|
import org.jmock.lib.action.CustomAction; |
36 |
|
import org.junit.runner.RunWith; |
37 |
|
import org.xwiki.component.manager.ComponentManager; |
38 |
|
import org.xwiki.rendering.block.Block; |
39 |
|
import org.xwiki.rendering.block.MacroBlock; |
40 |
|
import org.xwiki.rendering.block.WordBlock; |
41 |
|
import org.xwiki.rendering.test.integration.RenderingTestSuite; |
42 |
|
import org.xwiki.rendering.transformation.MacroTransformationContext; |
43 |
|
import org.xwiki.security.authorization.ContextualAuthorizationManager; |
44 |
|
import org.xwiki.skinx.SkinExtension; |
45 |
|
import org.xwiki.test.jmock.MockingComponentManager; |
46 |
|
import org.xwiki.velocity.VelocityEngine; |
47 |
|
import org.xwiki.velocity.VelocityManager; |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
@link |
52 |
|
|
53 |
|
@version |
54 |
|
@since |
55 |
|
|
56 |
|
@RunWith(RenderingTestSuite.class) |
|
|
| 100% |
Uncovered Elements: 0 (45) |
Complexity: 6 |
Complexity Density: 0.15 |
|
57 |
|
public class IntegrationTest |
58 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
|
59 |
2 |
@RenderingTestSuite.Initialized... |
60 |
|
@SuppressWarnings("unchecked") |
61 |
|
public void initialize(final MockingComponentManager componentManager) throws Exception |
62 |
|
{ |
63 |
2 |
Mockery mockery = new JUnit4Mockery(); |
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
2 |
componentManager.unregisterComponent(ComponentManager.class, "context"); |
70 |
|
|
71 |
2 |
final SkinExtension mockSsfx = |
72 |
|
componentManager.registerMockComponent(mockery, SkinExtension.class, "ssfx", "ssfxMock"); |
73 |
2 |
final SkinExtension mockJsfx = |
74 |
|
componentManager.registerMockComponent(mockery, SkinExtension.class, "jsfx", "jsfxMock"); |
75 |
2 |
mockery.checking(new Expectations() |
76 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
77 |
2 |
{... |
78 |
2 |
allowing(mockSsfx).use(with("uicomponents/container/columns.css"), with(any(Map.class))); |
79 |
2 |
allowing(mockSsfx).use(with("uicomponents/dashboard/dashboard.css"), with(any(Map.class))); |
80 |
2 |
allowing(mockJsfx).use(with("js/scriptaculous/dragdrop.js")); |
81 |
2 |
allowing(mockJsfx).use(with("js/scriptaculous/effects.js")); |
82 |
2 |
allowing(mockJsfx).use(with("js/xwiki/wysiwyg/xwe/XWikiWysiwyg.js"), with(any(Map.class))); |
83 |
2 |
allowing(mockJsfx).use(with("uicomponents/dashboard/dashboard.js"), with(any(Map.class))); |
84 |
|
} |
85 |
|
}); |
86 |
|
|
87 |
2 |
final GadgetSource mockGadgetSource = componentManager.registerMockComponent(mockery, GadgetSource.class); |
88 |
2 |
mockery.checking(new Expectations() |
89 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
90 |
2 |
{... |
91 |
|
|
92 |
2 |
allowing(mockGadgetSource).getGadgets(with("nested_velocity"), |
93 |
|
with(any(MacroTransformationContext.class))); |
94 |
2 |
will( |
95 |
|
returnValue( |
96 |
|
Arrays |
97 |
|
.asList( |
98 |
|
new Gadget("0", Arrays.<Block>asList(new WordBlock("title")), |
99 |
|
Arrays.<Block>asList(new MacroBlock("velocity", |
100 |
|
Collections.<String, String>emptyMap(), "someVelocityCodeHere", true)), |
101 |
|
"1,1")))); |
102 |
|
|
103 |
|
|
104 |
2 |
allowing(mockGadgetSource).getGadgets(with(aNull(String.class)), |
105 |
|
with(any(MacroTransformationContext.class))); |
106 |
2 |
will(returnValue(Arrays.asList(new Gadget("0", Arrays.<Block>asList(new WordBlock("title")), |
107 |
|
Arrays.<Block>asList(new WordBlock("content")), "1,1")))); |
108 |
|
|
109 |
2 |
allowing(mockGadgetSource).getDashboardSourceMetadata( |
110 |
|
with(AnyOf.anyOf(aNull(String.class), any(String.class))), |
111 |
|
with(any(MacroTransformationContext.class))); |
112 |
2 |
will(returnValue(Collections.<Block>emptyList())); |
113 |
|
|
114 |
2 |
allowing(mockGadgetSource).isEditing(); |
115 |
|
|
116 |
2 |
will(returnValue(true)); |
117 |
|
} |
118 |
|
}); |
119 |
|
|
120 |
|
|
121 |
|
|
122 |
2 |
final VelocityManager mockVelocityManager = |
123 |
|
componentManager.registerMockComponentWithId(mockery, VelocityManager.class, "velocityManagerMock"); |
124 |
2 |
mockery.checking(new Expectations() |
125 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
126 |
2 |
{... |
127 |
2 |
allowing(mockVelocityManager).getVelocityContext(); |
128 |
2 |
will(returnValue(new VelocityContext())); |
129 |
2 |
allowing(mockVelocityManager).getCurrentVelocityContext(); |
130 |
2 |
will(returnValue(new VelocityContext())); |
131 |
2 |
allowing(mockVelocityManager).getVelocityEngine(); |
132 |
2 |
will(doAll(new CustomAction("mockGetVelocityEngine") |
133 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
134 |
6 |
@Override... |
135 |
|
public Object invoke(Invocation invocation) throws Throwable |
136 |
|
{ |
137 |
6 |
VelocityEngine velocityEngine = componentManager.getInstance(VelocityEngine.class); |
138 |
6 |
Properties properties = new Properties(); |
139 |
6 |
properties.setProperty("resource.loader", "file"); |
140 |
6 |
velocityEngine.initialize(properties); |
141 |
|
|
142 |
6 |
return velocityEngine; |
143 |
|
} |
144 |
|
|
145 |
|
})); |
146 |
2 |
allowing(mockVelocityManager).evaluate(with(any(Writer.class)), with(any(String.class)), |
147 |
|
with(any(Reader.class))); |
148 |
2 |
will(doAll(new CustomAction("mockEvaluate") |
149 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
150 |
2 |
@Override... |
151 |
|
public Object invoke(Invocation invocation) throws Throwable |
152 |
|
{ |
153 |
2 |
VelocityEngine velocityEngine = mockVelocityManager.getVelocityEngine(); |
154 |
|
|
155 |
2 |
return velocityEngine.evaluate(mockVelocityManager.getVelocityContext(), |
156 |
|
(Writer) invocation.getParameter(0), (String) invocation.getParameter(1), |
157 |
|
(Reader) invocation.getParameter(2)); |
158 |
|
} |
159 |
|
|
160 |
|
})); |
161 |
|
} |
162 |
|
}); |
163 |
|
|
164 |
2 |
componentManager.registerMockComponent(mockery, ContextualAuthorizationManager.class); |
165 |
|
} |
166 |
|
} |