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.custom.calendar;
20  
21  import java.io.IOException;
22  
23  import javax.faces.FacesException;
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.shale.test.mock.MockResponseWriter;
32  
33  public class HtmlCalendarRendererTest extends AbstractTomahawkViewControllerTestCase
34  {
35      private HtmlInputCalendar inputCalendar;
36      
37      public HtmlCalendarRendererTest(String name)
38      {
39          super(name);
40      }
41      
42      public static Test suite() {
43          return new TestSuite(HtmlCalendarRendererTest.class);
44      }
45      
46      public void setUp() throws Exception {
47          super.setUp();
48          inputCalendar = new HtmlInputCalendar();
49          facesContext.getApplication().addComponent("org.apache.myfaces.HtmlInputTextHelp", "org.apache.myfaces.custom.inputTextHelp.HtmlInputTextHelp");
50      }
51      
52      public void tearDown() throws Exception {
53          super.tearDown();
54          inputCalendar = null;
55      }
56      
57      public void testRenderedAttributes() throws IOException {
58          System.out.println("Testing rendered attributes");
59          inputCalendar.setOnfocus("onfocusTest()");
60          inputCalendar.setOnmouseover("onMouseOverTest()");
61          inputCalendar.setRenderAsPopup(true);
62          
63          try {
64          inputCalendar.encodeEnd(facesContext);
65          } catch(FacesException fe) {
66              fe.printStackTrace();
67          }
68          facesContext.renderResponse();
69          System.out.println("---------------------------------------");
70          MockResponseWriter writer = (MockResponseWriter) facesContext.getResponseWriter();
71          System.out.println(writer.getWriter().toString());
72          System.out.println("\n---------------------------------------");
73      }
74      
75      public void testHtmlPropertyPassTru() throws Exception
76      {
77          HtmlRenderedAttr[] attrs = HtmlCheckAttributesUtil.generateBasicAttrs(); 
78          
79          inputCalendar.setRenderAsPopup(true);
80          
81          MockResponseWriter writer = (MockResponseWriter)facesContext.getResponseWriter();
82          HtmlCheckAttributesUtil.checkRenderedAttributes(
83                  inputCalendar, facesContext, writer, attrs);
84          if(HtmlCheckAttributesUtil.hasFailedAttrRender(attrs)) 
85          {
86              fail(HtmlCheckAttributesUtil.constructErrorMessage(attrs, writer.getWriter().toString()));
87          }
88      }
89  }