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;
20  
21  import java.io.StringWriter;
22  
23  import javax.el.ExpressionFactory;
24  import javax.faces.application.ViewHandler;
25  import javax.faces.component.UIViewRoot;
26  
27  import junit.framework.Assert;
28  
29  import org.apache.myfaces.test.mock.MockResponseWriter;
30  import org.apache.myfaces.view.facelets.ELExpressionCacheMode;
31  import org.apache.myfaces.view.facelets.FaceletTestCase;
32  import org.apache.myfaces.view.facelets.impl.FaceletCompositionContextImpl;
33  import org.junit.Test;
34  
35  public class HtmlRolePassedThroughTestCase extends FaceletTestCase
36  {
37  
38      @Override
39      protected void setUpServletObjects() throws Exception
40      {
41          super.setUpServletObjects();
42      }
43  
44      @Override
45      protected ExpressionFactory createExpressionFactory()
46      {
47          return new org.apache.el.ExpressionFactoryImpl();
48      }
49  
50      @Test
51      public void testRole() throws Exception
52      {
53          UIViewRoot root = facesContext.getViewRoot();
54          vdl.buildView(facesContext, root, "role.xhtml");
55  
56          StringWriter sw = new StringWriter();
57          MockResponseWriter mrw = new MockResponseWriter(sw);
58          facesContext.setResponseWriter(mrw);
59  
60          root.encodeAll(facesContext);
61          sw.flush();
62          //System.out.println("********************HTMLRolePassedThroughTest*****************");
63          //System.out.println(sw.toString());
64          //System.out.println("********************HTMLRolePassedThroughTest*****************");
65          Assert.assertTrue(sw.toString().contains("value=\"user name\" role=\"new presentation\""));
66          Assert.assertTrue(sw.toString().contains("id=\"helloForm:link\" role=\"new presentation\""));
67          Assert.assertTrue(sw.toString().contains("<table role=\"new presentation\">"));
68          Assert.assertTrue(sw.toString().contains("value=\"one\" role=\"new presentation\""));
69  
70          Assert.assertTrue(sw.toString().contains("id=\"helloForm:data\" role=\"new presentation\""));
71          Assert.assertTrue(sw.toString().contains("id=\"helloForm:graphic\" role=\"new presentation\""));
72          Assert.assertTrue(sw.toString().contains("type=\"file\" role=\"new presentation\""));
73          Assert.assertTrue(sw.toString().contains("name=\"helloForm:area\" role=\"new presentation\""));
74  
75          Assert.assertTrue(sw.toString().contains("id=\"helloForm:outputFormat\" role=\"new presentation\""));
76          Assert.assertTrue(sw.toString().contains("id=\"helloForm:outputLabel\" role=\"new presentation\""));
77          Assert.assertTrue(sw.toString().contains("name=\"helloForm:outputLink\" role=\"new presentation\""));
78          Assert.assertTrue(sw.toString().contains("id=\"helloForm:outputText\" role=\"new presentation\""));
79  
80          // Assert.assertTrue(sw.toString().contains("(?s).*<h:selectBooleanCheckbox\\s+role=\"new presentation\".*"));
81          // Assert.assertTrue(sw.toString().contains("(?s).*<h:selectManyCheckbox\\s+role=\"new presentation\".*"));
82          Assert.assertTrue(sw.toString().contains("name=\"helloForm:selectManyListbox\" multiple=\"multiple\" size=\"0\" role=\"new presentation\""));
83          Assert.assertTrue(sw.toString().contains("name=\"helloForm:selectManyMenu\" multiple=\"multiple\" size=\"1\" role=\"new presentation\""));
84  
85          Assert.assertTrue(sw.toString().contains("name=\"helloForm:selectOneListbox\" size=\"0\" role=\"new presentation\""));
86          Assert.assertTrue(sw.toString().contains("name=\"helloForm:selectOneMenu\" size=\"1\" role=\"new presentation\""));
87          // Assert.assertTrue(sw.toString().contains("(?s).*<h:selectOneRadio\\s+role=\"new presentation\".*"));
88  
89      }
90  }