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.custom.roundeddiv;
20  
21  import javax.servlet.ServletContext;
22  import javax.servlet.http.HttpServletRequest;
23  import javax.servlet.http.HttpServletResponse;
24  
25  import junit.framework.Test;
26  import junit.framework.TestSuite;
27  
28  import org.apache.myfaces.shared_tomahawk.config.MyfacesConfig;
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.myfaces.test.utils.MockTestExternalContext;
33  import org.apache.myfaces.test.utils.MockTestViewHandler;
34  import org.apache.shale.test.mock.MockHttpServletRequest;
35  import org.apache.shale.test.mock.MockHttpServletResponse;
36  import org.apache.shale.test.mock.MockResponseWriter;
37  import org.apache.shale.test.mock.MockServletContext;
38  
39  public class HtmlRoundedDivRendererTest extends AbstractTomahawkViewControllerTestCase
40  {
41      private MockResponseWriter writer;
42      private HtmlRoundedDiv roundedDiv;
43      
44      public HtmlRoundedDivRendererTest(String name)
45      {
46          super(name);
47      }
48      
49      public static Test suite() {
50          return new TestSuite(HtmlRoundedDivRendererTest.class);
51      }
52      
53      public void setUp() throws Exception {
54          super.setUp();
55          application.setViewHandler(new MockTestViewHandler());
56          writer = (MockResponseWriter)facesContext.getResponseWriter();
57          roundedDiv = new HtmlRoundedDiv();
58          
59          MockTestExternalContext extCtx = 
60              new MockTestExternalContext(
61                  (ServletContext)new MockServletContext(), 
62                  (HttpServletRequest)new MockHttpServletRequest(), 
63                  (HttpServletResponse)new MockHttpServletResponse());
64          extCtx.getApplicationMap().put(
65                  MyfacesConfig.class.getName(), new MyfacesConfig());
66          facesContext.setExternalContext(extCtx);
67      }
68      
69      public void tearDown() {
70          writer = null;
71          roundedDiv = null;
72      }    
73      
74      public void testHtmlPropertyPassTru() throws Exception
75      {
76          HtmlRenderedAttr[] attrs = {
77              //_UniversalProperties
78              new HtmlRenderedAttr("dir"), 
79              new HtmlRenderedAttr("lang"), 
80              new HtmlRenderedAttr("title"),
81              //_EventProperties
82              new HtmlRenderedAttr("onclick"), 
83              new HtmlRenderedAttr("ondblclick"), 
84              new HtmlRenderedAttr("onkeydown"), 
85              new HtmlRenderedAttr("onkeypress"),
86              new HtmlRenderedAttr("onkeyup"), 
87              new HtmlRenderedAttr("onmousedown"), 
88              new HtmlRenderedAttr("onmousemove"), 
89              new HtmlRenderedAttr("onmouseout"),
90              new HtmlRenderedAttr("onmouseover"), 
91              new HtmlRenderedAttr("onmouseup"),
92              //_StyleProperties
93              new HtmlRenderedAttr("style", "style", "style=\"style;position: relative;\""), 
94              new HtmlRenderedAttr("styleClass", "styleClass", "class=\"styleClass\""),
95          };
96  
97          try {
98          HtmlCheckAttributesUtil.checkRenderedAttributes(
99                  roundedDiv, facesContext, writer, attrs);
100         if(HtmlCheckAttributesUtil.hasFailedAttrRender(attrs)) 
101         {
102             fail(HtmlCheckAttributesUtil.constructErrorMessage(attrs, writer.getWriter().toString()));
103         }
104         } catch(Exception e) {
105             e.printStackTrace();
106         }
107     }    
108 }