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.template;
20
21 import java.io.StringWriter;
22
23 import javax.faces.component.UIViewRoot;
24
25 import org.apache.myfaces.test.mock.MockResponseWriter;
26 import org.apache.myfaces.view.facelets.FaceletTestCase;
27 import org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage;
28 import org.junit.Assert;
29 import org.junit.Test;
30
31 public class UserTagTestCase extends FaceletTestCase
32 {
33
34 @Override
35 protected void setUpServletObjects() throws Exception
36 {
37 super.setUpServletObjects();
38 servletContext.addInitParameter(FaceletViewDeclarationLanguage.PARAM_SKIP_COMMENTS, "true");
39 servletContext.addInitParameter(FaceletViewDeclarationLanguage.PARAM_LIBRARIES, "/user.taglib.xml");
40 }
41
42 @Test
43 public void testUserTag1() throws Exception {
44
45 UIViewRoot root = facesContext.getViewRoot();
46 vdl.buildView(facesContext, root, "userTagTest1.xhtml");
47
48 StringWriter sw = new StringWriter();
49 MockResponseWriter mrw = new MockResponseWriter(sw);
50 facesContext.setResponseWriter(mrw);
51 root.encodeAll(facesContext);
52 sw.flush();
53
54 String response = sw.toString();
55
56 Assert.assertTrue(response.contains("Do you see me?"));
57 }
58
59 @Test
60 public void testUserTag2() throws Exception {
61
62 UIViewRoot root = facesContext.getViewRoot();
63 vdl.buildView(facesContext, root, "userTagTest2.xhtml");
64
65 StringWriter sw = new StringWriter();
66 MockResponseWriter mrw = new MockResponseWriter(sw);
67 facesContext.setResponseWriter(mrw);
68 root.encodeAll(facesContext);
69 sw.flush();
70
71 String response = sw.toString();
72
73 Assert.assertTrue(response.contains("Do you see me?"));
74 Assert.assertFalse(response.contains("This text should not be rendered"));
75 }
76
77 @Test
78 public void testUserTag3() throws Exception {
79
80 UIViewRoot root = facesContext.getViewRoot();
81 vdl.buildView(facesContext, root, "userTagTest3.xhtml");
82
83 StringWriter sw = new StringWriter();
84 MockResponseWriter mrw = new MockResponseWriter(sw);
85 facesContext.setResponseWriter(mrw);
86 root.encodeAll(facesContext);
87 sw.flush();
88
89 String response = sw.toString();
90
91 Assert.assertTrue(response.contains("Do you see me?"));
92 Assert.assertFalse(response.contains("This text should not be rendered"));
93 }
94
95 @Test
96 public void testUserTag4() throws Exception {
97
98 UIViewRoot root = facesContext.getViewRoot();
99 vdl.buildView(facesContext, root, "userTagTest4.xhtml");
100
101 StringWriter sw = new StringWriter();
102 MockResponseWriter mrw = new MockResponseWriter(sw);
103 facesContext.setResponseWriter(mrw);
104 root.encodeAll(facesContext);
105 sw.flush();
106
107 String response = sw.toString();
108
109 Assert.assertTrue(response.contains("Do you see me?"));
110 Assert.assertFalse(response.contains("This text should not be rendered"));
111 }
112
113 @Test
114 public void testUserTag5() throws Exception {
115
116 UIViewRoot root = facesContext.getViewRoot();
117 vdl.buildView(facesContext, root, "userTagTest5.xhtml");
118
119 StringWriter sw = new StringWriter();
120 MockResponseWriter mrw = new MockResponseWriter(sw);
121 facesContext.setResponseWriter(mrw);
122 root.encodeAll(facesContext);
123 sw.flush();
124
125 String response = sw.toString();
126
127 Assert.assertTrue(response.contains("Do you see me?"));
128 Assert.assertFalse(response.contains("This text should not be rendered"));
129 }
130
131 @Test
132 public void testUserTag6() throws Exception {
133
134 UIViewRoot root = facesContext.getViewRoot();
135 vdl.buildView(facesContext, root, "userTagTest6.xhtml");
136
137 StringWriter sw = new StringWriter();
138 MockResponseWriter mrw = new MockResponseWriter(sw);
139 facesContext.setResponseWriter(mrw);
140 root.encodeAll(facesContext);
141 sw.flush();
142
143 String response = sw.toString();
144
145 Assert.assertTrue(response.contains("Do you see me?"));
146 Assert.assertFalse(response.contains("This text should not be rendered"));
147 }
148
149 @Test
150 public void testUserTag7() throws Exception {
151
152 UIViewRoot root = facesContext.getViewRoot();
153 vdl.buildView(facesContext, root, "userTagTest7.xhtml");
154
155 StringWriter sw = new StringWriter();
156 MockResponseWriter mrw = new MockResponseWriter(sw);
157 facesContext.setResponseWriter(mrw);
158 root.encodeAll(facesContext);
159 sw.flush();
160
161 String response = sw.toString();
162
163 Assert.assertTrue(response.contains("Do you see me?"));
164 Assert.assertFalse(response.contains("This text should not be rendered"));
165 }
166
167 @Test
168 public void testUserTag8() throws Exception {
169
170 UIViewRoot root = facesContext.getViewRoot();
171 vdl.buildView(facesContext, root, "userTagTest8.xhtml");
172
173 StringWriter sw = new StringWriter();
174 MockResponseWriter mrw = new MockResponseWriter(sw);
175 facesContext.setResponseWriter(mrw);
176 root.encodeAll(facesContext);
177 sw.flush();
178
179 String response = sw.toString();
180
181 Assert.assertTrue(response.contains("Do you see me?"));
182 Assert.assertFalse(response.contains("This text should not be rendered"));
183 }
184 }