1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.module.templating.renderers; |
35 |
|
|
36 |
|
import info.magnolia.cms.core.SystemProperty; |
37 |
|
import info.magnolia.module.templating.RenderableDefinition; |
38 |
|
import info.magnolia.module.templating.RenderingModel; |
39 |
|
import info.magnolia.cms.core.AggregationState; |
40 |
|
import info.magnolia.cms.core.Content; |
41 |
|
import info.magnolia.cms.util.ContentWrapper; |
42 |
|
import info.magnolia.context.MgnlContext; |
43 |
|
import info.magnolia.context.WebContext; |
44 |
|
import info.magnolia.module.templating.AbstractRenderer; |
45 |
|
import info.magnolia.module.templating.engine.DefaultRenderingEngine; |
46 |
|
import info.magnolia.module.templating.engine.RenderingEngine; |
47 |
|
import info.magnolia.module.templating.paragraphs.JspParagraphRenderer; |
48 |
|
import info.magnolia.test.ComponentsTestUtil; |
49 |
|
import junit.framework.TestCase; |
50 |
|
import static org.easymock.EasyMock.*; |
51 |
|
|
52 |
|
import java.lang.reflect.Method; |
53 |
|
import java.util.HashMap; |
54 |
|
import java.util.Map; |
55 |
|
|
56 |
|
|
57 |
|
@author |
58 |
|
@version |
59 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (32) |
Complexity: 4 |
Complexity Density: 0.15 |
|
60 |
|
public class JspTemplateRendererTest extends TestCase { |
61 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
62 |
1
|
protected void tearDown() throws Exception {... |
63 |
1
|
MgnlContext.setInstance(null); |
64 |
1
|
ComponentsTestUtil.clear(); |
65 |
1
|
SystemProperty.getProperties().clear(); |
66 |
1
|
super.tearDown(); |
67 |
|
} |
68 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 1 |
Complexity Density: 0.05 |
1
PASS
|
|
69 |
1
|
public void testExposesNodesAsMaps() throws Exception {... |
70 |
1
|
final WebContext magnoliaCtx = createStrictMock(WebContext.class); |
71 |
1
|
MgnlContext.setInstance(magnoliaCtx); |
72 |
1
|
ComponentsTestUtil.setImplementation(RenderingEngine.class, DefaultRenderingEngine.class); |
73 |
|
|
74 |
1
|
final Content page = createStrictMock(Content.class); |
75 |
1
|
expect(page.getHandle()).andReturn("/myPage").times(2); |
76 |
|
|
77 |
1
|
final AggregationState aggState = new AggregationState(); |
78 |
1
|
aggState.setMainContent(page); |
79 |
1
|
expect(magnoliaCtx.getAggregationState()).andStubReturn(aggState); |
80 |
|
|
81 |
1
|
replay(magnoliaCtx, page); |
82 |
1
|
final Map templateCtx = new HashMap(); |
83 |
1
|
final JspParagraphRenderer renderer = new JspParagraphRenderer(); |
84 |
|
|
85 |
|
|
86 |
1
|
Method setupContextMethod = AbstractRenderer.class.getDeclaredMethod("setupContext", new Class[]{Map.class, Content.class, RenderableDefinition.class, RenderingModel.class, Object.class}); |
87 |
1
|
setupContextMethod.setAccessible(true); |
88 |
1
|
setupContextMethod.invoke(renderer, new Object[]{templateCtx, page, null, null, null}); |
89 |
|
|
90 |
|
|
91 |
1
|
assertEquals("Unexpected amount of objects in context", 7, templateCtx.size()); |
92 |
1
|
assertTrue(templateCtx.get("actpage") instanceof Map); |
93 |
1
|
assertEquals(page, unwrap((Content) templateCtx.get("actpage"))); |
94 |
|
|
95 |
1
|
assertTrue(templateCtx.get("content") instanceof Map); |
96 |
1
|
assertEquals(page, unwrap((Content) templateCtx.get("content"))); |
97 |
|
|
98 |
1
|
verify(magnoliaCtx, page); |
99 |
|
} |
100 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
101 |
6
|
private Content unwrap(Content c) {... |
102 |
6
|
if (c instanceof ContentWrapper) { |
103 |
4
|
return unwrap(((ContentWrapper) c).getWrappedContent()); |
104 |
|
} |
105 |
2
|
return c; |
106 |
|
} |
107 |
|
} |