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  
20  package org.apache.myfaces.view.facelets;
21  
22  import javax.faces.component.UIOutput;
23  import javax.faces.component.UIViewRoot;
24  import javax.faces.component.html.HtmlOutputText;
25  
26  import org.apache.myfaces.renderkit.html.HtmlTextRenderer;
27  import org.apache.myfaces.view.facelets.util.FastWriter;
28  import org.apache.myfaces.test.mock.MockResponseWriter;
29  import org.junit.Test;
30  
31  public class TagTestCase extends FaceletTestCase {
32  
33      @Override
34      protected void setupComponents() throws Exception
35      {
36          application.addComponent(UIViewRoot.COMPONENT_TYPE,
37                  UIViewRoot.class.getName());
38          application.addComponent(HtmlOutputText.COMPONENT_TYPE,
39                  HtmlOutputText.class.getName());
40  
41      }
42  
43      @Override
44      protected void setupConvertersAndValidators() throws Exception
45      {
46      }
47  
48      @Override
49      protected void setupRenderers() throws Exception
50      {
51          renderKit.addRenderer(UIOutput.COMPONENT_FAMILY,
52                  "javax.faces.Text", new HtmlTextRenderer());
53      }
54      
55      @Test
56      public void testTagBody() throws Exception {
57          request.setAttribute("name", "Mr. Hookom");
58          UIViewRoot root = facesContext.getViewRoot();
59          vdl.buildView(facesContext, root,"userTag.xhtml");
60          FastWriter fw = new FastWriter();
61          MockResponseWriter mrw = new MockResponseWriter(fw);
62          facesContext.setResponseWriter(mrw);
63          root.encodeAll(facesContext);
64          //System.out.println(fw);
65      }
66  
67      @Test
68      public void testConditionalInsert() throws Exception {
69          UIViewRoot root = facesContext.getViewRoot();
70          vdl.buildView(facesContext, root,"userTagConditional.xhtml");
71          FastWriter fw = new FastWriter();
72          MockResponseWriter mrw = new MockResponseWriter(fw);
73          facesContext.setResponseWriter(mrw);
74          root.encodeAll(facesContext);
75          //System.out.println(fw);
76      }
77  
78  }