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.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          // Check component type
91          MyUIPanel3 comp2 = (MyUIPanel3) 
92              facesContext.getApplication().createComponent("myUIPanel3");
93          Assert.assertNotNull(comp2);
94          
95          endRequest();
96      }
97      
98      // Test for MYFACES-4003
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         // The "class" attribute should have been mapped to a "styleClass" attribute
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 }