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