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.el;
20  
21  import java.io.StringWriter;
22  import javax.el.ExpressionFactory;
23  import javax.faces.application.ViewHandler;
24  import javax.faces.component.UIViewRoot;
25  import org.apache.myfaces.test.mock.MockResponseWriter;
26  import org.apache.myfaces.view.facelets.ELExpressionCacheMode;
27  import org.apache.myfaces.view.facelets.FaceletTestCase;
28  import org.apache.myfaces.view.facelets.impl.FaceletCompositionContextImpl;
29  import org.junit.Assert;
30  import org.junit.Test;
31  
32  /**
33   *
34   * @author lu4242
35   */
36  public class CacheELExpressionsAlwaysRecompileTestCase extends FaceletTestCase
37  {
38      @Override
39      protected void setUpServletObjects() throws Exception
40      {
41          super.setUpServletObjects();
42          servletContext.addInitParameter(FaceletCompositionContextImpl.INIT_PARAM_CACHE_EL_EXPRESSIONS,
43              ELExpressionCacheMode.alwaysRecompile.toString());
44          servletContext.addInitParameter(ViewHandler.FACELETS_SKIP_COMMENTS_PARAM_NAME, "true");
45          servletContext.addInitParameter(ViewHandler.FACELETS_LIBRARIES_PARAM_NAME, "/user.taglib.xml");
46      }
47      
48      @Override
49      protected ExpressionFactory createExpressionFactory()
50      {
51          return new org.apache.el.ExpressionFactoryImpl();
52      }
53      
54      @Test
55      public void testUIParamCaching1() throws Exception
56      {
57          UIViewRoot root = facesContext.getViewRoot();
58          vdl.buildView(facesContext, root, "uiparamcache1.xhtml");
59  
60          StringWriter sw = new StringWriter();
61          MockResponseWriter mrw = new MockResponseWriter(sw);
62          facesContext.setResponseWriter(mrw);
63          
64          root.encodeAll(facesContext);
65          sw.flush();
66          Assert.assertTrue(sw.toString().contains("ALFA"));
67          Assert.assertTrue(sw.toString().contains("BETA"));
68          Assert.assertTrue(sw.toString().contains("GAMMA"));
69          Assert.assertTrue(sw.toString().contains("OMEGA"));
70      }
71      
72      @Test
73      public void testUserTagCaching1() throws Exception
74      {
75          UIViewRoot root = facesContext.getViewRoot();
76          vdl.buildView(facesContext, root, "usertagtest1.xhtml");
77  
78          StringWriter sw = new StringWriter();
79          MockResponseWriter mrw = new MockResponseWriter(sw);
80          facesContext.setResponseWriter(mrw);
81          
82          root.encodeAll(facesContext);
83          sw.flush();
84          Assert.assertTrue(sw.toString().contains("ALFA"));
85          Assert.assertTrue(sw.toString().contains("BETA"));
86          Assert.assertTrue(sw.toString().contains("GAMMA"));
87          Assert.assertTrue(sw.toString().contains("OMEGA"));
88      }
89  
90      @Test
91      public void testUIParamIncludeCaching1() throws Exception
92      {
93          UIViewRoot root = facesContext.getViewRoot();
94          vdl.buildView(facesContext, root, "includetagtest1.xhtml");
95  
96          StringWriter sw = new StringWriter();
97          MockResponseWriter mrw = new MockResponseWriter(sw);
98          facesContext.setResponseWriter(mrw);
99          
100         root.encodeAll(facesContext);
101         sw.flush();
102         Assert.assertTrue(sw.toString().contains("ALFA"));
103         Assert.assertTrue(sw.toString().contains("BETA"));
104         Assert.assertTrue(sw.toString().contains("GAMMA"));
105         Assert.assertTrue(sw.toString().contains("OMEGA"));
106     }
107 }