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.renderkit.html.behavior;
20  
21  import javax.faces.component.UIComponent;
22  import javax.faces.component.UISelectItem;
23  import javax.faces.component.UIViewRoot;
24  import javax.faces.component.behavior.AjaxBehavior;
25  import javax.faces.component.behavior.ClientBehaviorHolder;
26  import javax.faces.component.html.HtmlSelectManyCheckbox;
27  
28  import org.junit.Assert;
29  import org.junit.Test;
30  
31  /**
32   * @author Leonardo Uribe (latest modification by $Author$)
33   * @version $Revision$ $Date$
34   */
35  public class HtmlSelectManyCheckboxClientBehaviorRendererTest extends AbstractClientBehaviorTestCase
36  {
37      private HtmlRenderedClientEventAttr[] attrs = null;
38      
39      @Override
40      public void setUp() throws Exception
41      {
42          super.setUp();
43          attrs = HtmlClientEventAttributesUtil.generateClientBehaviorInputEventAttrs();
44      }
45  
46      @Override
47      public void tearDown() throws Exception
48      {
49          super.tearDown();
50          attrs = null;
51      }
52  
53  
54      @Override
55      protected UIComponent createComponentToTest()
56      {
57          UIComponent component = new HtmlSelectManyCheckbox();
58          UISelectItem item = new UISelectItem();
59          item.setItemValue("value1");
60          component.getChildren().add(item);
61          return component;
62      }
63  
64      @Override
65      protected HtmlRenderedClientEventAttr[] getClientBehaviorHtmlRenderedAttributes()
66      {
67          return attrs;
68      }
69      
70      public void testClientBehaviorHolderRendersIdAndName() 
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                  Assert.assertTrue(output.matches(".+ name=\".+\".+"));
85                  outputWriter.reset();
86              }
87              catch (Exception e)
88              {
89                  Assert.fail(e.getMessage());
90              }
91          }
92      }
93      
94  }