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.ppr;
20  
21  import javax.faces.component.html.HtmlCommandButton;
22  
23  import junit.framework.Test;
24  import junit.framework.TestSuite;
25  
26  import org.apache.myfaces.component.html.ext.HtmlPanelGroup;
27  import org.apache.myfaces.custom.form.HtmlForm;
28  import org.apache.myfaces.test.AbstractTomahawkViewControllerTestCase;
29  import org.apache.myfaces.test.utils.HtmlCheckAttributesUtil;
30  import org.apache.myfaces.test.utils.HtmlRenderedAttr;
31  import org.apache.shale.test.mock.MockResponseWriter;
32  
33  public class PPRPanelGroupRendererTest extends AbstractTomahawkViewControllerTestCase
34  {
35      private MockResponseWriter writer;
36      private PPRPanelGroup panelGroup;
37      
38      public PPRPanelGroupRendererTest(String name)
39      {
40          super(name);
41      }
42      
43      public static Test suite() {
44          return new TestSuite(PPRPanelGroupRendererTest.class);
45      }
46      
47      public void setUp() throws Exception {
48          super.setUp();
49          writer = (MockResponseWriter)facesContext.getResponseWriter();
50          panelGroup = new PPRPanelGroup();
51          
52          HtmlForm form = new HtmlForm();
53          HtmlPanelGroup pg = new HtmlPanelGroup();
54          HtmlCommandButton btn = new HtmlCommandButton();
55          form.getChildren().add(pg);
56          pg.getChildren().add(panelGroup);
57          pg.getChildren().add(btn);
58          
59          btn.setId("triggerButton");
60          panelGroup.setId("pprPanel");
61          panelGroup.setPartialTriggerPattern("triggerButton");
62      }
63      
64      public void tearDown() {
65          writer = null;
66          panelGroup = null;
67      }    
68      
69      public void testHtmlPropertyPassTru() throws Exception
70      {
71          HtmlRenderedAttr[] attrs = HtmlCheckAttributesUtil.generateBasicReadOnlyAttrs();
72  
73          HtmlCheckAttributesUtil.checkRenderedAttributes(
74                  panelGroup, facesContext, writer, attrs);
75          if(HtmlCheckAttributesUtil.hasFailedAttrRender(attrs)) 
76          {
77              fail(HtmlCheckAttributesUtil.constructErrorMessage(attrs, writer.getWriter().toString()));
78          }
79      }    
80      
81      public void testHtmlPropertyPassTruNotRendered() throws Exception
82      {
83          HtmlRenderedAttr[] attrs = HtmlCheckAttributesUtil.generateAttrsNotRenderedForReadOnly();
84  
85          HtmlCheckAttributesUtil.checkRenderedAttributes(
86                  panelGroup, facesContext, writer, attrs);
87          if(HtmlCheckAttributesUtil.hasFailedAttrRender(attrs)) 
88          {
89              fail(HtmlCheckAttributesUtil.constructErrorMessage(attrs, writer.getWriter().toString()));
90          }
91      }    
92  }