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.view.facelets;
20  
21  import org.junit.Assert;
22  import org.junit.Test;
23  
24  import javax.faces.component.UIComponent;
25  import javax.faces.component.UIPanel;
26  import javax.faces.component.UIViewParameter;
27  import javax.faces.component.UIViewRoot;
28  import javax.faces.view.ViewMetadata;
29  
30  /**
31   * Test cases for FaceletViewDeclarationLanguage.
32   *
33   * @author Jakob Korherr
34   */
35  public class FaceletViewDeclarationLanguageTest extends FaceletTestCase
36  {
37  
38      /**
39       * Test case for MYFACES-3002.
40       */
41      @Test
42      public void testBuildViewUIViewParameters() throws Exception
43      {
44          // build a UIViewRoot with a UIViewParameter
45          ViewMetadata viewMetadata = this.vdl.getViewMetadata(facesContext, "viewparameter1.xhtml");
46          UIViewRoot root = viewMetadata.createMetadataView(facesContext);
47          facesContext.setViewRoot(root);
48  
49          // UIViewParameter must be there
50          checkUIViewParameter(root);
51  
52          // build and render view (must not remove UIViewParameter)
53          vdl.buildView(facesContext, root, "viewparameter1.xhtml");
54          vdl.renderView(facesContext, root);
55  
56          // UIViewParameter must still be there, because its value is saved in the state!
57          checkUIViewParameter(root);
58      }
59  
60      private void checkUIViewParameter(UIViewRoot root)
61      {
62          // the metadata facet MUST be there
63          UIComponent metadataFacet = root.getFacet(UIViewRoot.METADATA_FACET_NAME);
64          Assert.assertNotNull(metadataFacet);
65          Assert.assertTrue(metadataFacet instanceof UIPanel); // the metadata-facet must be a UIPanel
66  
67          // get the UIViewParameter
68          UIComponent viewParameter = metadataFacet.getChildren().get(0);
69          Assert.assertTrue(viewParameter instanceof UIViewParameter);
70      }
71  
72  }