1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.view.facelets.tag.ui;
20
21 import javax.faces.component.UIViewRoot;
22 import javax.faces.context.ResponseWriter;
23
24 import org.apache.myfaces.view.facelets.FaceletTestCase;
25 import org.apache.myfaces.view.facelets.util.FastWriter;
26 import org.junit.Assert;
27 import org.junit.Test;
28
29
30
31
32
33
34
35 public class TemplateTestCase extends FaceletTestCase
36 {
37
38 private FastWriter _writer;
39
40 public void setUp() throws Exception
41 {
42 super.setUp();
43
44
45 _writer = new FastWriter();
46 ResponseWriter rw = facesContext.getResponseWriter();
47 rw = rw.cloneWithWriter(_writer);
48 facesContext.setResponseWriter(rw);
49 }
50
51 @Override
52 public void tearDown() throws Exception
53 {
54 _writer = null;
55
56 super.tearDown();
57 }
58
59
60
61
62
63
64 @Test
65 public void testInsertWithoutNameComposition() throws Exception
66 {
67 _testInsertWithoutName("s_page_composition.xhtml");
68 }
69
70
71
72
73
74
75 @Test
76 public void testInsertWithoutNameDecorate() throws Exception
77 {
78 _testInsertWithoutName("s_page_decorate.xhtml");
79 }
80
81 private void _testInsertWithoutName(String page) throws Exception
82 {
83 UIViewRoot root = facesContext.getViewRoot();
84 vdl.buildView(facesContext, root, page);
85
86
87 root.encodeAll(facesContext);
88 final String output = _writer.toString();
89
90
91 Assert.assertTrue(output.contains("<span id=\"body\">BODY</span>"));
92 Assert.assertTrue(output.contains("<span id=\"popupSpan\"><p>[POPUPCONTENT]</p></span>"));
93 }
94
95
96
97
98
99
100 @Test
101 public void testInsertWithDefinedNameDecorate() throws Exception
102 {
103 _testInsertWithDefinedName("decorate_with_template_and_define.xhtml");
104 }
105
106
107
108
109
110
111 @Test
112 public void testInsertWithDefinedNameComposition() throws Exception
113 {
114 _testInsertWithDefinedName("composition_with_template_and_define.xhtml");
115 }
116
117 private void _testInsertWithDefinedName(String page) throws Exception
118 {
119 UIViewRoot root = facesContext.getViewRoot();
120 vdl.buildView(facesContext, root, page);
121
122
123 root.encodeAll(facesContext);
124 final String output = _writer.toString();
125
126
127 Assert.assertTrue(output.contains("<span>defined content</span>"));
128 }
129
130
131
132
133
134
135
136 @Test
137 public void testInsertWithoutDefinedNameDecorate() throws Exception
138 {
139 _testInsertWithoutDefinedName("decorate_with_template.xhtml");
140 }
141
142
143
144
145
146
147
148 @Test
149 public void testInsertWithoutDefinedNameComposition() throws Exception
150 {
151 _testInsertWithoutDefinedName("composition_with_template.xhtml");
152 }
153
154 private void _testInsertWithoutDefinedName(String page) throws Exception
155 {
156 UIViewRoot root = facesContext.getViewRoot();
157 vdl.buildView(facesContext, root, page);
158
159
160 root.encodeAll(facesContext);
161 final String output = _writer.toString();
162
163
164 Assert.assertTrue(output
165 .contains("<span>default ui:insert content</span>"));
166 }
167
168
169
170
171
172
173
174
175 @Test
176 public void _testMultilevelTemplating() throws Exception
177 {
178 UIViewRoot root = facesContext.getViewRoot();
179 vdl.buildView(facesContext, root,
180 "multilevel_template_OuterClient_with_define.xhtml");
181
182
183 root.encodeAll(facesContext);
184 String output = _writer.toString();
185 output = output.replaceAll("(?s)<!--.*?-->", "");
186
187
188 Assert.assertTrue(output.contains("<body>inner content</body>"));
189 }
190
191
192
193
194
195
196
197
198
199 @Test
200 public void _testMultilevelTemplatingInnerFallback() throws Exception
201 {
202 UIViewRoot root = facesContext.getViewRoot();
203 vdl.buildView(facesContext, root,
204 "multilevel_template_OuterClient.xhtml");
205
206
207 root.encodeAll(facesContext);
208 String output = _writer.toString();
209 output = output.replaceAll("(?s)<!--.*?-->", "");
210
211
212 Assert.assertTrue(output
213 .contains("<body>inner fallback content</body>"));
214 }
215
216 }