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.renderkit.html.ext;
20  
21  
22  
23  import javax.faces.component.html.HtmlForm;
24  
25  import junit.framework.Test;
26  import junit.framework.TestSuite;
27  
28  import org.apache.myfaces.test.AbstractTomahawkViewControllerTestCase;
29  import org.apache.myfaces.test.utils.HtmlCheckAttributesUtil;
30  import org.apache.myfaces.test.utils.HtmlRenderedAttr;
31  import org.apache.myfaces.test.utils.MockTestViewHandler;
32  import org.apache.shale.test.mock.MockResponseWriter;
33  
34  public class HtmlFormRendererTest extends AbstractTomahawkViewControllerTestCase
35  {
36      private MockResponseWriter writer;
37      private HtmlForm form;
38      
39      public HtmlFormRendererTest(String name)
40      {
41          super(name);
42      }
43      
44      public static Test suite() {
45          return new TestSuite(HtmlFormRendererTest.class);
46      }
47      
48      public void setUp() throws Exception {
49          super.setUp();
50          writer = (MockResponseWriter)facesContext.getResponseWriter();
51          application.setViewHandler(new MockTestViewHandler());
52          
53          form = new HtmlForm();
54      }
55      
56      public void tearDown() {
57          writer = null;
58          form = null;
59      }    
60      
61      public void testHtmlPropertyPassTru() throws Exception 
62      { 
63          HtmlRenderedAttr[] attrs = HtmlCheckAttributesUtil.generateBasicReadOnlyAttrs();
64          HtmlCheckAttributesUtil.checkRenderedAttributes(
65                  form, facesContext, writer, attrs);
66  
67          if(HtmlCheckAttributesUtil.hasFailedAttrRender(attrs)) {
68              fail(HtmlCheckAttributesUtil.constructErrorMessage(attrs, writer.getWriter().toString()));
69          }
70      }
71      
72      public void testHtmlPropertyPassTruNotRendered() throws Exception 
73      { 
74          HtmlRenderedAttr[] attrs = HtmlCheckAttributesUtil.generateAttrsNotRenderedForReadOnly();
75  
76          HtmlCheckAttributesUtil.checkRenderedAttributes(
77                  form, facesContext, writer, attrs);
78          if(HtmlCheckAttributesUtil.hasFailedAttrRender(attrs)) {
79              fail(HtmlCheckAttributesUtil.constructErrorMessage(attrs, writer.getWriter().toString()));
80          }
81      }
82  }