View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.view.facelets.tag.ui.template;
20  
21  import java.io.StringWriter;
22  import javax.faces.application.ViewHandler;
23  
24  import javax.faces.component.UIViewRoot;
25  
26  import org.apache.myfaces.test.mock.MockResponseWriter;
27  import org.apache.myfaces.view.facelets.FaceletTestCase;
28  import org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage;
29  import org.junit.Assert;
30  import org.junit.Test;
31  
32  public class UserTagTestCase extends FaceletTestCase
33  {
34      
35      @Override
36      protected void setUpServletObjects() throws Exception
37      {
38          super.setUpServletObjects();
39          servletContext.addInitParameter(ViewHandler.FACELETS_SKIP_COMMENTS_PARAM_NAME, "true");
40          servletContext.addInitParameter(ViewHandler.FACELETS_LIBRARIES_PARAM_NAME, "/user.taglib.xml");
41      }
42      
43      @Test
44      public void testUserTag1() throws Exception {
45          
46          UIViewRoot root = facesContext.getViewRoot();
47          vdl.buildView(facesContext, root, "userTagTest1.xhtml");
48          
49          StringWriter sw = new StringWriter();
50          MockResponseWriter mrw = new MockResponseWriter(sw);
51          facesContext.setResponseWriter(mrw);
52          root.encodeAll(facesContext);
53          sw.flush();
54          
55          String response = sw.toString();
56          
57          Assert.assertTrue(response.contains("Do you see me?"));
58      }
59  
60      @Test
61      public void testUserTag2() throws Exception {
62          
63          UIViewRoot root = facesContext.getViewRoot();
64          vdl.buildView(facesContext, root, "userTagTest2.xhtml");
65          
66          StringWriter sw = new StringWriter();
67          MockResponseWriter mrw = new MockResponseWriter(sw);
68          facesContext.setResponseWriter(mrw);
69          root.encodeAll(facesContext);
70          sw.flush();
71          
72          String response = sw.toString();
73          
74          Assert.assertTrue(response.contains("Do you see me?"));
75          Assert.assertFalse(response.contains("This text should not be rendered"));
76      }
77      
78      @Test
79      public void testUserTag3() throws Exception {
80          
81          UIViewRoot root = facesContext.getViewRoot();
82          vdl.buildView(facesContext, root, "userTagTest3.xhtml");
83          
84          StringWriter sw = new StringWriter();
85          MockResponseWriter mrw = new MockResponseWriter(sw);
86          facesContext.setResponseWriter(mrw);
87          root.encodeAll(facesContext);
88          sw.flush();
89          
90          String response = sw.toString();
91          
92          Assert.assertTrue(response.contains("Do you see me?"));
93          Assert.assertFalse(response.contains("This text should not be rendered"));
94      }
95      
96      @Test
97      public void testUserTag4() throws Exception {
98          
99          UIViewRoot root = facesContext.getViewRoot();
100         vdl.buildView(facesContext, root, "userTagTest4.xhtml");
101         
102         StringWriter sw = new StringWriter();
103         MockResponseWriter mrw = new MockResponseWriter(sw);
104         facesContext.setResponseWriter(mrw);
105         root.encodeAll(facesContext);
106         sw.flush();
107         
108         String response = sw.toString();
109         
110         Assert.assertTrue(response.contains("Do you see me?"));
111         Assert.assertFalse(response.contains("This text should not be rendered"));
112     }
113     
114     @Test
115     public void testUserTag5() throws Exception {
116         
117         UIViewRoot root = facesContext.getViewRoot();
118         vdl.buildView(facesContext, root, "userTagTest5.xhtml");
119         
120         StringWriter sw = new StringWriter();
121         MockResponseWriter mrw = new MockResponseWriter(sw);
122         facesContext.setResponseWriter(mrw);
123         root.encodeAll(facesContext);
124         sw.flush();
125         
126         String response = sw.toString();
127         
128         Assert.assertTrue(response.contains("Do you see me?"));
129         Assert.assertFalse(response.contains("This text should not be rendered"));
130     }
131 
132     @Test
133     public void testUserTag6() throws Exception {
134         
135         UIViewRoot root = facesContext.getViewRoot();
136         vdl.buildView(facesContext, root, "userTagTest6.xhtml");
137         
138         StringWriter sw = new StringWriter();
139         MockResponseWriter mrw = new MockResponseWriter(sw);
140         facesContext.setResponseWriter(mrw);
141         root.encodeAll(facesContext);
142         sw.flush();
143         
144         String response = sw.toString();
145         
146         Assert.assertTrue(response.contains("Do you see me?"));
147         Assert.assertFalse(response.contains("This text should not be rendered"));
148     }
149     
150     @Test
151     public void testUserTag7() throws Exception {
152         
153         UIViewRoot root = facesContext.getViewRoot();
154         vdl.buildView(facesContext, root, "userTagTest7.xhtml");
155         
156         StringWriter sw = new StringWriter();
157         MockResponseWriter mrw = new MockResponseWriter(sw);
158         facesContext.setResponseWriter(mrw);
159         root.encodeAll(facesContext);
160         sw.flush();
161         
162         String response = sw.toString();
163         
164         Assert.assertTrue(response.contains("Do you see me?"));
165         Assert.assertFalse(response.contains("This text should not be rendered"));
166     }
167     
168     @Test
169     public void testUserTag8() throws Exception {
170         
171         UIViewRoot root = facesContext.getViewRoot();
172         vdl.buildView(facesContext, root, "userTagTest8.xhtml");
173         
174         StringWriter sw = new StringWriter();
175         MockResponseWriter mrw = new MockResponseWriter(sw);
176         facesContext.setResponseWriter(mrw);
177         root.encodeAll(facesContext);
178         sw.flush();
179         
180         String response = sw.toString();
181         
182         Assert.assertTrue(response.contains("Do you see me?"));
183         Assert.assertFalse(response.contains("This text should not be rendered"));
184     }
185 }