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.ext;
20  
21  import javax.faces.application.FacesMessage;
22  import javax.faces.component.html.HtmlForm;
23  import javax.faces.component.html.HtmlInputText;
24  
25  import junit.framework.Test;
26  import junit.framework.TestSuite;
27  
28  import org.apache.myfaces.component.html.ext.HtmlMessage;
29  import org.apache.myfaces.test.AbstractTomahawkViewControllerTestCase;
30  import org.apache.myfaces.test.utils.HtmlCheckAttributesUtil;
31  import org.apache.myfaces.test.utils.HtmlRenderedAttr;
32  import org.apache.shale.test.mock.MockResponseWriter;
33  
34  public class HtmlMessageRendererTest extends AbstractTomahawkViewControllerTestCase
35  {
36      private static final String ERROR_CLASS = "errorClass";
37      private static final String WARN_CLASS = "warnClass";
38      private static final String INFO_CLASS = "infoClass";
39      
40      private HtmlMessage message;
41      private HtmlForm form;
42      private HtmlInputText inputText;
43  
44      public HtmlMessageRendererTest(String name)
45      {
46          super(name);
47      }
48      
49      public static Test suite() {
50          return new TestSuite(HtmlMessageRendererTest.class);
51      }
52  
53      public void setUp() throws Exception
54      {
55          super.setUp();
56  
57          form = new HtmlForm();
58          inputText = new HtmlInputText();
59          inputText.setParent(form);
60          inputText.setId("myInputId");
61          
62          message = new HtmlMessage();
63          message.setErrorClass(ERROR_CLASS);
64          message.setWarnClass(WARN_CLASS);
65          message.setInfoClass(INFO_CLASS);
66          message.setParent(form);
67          
68          form.getChildren().add(inputText);
69          form.getChildren().add(message);
70          
71          facesContext.addMessage(inputText.getClientId(facesContext), 
72                  new FacesMessage("Validation message here."));
73      }
74  
75      public void tearDown() throws Exception
76      {
77          super.tearDown();
78      }    
79      
80      public void testHtmlPropertyPassTru() throws Exception
81      {
82          HtmlRenderedAttr[] attrs = {
83              //_UniversalProperties
84              new HtmlRenderedAttr("dir"), 
85              new HtmlRenderedAttr("lang"), 
86              new HtmlRenderedAttr("title"),
87              //_EventProperties
88              new HtmlRenderedAttr("onclick"), 
89              new HtmlRenderedAttr("ondblclick"), 
90              new HtmlRenderedAttr("onkeydown"), 
91              new HtmlRenderedAttr("onkeypress"),
92              new HtmlRenderedAttr("onkeyup"), 
93              new HtmlRenderedAttr("onmousedown"), 
94              new HtmlRenderedAttr("onmousemove"), 
95              new HtmlRenderedAttr("onmouseout"),
96              new HtmlRenderedAttr("onmouseover"), 
97              new HtmlRenderedAttr("onmouseup"),
98              //_StyleProperties
99              new HtmlRenderedAttr("style"), 
100             new HtmlRenderedAttr("styleClass", "styleClass", "class=\"infoClass\""),
101         };
102         
103         facesContext.addMessage("test1", new FacesMessage(FacesMessage.SEVERITY_WARN, "warnSumary", "detailWarnSummary"));
104         message.setStyle("left: 48px; top: 432px; position: absolute");
105         message.setFor("myInputId");
106         
107         MockResponseWriter writer = (MockResponseWriter)facesContext.getResponseWriter();
108         HtmlCheckAttributesUtil.checkRenderedAttributes(
109                 message, facesContext, writer, attrs);
110         if(HtmlCheckAttributesUtil.hasFailedAttrRender(attrs)) {
111             fail(HtmlCheckAttributesUtil.constructErrorMessage(attrs, writer.getWriter().toString()));
112         }
113     }
114 }