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.component.html.ext.behavior;
20  
21  import javax.faces.component.UIComponent;
22  import javax.faces.component.UISelectItem;
23  import javax.faces.component.behavior.AjaxBehavior;
24  import javax.faces.component.behavior.ClientBehaviorHolder;
25  
26  import org.apache.myfaces.component.behavior.AbstractClientBehaviorTestCase;
27  import org.apache.myfaces.component.behavior.HtmlClientEventAttributesUtil;
28  import org.apache.myfaces.component.behavior.HtmlRenderedClientEventAttr;
29  import org.apache.myfaces.component.html.ext.HtmlSelectOneRadio;
30  import org.junit.Assert;
31  
32  /**
33   * @author Leonardo Uribe (latest modification by $Author: jankeesvanandel $)
34   * @version $Revision: 799929 $ $Date: 2009-08-01 16:29:33 -0500 (sáb, 01 ago 2009) $
35   */
36  public class HtmlSelectOneRadioClientBehaviorRendererTest extends AbstractClientBehaviorTestCase
37  {
38      private HtmlRenderedClientEventAttr[] attrs = null;
39      
40      @Override
41      public void setUp() throws Exception
42      {
43          super.setUp();
44          attrs = HtmlClientEventAttributesUtil.generateClientBehaviorInputEventAttrs();
45      }
46  
47      @Override
48      public void tearDown() throws Exception
49      {
50          super.tearDown();
51          attrs = null;
52      }
53  
54  
55      @Override
56      protected UIComponent createComponentToTest()
57      {
58          UIComponent component = new HtmlSelectOneRadio();
59          UISelectItem item = new UISelectItem();
60          item.setItemValue("value1");
61          component.getChildren().add(item);
62          return component;
63      }
64  
65      @Override
66      protected HtmlRenderedClientEventAttr[] getClientBehaviorHtmlRenderedAttributes()
67      {
68          return attrs;
69      }
70      
71      @Override
72      public void testClientBehaviorHolderRendersId() 
73      {
74          HtmlRenderedClientEventAttr[] attrs = getClientBehaviorHtmlRenderedAttributes();
75          
76          for (int i = 0; i < attrs.length; i++)
77          {
78              UIComponent component = createComponentToTest();
79              ClientBehaviorHolder clientBehaviorHolder = (ClientBehaviorHolder) component;
80              clientBehaviorHolder.addClientBehavior(attrs[i].getClientEvent(), new AjaxBehavior());
81              try 
82              {
83                  component.encodeAll(facesContext);
84                  String output = outputWriter.toString();
85                  Assert.assertTrue(output.matches(".+ id=\".+\".+"));
86                  outputWriter.reset();
87              }
88              catch (Exception e)
89              {
90                  Assert.fail(e.getMessage());
91              }
92          }
93      }
94      
95      @Override
96      public void testClientBehaviorHolderRendersName() 
97      {
98          HtmlRenderedClientEventAttr[] attrs = getClientBehaviorHtmlRenderedAttributes();
99          
100         for (int i = 0; i < attrs.length; i++)
101         {
102             UIComponent component = createComponentToTest();
103             ClientBehaviorHolder clientBehaviorHolder = (ClientBehaviorHolder) component;
104             clientBehaviorHolder.addClientBehavior(attrs[i].getClientEvent(), new AjaxBehavior());
105             try 
106             {
107                 component.encodeAll(facesContext);
108                 String output = outputWriter.toString();
109                 Assert.assertTrue(output.matches(".+ name=\".+\".+"));
110                 outputWriter.reset();
111             }
112             catch (Exception e)
113             {
114                 Assert.fail(e.getMessage());
115             }
116         }
117     }
118 }