1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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 }