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.renderkit.html;
20  
21  import java.io.IOException;
22  import java.io.StringWriter;
23  
24  import javax.faces.component.html.HtmlInputText;
25  import javax.faces.component.html.HtmlOutputText;
26  
27  import junit.framework.Test;
28  import junit.framework.TestSuite;
29  
30  import org.apache.myfaces.test.utils.HtmlCheckAttributesUtil;
31  import org.apache.myfaces.test.utils.HtmlRenderedAttr;
32  import org.apache.shale.test.base.AbstractJsfTestCase;
33  import org.apache.shale.test.mock.MockRenderKitFactory;
34  import org.apache.shale.test.mock.MockResponseWriter;
35  
36  /**
37   * @author Bruno Aranda (latest modification by $Author: lu4242 $)
38   * @version $Revision: 700597 $ $Date: 2008-09-30 17:08:35 -0500 (Tue, 30 Sep 2008) $
39   */
40  public class HtmlTextRendererTest extends AbstractJsfTestCase
41  {
42  
43      public static Test suite()
44      {
45          return new TestSuite(HtmlTextRendererTest.class); // needed in maven
46      }
47  
48      private MockResponseWriter writer ;
49      private HtmlOutputText outputText;
50      private HtmlInputText inputText;
51  
52      public HtmlTextRendererTest(String name)
53      {
54          super(name);
55      }
56  
57      public void setUp()
58      {
59          super.setUp();
60  
61          outputText = new HtmlOutputText();
62          inputText = new HtmlInputText();
63  
64          writer = new MockResponseWriter(new StringWriter(), null, null);
65          facesContext.setResponseWriter(writer);
66          // TODO remove these two lines once shale-test goes alpha, see MYFACES-1155
67          facesContext.getViewRoot().setRenderKitId(MockRenderKitFactory.HTML_BASIC_RENDER_KIT);
68          facesContext.getRenderKit().addRenderer(
69                  outputText.getFamily(),
70                  outputText.getRendererType(),
71                  new HtmlTextRenderer());
72          facesContext.getRenderKit().addRenderer(
73                  inputText.getFamily(),
74                  inputText.getRendererType(),
75                  new HtmlTextRenderer());
76      }
77  
78      public void tearDown()
79      {
80          super.tearDown();
81          outputText = null;
82          inputText = null;
83          writer = null;
84      }
85  
86      public void testStyleClassAttr() throws IOException
87      {
88          outputText.setValue("Output");
89          outputText.setStyleClass("myStyleClass");
90  
91          outputText.encodeEnd(facesContext);
92          facesContext.renderResponse();
93  
94          String output = writer.getWriter().toString();
95  
96          assertEquals("<span class=\"myStyleClass\">Output</span>", output);
97          assertNotSame("Output", output);
98      }
99  
100     public void testHtmlPropertyPassTru() throws Exception
101     {
102         HtmlRenderedAttr[] attrs = HtmlCheckAttributesUtil.generateBasicAttrs();
103         
104 
105         HtmlCheckAttributesUtil.checkRenderedAttributes(
106                 inputText, facesContext, writer, attrs);
107         if(HtmlCheckAttributesUtil.hasFailedAttrRender(attrs)) {
108             fail(HtmlCheckAttributesUtil.constructErrorMessage(attrs, writer.getWriter().toString()));
109         }
110     }
111 }