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.jsf.html;
20  
21  import java.io.StringWriter;
22  
23  import javax.faces.component.UIComponent;
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.junit.Assert;
29  import org.junit.Test;
30  
31  public class HtmlOutputScriptTestCase extends FaceletTestCase
32  {
33      @Test
34      public void testSimpleOutputScript() throws Exception
35      {
36          UIViewRoot root = facesContext.getViewRoot();
37          vdl.buildView(facesContext, root, "testSimpleOutputScript.xhtml");
38          
39          UIComponent head = root.findComponent("head");
40          Assert.assertNotNull(head);
41          UIComponent body = root.findComponent("body");
42          Assert.assertNotNull(body);
43          
44          StringWriter sw = new StringWriter();
45          MockResponseWriter mrw = new MockResponseWriter(sw);
46          facesContext.setResponseWriter(mrw);
47          
48          root.encodeAll(facesContext);
49          sw.flush();
50          //System.out.print(sw.toString());
51      }
52      
53      @Test
54      public void testSimpleTargetHeadOutputScript() throws Exception
55      {
56          UIViewRoot root = facesContext.getViewRoot();
57          vdl.buildView(facesContext, root, "testSimpleTargetHeadOutputScript.xhtml");
58          
59          UIComponent head = root.findComponent("head");
60          Assert.assertNotNull(head);
61          UIComponent body = root.findComponent("body");
62          Assert.assertNotNull(body);
63          
64          StringWriter sw = new StringWriter();
65          MockResponseWriter mrw = new MockResponseWriter(sw);
66          facesContext.setResponseWriter(mrw);
67          
68          root.encodeAll(facesContext);
69          sw.flush();
70          //System.out.print(sw.toString());
71      }
72      
73      @Test
74      public void testMultipleTargetHeadOutputScript() throws Exception
75      {
76          UIViewRoot root = facesContext.getViewRoot();
77          vdl.buildView(facesContext, root, "testMultipleTargetHeadOutputScript.xhtml");
78          
79          UIComponent head = root.findComponent("head");
80          Assert.assertNotNull(head);
81          UIComponent body = root.findComponent("body");
82          Assert.assertNotNull(body);
83          
84          StringWriter sw = new StringWriter();
85          MockResponseWriter mrw = new MockResponseWriter(sw);
86          facesContext.setResponseWriter(mrw);
87          
88          root.encodeAll(facesContext);
89          sw.flush();
90          //System.out.print(sw.toString());
91      } 
92  }