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.custom.selectOneRow;
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 SelectOneRowClientBehaviorRendererTest 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          SelectOneRow selectOneRow = new SelectOneRow();   
59          selectOneRow.setGroupName("groupName");
60          return selectOneRow;
61      }
62  
63      @Override
64      protected HtmlRenderedClientEventAttr[] getClientBehaviorHtmlRenderedAttributes()
65      {
66          return attrs;
67      }
68      
69      @Override
70      public void testClientBehaviorHolderRendersId() 
71      {
72          HtmlRenderedClientEventAttr[] attrs = getClientBehaviorHtmlRenderedAttributes();
73          
74          for (int i = 0; i < attrs.length; i++)
75          {
76              UIComponent component = createComponentToTest();
77              ClientBehaviorHolder clientBehaviorHolder = (ClientBehaviorHolder) component;
78              clientBehaviorHolder.addClientBehavior(attrs[i].getClientEvent(), new AjaxBehavior());
79              try 
80              {
81                  component.encodeAll(facesContext);
82                  String output = outputWriter.toString();
83                  Assert.assertTrue(output.matches(".+ id=\".+\".+"));
84                  outputWriter.reset();
85              }
86              catch (Exception e)
87              {
88                  Assert.fail(e.getMessage());
89              }
90          }
91      }
92      
93      @Override
94      public void testClientBehaviorHolderRendersName() 
95      {
96          HtmlRenderedClientEventAttr[] attrs = getClientBehaviorHtmlRenderedAttributes();
97          
98          for (int i = 0; i < attrs.length; i++)
99          {
100             UIComponent component = createComponentToTest();
101             ClientBehaviorHolder clientBehaviorHolder = (ClientBehaviorHolder) component;
102             clientBehaviorHolder.addClientBehavior(attrs[i].getClientEvent(), new AjaxBehavior());
103             try 
104             {
105                 component.encodeAll(facesContext);
106                 String output = outputWriter.toString();
107                 Assert.assertTrue(output.matches(".+ name=\".+\".+"));
108                 outputWriter.reset();
109             }
110             catch (Exception e)
111             {
112                 Assert.fail(e.getMessage());
113             }
114         }
115     }
116 }