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.jstl.core;
20
21 import javax.el.ExpressionFactory;
22 import javax.faces.application.ViewHandler;
23 import javax.faces.component.UIViewRoot;
24 import javax.faces.context.ResponseWriter;
25
26 import org.apache.myfaces.view.facelets.FaceletTestCase;
27 import org.apache.myfaces.view.facelets.util.FastWriter;
28 import org.junit.Assert;
29 import org.junit.Test;
30
31 public class CsetTestCase extends FaceletTestCase {
32
33
34 @Override
35 protected void setUpServletObjects() throws Exception
36 {
37 super.setUpServletObjects();
38 servletContext.addInitParameter(ViewHandler.FACELETS_SKIP_COMMENTS_PARAM_NAME, "true");
39 servletContext.addInitParameter(ViewHandler.FACELETS_LIBRARIES_PARAM_NAME, "/user.taglib.xml");
40 }
41
42 @Override
43 protected ExpressionFactory createExpressionFactory()
44 {
45
46
47 return new org.apache.el.ExpressionFactoryImpl();
48 }
49
50
51
52
53
54
55 @Test
56 public void testCsetPageScope1() throws Exception
57 {
58 UIViewRoot root = facesContext.getViewRoot();
59 vdl.buildView(facesContext, root, "csetpagescope1.xhtml");
60
61 FastWriter fw = new FastWriter();
62 ResponseWriter rw = facesContext.getResponseWriter();
63 rw = rw.cloneWithWriter(fw);
64 facesContext.setResponseWriter(rw);
65 root.encodeAll(facesContext);
66 rw.flush();
67
68 String result = fw.toString();
69 Assert.assertFalse("Output should not contain 'doNotPrintValue'", result.contains("doNotPrintValue"));
70 }
71
72
73
74
75
76
77 @Test
78 public void testCsetPageScope2() throws Exception
79 {
80 UIViewRoot root = facesContext.getViewRoot();
81 vdl.buildView(facesContext, root, "csetpagescope2.xhtml");
82
83 FastWriter fw = new FastWriter();
84 ResponseWriter rw = facesContext.getResponseWriter();
85 rw = rw.cloneWithWriter(fw);
86 facesContext.setResponseWriter(rw);
87 root.encodeAll(facesContext);
88 rw.flush();
89
90 String result = fw.toString();
91 Assert.assertFalse("Output should not contain 'doNotPrintValue'", result.contains("doNotPrintValue"));
92 }
93
94
95
96
97
98
99
100
101 @Test
102 public void testCsetPageScope3() throws Exception
103 {
104 UIViewRoot root = facesContext.getViewRoot();
105 vdl.buildView(facesContext, root, "csetpagescope3.xhtml");
106
107 FastWriter fw = new FastWriter();
108 ResponseWriter rw = facesContext.getResponseWriter();
109 rw = rw.cloneWithWriter(fw);
110 facesContext.setResponseWriter(rw);
111 root.encodeAll(facesContext);
112 rw.flush();
113
114 String result = fw.toString();
115 Assert.assertFalse("Output should not contain 'doNotPrintValue'", result.contains("doNotPrintValue"));
116 }
117
118
119
120
121
122
123 @Test
124 public void testCsetPageScope4() throws Exception
125 {
126 UIViewRoot root = facesContext.getViewRoot();
127 vdl.buildView(facesContext, root, "csetpagescope4.xhtml");
128
129 FastWriter fw = new FastWriter();
130 ResponseWriter rw = facesContext.getResponseWriter();
131 rw = rw.cloneWithWriter(fw);
132 facesContext.setResponseWriter(rw);
133 root.encodeAll(facesContext);
134 rw.flush();
135
136 String result = fw.toString();
137 Assert.assertFalse("Output should not contain 'doNotPrintValue'", result.contains("doNotPrintValue"));
138 }
139
140
141
142
143
144
145 @Test
146 public void testCsetPageScope5() throws Exception
147 {
148 UIViewRoot root = facesContext.getViewRoot();
149 vdl.buildView(facesContext, root, "csetpagescope5.xhtml");
150
151 FastWriter fw = new FastWriter();
152 ResponseWriter rw = facesContext.getResponseWriter();
153 rw = rw.cloneWithWriter(fw);
154 facesContext.setResponseWriter(rw);
155 root.encodeAll(facesContext);
156 rw.flush();
157
158 String result = fw.toString();
159 Assert.assertFalse("Output should not contain 'doNotPrintValue'", result.contains("doNotPrintValue"));
160 }
161
162
163
164
165
166
167
168 @Test
169 public void testCsetPageScope6() throws Exception
170 {
171 UIViewRoot root = facesContext.getViewRoot();
172 vdl.buildView(facesContext, root, "csetpagescope6.xhtml");
173
174 FastWriter fw = new FastWriter();
175 ResponseWriter rw = facesContext.getResponseWriter();
176 rw = rw.cloneWithWriter(fw);
177 facesContext.setResponseWriter(rw);
178 root.encodeAll(facesContext);
179 rw.flush();
180
181 String result = fw.toString();
182 Assert.assertTrue("Output should contain 'rightValue'", result.contains("rightValue"));
183 Assert.assertFalse("Output should not contain 'doNotPrintValue'", result.contains("doNotPrintValue"));
184 }
185
186
187
188
189
190
191 @Test
192 public void testCsetPageScope7() throws Exception
193 {
194 UIViewRoot root = facesContext.getViewRoot();
195 vdl.buildView(facesContext, root, "csetpagescope7.xhtml");
196
197 FastWriter fw = new FastWriter();
198 ResponseWriter rw = facesContext.getResponseWriter();
199 rw = rw.cloneWithWriter(fw);
200 facesContext.setResponseWriter(rw);
201 root.encodeAll(facesContext);
202 rw.flush();
203
204 String result = fw.toString();
205 Assert.assertTrue("Output should contain 'rightValue'", result.contains("rightValue"));
206 Assert.assertFalse("Output should not contain 'doNotPrintValue'", result.contains("doNotPrintValue"));
207 }
208 }