1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.myfaces.view.facelets.tag.jsf.html;
21
22 import javax.el.MethodExpression;
23 import javax.faces.component.ActionSource2;
24 import javax.faces.component.UIComponent;
25 import javax.faces.component.UIForm;
26 import javax.faces.component.UIOutput;
27 import javax.faces.component.UIParameter;
28 import javax.faces.component.UIViewRoot;
29 import javax.faces.component.html.HtmlCommandButton;
30 import javax.faces.component.html.HtmlForm;
31 import javax.faces.component.html.HtmlOutputText;
32 import javax.faces.component.html.HtmlPanelGrid;
33
34 import org.apache.myfaces.renderkit.html.HtmlButtonRenderer;
35 import org.apache.myfaces.renderkit.html.HtmlFormRenderer;
36 import org.apache.myfaces.renderkit.html.HtmlGridRenderer;
37 import org.apache.myfaces.renderkit.html.HtmlTextRenderer;
38 import org.apache.myfaces.view.facelets.FaceletTestCase;
39 import org.junit.Assert;
40 import org.junit.Test;
41
42 public class HtmlTestCase extends FaceletTestCase {
43
44 @Override
45 protected void setupComponents() throws Exception
46 {
47 application.addComponent(UIViewRoot.COMPONENT_TYPE,
48 UIViewRoot.class.getName());
49 application.addComponent(HtmlCommandButton.COMPONENT_TYPE,
50 HtmlCommandButton.class.getName());
51 application.addComponent(HtmlForm.COMPONENT_TYPE,
52 HtmlForm.class.getName());
53 application.addComponent(HtmlPanelGrid.COMPONENT_TYPE,
54 HtmlPanelGrid.class.getName());
55 application.addComponent(HtmlOutputText.COMPONENT_TYPE,
56 HtmlOutputText.class.getName());
57 application.addComponent(UIParameter.COMPONENT_TYPE,
58 UIParameter.class.getName());
59 }
60
61 @Override
62 protected void setupConvertersAndValidators() throws Exception
63 {
64 }
65
66 @Override
67 protected void setupRenderers() throws Exception
68 {
69 renderKit.addRenderer(UIOutput.COMPONENT_FAMILY,
70 "javax.faces.Text", new HtmlTextRenderer());
71 renderKit.addRenderer(UIForm.COMPONENT_FAMILY,
72 "javax.faces.Form", new HtmlFormRenderer());
73 renderKit.addRenderer(HtmlCommandButton.COMPONENT_FAMILY,
74 "javax.faces.Button", new HtmlButtonRenderer());
75 renderKit.addRenderer(HtmlPanelGrid.COMPONENT_FAMILY,
76 "javax.faces.Grid", new HtmlGridRenderer());
77 }
78
79 @Test
80 public void testCommandComponent() throws Exception {
81 request.getSession().setAttribute("test", new MockBean());
82 UIViewRoot root = facesContext.getViewRoot();
83 vdl.buildView(facesContext, root, "componentOwner.xml");
84
85 UIComponent c = root.findComponent("cmd");
86 Assert.assertNotNull("cmd", c);
87
88 Object v = c.getAttributes().get("id");
89 Assert.assertEquals("id", "cmd", v);
90
91 ActionSource2 as2 = (ActionSource2) c;
92 MethodExpression me = as2.getActionExpression();
93 Assert.assertNotNull("method", me);
94
95 String result = (String) me.invoke(facesContext.getELContext(), null);
96
97 }
98
99 @Test
100 public void testCommandButton() throws Exception {
101 UIViewRoot root = facesContext.getViewRoot();
102 vdl.buildView(facesContext, root, "commandButton.xml");
103
104 UIComponent c = root.findComponent("form:button");
105 Assert.assertNotNull("button", c);
106
107 Object v = c.getAttributes().get("id");
108 Assert.assertEquals("id", "button", v);
109 }
110
111 @Test
112 public void testPanelGrid() throws Exception {
113 UIViewRoot root = facesContext.getViewRoot();
114 vdl.buildView(facesContext, root, "panelGrid.xml");
115 }
116
117 }