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  
20  package org.apache.myfaces.view.facelets.tag.ui;
21  
22  import java.io.StringWriter;
23  
24  import javax.faces.component.UIViewRoot;
25  
26  import org.apache.myfaces.test.mock.MockResponseWriter;
27  import org.apache.myfaces.view.facelets.FaceletTestCase;
28  import org.junit.Assert;
29  import org.junit.Test;
30  
31  public class DefineIncludeTestCase extends FaceletTestCase {
32  
33      @Override
34      protected void setupComponents() throws Exception
35      {
36          application.addComponent(UIViewRoot.COMPONENT_TYPE,
37                  UIViewRoot.class.getName());
38      }
39  
40      @Override
41      protected void setupConvertersAndValidators() throws Exception
42      {
43      }
44  
45      @Override
46      protected void setupRenderers() throws Exception
47      {
48      }
49  
50      @Test
51      public void testDefineInclude() throws Exception {
52          UIViewRoot root = facesContext.getViewRoot();
53          vdl.buildView(facesContext, root, "defineInclude.xml");
54          
55          StringWriter sw = new StringWriter();
56          MockResponseWriter mrw = new MockResponseWriter(sw);
57          facesContext.setResponseWriter(mrw);
58          root.encodeAll(facesContext);
59          sw.flush();
60          
61          String response = sw.toString();
62          //Two Hello World, the first one by a ui:include on defineInclude.xml,
63          //the second one injected on subdir/template.xml
64          Assert.assertEquals("Hello World!Hello World!", response);
65          //the content of subdir/template.xml ui:insert is ignored
66          Assert.assertFalse(response.contains("Not Found"));
67          
68          //System.out.println("************************");
69          //System.out.println(sw.toString());
70          //System.out.println("************************");
71      }
72  
73  }