1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.view.facelets.el;
20
21 import java.io.StringWriter;
22 import javax.el.ExpressionFactory;
23 import javax.faces.component.UIComponent;
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
35
36 public class CacheELExpressionsTestCase extends FaceletTestCase
37 {
38 @Override
39 protected ExpressionFactory createExpressionFactory()
40 {
41 return new org.apache.el.ExpressionFactoryImpl();
42 }
43
44 @Test
45 public void testUIParamCaching1() throws Exception
46 {
47
48 servletContext.addInitParameter(FaceletCompositionContextImpl.INIT_PARAM_CACHE_EL_EXPRESSIONS,
49 ELExpressionCacheMode.allowCset.toString());
50
51 UIViewRoot root = facesContext.getViewRoot();
52 vdl.buildView(facesContext, root, "uiparamcache1.xhtml");
53
54 StringWriter sw = new StringWriter();
55 MockResponseWriter mrw = new MockResponseWriter(sw);
56 facesContext.setResponseWriter(mrw);
57
58 root.encodeAll(facesContext);
59 sw.flush();
60 Assert.assertTrue(sw.toString().contains("ALFA"));
61 Assert.assertTrue(sw.toString().contains("BETA"));
62 Assert.assertTrue(sw.toString().contains("GAMMA"));
63 Assert.assertTrue(sw.toString().contains("OMEGA"));
64 }
65
66 @Test
67 public void testUIParamCaching2() throws Exception
68 {
69
70 servletContext.addInitParameter(FaceletCompositionContextImpl.INIT_PARAM_CACHE_EL_EXPRESSIONS,
71 ELExpressionCacheMode.strict.toString());
72
73 UIViewRoot root = facesContext.getViewRoot();
74 vdl.buildView(facesContext, root, "uiparamcache1.xhtml");
75
76 StringWriter sw = new StringWriter();
77 MockResponseWriter mrw = new MockResponseWriter(sw);
78 facesContext.setResponseWriter(mrw);
79
80 root.encodeAll(facesContext);
81 sw.flush();
82 Assert.assertTrue(sw.toString().contains("ALFA"));
83 Assert.assertTrue(sw.toString().contains("BETA"));
84 Assert.assertTrue(sw.toString().contains("GAMMA"));
85 Assert.assertTrue(sw.toString().contains("OMEGA"));
86 }
87
88 }