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.tag.ui;
21  
22  import java.io.StringWriter;
23  import javax.faces.component.UIForm;
24  import javax.faces.component.UIOutput;
25  import javax.faces.component.UIParameter;
26  import javax.faces.component.UIViewRoot;
27  import javax.faces.component.html.HtmlCommandButton;
28  import javax.faces.component.html.HtmlForm;
29  import javax.faces.component.html.HtmlOutputText;
30  import javax.faces.component.html.HtmlPanelGrid;
31  import org.apache.myfaces.renderkit.html.HtmlButtonRenderer;
32  import org.apache.myfaces.renderkit.html.HtmlFormRenderer;
33  import org.apache.myfaces.renderkit.html.HtmlGridRenderer;
34  import org.apache.myfaces.renderkit.html.HtmlTextRenderer;
35  import org.apache.myfaces.test.mock.MockResponseWriter;
36  import org.apache.myfaces.view.facelets.FaceletTestCase;
37  import org.junit.Assert;
38  import org.junit.Test;
39  
40  /**
41   *
42   * @author lu4242
43   */
44  public class RemoveTestCase extends FaceletTestCase
45  {
46      @Override
47      protected void setupComponents() throws Exception
48      {
49          application.addComponent(UIViewRoot.COMPONENT_TYPE,
50                  UIViewRoot.class.getName());
51          application.addComponent(HtmlCommandButton.COMPONENT_TYPE,
52                  HtmlCommandButton.class.getName());
53          application.addComponent(HtmlForm.COMPONENT_TYPE,
54                  HtmlForm.class.getName());
55          application.addComponent(HtmlPanelGrid.COMPONENT_TYPE,
56                  HtmlPanelGrid.class.getName());
57          application.addComponent(HtmlOutputText.COMPONENT_TYPE,
58                  HtmlOutputText.class.getName());
59          application.addComponent(UIParameter.COMPONENT_TYPE,
60                  UIParameter.class.getName());
61      }
62  
63      @Override
64      protected void setupConvertersAndValidators() throws Exception
65      {
66      }
67  
68      @Override
69      protected void setupRenderers() throws Exception
70      {
71          renderKit.addRenderer(UIOutput.COMPONENT_FAMILY,
72                  "javax.faces.Text", new HtmlTextRenderer());
73          renderKit.addRenderer(UIForm.COMPONENT_FAMILY,
74                  "javax.faces.Form", new HtmlFormRenderer());
75          renderKit.addRenderer(HtmlCommandButton.COMPONENT_FAMILY,
76                  "javax.faces.Button", new HtmlButtonRenderer());
77          renderKit.addRenderer(HtmlPanelGrid.COMPONENT_FAMILY,
78                  "javax.faces.Grid", new HtmlGridRenderer());
79      }        
80      
81      @Test
82      public void testRemoveMetadata() throws Exception {
83          
84          request.setAttribute("beanValue", "hello");
85          UIViewRoot root = facesContext.getViewRoot();
86          vdl.buildView(facesContext, root, "testRemoveMetadata.xhtml");
87  
88          Assert.assertNull(root.getFacet(UIViewRoot.METADATA_FACET_NAME));
89          
90          StringWriter sw = new StringWriter();
91          MockResponseWriter mrw = new MockResponseWriter(sw);
92          facesContext.setResponseWriter(mrw);
93          
94          root.encodeAll(facesContext);
95          sw.flush();
96          
97          //System.out.println(sw.toString());
98          Assert.assertFalse(sw.toString().contains("ui:remove"));
99          Assert.assertFalse(sw.toString().contains("f:metadata"));
100         Assert.assertFalse(sw.toString().contains("Should not be here"));
101     }    
102     
103 
104 }