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.tag.ui;
20
21 import javax.el.ExpressionFactory;
22 import javax.faces.application.ViewHandler;
23 import javax.faces.component.UIOutput;
24 import javax.faces.component.UIViewRoot;
25 import javax.faces.component.html.HtmlOutputText;
26 import javax.faces.context.ResponseWriter;
27
28 import org.apache.myfaces.config.RuntimeConfig;
29 import org.apache.myfaces.renderkit.html.HtmlTextRenderer;
30 import org.apache.myfaces.test.mock.MockExternalContext;
31 import org.apache.myfaces.test.mock.MockResponseWriter;
32 import org.apache.myfaces.view.facelets.FaceletTestCase;
33 import org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage;
34 import org.apache.myfaces.view.facelets.util.FastWriter;
35 import org.junit.Assert;
36 import org.junit.Test;
37
38 public class TestUserTags extends FaceletTestCase {
39
40 @Override
41 protected void setUpServletObjects() throws Exception
42 {
43 super.setUpServletObjects();
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
52
53 return new org.apache.el.ExpressionFactoryImpl();
54 }
55
56 @Override
57 protected void setupComponents() throws Exception
58 {
59 application.addComponent(UIViewRoot.COMPONENT_TYPE,
60 UIViewRoot.class.getName());
61 application.addComponent(HtmlOutputText.COMPONENT_TYPE,
62 HtmlOutputText.class.getName());
63 }
64
65 @Override
66 protected void setupConvertersAndValidators() throws Exception
67 {
68 }
69
70 @Override
71 protected void setupRenderers() throws Exception
72 {
73 renderKit.addRenderer(UIOutput.COMPONENT_FAMILY,
74 "javax.faces.Text", new HtmlTextRenderer());
75 }
76
77 @Test
78 public void testClientClient() throws Exception {
79 request.setAttribute("test", "foo");
80
81 UIViewRoot root = facesContext.getViewRoot();
82 vdl.buildView(facesContext, root, "test-tags.xml");
83
84 FastWriter fw = new FastWriter();
85 MockResponseWriter mrw = new MockResponseWriter(fw);
86 facesContext.setResponseWriter(mrw);
87 root.encodeAll(facesContext);
88
89 }
90
91
92
93
94
95
96 @Test
97 public void testUserTag1() throws Exception
98 {
99 UIViewRoot root = facesContext.getViewRoot();
100 vdl.buildView(facesContext, root, "usertagtest1.xhtml");
101
102 FastWriter fw = new FastWriter();
103 ResponseWriter rw = facesContext.getResponseWriter();
104 rw = rw.cloneWithWriter(fw);
105 facesContext.setResponseWriter(rw);
106 root.encodeAll(facesContext);
107 rw.flush();
108
109 String result = fw.toString();
110 Assert.assertTrue("Output should contain 'value1'", result.contains("value1"));
111 Assert.assertFalse("Output should not contain 'value2'", result.contains("value2"));
112 Assert.assertFalse("Output should not contain 'value3'", result.contains("value3"));
113 }
114
115
116
117
118
119
120 @Test
121 public void testUserTag2() throws Exception
122 {
123 UIViewRoot root = facesContext.getViewRoot();
124 vdl.buildView(facesContext, root, "usertagtest2.xhtml");
125
126 FastWriter fw = new FastWriter();
127 ResponseWriter rw = facesContext.getResponseWriter();
128 rw = rw.cloneWithWriter(fw);
129 facesContext.setResponseWriter(rw);
130 root.encodeAll(facesContext);
131 rw.flush();
132
133 String result = fw.toString();
134 Assert.assertTrue("Output should contain 'value2'", result.contains("value2"));
135 Assert.assertFalse("Output should not contain 'value3'", result.contains("value3"));
136 Assert.assertFalse("Output should not contain 'value1'", result.contains("value1"));
137 }
138 }