1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.myfaces.view.facelets.tag.ui;
21
22 import javax.el.ExpressionFactory;
23 import javax.faces.component.UINamingContainer;
24 import javax.faces.component.UIOutput;
25 import javax.faces.component.UIPanel;
26 import javax.faces.component.UIViewRoot;
27 import javax.faces.component.html.HtmlOutputText;
28 import javax.faces.context.ResponseWriter;
29
30 import org.apache.myfaces.config.RuntimeConfig;
31 import org.apache.myfaces.renderkit.html.HtmlCompositeComponentRenderer;
32 import org.apache.myfaces.renderkit.html.HtmlCompositeFacetRenderer;
33 import org.apache.myfaces.renderkit.html.HtmlTextRenderer;
34 import org.apache.myfaces.test.mock.MockExternalContext;
35 import org.apache.myfaces.view.facelets.ELExpressionCacheMode;
36 import org.apache.myfaces.view.facelets.FaceletTestCase;
37 import org.apache.myfaces.view.facelets.impl.FaceletCompositionContextImpl;
38 import org.apache.myfaces.view.facelets.tag.jsf.ComponentSupport;
39 import org.apache.myfaces.view.facelets.util.FastWriter;
40 import org.junit.Assert;
41 import org.junit.Test;
42
43 public class IncludeParamTestCase extends FaceletTestCase
44 {
45
46 @Override
47 protected void setupComponents() throws Exception
48 {
49 application.addComponent(UIViewRoot.COMPONENT_TYPE, UIViewRoot.class
50 .getName());
51 application.addComponent(HtmlOutputText.COMPONENT_TYPE,
52 HtmlOutputText.class.getName());
53 application.addComponent(UINamingContainer.COMPONENT_TYPE,
54 UINamingContainer.class.getName());
55 application.addComponent(UIPanel.COMPONENT_TYPE,
56 UIPanel.class.getName());
57 }
58
59 @Override
60 protected void setupConvertersAndValidators() throws Exception
61 {
62 }
63
64 @Override
65 protected void setupRenderers() throws Exception
66 {
67 renderKit.addRenderer(UIOutput.COMPONENT_FAMILY, "javax.faces.Text",
68 new HtmlTextRenderer());
69 renderKit.addRenderer(UINamingContainer.COMPONENT_TYPE,
70 "javax.faces.Composite", new HtmlCompositeComponentRenderer());
71 renderKit.addRenderer(UIOutput.COMPONENT_TYPE,
72 "javax.faces.CompositeFacet", new HtmlCompositeFacetRenderer());
73 }
74
75 @Override
76 protected ExpressionFactory createExpressionFactory()
77 {
78
79
80 return new org.apache.el.ExpressionFactoryImpl();
81 }
82
83 @Test
84 public void testCaching() throws Exception
85 {
86 UIViewRoot root = facesContext.getViewRoot();
87
88 request.setAttribute("test", "test2.xml");
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114 System.out.println("ApplicationImpl:" + facesContext.getApplication().getClass().getName());
115 System.out.println("ExpressionFactory:" + facesContext.getApplication().getExpressionFactory().getClass().getName());
116
117 vdl.buildView(facesContext, root, "test1.xml");
118
119 FastWriter fw = new FastWriter();
120 ResponseWriter rw = facesContext.getResponseWriter();
121 rw = rw.cloneWithWriter(fw);
122 facesContext.setResponseWriter(rw);
123 root.encodeAll(facesContext);
124
125 String result = fw.toString();
126
127 Assert.assertTrue("Output:" + result, result.contains("<p>Component value: page test2</p>"));
128 Assert.assertTrue("Output:" + result,result.contains("<p>Inline EL value: page test2</p>"));
129
130
131
132 ComponentSupport.removeTransient(root);
133
134 request.setAttribute("test", "test3.xml");
135
136 facesContext.setViewRoot(facesContext.getApplication().getViewHandler()
137 .createView(facesContext, "/test"));
138 root = facesContext.getViewRoot();
139
140 vdl.buildView(facesContext, root, "test1.xml");
141
142 fw = new FastWriter();
143 rw = facesContext.getResponseWriter();
144 rw = rw.cloneWithWriter(fw);
145 facesContext.setResponseWriter(rw);
146 root.encodeAll(facesContext);
147 rw.flush();
148
149
150 result = fw.toString();
151
152 Assert.assertTrue("Output:" + result, result.contains("<p>Component value: page test3</p>"));
153 Assert.assertTrue("Output:" + result, result.contains("<p>Inline EL value: page test3</p>"));
154
155 }
156
157 @Test
158 public void testSimpleCompositionParam() throws Exception
159 {
160 UIViewRoot root = facesContext.getViewRoot();
161 vdl.buildView(facesContext, root, "simpleCompositionParam.xhtml");
162
163 FastWriter fw = new FastWriter();
164 ResponseWriter rw = facesContext.getResponseWriter();
165 rw = rw.cloneWithWriter(fw);
166 facesContext.setResponseWriter(rw);
167 root.encodeAll(facesContext);
168 rw.flush();
169
170 String result = fw.toString();
171 Assert.assertTrue("Output:" + result, result.contains("value1"));
172 }
173
174
175
176
177
178
179
180 @Test
181 public void testUIParamTemplateScope1() throws Exception
182 {
183 UIViewRoot root = facesContext.getViewRoot();
184 vdl.buildView(facesContext, root, "uiparamtemplatescope1.xhtml");
185
186 FastWriter fw = new FastWriter();
187 ResponseWriter rw = facesContext.getResponseWriter();
188 rw = rw.cloneWithWriter(fw);
189 facesContext.setResponseWriter(rw);
190 root.encodeAll(facesContext);
191 rw.flush();
192
193 String result = fw.toString();
194 Assert.assertTrue("Output should contain 'rightValue'", result.contains("rightValue"));
195 Assert.assertFalse("Output should not contain 'doNotPrintValue'", result.contains("doNotPrintValue"));
196 }
197
198
199
200
201
202
203
204 @Test
205 public void testUIParamTemplateScope2() throws Exception
206 {
207 UIViewRoot root = facesContext.getViewRoot();
208 vdl.buildView(facesContext, root, "uiparamtemplatescope2.xhtml");
209
210 FastWriter fw = new FastWriter();
211 ResponseWriter rw = facesContext.getResponseWriter();
212 rw = rw.cloneWithWriter(fw);
213 facesContext.setResponseWriter(rw);
214 root.encodeAll(facesContext);
215 rw.flush();
216
217 String result = fw.toString();
218 Assert.assertFalse("Output should not contain 'doNotPrintValue'", result.contains("doNotPrintValue"));
219 }
220
221
222
223
224
225
226
227 @Test
228 public void testUIParamTemplateScope3() throws Exception
229 {
230 UIViewRoot root = facesContext.getViewRoot();
231 vdl.buildView(facesContext, root, "uiparamtemplatescope3.xhtml");
232
233 FastWriter fw = new FastWriter();
234 ResponseWriter rw = facesContext.getResponseWriter();
235 rw = rw.cloneWithWriter(fw);
236 facesContext.setResponseWriter(rw);
237 root.encodeAll(facesContext);
238 rw.flush();
239
240 String result = fw.toString();
241 Assert.assertTrue("Output should contain 'rightValue'", result.contains("rightValue"));
242 Assert.assertFalse("Output should not contain 'doNotPrintValue'", result.contains("doNotPrintValue"));
243 }
244
245
246
247
248
249
250
251 @Test
252 public void testUIParamTemplateScope4() throws Exception
253 {
254 UIViewRoot root = facesContext.getViewRoot();
255 vdl.buildView(facesContext, root, "uiparamtemplatescope4.xhtml");
256
257 FastWriter fw = new FastWriter();
258 ResponseWriter rw = facesContext.getResponseWriter();
259 rw = rw.cloneWithWriter(fw);
260 facesContext.setResponseWriter(rw);
261 root.encodeAll(facesContext);
262 rw.flush();
263
264 String result = fw.toString();
265 Assert.assertTrue("Output should contain 'rightValue'", result.contains("rightValue"));
266 Assert.assertFalse("Output should not contain 'doNotPrintValue'", result.contains("doNotPrintValue"));
267 }
268
269
270
271
272
273
274 @Test
275 public void testUIParamTemplateScope5() throws Exception
276 {
277 UIViewRoot root = facesContext.getViewRoot();
278 vdl.buildView(facesContext, root, "uiparamtemplatescope5.xhtml");
279
280 FastWriter fw = new FastWriter();
281 ResponseWriter rw = facesContext.getResponseWriter();
282 rw = rw.cloneWithWriter(fw);
283 facesContext.setResponseWriter(rw);
284 root.encodeAll(facesContext);
285 rw.flush();
286
287 String result = fw.toString();
288 Assert.assertTrue("Output should contain 'rightValue'", result.contains("rightValue"));
289 Assert.assertTrue("Output should contain 'right2Value'", result.contains("right2Value"));
290 Assert.assertFalse("Output should not contain 'doNotPrintValue'", result.contains("doNotPrintValue"));
291 }
292
293
294
295
296
297
298
299 @Test
300 public void testUIParamTemplateScope6() throws Exception
301 {
302 UIViewRoot root = facesContext.getViewRoot();
303 vdl.buildView(facesContext, root, "uiparamtemplatescope6.xhtml");
304
305 FastWriter fw = new FastWriter();
306 ResponseWriter rw = facesContext.getResponseWriter();
307 rw = rw.cloneWithWriter(fw);
308 facesContext.setResponseWriter(rw);
309 root.encodeAll(facesContext);
310 rw.flush();
311
312 String result = fw.toString();
313 Assert.assertTrue("Output should contain 'rightValue'", result.contains("rightValue"));
314 Assert.assertFalse("Output should not contain 'doNotPrintValue'", result.contains("doNotPrintValue"));
315 }
316
317
318
319
320
321
322
323
324 @Test
325 public void testUIParamTemplateScope7() throws Exception
326 {
327 UIViewRoot root = facesContext.getViewRoot();
328 vdl.buildView(facesContext, root, "uiparamtemplatescope7.xhtml");
329
330 FastWriter fw = new FastWriter();
331 ResponseWriter rw = facesContext.getResponseWriter();
332 rw = rw.cloneWithWriter(fw);
333 facesContext.setResponseWriter(rw);
334 root.encodeAll(facesContext);
335 rw.flush();
336
337 String result = fw.toString();
338 Assert.assertTrue("Output should contain 'value1'", result.contains("value1"));
339 Assert.assertTrue("Output should contain 'value2'", result.contains("value2"));
340 Assert.assertTrue("Output should contain 'value3'", result.contains("value3"));
341 Assert.assertTrue("Output should contain 'value4'", result.contains("value4"));
342 Assert.assertTrue("Output should contain 'value5'", result.contains("value5"));
343 Assert.assertTrue("Output should contain 'valu1e5'", result.contains("valu1e5"));
344 Assert.assertTrue("Output should contain 'valu1e6'", result.contains("valu1e6"));
345 Assert.assertFalse("Output should not contain 'value6'", result.contains("value6"));
346 }
347 }