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