1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.view.facelets.test.component;
20
21 import javax.el.ExpressionFactory;
22 import javax.faces.application.StateManager;
23 import javax.faces.component.UIComponent;
24 import junit.framework.Assert;
25
26 import org.apache.myfaces.mc.test.core.AbstractMyFacesRequestTestCase;
27 import org.apache.myfaces.shared.config.MyfacesConfig;
28 import org.junit.Test;
29
30 public class FacesComponentAnnotationMyFacesRequestTestCase extends AbstractMyFacesRequestTestCase
31 {
32
33 @Override
34 protected boolean isScanAnnotations()
35 {
36 return true;
37 }
38
39 @Override
40 protected void setUpWebConfigParams() throws Exception
41 {
42 super.setUpWebConfigParams();
43 servletContext.addInitParameter("org.apache.myfaces.annotation.SCAN_PACKAGES","org.apache.myfaces.view.facelets.test.component");
44 servletContext.addInitParameter(StateManager.STATE_SAVING_METHOD_PARAM_NAME, StateManager.STATE_SAVING_METHOD_CLIENT);
45 servletContext.addInitParameter("javax.faces.PARTIAL_STATE_SAVING", "true");
46 servletContext.addInitParameter(MyfacesConfig.INIT_PARAM_REFRESH_TRANSIENT_BUILD_ON_PSS, "auto");
47 }
48
49 protected ExpressionFactory createExpressionFactory()
50 {
51 return new org.apache.el.ExpressionFactoryImpl();
52 }
53
54 @Test
55 public void testUIPanel1() throws Exception
56 {
57 startViewRequest("/testMyUIPanel1.xhtml");
58 processLifecycleExecuteAndRender();
59
60 UIComponent comp = facesContext.getViewRoot().findComponent("panel1");
61 Assert.assertNotNull(comp);
62 Assert.assertTrue(comp instanceof MyUIPanel1);
63
64 endRequest();
65 }
66
67 @Test
68 public void testUIPanel2() throws Exception
69 {
70 startViewRequest("/testMyUIPanel2.xhtml");
71 processLifecycleExecuteAndRender();
72
73 UIComponent comp = facesContext.getViewRoot().findComponent("panel1");
74 Assert.assertNotNull(comp);
75 Assert.assertTrue(comp instanceof MyUIPanel2);
76
77 endRequest();
78 }
79
80 @Test
81 public void testUIPanel3() throws Exception
82 {
83 startViewRequest("/testMyUIPanel3.xhtml");
84 processLifecycleExecuteAndRender();
85
86 UIComponent comp = facesContext.getViewRoot().findComponent("panel3");
87 Assert.assertNotNull(comp);
88 Assert.assertTrue(comp instanceof MyUIPanel3);
89
90
91 MyUIPanel3 comp2 = (MyUIPanel3)
92 facesContext.getApplication().createComponent("myUIPanel3");
93 Assert.assertNotNull(comp2);
94
95 endRequest();
96 }
97
98
99 @Test
100 public void testInputTextWithClass() throws Exception
101 {
102 startViewRequest("/testClassAttribute.xhtml");
103 processLifecycleExecuteAndRender();
104
105 UIComponent jsfInputText = facesContext.getViewRoot().findComponent("form:JSF_inputText");
106 Assert.assertNotNull(jsfInputText);
107 Assert.assertEquals("TEST", jsfInputText.getAttributes().get("styleClass"));
108
109
110 UIComponent testInputText = facesContext.getViewRoot().findComponent("form:test_inputText");
111 Assert.assertNotNull(testInputText);
112 Assert.assertEquals("TEST", testInputText.getAttributes().get("styleClass"));
113
114 endRequest();
115 }
116 }