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; |
35 |
|
|
36 |
|
import info.magnolia.cms.core.Content; |
37 |
|
import info.magnolia.cms.core.SystemProperty; |
38 |
|
import info.magnolia.context.MgnlContext; |
39 |
|
import info.magnolia.context.WebContext; |
40 |
|
import info.magnolia.test.ComponentsTestUtil; |
41 |
|
import info.magnolia.test.MgnlTestCase; |
42 |
|
import info.magnolia.test.mock.MockUtil; |
43 |
|
|
44 |
|
import java.io.IOException; |
45 |
|
import java.io.StringWriter; |
46 |
|
|
47 |
|
import javax.jcr.RepositoryException; |
48 |
|
import javax.servlet.jsp.PageContext; |
49 |
|
|
50 |
|
import static org.easymock.classextension.EasyMock.*; |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
@author |
55 |
|
@version |
56 |
|
|
|
|
| 98.2% |
Uncovered Elements: 1 (57) |
Complexity: 7 |
Complexity Density: 0.14 |
|
57 |
|
public class ParagraphRenderingFacadeTest extends MgnlTestCase { |
58 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
59 |
3
|
protected void setUp() throws Exception {... |
60 |
3
|
MgnlContext.setInstance(null); |
61 |
3
|
super.setUp(); |
62 |
|
} |
63 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
64 |
3
|
protected void tearDown() throws Exception {... |
65 |
3
|
MgnlContext.setInstance(null); |
66 |
3
|
ComponentsTestUtil.clear(); |
67 |
3
|
SystemProperty.getProperties().clear(); |
68 |
3
|
super.tearDown(); |
69 |
|
} |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 1 |
Complexity Density: 0.07 |
1
PASS
|
|
71 |
1
|
public void testRenderCallsTheAppropriateRenderer() throws Exception {... |
72 |
1
|
final ParagraphRendererManager prm = new ParagraphRendererManager(); |
73 |
1
|
prm.onRegister(getNode(CONFIGNODE1_RENDERER, "/modules/test/paragraph-renderers")); |
74 |
1
|
final ParagraphRenderingFacade prf = new ParagraphRenderingFacade(prm, null); |
75 |
|
|
76 |
1
|
final Paragraph tra = new Paragraph(); |
77 |
1
|
tra.setName("para-one"); |
78 |
1
|
tra.setType("foo"); |
79 |
1
|
final StringWriter res = new StringWriter(); |
80 |
1
|
prf.render(null, tra, res); |
81 |
1
|
assertEquals("tralala:para-one", res.toString()); |
82 |
|
|
83 |
1
|
final Paragraph tru = new Paragraph(); |
84 |
1
|
tru.setName("para-two"); |
85 |
1
|
tru.setType("bar"); |
86 |
1
|
final StringWriter res2 = new StringWriter(); |
87 |
1
|
prf.render(null, tru, res2); |
88 |
1
|
assertEquals("trululu:para-two", res2.toString()); |
89 |
|
} |
90 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 1 |
Complexity Density: 0.07 |
1
PASS
|
|
91 |
1
|
public void testSetsJspPageContext() throws Exception {... |
92 |
1
|
final ParagraphRendererManager prm = new ParagraphRendererManager(); |
93 |
1
|
prm.onRegister(getNode(CONFIGNODE1_RENDERER, "/modules/test/paragraph-renderers")); |
94 |
1
|
final ParagraphRenderingFacade prf = new ParagraphRenderingFacade(prm, null); |
95 |
|
|
96 |
1
|
final Paragraph tra = new Paragraph(); |
97 |
1
|
tra.setName("para-one"); |
98 |
1
|
tra.setType("foo"); |
99 |
1
|
final StringWriter res = new StringWriter(); |
100 |
|
|
101 |
1
|
PageContext pageContext = createMock(PageContext.class); |
102 |
1
|
WebContext webContext = createStrictMock(WebContext.class); |
103 |
|
|
104 |
1
|
webContext.setPageContext(pageContext); |
105 |
|
|
106 |
1
|
replay(pageContext, webContext); |
107 |
1
|
MgnlContext.setInstance(webContext); |
108 |
1
|
prf.render(null, tra, res, pageContext); |
109 |
1
|
verify(pageContext, webContext); |
110 |
|
|
111 |
1
|
assertEquals("tralala:para-one", res.toString()); |
112 |
|
} |
113 |
|
|
|
|
| 92.9% |
Uncovered Elements: 1 (14) |
Complexity: 2 |
Complexity Density: 0.14 |
1
PASS
|
|
114 |
1
|
public void testUsesTheAppropriateParagraphWhenNotExplicitelyPassed() throws Exception {... |
115 |
1
|
final ParagraphRendererManager prm = new ParagraphRendererManager(); |
116 |
1
|
final ParagraphManager pm = new ParagraphManager(); |
117 |
1
|
final ParagraphRenderingFacade prf = new ParagraphRenderingFacade(prm, pm); |
118 |
|
|
119 |
1
|
prm.onRegister(getNode(CONFIGNODE1_RENDERER, "/modules/test/paragraph-renderers")); |
120 |
1
|
final Content content = getNode(CONTENTNODE1, "/foo/bar/MyPage"); |
121 |
|
|
122 |
1
|
try { |
123 |
1
|
prf.render(content, new StringWriter()); |
124 |
0
|
fail("should have failed"); |
125 |
|
} |
126 |
|
catch (IllegalStateException e) { |
127 |
1
|
assertEquals("Paragraph para1 not found for page /foo/bar/MyPage", e.getMessage()); |
128 |
|
} |
129 |
|
|
130 |
|
|
131 |
1
|
pm.addParagraphToCache(getNode(CONFIG_PARAGRAPH1, "modules/test/paragraph/para1")); |
132 |
1
|
pm.addParagraphToCache(getNode(CONFIG_PARAGRAPH2, "modules/test/paragraph/para2")); |
133 |
1
|
final StringWriter out = new StringWriter(); |
134 |
1
|
prf.render(content, out); |
135 |
1
|
assertEquals("tralala:para1", out.toString()); |
136 |
|
} |
137 |
|
|
138 |
|
private static final String CONFIGNODE1_RENDERER = "" |
139 |
|
+ "modules.test.paragraph-renderers.foo.@type=mgnl:contentNode\n" |
140 |
|
+ "modules.test.paragraph-renderers.foo.name=foo\n" |
141 |
|
+ "modules.test.paragraph-renderers.foo.class=info.magnolia.module.templating.ParagraphRendererManagerTest$DummyParagraphRenderer\n" |
142 |
|
+ "modules.test.paragraph-renderers.bar.@type=mgnl:contentNode\n" |
143 |
|
+ "modules.test.paragraph-renderers.bar.name=bar\n" |
144 |
|
+ "modules.test.paragraph-renderers.bar.class=info.magnolia.module.templating.ParagraphRendererManagerTest$OtherDummyParagraphRenderer"; |
145 |
|
|
146 |
|
private static final String CONFIG_PARAGRAPH1 = "" |
147 |
|
+ "modules.test.paragraph.para1.@type=mgnl:contentNode\n" |
148 |
|
+ "modules.test.paragraph.para1.name=para1\n" |
149 |
|
+ "modules.test.paragraph.para1.type=foo"; |
150 |
|
|
151 |
|
private static final String CONFIG_PARAGRAPH2 = "" |
152 |
|
+ "modules.test.paragraph.para2.@type=mgnl:contentNode\n" |
153 |
|
+ "modules.test.paragraph.para2.name=para2\n" |
154 |
|
+ "modules.test.paragraph.para2.type=foo"; |
155 |
|
|
156 |
|
private static final String CONTENTNODE1 = "" |
157 |
|
+ "foo.bar.MyPage.text=hello\n" |
158 |
|
+ "foo.bar.MyPage.MetaData.mgnl\\:template=para1"; |
159 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
160 |
6
|
private Content getNode(String configNode, String path) throws IOException, RepositoryException {... |
161 |
6
|
return MockUtil.createHierarchyManager(configNode).getContent(path); |
162 |
|
} |
163 |
|
} |